diff --git a/app/models/hooks/project_hook.rb b/app/models/hooks/project_hook.rb index 836a75b0608d11ca3ae693f01fb5bc15e17dede4..c631e7a7df580ed5030bdb46747b3dc233f6f709 100644 --- a/app/models/hooks/project_hook.rb +++ b/app/models/hooks/project_hook.rb @@ -2,6 +2,7 @@ class ProjectHook < WebHook belongs_to :project scope :issue_hooks, -> { where(issues_events: true) } + scope :confidential_issue_hooks, -> { where(confidential_issues_events: true) } scope :note_hooks, -> { where(note_events: true) } scope :merge_request_hooks, -> { where(merge_requests_events: true) } scope :build_hooks, -> { where(build_events: true) } diff --git a/app/models/service.rb b/app/models/service.rb index 7333f8d381b3b968552c0cf4ceffad1d1f31e071..198e7247838ba9ba416ae1742ef2e43a81e035fc 100644 --- a/app/models/service.rb +++ b/app/models/service.rb @@ -34,6 +34,7 @@ class Service < ActiveRecord::Base scope :push_hooks, -> { where(push_events: true, active: true) } scope :tag_push_hooks, -> { where(tag_push_events: true, active: true) } scope :issue_hooks, -> { where(issues_events: true, active: true) } + scope :confidential_issue_hooks, -> { where(confidential_issues_events: true, active: true) } scope :merge_request_hooks, -> { where(merge_requests_events: true, active: true) } scope :note_hooks, -> { where(note_events: true, active: true) } scope :build_hooks, -> { where(build_events: true, active: true) } diff --git a/app/services/issues/base_service.rb b/app/services/issues/base_service.rb index 241efc44d3609377fb21a786afc2d34f0699192f..9ea3ce084bae192d624ee7fa2a0fbfb0c7a22da4 100644 --- a/app/services/issues/base_service.rb +++ b/app/services/issues/base_service.rb @@ -14,11 +14,10 @@ module Issues end def execute_hooks(issue, action = 'open') - return if issue.confidential? - - issue_data = hook_data(issue, action) - issue.project.execute_hooks(issue_data, :issue_hooks) - issue.project.execute_services(issue_data, :issue_hooks) + issue_data = hook_data(issue, action) + hooks_scope = issue.confidential? ? :confidential_issue_hooks : :issue_hooks + issue.project.execute_hooks(issue_data, hooks_scope) + issue.project.execute_services(issue_data, hooks_scope) end end end diff --git a/spec/services/issues/close_service_spec.rb b/spec/services/issues/close_service_spec.rb index 4df99e41987494081a7ccfe7fe6567079ed25d9d..5dfb33f4b28d5499f9e0f61dfbd6fa700bc76aa9 100644 --- a/spec/services/issues/close_service_spec.rb +++ b/spec/services/issues/close_service_spec.rb @@ -53,12 +53,21 @@ describe Issues::CloseService, services: true do end end + context 'when issue is not confidential' do + it 'executes issue hooks' do + expect(project).to receive(:execute_hooks).with(an_instance_of(Hash), :issue_hooks) + expect(project).to receive(:execute_services).with(an_instance_of(Hash), :issue_hooks) + + described_class.new(project, user).execute(issue) + end + end + context 'when issue is confidential' do - it 'does not execute hooks' do + it 'executes confidential issue hooks' do issue = create(:issue, :confidential, project: project) - expect(project).not_to receive(:execute_hooks) - expect(project).not_to receive(:execute_services) + expect(project).to receive(:execute_hooks).with(an_instance_of(Hash), :confidential_issue_hooks) + expect(project).to receive(:execute_services).with(an_instance_of(Hash), :confidential_issue_hooks) described_class.new(project, user).execute(issue) end diff --git a/spec/services/issues/create_service_spec.rb b/spec/services/issues/create_service_spec.rb index 81beca47738d659cf4421cdcaad948ff55b94729..58569ba96c3ae70f0f82df97fd8f94331307b51e 100644 --- a/spec/services/issues/create_service_spec.rb +++ b/spec/services/issues/create_service_spec.rb @@ -73,11 +73,20 @@ describe Issues::CreateService, services: true do end end - it 'does not execute hooks when issue is confidential' do + it 'executes issue hooks when issue is not confidential' do + opts = { title: 'Title', description: 'Description', confidential: false } + + expect(project).to receive(:execute_hooks).with(an_instance_of(Hash), :issue_hooks) + expect(project).to receive(:execute_services).with(an_instance_of(Hash), :issue_hooks) + + described_class.new(project, user, opts).execute + end + + it 'executes confidential issue hooks when issue is confidential' do opts = { title: 'Title', description: 'Description', confidential: true } - expect(project).not_to receive(:execute_hooks) - expect(project).not_to receive(:execute_services) + expect(project).to receive(:execute_hooks).with(an_instance_of(Hash), :confidential_issue_hooks) + expect(project).to receive(:execute_services).with(an_instance_of(Hash), :confidential_issue_hooks) described_class.new(project, user, opts).execute end diff --git a/spec/services/issues/reopen_service_spec.rb b/spec/services/issues/reopen_service_spec.rb index 4549e2b395ba98a630936c86d702c18ce78a9ccb..93a8270fd16e477c97aab4842539e19eb76c032b 100644 --- a/spec/services/issues/reopen_service_spec.rb +++ b/spec/services/issues/reopen_service_spec.rb @@ -5,7 +5,7 @@ describe Issues::ReopenService, services: true do let(:issue) { create(:issue, :closed, project: project) } describe '#execute' do - context 'current user is not authorized to reopen issue' do + context 'when user is not authorized to reopen issue' do before do guest = create(:user) project.team << [guest, :guest] @@ -20,17 +20,31 @@ describe Issues::ReopenService, services: true do end end - context 'when issue is confidential' do - it 'does not execute hooks' do - user = create(:user) + context 'when user is authrized to reopen issue' do + let(:user) { create(:user) } + + before do project.team << [user, :master] + end + + context 'when issue is not confidential' do + it 'executes issue hooks' do + expect(project).to receive(:execute_hooks).with(an_instance_of(Hash), :issue_hooks) + expect(project).to receive(:execute_services).with(an_instance_of(Hash), :issue_hooks) - issue = create(:issue, :confidential, :closed, project: project) + described_class.new(project, user).execute(issue) + end + end - expect(project).not_to receive(:execute_hooks) - expect(project).not_to receive(:execute_services) + context 'when issue is confidential' do + it 'executes confidential issue hooks' do + issue = create(:issue, :confidential, :closed, project: project) - described_class.new(project, user).execute(issue) + expect(project).to receive(:execute_hooks).with(an_instance_of(Hash), :confidential_issue_hooks) + expect(project).to receive(:execute_services).with(an_instance_of(Hash), :confidential_issue_hooks) + + described_class.new(project, user).execute(issue) + end end end end diff --git a/spec/services/issues/update_service_spec.rb b/spec/services/issues/update_service_spec.rb index 3c3a861b3af941f5a407d8688467dc1e15bdb578..4f5375a3583a2fbbecf73301d07181171e3bdabc 100644 --- a/spec/services/issues/update_service_spec.rb +++ b/spec/services/issues/update_service_spec.rb @@ -105,9 +105,9 @@ describe Issues::UpdateService, services: true do expect(note.note).to eq 'Made the issue confidential' end - it 'does not execute hooks' do - expect(project).not_to receive(:execute_hooks) - expect(project).not_to receive(:execute_services) + it 'executes confidential issue hooks' do + expect(project).to receive(:execute_hooks).with(an_instance_of(Hash), :confidential_issue_hooks) + expect(project).to receive(:execute_services).with(an_instance_of(Hash), :confidential_issue_hooks) update_issue(confidential: true) end