Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
4ca73f56
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,发现更多精彩内容 >>
提交
4ca73f56
编写于
3月 28, 2016
作者:
D
Dmitriy Zaporozhets
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Small refactoring and cleanup of notification logic
Signed-off-by:
N
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
上级
b8f38437
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
8 addition
and
64 deletion
+8
-64
app/helpers/notifications_helper.rb
app/helpers/notifications_helper.rb
+2
-10
app/models/member.rb
app/models/member.rb
+2
-0
app/models/members/group_member.rb
app/models/members/group_member.rb
+0
-1
app/models/members/project_member.rb
app/models/members/project_member.rb
+0
-1
app/models/notification.rb
app/models/notification.rb
+0
-46
spec/models/notification_setting_spec.rb
spec/models/notification_setting_spec.rb
+1
-0
spec/services/notification_service_spec.rb
spec/services/notification_service_spec.rb
+3
-6
未找到文件。
app/helpers/notifications_helper.rb
浏览文件 @
4ca73f56
...
...
@@ -22,16 +22,12 @@ module NotificationsHelper
def
notification_title
(
level
)
case
level
.
to_sym
when
:disabled
'Disabled'
when
:participating
'Participate'
when
:watch
'Watch'
when
:mention
'On mention'
when
:global
'Global'
else
level
.
to_s
.
titlecase
end
end
...
...
@@ -50,10 +46,6 @@ module NotificationsHelper
end
end
def
notification_label
(
setting
)
notification_title
(
setting
.
level
)
end
def
active_level_for
(
setting
,
level
)
'active'
if
setting
.
level
==
level
end
...
...
app/models/member.rb
浏览文件 @
4ca73f56
...
...
@@ -62,6 +62,8 @@ class Member < ActiveRecord::Base
delegate
:name
,
:username
,
:email
,
to: :user
,
prefix:
true
default_value_for
:notification_level
,
NotificationSetting
.
levels
[
:global
]
class
<<
self
def
find_by_invite_token
(
invite_token
)
invite_token
=
Devise
.
token_generator
.
digest
(
self
,
:invite_token
,
invite_token
)
...
...
app/models/members/group_member.rb
浏览文件 @
4ca73f56
...
...
@@ -24,7 +24,6 @@ class GroupMember < Member
# Make sure group member points only to group as it source
default_value_for
:source_type
,
SOURCE_TYPE
default_value_for
:notification_level
,
Notification
::
N_GLOBAL
validates_format_of
:source_type
,
with:
/\ANamespace\z/
default_scope
{
where
(
source_type:
SOURCE_TYPE
)
}
...
...
app/models/members/project_member.rb
浏览文件 @
4ca73f56
...
...
@@ -27,7 +27,6 @@ class ProjectMember < Member
# Make sure project member points only to project as it source
default_value_for
:source_type
,
SOURCE_TYPE
default_value_for
:notification_level
,
Notification
::
N_GLOBAL
validates_format_of
:source_type
,
with:
/\AProject\z/
default_scope
{
where
(
source_type:
SOURCE_TYPE
)
}
...
...
app/models/notification.rb
浏览文件 @
4ca73f56
class
Notification
#
# Notification levels
#
N_DISABLED
=
0
N_PARTICIPATING
=
1
N_WATCH
=
2
N_GLOBAL
=
3
N_MENTION
=
4
attr_accessor
:target
class
<<
self
def
notification_levels
[
N_DISABLED
,
N_MENTION
,
N_PARTICIPATING
,
N_WATCH
]
end
def
options_with_labels
{
disabled:
N_DISABLED
,
participating:
N_PARTICIPATING
,
watch:
N_WATCH
,
mention:
N_MENTION
,
global:
N_GLOBAL
}
end
def
project_notification_levels
[
N_DISABLED
,
N_MENTION
,
N_PARTICIPATING
,
N_WATCH
,
N_GLOBAL
]
end
end
delegate
:disabled?
,
:participating?
,
:watch?
,
:global?
,
:mention?
,
to: :target
def
initialize
(
target
)
...
...
@@ -39,21 +10,4 @@ class Notification
def
level
target
.
notification_level
end
def
to_s
case
level
when
N_DISABLED
'Disabled'
when
N_PARTICIPATING
'Participating'
when
N_WATCH
'Watching'
when
N_MENTION
'On mention'
when
N_GLOBAL
'Global'
else
# do nothing
end
end
end
spec/models/notification_setting_spec.rb
浏览文件 @
4ca73f56
...
...
@@ -3,6 +3,7 @@ require 'rails_helper'
RSpec
.
describe
NotificationSetting
,
type: :model
do
describe
"Associations"
do
it
{
is_expected
.
to
belong_to
(
:user
)
}
it
{
is_expected
.
to
belong_to
(
:source
)
}
end
describe
"Validation"
do
...
...
spec/services/notification_service_spec.rb
浏览文件 @
4ca73f56
...
...
@@ -88,12 +88,9 @@ describe NotificationService, services: true do
note
.
project
.
namespace_id
=
group
.
id
note
.
project
.
group
.
add_user
(
@u_watcher
,
GroupMember
::
MASTER
)
note
.
project
.
save
user_project
=
note
.
project
.
project_members
.
find_by_user_id
(
@u_watcher
.
id
)
user_project
.
notification
.
level
=
:participating
user_project
.
save
group_member
=
note
.
project
.
group
.
group_members
.
find_by_user_id
(
@u_watcher
.
id
)
group_member
.
notification
.
level
=
:global
group_member
.
notification
.
save
@u_watcher
.
notification_settings
.
find_by
(
source:
note
.
project
).
participating!
@u_watcher
.
notification_settings
.
find_by
(
source:
note
.
project
.
group
).
global!
ActionMailer
::
Base
.
deliveries
.
clear
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录