mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-10 15:14:33 +08:00
Finish the user settings jsonb, also fix references throughout app
Closes SCI-1475.
This commit is contained in:
parent
c62002381b
commit
9227ea5854
8 changed files with 27 additions and 21 deletions
|
@ -180,7 +180,7 @@ module Users
|
||||||
message: sanitize_input(message)
|
message: sanitize_input(message)
|
||||||
)
|
)
|
||||||
|
|
||||||
if target_user.assignments_notification
|
if target_user.settings[:notifications][:assignments]
|
||||||
UserNotification.create(notification: notification, user: target_user)
|
UserNotification.create(notification: notification, user: target_user)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -77,15 +77,15 @@ module Users
|
||||||
end
|
end
|
||||||
|
|
||||||
def notifications_settings
|
def notifications_settings
|
||||||
@user.assignments_notification =
|
@user.settings[:notifications][:assignments] =
|
||||||
params[:assignments_notification] ? true : false
|
params[:assignments_notification] ? true : false
|
||||||
@user.recent_notification =
|
@user.settings[:notifications][:recent] =
|
||||||
params[:recent_notification] ? true : false
|
params[:recent_notification] ? true : false
|
||||||
@user.recent_notification_email =
|
@user.settings[:notifications][:recent_email] =
|
||||||
params[:recent_notification_email] ? true : false
|
params[:recent_notification_email] ? true : false
|
||||||
@user.assignments_notification_email =
|
@user.settings[:notifications][:assignments_email] =
|
||||||
params[:assignments_notification_email] ? true : false
|
params[:assignments_notification_email] ? true : false
|
||||||
@user.system_message_notification_email =
|
@user.settings[:notifications][:system_message_email] =
|
||||||
params[:system_message_notification_email] ? true : false
|
params[:system_message_notification_email] ? true : false
|
||||||
|
|
||||||
if @user.save
|
if @user.save
|
||||||
|
@ -115,7 +115,7 @@ module Users
|
||||||
|
|
||||||
def update_params
|
def update_params
|
||||||
params.require(:user).permit(
|
params.require(:user).permit(
|
||||||
settings: :time_zone
|
:time_zone
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -100,7 +100,7 @@ module ApplicationHelper
|
||||||
title: sanitize_input(title),
|
title: sanitize_input(title),
|
||||||
message: sanitize_input(message)
|
message: sanitize_input(message)
|
||||||
)
|
)
|
||||||
if target_user.assignments_notification
|
if target_user.settings[:notifications][:assignments]
|
||||||
UserNotification.create(notification: notification, user: target_user)
|
UserNotification.create(notification: notification, user: target_user)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -44,7 +44,7 @@ module NotificationsHelper
|
||||||
message: sanitize_input(message)
|
message: sanitize_input(message)
|
||||||
)
|
)
|
||||||
|
|
||||||
if target_user.assignments_notification
|
if target_user.settings[:notifications][:assignments]
|
||||||
UserNotification.create(notification: notification, user: target_user)
|
UserNotification.create(notification: notification, user: target_user)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -118,9 +118,9 @@ class Activity < ApplicationRecord
|
||||||
|
|
||||||
project.users.each do |project_user|
|
project.users.each do |project_user|
|
||||||
next if project_user == user
|
next if project_user == user
|
||||||
next if !project_user.assignments_notification &&
|
next if !project_user.settings[:notifications][:assignments] &&
|
||||||
notification.type_of == 'assignment'
|
notification.type_of == 'assignment'
|
||||||
next if !project_user.recent_notification &&
|
next if !project_user.settings[:notifications][:recent] &&
|
||||||
notification.type_of == 'recent_changes'
|
notification.type_of == 'recent_changes'
|
||||||
UserNotification.create(notification: notification, user: project_user)
|
UserNotification.create(notification: notification, user: project_user)
|
||||||
end
|
end
|
||||||
|
|
|
@ -36,6 +36,8 @@ class User < ApplicationRecord
|
||||||
size: { less_than: Constants::AVATAR_MAX_SIZE_MB.megabytes }
|
size: { less_than: Constants::AVATAR_MAX_SIZE_MB.megabytes }
|
||||||
validate :time_zone_check
|
validate :time_zone_check
|
||||||
|
|
||||||
|
store_accessor :settings, :time_zone
|
||||||
|
|
||||||
default_settings(
|
default_settings(
|
||||||
time_zone: 'UTC',
|
time_zone: 'UTC',
|
||||||
notifications: {
|
notifications: {
|
||||||
|
|
|
@ -40,17 +40,17 @@ class UserNotification < ApplicationRecord
|
||||||
send_email_notification(
|
send_email_notification(
|
||||||
user,
|
user,
|
||||||
notification
|
notification
|
||||||
) if user.system_message_notification_email
|
) if user.settings[:notifications][:system_message_email]
|
||||||
when 'assignment'
|
when 'assignment'
|
||||||
send_email_notification(
|
send_email_notification(
|
||||||
user,
|
user,
|
||||||
notification
|
notification
|
||||||
) if user.assignments_notification_email
|
) if user.settings[:notifications][:assignments_email]
|
||||||
when 'recent_changes'
|
when 'recent_changes'
|
||||||
send_email_notification(
|
send_email_notification(
|
||||||
user,
|
user,
|
||||||
notification
|
notification
|
||||||
) if user.recent_notification_email
|
) if user.settings[:notifications][:recent_email]
|
||||||
when 'deliver'
|
when 'deliver'
|
||||||
send_email_notification(
|
send_email_notification(
|
||||||
user,
|
user,
|
||||||
|
|
|
@ -12,7 +12,11 @@
|
||||||
<%= form_for(@user,
|
<%= form_for(@user,
|
||||||
url: update_preferences_path(format: :json),
|
url: update_preferences_path(format: :json),
|
||||||
remote: true,
|
remote: true,
|
||||||
html: { method: :put, 'data-for' => 'settings[time_zone]' }) do |f| %>
|
html: {
|
||||||
|
method: :put,
|
||||||
|
'data-for' => 'settings[time_zone]',
|
||||||
|
'data-turbolinks' => false
|
||||||
|
}) do |f| %>
|
||||||
<div data-part="view">
|
<div data-part="view">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<%= f.label t("users.settings.account.preferences.edit.time_zone_label") %>
|
<%= f.label t("users.settings.account.preferences.edit.time_zone_label") %>
|
||||||
|
@ -75,7 +79,7 @@
|
||||||
<%=t 'notifications.form.notification_scinote' %>
|
<%=t 'notifications.form.notification_scinote' %>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-8">
|
<div class="col-sm-8">
|
||||||
<%= check_box_tag :assignments_notification, @user.assignments_notification %>
|
<%= check_box_tag :assignments_notification, @user.settings[:notifications][:assignments] %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
@ -83,7 +87,7 @@
|
||||||
<%=t 'notifications.form.notification_email' %>
|
<%=t 'notifications.form.notification_email' %>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-8">
|
<div class="col-sm-8">
|
||||||
<%= check_box_tag :assignments_notification_email, @user.assignments_notification_email %>
|
<%= check_box_tag :assignments_notification_email, @user.settings[:notifications][:assignments_email] %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -100,7 +104,7 @@
|
||||||
<%=t 'notifications.form.notification_scinote' %>
|
<%=t 'notifications.form.notification_scinote' %>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-8">
|
<div class="col-sm-8">
|
||||||
<%= check_box_tag :recent_notification, @user.recent_notification %>
|
<%= check_box_tag :recent_notification, @user.settings[:notifications][:recent] %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
@ -108,7 +112,7 @@
|
||||||
<%=t 'notifications.form.notification_email' %>
|
<%=t 'notifications.form.notification_email' %>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-8">
|
<div class="col-sm-8">
|
||||||
<%= check_box_tag :recent_notification_email, @user.recent_notification_email %>
|
<%= check_box_tag :recent_notification_email, @user.settings[:notifications][:recent_email] %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -133,7 +137,7 @@
|
||||||
<%=t 'notifications.form.notification_email' %>
|
<%=t 'notifications.form.notification_email' %>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-8">
|
<div class="col-sm-8">
|
||||||
<%= check_box_tag :system_message_notification_email, @user.system_message_notification_email %>
|
<%= check_box_tag :system_message_notification_email, @user.settings[:notifications][:system_message_email] %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Add table
Reference in a new issue