summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Edwards-Jones <jedwardsjones@gitlab.com>2016-10-07 17:16:42 +0100
committerJames Edwards-Jones <jedwardsjones@gitlab.com>2016-10-07 17:16:42 +0100
commit8d2de73a83b98741dbbbc21fe2cbcdaf7840996d (patch)
tree40ff182e4b1f351bbabc81a7319844322f5d7ff2
parent492b4332a46fa0ae7d6547fe7417977f34c77b99 (diff)
downloadgitlab-ce-8d2de73a83b98741dbbbc21fe2cbcdaf7840996d.tar.gz
fixup! Added link to bulk assign issues to MR author. (Issue #18876)
-rw-r--r--app/controllers/projects/merge_requests_controller.rb2
-rw-r--r--app/services/merge_requests/assign_issues_service.rb6
-rw-r--r--spec/controllers/projects/merge_requests_controller_spec.rb17
3 files changed, 22 insertions, 3 deletions
diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb
index 8bbf3ec67b3..17dc89f717b 100644
--- a/app/controllers/projects/merge_requests_controller.rb
+++ b/app/controllers/projects/merge_requests_controller.rb
@@ -29,6 +29,8 @@ class Projects::MergeRequestsController < Projects::ApplicationController
# Allow modify merge_request
before_action :authorize_update_merge_request!, only: [:close, :edit, :update, :remove_wip, :sort]
+ before_action :authenticate_user!, only: [:assign_related_issues]
+
before_action :authorize_can_resolve_conflicts!, only: [:conflicts, :resolve_conflicts]
def index
diff --git a/app/services/merge_requests/assign_issues_service.rb b/app/services/merge_requests/assign_issues_service.rb
index 2e84f844449..f636e5fec4f 100644
--- a/app/services/merge_requests/assign_issues_service.rb
+++ b/app/services/merge_requests/assign_issues_service.rb
@@ -3,9 +3,9 @@ module MergeRequests
def assignable_issues
@assignable_issues ||= begin
if current_user == merge_request.author
- closes_issues.
- reject { |issue| issue.assignee_id? }.
- select { |issue| can?(current_user, :admin_issue, issue) }
+ closes_issues.select do |issue|
+ !issue.assignee_id? && can?(current_user, :admin_issue, issue)
+ end
else
[]
end
diff --git a/spec/controllers/projects/merge_requests_controller_spec.rb b/spec/controllers/projects/merge_requests_controller_spec.rb
index 18041bce482..2a68e5a2c9b 100644
--- a/spec/controllers/projects/merge_requests_controller_spec.rb
+++ b/spec/controllers/projects/merge_requests_controller_spec.rb
@@ -738,5 +738,22 @@ describe Projects::MergeRequestsController do
expect(flash[:notice]).to eq '1 issue has been assigned to you'
end
+
+ it 'calls MergeRequests::AssignIssuesService' do
+ expect(MergeRequests::AssignIssuesService).to receive(:new).
+ with(project, user, merge_request: merge_request).
+ and_return(double(execute: {count: 1}))
+
+ post_assign_issues
+ end
+
+ it 'is skipped when not signed in' do
+ project.update!(visibility_level: Gitlab::VisibilityLevel::PUBLIC)
+ sign_out(:user)
+
+ expect(MergeRequests::AssignIssuesService).not_to receive(:new)
+
+ post_assign_issues
+ end
end
end