Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
03e08ab7
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,发现更多精彩内容 >>
提交
03e08ab7
编写于
4月 26, 2019
作者:
W
Wei-Meng Lee
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Guarantee order of notification settings
上级
31775ad8
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
12 addition
and
14 deletion
+12
-14
app/mailers/notify.rb
app/mailers/notify.rb
+2
-10
app/models/group.rb
app/models/group.rb
+8
-2
app/models/namespace.rb
app/models/namespace.rb
+2
-2
未找到文件。
app/mailers/notify.rb
浏览文件 @
03e08ab7
...
...
@@ -82,16 +82,8 @@ class Notify < BaseMailer
group_notification_email
=
nil
if
notification_group
# Get notification group's and ancestors' notification settings
group_ids
=
notification_group
.
self_and_ancestors_ids
notification_settings
=
notification_group
.
notification_settings
.
where
(
user:
@current_user
)
# rubocop: disable CodeReuse/ActiveRecord
# Exploit notification_group.self_and_ancestors_ids being ordered from
# most nested to least nested to iterate through group ancestors
group_ids
.
each
do
|
group_id
|
group_notification_email
=
notification_settings
.
find
{
|
ns
|
ns
.
source_id
==
group_id
}
&
.
notification_email
break
if
group_notification_email
.
present?
end
notification_settings
=
notification_group
.
notification_settings
(
hierarchy_order: :asc
).
where
(
user:
@current_user
)
# rubocop: disable CodeReuse/ActiveRecord
group_notification_email
=
notification_settings
.
find
{
|
n
|
n
.
notification_email
.
present?
}
&
.
notification_email
end
# Return group-specific email address if present, otherwise return global
...
...
app/models/group.rb
浏览文件 @
03e08ab7
...
...
@@ -126,10 +126,16 @@ class Group < Namespace
# Overrides notification_settings has_many association
# This allows to apply notification settings from parent groups
# to child groups and projects.
def
notification_settings
def
notification_settings
(
hierarchy_order:
nil
)
source_type
=
self
.
class
.
base_class
.
name
settings
=
NotificationSetting
.
where
(
source_type:
source_type
,
source_id:
self_and_ancestors_ids
)
NotificationSetting
.
where
(
source_type:
source_type
,
source_id:
self_and_ancestors_ids
)
return
settings
unless
hierarchy_order
&&
self_and_ancestors_ids
.
length
>
1
settings
.
joins
(
"LEFT JOIN (
#{
self_and_ancestors
(
hierarchy_order:
hierarchy_order
).
to_sql
}
) AS ordered_groups ON notification_settings.source_id = ordered_groups.id"
)
.
select
(
'notification_settings.*, ordered_groups.depth AS depth'
)
.
order
(
"ordered_groups.depth
#{
hierarchy_order
}
"
)
end
def
to_reference
(
_from
=
nil
,
full:
nil
)
...
...
app/models/namespace.rb
浏览文件 @
03e08ab7
...
...
@@ -206,12 +206,12 @@ class Namespace < ApplicationRecord
.
ancestors
(
upto:
top
,
hierarchy_order:
hierarchy_order
)
end
def
self_and_ancestors
def
self_and_ancestors
(
hierarchy_order:
nil
)
return
self
.
class
.
where
(
id:
id
)
unless
parent_id
Gitlab
::
ObjectHierarchy
.
new
(
self
.
class
.
where
(
id:
id
))
.
base_and_ancestors
.
base_and_ancestors
(
hierarchy_order:
hierarchy_order
)
end
# Returns all the descendants of the current namespace.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录