Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
03e08ab7
Commit
03e08ab7
authored
Apr 26, 2019
by
Wei-Meng Lee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Guarantee order of notification settings
parent
31775ad8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
14 deletions
+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
No files found.
app/mailers/notify.rb
View file @
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
View file @
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
View file @
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.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment