diff options
author | Robert Speicher <robert@gitlab.com> | 2016-07-07 23:17:24 +0300 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2016-07-07 23:17:24 +0300 |
commit | 91cf0387dd91b380647457c41edd948a357b620c (patch) | |
tree | 1c671215783980e1ed3e49c42ef8dda5d1004735 /app | |
parent | 68155ee73b549a4f79744bb325542c29d45c71ea (diff) | |
parent | ea25e0918b77c2345585a968fbf5b73bb544aac7 (diff) |
Merge branch 'pending-delete-project-notifications' into 'master'
Exclude projects pending delete from notifications
Make `NotificationSetting.for_projects` exclude projects that are excluded by the default scope on `Project`. (At the moment, that's projects with `pending_delete: true`.)
See https://gitlab.com/gitlab-com/support-forum/issues/819
See merge request !5138
Diffstat (limited to 'app')
-rw-r--r-- | app/models/notification_setting.rb | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/app/models/notification_setting.rb b/app/models/notification_setting.rb index d41fc7073c6..121b598b8f3 100644 --- a/app/models/notification_setting.rb +++ b/app/models/notification_setting.rb @@ -5,6 +5,7 @@ class NotificationSetting < ActiveRecord::Base belongs_to :user belongs_to :source, polymorphic: true + belongs_to :project, foreign_key: 'source_id' validates :user, presence: true validates :level, presence: true @@ -13,7 +14,13 @@ class NotificationSetting < ActiveRecord::Base allow_nil: true } scope :for_groups, -> { where(source_type: 'Namespace') } - scope :for_projects, -> { where(source_type: 'Project') } + + # Exclude projects not included by the Project model's default scope (those that are + # pending delete). + # + scope :for_projects, -> do + includes(:project).references(:projects).where(source_type: 'Project').where.not(projects: { id: nil }) + end EMAIL_EVENTS = [ :new_note, |