From ac3de494bde32e4ce13bd665d1de3132b84c002d Mon Sep 17 00:00:00 2001 From: Patrick Bajao Date: Wed, 19 Jun 2019 16:56:17 +0800 Subject: Support branch creation from confidential issue Accept a `confidential_issue_project_id` param which will be used for the system note target. This also includes some refactoring on the spec to use shared examples. --- .../projects/branches_controller_spec.rb | 69 ++++++++++++++++++++++ 1 file changed, 69 insertions(+) (limited to 'spec/controllers/projects/branches_controller_spec.rb') diff --git a/spec/controllers/projects/branches_controller_spec.rb b/spec/controllers/projects/branches_controller_spec.rb index cf201c9f735..8c349b1e988 100644 --- a/spec/controllers/projects/branches_controller_spec.rb +++ b/spec/controllers/projects/branches_controller_spec.rb @@ -103,6 +103,75 @@ describe Projects::BranchesController do } end + context 'confidential_issue_project_id is present' do + let(:confidential_issue_project) { create(:project) } + + def create_branch_with_confidential_issue_project + post( + :create, + params: { + namespace_id: project.namespace, + project_id: project, + branch_name: branch, + confidential_issue_project_id: confidential_issue_project.id, + issue_iid: issue.iid + } + ) + end + + context 'create_confidential_merge_request feature is enabled' do + before do + stub_feature_flags(create_confidential_merge_request: true) + end + + context 'user cannot push code to issue project' do + let(:issue) { create(:issue, project: confidential_issue_project) } + + it 'does not post a system note' do + expect(SystemNoteService).not_to receive(:new_issue_branch) + + create_branch_with_confidential_issue_project + end + end + + context 'user can push code to issue project' do + before do + confidential_issue_project.add_developer(user) + end + + context 'issue is under the specified project' do + let(:issue) { create(:issue, project: confidential_issue_project) } + + it 'posts a system note' do + expect(SystemNoteService).to receive(:new_issue_branch).with(issue, confidential_issue_project, user, "1-feature-branch", branch_project: project) + + create_branch_with_confidential_issue_project + end + end + + context 'issue is not under the specified project' do + it 'does not post a system note' do + expect(SystemNoteService).not_to receive(:new_issue_branch) + + create_branch_with_confidential_issue_project + end + end + end + end + + context 'create_confidential_merge_request feature is disabled' do + before do + stub_feature_flags(create_confidential_merge_request: false) + end + + it 'posts a system note on project' do + expect(SystemNoteService).to receive(:new_issue_branch).with(issue, project, user, "1-feature-branch", branch_project: project) + + create_branch_with_confidential_issue_project + end + end + end + context 'repository-less project' do let(:project) { create :project } -- cgit v1.2.1 From 1ca5520bd6f3447ada3a1120d2a3bd445ab6746a Mon Sep 17 00:00:00 2001 From: Patrick Bajao Date: Fri, 28 Jun 2019 14:08:26 -0800 Subject: Fix issues when creating system notes When `confidential_issue_project_id` is set and the issue is under that project, create the a note about branch creation in that project. If not, do nothing. When creating `new_merge_request` system note, set the project where the MR will be referenced from so it'll be linked to when the MR is created in another project. --- spec/controllers/projects/branches_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/controllers/projects/branches_controller_spec.rb') diff --git a/spec/controllers/projects/branches_controller_spec.rb b/spec/controllers/projects/branches_controller_spec.rb index 8c349b1e988..712c3fa0ffe 100644 --- a/spec/controllers/projects/branches_controller_spec.rb +++ b/spec/controllers/projects/branches_controller_spec.rb @@ -92,7 +92,7 @@ describe Projects::BranchesController do end it 'posts a system note' do - expect(SystemNoteService).to receive(:new_issue_branch).with(issue, project, user, "1-feature-branch") + expect(SystemNoteService).to receive(:new_issue_branch).with(issue, project, user, "1-feature-branch", branch_project: project) post :create, params: { -- cgit v1.2.1 From 6b68acbfe9db1d3c855d7505817ebca62e3a61c1 Mon Sep 17 00:00:00 2001 From: Patrick Bajao Date: Mon, 1 Jul 2019 16:23:23 +0800 Subject: Check if user can `update_issue` on project If user can update an issue under the specified confidential issue project, should be able to find the project. --- spec/controllers/projects/branches_controller_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'spec/controllers/projects/branches_controller_spec.rb') diff --git a/spec/controllers/projects/branches_controller_spec.rb b/spec/controllers/projects/branches_controller_spec.rb index 712c3fa0ffe..dbc8681eb49 100644 --- a/spec/controllers/projects/branches_controller_spec.rb +++ b/spec/controllers/projects/branches_controller_spec.rb @@ -124,7 +124,7 @@ describe Projects::BranchesController do stub_feature_flags(create_confidential_merge_request: true) end - context 'user cannot push code to issue project' do + context 'user cannot update issue' do let(:issue) { create(:issue, project: confidential_issue_project) } it 'does not post a system note' do @@ -134,9 +134,9 @@ describe Projects::BranchesController do end end - context 'user can push code to issue project' do + context 'user can update issue' do before do - confidential_issue_project.add_developer(user) + confidential_issue_project.add_reporter(user) end context 'issue is under the specified project' do -- cgit v1.2.1