diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2018-06-07 20:10:45 +0000 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2018-06-07 20:10:45 +0000 |
commit | 6e614bd5e03e55a6b64a89b1cdbf2973bdd6ca84 (patch) | |
tree | d5b71bf7d2f32e5f4fc8fdb658762e343433a869 /app/models/group.rb | |
parent | 27aa2e544b9f97b701888bd17d517c5f2b697f91 (diff) | |
parent | afe5d7d56ee771dac6e4a97d23e69d678c03da2d (diff) | |
download | gitlab-ce-6e614bd5e03e55a6b64a89b1cdbf2973bdd6ca84.tar.gz |
Merge branch 'issue_44230' into 'master'
Apply notification settings level of groups to all child objects
Closes #44230
See merge request gitlab-org/gitlab-ce!19191
Diffstat (limited to 'app/models/group.rb')
-rw-r--r-- | app/models/group.rb | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/app/models/group.rb b/app/models/group.rb index aeb50fb9bb7..9c171de7fc3 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -11,6 +11,7 @@ class Group < Namespace include GroupDescendant include TokenAuthenticatable include WithUploads + include Gitlab::Utils::StrongMemoize has_many :group_members, -> { where(requested_at: nil) }, dependent: :destroy, as: :source # rubocop:disable Cop/ActiveRecordDependent alias_method :members, :group_members @@ -26,7 +27,11 @@ class Group < Namespace has_many :milestones has_many :project_group_links, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent has_many :shared_projects, through: :project_group_links, source: :project + + # Overridden on another method + # Left here just to be dependent: :destroy has_many :notification_settings, dependent: :destroy, as: :source # rubocop:disable Cop/ActiveRecordDependent + has_many :labels, class_name: 'GroupLabel' has_many :variables, class_name: 'Ci::GroupVariable' has_many :custom_attributes, class_name: 'GroupCustomAttribute' @@ -88,6 +93,15 @@ class Group < Namespace end end + # Overrides notification_settings has_many association + # This allows to apply notification settings from parent groups + # to child groups and projects. + def notification_settings + source_type = self.class.base_class.name + + NotificationSetting.where(source_type: source_type, source_id: self_and_ancestors_ids) + end + def to_reference(_from = nil, full: nil) "#{self.class.reference_prefix}#{full_path}" end @@ -225,6 +239,12 @@ class Group < Namespace members_with_parents.pluck(:user_id) end + def self_and_ancestors_ids + strong_memoize(:self_and_ancestors_ids) do + self_and_ancestors.pluck(:id) + end + end + def members_with_parents # Avoids an unnecessary SELECT when the group has no parents source_ids = |