Rename notifications settings accessor [SCI-1864]

This commit is contained in:
Oleksii Kriuchykhin 2017-12-07 13:59:33 +01:00
parent 022c81ec1f
commit 6256acdfea
10 changed files with 25 additions and 31 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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,

View file

@ -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

View file

@ -7,4 +7,3 @@ json.user do
json.system_message_email user.system_message_notification_email
end
end

View file

@ -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