Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
39ead205
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
39ead205
编写于
6月 09, 2016
作者:
F
Felipe Artur
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove notification level fild from users, improve migrations and specs
上级
8f6d43e0
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
55 addition
and
57 deletion
+55
-57
app/controllers/profiles/notifications_controller.rb
app/controllers/profiles/notifications_controller.rb
+5
-8
app/helpers/notifications_helper.rb
app/helpers/notifications_helper.rb
+2
-15
app/models/user.rb
app/models/user.rb
+6
-3
app/services/notification_service.rb
app/services/notification_service.rb
+5
-3
db/migrate/20160607201627_migrate_users_notification_level.rb
...igrate/20160607201627_migrate_users_notification_level.rb
+0
-24
db/migrate/20160610140403_remove_notification_setting_not_null_constraints.rb
...40403_remove_notification_setting_not_null_constraints.rb
+5
-1
db/migrate/20160610201627_migrate_users_notification_level.rb
...igrate/20160610201627_migrate_users_notification_level.rb
+21
-0
db/migrate/20160610301627_remove_notification_level_from_users.rb
...te/20160610301627_remove_notification_level_from_users.rb
+7
-0
spec/services/notification_service_spec.rb
spec/services/notification_service_spec.rb
+4
-3
未找到文件。
app/controllers/profiles/notifications_controller.rb
浏览文件 @
39ead205
...
...
@@ -17,21 +17,18 @@ class Profiles::NotificationsController < Profiles::ApplicationController
end
def
user_params
params
.
require
(
:user
).
permit
(
:notification_email
,
:notification_level
)
params
.
require
(
:user
).
permit
(
:notification_email
)
end
def
notification
_params
params
.
require
(
:
notification_
level
)
def
global_notification_setting
_params
params
.
require
(
:
global_notification_setting
).
permit
(
:
level
)
end
private
def
update_notification_settings
return
true
unless
notification
_params
return
true
unless
global_notification_setting
_params
notification_setting
=
current_user
.
global_notification_setting
notification_setting
.
level
=
notification_params
notification_setting
.
save
current_user
.
global_notification_setting
.
update_attributes
(
global_notification_setting_params
)
end
end
app/helpers/notifications_helper.rb
浏览文件 @
39ead205
...
...
@@ -71,26 +71,13 @@ module NotificationsHelper
html
<<
content_tag
(
:div
,
class:
"radio"
)
do
content_tag
(
:label
,
{
value:
level
})
do
radio_button_tag
(
:
notification_level
,
level
,
@global_notification_setting
.
level
.
to_sym
==
level
)
+
radio_button_tag
(
:
"global_notification_setting[level]"
,
level
,
@global_notification_setting
.
level
.
to_sym
==
level
)
+
content_tag
(
:div
,
level
.
to_s
.
capitalize
,
class:
"level-title"
)
+
content_tag
(
:p
,
notification_
level_
description
(
level
))
content_tag
(
:p
,
notification_description
(
level
))
end
end
end
html
.
html_safe
end
def
notification_level_description
(
level
)
case
level
when
:disabled
"You will not get any notifications via email"
when
:mention
"You will receive notifications only for comments in which you were @mentioned"
when
:participating
"You will only receive notifications from related resources (e.g. from your commits or assigned issues)"
when
:watch
"You will receive notifications for any activity"
end
end
end
app/models/user.rb
浏览文件 @
39ead205
...
...
@@ -797,9 +797,12 @@ class User < ActiveRecord::Base
# Lazy load global notification setting
# Initializes User setting with Participating level if setting not persisted
def
global_notification_setting
setting
=
notification_settings
.
find_or_initialize_by
(
source:
nil
)
setting
.
level
=
NotificationSetting
.
levels
[
DEFAULT_NOTIFICATION_LEVEL
]
unless
setting
.
persisted?
setting
return
@global_notification_setting
if
defined?
(
@global_notification_setting
)
@global_notification_setting
=
notification_settings
.
find_or_initialize_by
(
source:
nil
)
@global_notification_setting
.
update_attributes
(
level:
NotificationSetting
.
levels
[
DEFAULT_NOTIFICATION_LEVEL
])
unless
@global_notification_setting
.
persisted?
@global_notification_setting
end
def
assigned_open_merge_request_count
(
force:
false
)
...
...
app/services/notification_service.rb
浏览文件 @
39ead205
...
...
@@ -353,7 +353,9 @@ class NotificationService
users
=
users
.
reject
(
&
:blocked?
)
users
.
reject
do
|
user
|
next
user
.
global_notification_setting
.
level
==
level
unless
project
global_notification_setting
=
user
.
global_notification_setting
next
global_notification_setting
.
level
==
level
unless
project
setting
=
user
.
notification_settings_for
(
project
)
...
...
@@ -362,13 +364,13 @@ class NotificationService
end
# reject users who globally set mention notification and has no setting per project/group
next
user
.
global_notification_setting
.
level
==
level
unless
setting
next
global_notification_setting
.
level
==
level
unless
setting
# reject users who set mention notification in project
next
true
if
setting
.
level
==
level
# reject users who have mention level in project and disabled in global settings
setting
.
global?
&&
user
.
global_notification_setting
.
level
==
level
setting
.
global?
&&
global_notification_setting
.
level
==
level
end
end
...
...
db/migrate/20160607201627_migrate_users_notification_level.rb
已删除
100644 → 0
浏览文件 @
8f6d43e0
class
MigrateUsersNotificationLevel
<
ActiveRecord
::
Migration
# Migrates only users which changes theier default notification level :participating
# creating a new record on notification settins table
def
up
changed_users
=
exec_query
(
%Q{
SELECT id, notification_level
FROM users
WHERE notification_level != 1
}
)
changed_users
.
each
do
|
row
|
uid
=
row
[
'id'
]
u_notification_level
=
row
[
'notification_level'
]
execute
(
%Q{
INSERT INTO notification_settings
(user_id, level, created_at, updated_at)
VALUES
(
#{
uid
}
,
#{
u_notification_level
}
, now(), now())
}
)
end
end
end
db/migrate/201606
06192159
_remove_notification_setting_not_null_constraints.rb
→
db/migrate/201606
10140403
_remove_notification_setting_not_null_constraints.rb
浏览文件 @
39ead205
...
...
@@ -2,6 +2,10 @@ class RemoveNotificationSettingNotNullConstraints < ActiveRecord::Migration
def
up
change_column
:notification_settings
,
:source_type
,
:string
,
null:
true
change_column
:notification_settings
,
:source_id
,
:integer
,
null:
true
change_column
:users
,
:notification_level
,
:integer
,
null:
true
end
def
down
change_column
:notification_settings
,
:source_type
,
:string
,
null:
false
change_column
:notification_settings
,
:source_id
,
:integer
,
null:
false
end
end
db/migrate/20160610201627_migrate_users_notification_level.rb
0 → 100644
浏览文件 @
39ead205
class
MigrateUsersNotificationLevel
<
ActiveRecord
::
Migration
# Migrates only users who changed their default notification level :participating
# creating a new record on notification settings table
def
up
execute
(
%Q{
INSERT INTO notification_settings
(user_id, level, created_at, updated_at)
(SELECT id, notification_level, created_at, updated_at FROM users WHERE notification_level != 1)
}
)
end
# Migrates from notification settings back to user notification_level
# If no value is found the default level of 1 will be used
def
down
execute
(
%Q{
UPDATE users u SET
notification_level = COALESCE((SELECT level FROM notification_settings WHERE user_id = u.id AND source_type IS NULL), 1)
}
)
end
end
db/migrate/20160610301627_remove_notification_level_from_users.rb
0 → 100644
浏览文件 @
39ead205
class
RemoveNotificationLevelFromUsers
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
def
change
remove_column
:users
,
:notification_level
,
:integer
end
end
spec/services/notification_service_spec.rb
浏览文件 @
39ead205
...
...
@@ -85,13 +85,14 @@ describe NotificationService, services: true do
context
'participating'
do
context
'by note'
do
before
do
ActionMailer
::
Base
.
deliveries
.
clear
note
.
author
=
@u_lazy_participant
note
.
save
notification
.
new_note
(
note
)
end
it
{
should_email
(
@u_lazy_participant
)
}
it
{
should_
not_
email
(
@u_lazy_participant
)
}
end
end
end
...
...
@@ -953,8 +954,8 @@ describe NotificationService, services: true do
def
add_users_with_subscription
(
project
,
issuable
)
@subscriber
=
create
:user
@unsubscriber
=
create
:user
@subscribed_participant
=
create
(
:user
,
username:
'subscribed_participant'
,
notification_level:
:participating
)
@watcher_and_subscriber
=
create
(
:user
,
notification_level:
:watch
)
@subscribed_participant
=
create
_global_setting_for
(
create
(
:user
,
username:
'subscribed_participant'
),
:participating
)
@watcher_and_subscriber
=
create
_global_setting_for
(
create
(
:user
),
:watch
)
project
.
team
<<
[
@subscribed_participant
,
:master
]
project
.
team
<<
[
@subscriber
,
:master
]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录