summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorSean McGivern <sean@gitlab.com>2016-07-07 12:41:48 +0100
committerSean McGivern <sean@gitlab.com>2016-07-07 17:14:21 +0100
commit808642775a850bf4f3ec41ced030f3f60a374085 (patch)
treecf39b4e5f56984211701124d053aab65766dee91 /app/models
parent3c89a788c795fba2b050a0af0d8261e302d8cded (diff)
downloadgitlab-ce-pending-delete-project-notifications.tar.gz
Exclude projects pending delete from notificationspending-delete-project-notifications
If the Sidekiq job fails for some reason, a project can be 'stuck' pending deletion. The project can't be viewed, so it shouldn't be available through the notification settings association as this will throw an exception when we try to show the link.
Diffstat (limited to 'app/models')
-rw-r--r--app/models/notification_setting.rb9
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,