Merge pull request #903 from okriuchykhin/ok_SCI_1864

Rename notifications settings accessor [SCI-1864]
This commit is contained in:
okriuchykhin 2017-12-13 12:57:56 +01:00 committed by GitHub
commit 2fa7591f36
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 36 additions and 42 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

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

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

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

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

@ -79,7 +79,7 @@
<%=t 'notifications.form.notification_scinote' %>
</div>
<div class="col-sm-8">
<%= check_box_tag :assignments_notification, @user.settings[:notifications][:assignments] %>
<%= check_box_tag :assignments_notification, @user.assignments_notification %>
</div>
</div>
<div class="row">
@ -87,7 +87,7 @@
<%=t 'notifications.form.notification_email' %>
</div>
<div class="col-sm-8">
<%= check_box_tag :assignments_notification_email, @user.settings[:notifications][:assignments_email] %>
<%= check_box_tag :assignments_notification_email, @user.assignments_email_notification %>
</div>
</div>
</div>
@ -104,7 +104,7 @@
<%=t 'notifications.form.notification_scinote' %>
</div>
<div class="col-sm-8">
<%= check_box_tag :recent_notification, @user.settings[:notifications][:recent] %>
<%= check_box_tag :recent_notification, @user.recent_notification %>
</div>
</div>
<div class="row">
@ -112,7 +112,7 @@
<%=t 'notifications.form.notification_email' %>
</div>
<div class="col-sm-8">
<%= check_box_tag :recent_notification_email, @user.settings[:notifications][:recent_email] %>
<%= check_box_tag :recent_notification_email, @user.recent_email_notification %>
</div>
</div>
</div>
@ -137,7 +137,7 @@
<%=t 'notifications.form.notification_email' %>
</div>
<div class="col-sm-8">
<%= 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 %>
</div>
</div>
</div>

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