Commit 91cf0387 authored by Robert Speicher's avatar Robert Speicher

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
parents 68155ee7 ea25e091
...@@ -18,6 +18,7 @@ v 8.10.0 (unreleased) ...@@ -18,6 +18,7 @@ v 8.10.0 (unreleased)
- Fix MR-auto-close text added to description. !4836 - Fix MR-auto-close text added to description. !4836
- Fix issue, preventing users w/o push access to sort tags !5105 (redetection) - Fix issue, preventing users w/o push access to sort tags !5105 (redetection)
- Add Spring EmojiOne updates. - Add Spring EmojiOne updates.
- Fix viewing notification settings when a project is pending deletion
- Fix pagination when sorting by columns with lots of ties (like priority) - Fix pagination when sorting by columns with lots of ties (like priority)
- Updated project header design - Updated project header design
- Exclude email check from the standard health check - Exclude email check from the standard health check
......
...@@ -5,6 +5,7 @@ class NotificationSetting < ActiveRecord::Base ...@@ -5,6 +5,7 @@ class NotificationSetting < ActiveRecord::Base
belongs_to :user belongs_to :user
belongs_to :source, polymorphic: true belongs_to :source, polymorphic: true
belongs_to :project, foreign_key: 'source_id'
validates :user, presence: true validates :user, presence: true
validates :level, presence: true validates :level, presence: true
...@@ -13,7 +14,13 @@ class NotificationSetting < ActiveRecord::Base ...@@ -13,7 +14,13 @@ class NotificationSetting < ActiveRecord::Base
allow_nil: true } allow_nil: true }
scope :for_groups, -> { where(source_type: 'Namespace') } 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 = [ EMAIL_EVENTS = [
:new_note, :new_note,
......
FactoryGirl.define do
factory :notification_setting do
source factory: :empty_project
user
level 3
events []
end
end
...@@ -38,4 +38,21 @@ RSpec.describe NotificationSetting, type: :model do ...@@ -38,4 +38,21 @@ RSpec.describe NotificationSetting, type: :model do
end end
end end
end end
describe '#for_projects' do
let(:user) { create(:user) }
before do
1.upto(4) do |i|
setting = create(:notification_setting, user: user)
setting.project.update_attributes(pending_delete: true) if i.even?
end
end
it 'excludes projects pending delete' do
expect(user.notification_settings.for_projects).to all(have_attributes(project: an_instance_of(Project)))
expect(user.notification_settings.for_projects.map(&:project)).to all(have_attributes(pending_delete: false))
end
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment