diff --git a/app/controllers/client_api/users/users_controller.rb b/app/controllers/client_api/users/users_controller.rb index 89d148d76..6ef300d69 100644 --- a/app/controllers/client_api/users/users_controller.rb +++ b/app/controllers/client_api/users/users_controller.rb @@ -1,7 +1,6 @@ module ClientApi module Users class UsersController < ApplicationController - def sign_out_user respond_to do |format| if sign_out current_user @@ -13,15 +12,11 @@ module ClientApi end def preferences_info - settings = current_user.settings respond_to do |format| format.json do render template: 'client_api/users/preferences', status: :ok, - locals: { - timeZone: settings['time_zone'], - notifications: settings['notifications'] - } + locals: { user: current_user } end end end diff --git a/app/controllers/users/invitations_controller.rb b/app/controllers/users/invitations_controller.rb index ef22e3d39..48e8195cb 100644 --- a/app/controllers/users/invitations_controller.rb +++ b/app/controllers/users/invitations_controller.rb @@ -180,7 +180,7 @@ module Users message: sanitize_input(message) ) - if target_user.settings[:notifications][:assignments] + if target_user.assignments_notification UserNotification.create(notification: notification, user: target_user) end end diff --git a/app/controllers/users/settings/account/preferences_controller.rb b/app/controllers/users/settings/account/preferences_controller.rb index 4cfc94463..2f951fff2 100644 --- a/app/controllers/users/settings/account/preferences_controller.rb +++ b/app/controllers/users/settings/account/preferences_controller.rb @@ -77,15 +77,15 @@ module Users end def notifications_settings - @user.settings[:notifications][:assignments] = + @user.assignments_notification = params[:assignments_notification] ? true : false - @user.settings[:notifications][:recent] = + @user.recent_notification = params[:recent_notification] ? true : false - @user.settings[:notifications][:recent_email] = + @user.recent_email_notification = params[:recent_notification_email] ? true : false - @user.settings[:notifications][:assignments_email] = + @user.assignments_email_notification = params[:assignments_notification_email] ? true : false - @user.settings[:notifications][:system_message_email] = + @user.system_message_email_notification = params[:system_message_notification_email] ? true : false if @user.save diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 7a5222ee0..59dc86689 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -100,7 +100,7 @@ module ApplicationHelper title: sanitize_input(title), message: sanitize_input(message) ) - if target_user.settings[:notifications][:assignments] + if target_user.assignments_notification UserNotification.create(notification: notification, user: target_user) end end diff --git a/app/helpers/notifications_helper.rb b/app/helpers/notifications_helper.rb index 248fd5b11..f41eb90ac 100644 --- a/app/helpers/notifications_helper.rb +++ b/app/helpers/notifications_helper.rb @@ -44,7 +44,7 @@ module NotificationsHelper message: sanitize_input(message) ) - if target_user.settings[:notifications][:assignments] + if target_user.assignments_notification UserNotification.create(notification: notification, user: target_user) end end diff --git a/app/models/activity.rb b/app/models/activity.rb index ea4eaa90a..e4dd2d029 100644 --- a/app/models/activity.rb +++ b/app/models/activity.rb @@ -118,9 +118,9 @@ class Activity < ApplicationRecord project.users.each do |project_user| next if project_user == user - next if !project_user.settings[:notifications][:assignments] && + next if !project_user.assignments_notification && notification.type_of == 'assignment' - next if !project_user.settings[:notifications][:recent] && + next if !project_user.recent_notification && notification.type_of == 'recent_changes' UserNotification.create(notification: notification, user: project_user) end diff --git a/app/models/user.rb b/app/models/user.rb index 6d76d455b..e99cd580a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -37,11 +37,11 @@ class User < ApplicationRecord message: I18n.t('client_api.user.avatar_too_big') } validate :time_zone_check - store_accessor :settings, :time_zone, :notifications + store_accessor :settings, :time_zone, :notifications_settings default_settings( time_zone: 'UTC', - notifications: { + notifications_settings: { assignments: true, assignments_email: false, recent: true, @@ -405,7 +405,7 @@ class User < ApplicationRecord NOTIFICATIONS_TYPES.each do |name| define_method(name) do attr_name = name.gsub('_notification', '') - self.notifications.fetch(attr_name.to_sym) + notifications_settings.fetch(attr_name.to_sym) end end @@ -413,7 +413,7 @@ class User < ApplicationRecord NOTIFICATIONS_TYPES.each do |name| define_method("#{name}=") do |value| attr_name = name.gsub('_notification', '').to_sym - self.notifications[attr_name] = value + notifications_settings[attr_name] = value save end end diff --git a/app/models/user_notification.rb b/app/models/user_notification.rb index ba9e494e3..d034a563c 100644 --- a/app/models/user_notification.rb +++ b/app/models/user_notification.rb @@ -40,17 +40,17 @@ class UserNotification < ApplicationRecord send_email_notification( user, notification - ) if user.settings[:notifications][:system_message_email] + ) if user.system_message_email_notification when 'assignment' send_email_notification( user, notification - ) if user.settings[:notifications][:assignments_email] + ) if user.assignments_email_notification when 'recent_changes' send_email_notification( user, notification - ) if user.settings[:notifications][:recent_email] + ) if user.recent_email_notification when 'deliver' send_email_notification( user, diff --git a/app/services/client_api/invitations_service.rb b/app/services/client_api/invitations_service.rb index 5e08b6623..63380c239 100644 --- a/app/services/client_api/invitations_service.rb +++ b/app/services/client_api/invitations_service.rb @@ -151,7 +151,7 @@ module ClientApi message: sanitize_input(message) ) - if target_user.settings[:notifications][:assignments] + if target_user.assignments_notification UserNotification.create(notification: notification, user: target_user) end end diff --git a/app/views/client_api/users/preferences.json.jbuilder b/app/views/client_api/users/preferences.json.jbuilder index afbafe752..9708ea0dc 100644 --- a/app/views/client_api/users/preferences.json.jbuilder +++ b/app/views/client_api/users/preferences.json.jbuilder @@ -1,6 +1,6 @@ -json.timeZone timeZone -json.assignments_notification notifications['assignments'] -json.assignments_email_notification notifications['assignments_email'] -json.recent_notification notifications['recent'] -json.recent_email_notification notifications['recent_email'] -json.system_message_email_notification notifications['system_message_email'] +json.timeZone user.time_zone +json.assignments_notification user.assignments_notification +json.assignments_email_notification user.assignments_email_notification +json.recent_notification user.recent_notification +json.recent_email_notification user.recent_email_notification +json.system_message_email_notification user.system_message_email_notification diff --git a/app/views/client_api/users/profile_notifications.json.jbuilder b/app/views/client_api/users/profile_notifications.json.jbuilder index bc9cf5725..63a143829 100644 --- a/app/views/client_api/users/profile_notifications.json.jbuilder +++ b/app/views/client_api/users/profile_notifications.json.jbuilder @@ -7,4 +7,3 @@ json.user do json.system_message_email user.system_message_notification_email end end - diff --git a/app/views/users/settings/account/preferences/index.html.erb b/app/views/users/settings/account/preferences/index.html.erb index 1ca883a3c..4aff9877b 100644 --- a/app/views/users/settings/account/preferences/index.html.erb +++ b/app/views/users/settings/account/preferences/index.html.erb @@ -79,7 +79,7 @@ <%=t 'notifications.form.notification_scinote' %>
- <%= check_box_tag :assignments_notification, @user.settings[:notifications][:assignments] %> + <%= check_box_tag :assignments_notification, @user.assignments_notification %>
@@ -87,7 +87,7 @@ <%=t 'notifications.form.notification_email' %>
- <%= check_box_tag :assignments_notification_email, @user.settings[:notifications][:assignments_email] %> + <%= check_box_tag :assignments_notification_email, @user.assignments_email_notification %>
@@ -104,7 +104,7 @@ <%=t 'notifications.form.notification_scinote' %>
- <%= check_box_tag :recent_notification, @user.settings[:notifications][:recent] %> + <%= check_box_tag :recent_notification, @user.recent_notification %>
@@ -112,7 +112,7 @@ <%=t 'notifications.form.notification_email' %>
- <%= check_box_tag :recent_notification_email, @user.settings[:notifications][:recent_email] %> + <%= check_box_tag :recent_notification_email, @user.recent_email_notification %>
@@ -137,7 +137,7 @@ <%=t 'notifications.form.notification_email' %>
- <%= check_box_tag :system_message_notification_email, @user.settings[:notifications][:system_message_email] %> + <%= check_box_tag :system_message_notification_email, @user.system_message_email_notification %>
diff --git a/db/migrate/20170809131000_refactor_user_settings.rb b/db/migrate/20170809131000_refactor_user_settings.rb index 4dd54cf8d..ac476a3cc 100644 --- a/db/migrate/20170809131000_refactor_user_settings.rb +++ b/db/migrate/20170809131000_refactor_user_settings.rb @@ -5,7 +5,7 @@ class RefactorUserSettings < ActiveRecord::Migration[5.1] User.find_each do |user| settings = { time_zone: user['time_zone'], - notifications: { + notifications_settings: { assignments: user['assignments_notification'], assignments_email: user['assignments_notification_email'], recent: user['recent_notification'], @@ -36,15 +36,15 @@ class RefactorUserSettings < ActiveRecord::Migration[5.1] User.find_each do |user| user.time_zone = user.settings[:time_zone] user.assignments_notification = - user.settings[:notifications][:assignments] + user.settings[:notifications_settings][:assignments] user.assignments_notification_email = - user.settings[:notifications][:assignments_email] + user.settings[:notifications_settings][:assignments_email] user.recent_notification = - user.settings[:notifications][:recent] + user.settings[:notifications_settings][:recent] user.recent_notification_email = - user.settings[:notifications][:recent_email] + user.settings[:notifications_settings][:recent_email] user.system_message_notification_email = - user.settings[:notifications][:system_message_email] + user.settings[:notifications_settings][:system_message_email] user.save end