diff options
author | Felipe Artur <felipefac@gmail.com> | 2018-05-28 15:43:46 -0300 |
---|---|---|
committer | Felipe Artur <felipefac@gmail.com> | 2018-06-07 15:47:39 -0300 |
commit | afe5d7d56ee771dac6e4a97d23e69d678c03da2d (patch) | |
tree | d4852e794d3c526863eb2ff0bd3d7f399cd40de1 /app/models/group.rb | |
parent | 439adb96dadd49124d080db0db0b0076d2049c6b (diff) | |
download | gitlab-ce-afe5d7d56ee771dac6e4a97d23e69d678c03da2d.tar.gz |
Apply notification settings level of groups to all child objects
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 8fb77a7869d..1bd718d0a92 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 @@ -220,6 +234,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 = |