Use the right default notification settings for non members

This commit is contained in:
Felipe Artur 2016-05-19 19:20:06 -04:00
parent fc9844e8e1
commit 6fb9bf87c4
4 changed files with 12 additions and 23 deletions

View file

@ -777,13 +777,7 @@ class User < ActiveRecord::Base
end end
def notification_settings_for(source) def notification_settings_for(source)
notification_setting = notification_settings.find_or_initialize_by(source: source) notification_settings.find_or_initialize_by(source: source)
if source.is_a?(Project) && !source.team.member?(id) && !notification_setting.persisted?
notification_setting.level = :disabled
end
notification_setting
end end
private private

View file

@ -24,20 +24,20 @@ describe ProjectsController do
context "and does not have notification setting" do context "and does not have notification setting" do
it "initializes notification as disabled" do it "initializes notification as disabled" do
get :show, namespace_id: public_project.namespace.path, id: public_project.path get :show, namespace_id: public_project.namespace.path, id: public_project.path
expect(assigns(:notification_setting).level).to eq("disabled") expect(assigns(:notification_setting).level).to eq("global")
end end
end end
context "and has notification setting" do context "and has notification setting" do
before do before do
setting = user.notification_settings_for(public_project) setting = user.notification_settings_for(public_project)
setting.level = :global setting.level = :watch
setting.save setting.save
end end
it "shows current notification setting" do it "shows current notification setting" do
get :show, namespace_id: public_project.namespace.path, id: public_project.path get :show, namespace_id: public_project.namespace.path, id: public_project.path
expect(assigns(:notification_setting).level).to eq("global") expect(assigns(:notification_setting).level).to eq("watch")
end end
end end
end end
@ -45,6 +45,7 @@ describe ProjectsController do
context "rendering default project view" do context "rendering default project view" do
render_views render_views
it "renders the activity view" do it "renders the activity view" do
allow(controller).to receive(:current_user).and_return(user) allow(controller).to receive(:current_user).and_return(user)
allow(user).to receive(:project_view).and_return('activity') allow(user).to receive(:project_view).and_return('activity')

View file

@ -17,7 +17,6 @@ describe MergeRequests::UpdateService, services: true do
before do before do
project.team << [user, :master] project.team << [user, :master]
project.team << [user2, :developer] project.team << [user2, :developer]
project.team << [user3, :developer]
end end
describe 'execute' do describe 'execute' do

View file

@ -35,7 +35,7 @@ describe NotificationService, services: true do
describe 'Notes' do describe 'Notes' do
context 'issue note' do context 'issue note' do
let(:project) { create(:empty_project, :internal) } let(:project) { create(:empty_project, :private) }
let(:issue) { create(:issue, project: project, assignee: create(:user)) } let(:issue) { create(:issue, project: project, assignee: create(:user)) }
let(:mentioned_issue) { create(:issue, assignee: issue.assignee) } let(:mentioned_issue) { create(:issue, assignee: issue.assignee) }
let(:note) { create(:note_on_issue, noteable: issue, project_id: issue.project_id, note: '@mention referenced, @outsider also') } let(:note) { create(:note_on_issue, noteable: issue, project_id: issue.project_id, note: '@mention referenced, @outsider also') }
@ -52,8 +52,8 @@ describe NotificationService, services: true do
it do it do
add_users_with_subscription(note.project, issue) add_users_with_subscription(note.project, issue)
# Ensure create SentNotification by noteable = issue 7 times, not noteable = note # Ensure create SentNotification by noteable = issue 6 times, not noteable = note
expect(SentNotification).to receive(:record).with(issue, any_args).exactly(8).times expect(SentNotification).to receive(:record).with(issue, any_args).exactly(7).times
ActionMailer::Base.deliveries.clear ActionMailer::Base.deliveries.clear
@ -66,7 +66,7 @@ describe NotificationService, services: true do
should_email(@subscriber) should_email(@subscriber)
should_email(@watcher_and_subscriber) should_email(@watcher_and_subscriber)
should_email(@subscribed_participant) should_email(@subscribed_participant)
should_email(@u_guest_watcher) should_not_email(@u_guest_watcher)
should_not_email(note.author) should_not_email(note.author)
should_not_email(@u_participating) should_not_email(@u_participating)
should_not_email(@u_disabled) should_not_email(@u_disabled)
@ -101,7 +101,7 @@ describe NotificationService, services: true do
should_email(note.noteable.author) should_email(note.noteable.author)
should_email(note.noteable.assignee) should_email(note.noteable.assignee)
should_email(@u_mentioned) should_email(@u_mentioned)
should_email(@u_guest_watcher) should_not_email(@u_guest_watcher)
should_not_email(@u_watcher) should_not_email(@u_watcher)
should_not_email(note.author) should_not_email(note.author)
should_not_email(@u_participating) should_not_email(@u_participating)
@ -121,10 +121,7 @@ describe NotificationService, services: true do
let(:note) { create(:note_on_issue, noteable: confidential_issue, project: project, note: "#{author.to_reference} #{assignee.to_reference} #{non_member.to_reference} #{member.to_reference} #{admin.to_reference}") } let(:note) { create(:note_on_issue, noteable: confidential_issue, project: project, note: "#{author.to_reference} #{assignee.to_reference} #{non_member.to_reference} #{member.to_reference} #{admin.to_reference}") }
it 'filters out users that can not read the issue' do it 'filters out users that can not read the issue' do
project.team << [admin, :master]
project.team << [author, :developer]
project.team << [member, :developer] project.team << [member, :developer]
project.team << [assignee, :developer]
expect(SentNotification).to receive(:record).with(confidential_issue, any_args).exactly(4).times expect(SentNotification).to receive(:record).with(confidential_issue, any_args).exactly(4).times
@ -148,7 +145,7 @@ describe NotificationService, services: true do
before do before do
build_team(note.project) build_team(note.project)
note.project.team << [[note.author, note.noteable.author, note.noteable.assignee], :master] note.project.team << [note.author, :master]
ActionMailer::Base.deliveries.clear ActionMailer::Base.deliveries.clear
end end
@ -190,7 +187,7 @@ describe NotificationService, services: true do
before do before do
build_team(note.project) build_team(note.project)
note.project.team << [[note.author, note.noteable.author], :master] note.project.team << [note.author, :master]
ActionMailer::Base.deliveries.clear ActionMailer::Base.deliveries.clear
end end
@ -269,7 +266,6 @@ describe NotificationService, services: true do
before do before do
build_team(issue.project) build_team(issue.project)
add_users_with_subscription(issue.project, issue) add_users_with_subscription(issue.project, issue)
project.team << [[issue.assignee, issue.author], :developer]
ActionMailer::Base.deliveries.clear ActionMailer::Base.deliveries.clear
end end
@ -510,7 +506,6 @@ describe NotificationService, services: true do
before do before do
build_team(merge_request.target_project) build_team(merge_request.target_project)
add_users_with_subscription(merge_request.target_project, merge_request) add_users_with_subscription(merge_request.target_project, merge_request)
project.team << [merge_request.assignee, :developer]
ActionMailer::Base.deliveries.clear ActionMailer::Base.deliveries.clear
end end