diff --git a/app/controllers/merge_requests_controller.rb b/app/controllers/merge_requests_controller.rb index 67f9617833523d2c8cfbbaa0885da01c5e473a51..c8fe2e6bfe8a0bb863440fdc49d435e9f5a4e44c 100644 --- a/app/controllers/merge_requests_controller.rb +++ b/app/controllers/merge_requests_controller.rb @@ -81,7 +81,8 @@ class MergeRequestsController < ProjectResourceController end def automerge - return access_denied! unless can?(current_user, :accept_mr, @project) + return access_denied! unless allowed_to_merge? + if @merge_request.opened? && @merge_request.can_be_merged? @merge_request.should_remove_source_branch = params[:should_remove_source_branch] @merge_request.automerge!(current_user) @@ -143,5 +144,18 @@ class MergeRequestsController < ProjectResourceController # or from cache if already merged @commits = @merge_request.commits @commits = CommitDecorator.decorate(@commits) + + @allowed_to_merge = allowed_to_merge? + @show_merge_controls = @merge_request.opened? && @commits.any? && @allowed_to_merge + end + + def allowed_to_merge? + action = if project.protected_branch?(@merge_request.target_branch) + :push_code_to_protected_branches + else + :push_code + end + + can?(current_user, action, @project) end end diff --git a/app/models/ability.rb b/app/models/ability.rb index 6fda2e52c7c6fdfc50371c01b35db4394785efa1..41f7127403c911a6bb603d7e97675f864e71e13f 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -91,7 +91,6 @@ class Ability :admin_team_member, :admin_merge_request, :admin_note, - :accept_mr, :admin_wiki, :admin_project ] diff --git a/app/services/git_push_service.rb b/app/services/git_push_service.rb index 40d57c67573542659026606ad651809b94b0ffa9..208ccf699d29e3e51c3d3001524e4958407de7e3 100644 --- a/app/services/git_push_service.rb +++ b/app/services/git_push_service.rb @@ -19,6 +19,8 @@ class GitPushService # Collect data for this git push @push_data = post_receive_data(oldrev, newrev, ref) + create_push_event + project.ensure_satellite_exists project.discover_default_branch @@ -27,8 +29,6 @@ class GitPushService project.execute_hooks(@push_data.dup) project.execute_services(@push_data.dup) end - - create_push_event end # This method provide a sample data diff --git a/app/views/merge_requests/show/_mr_accept.html.haml b/app/views/merge_requests/show/_mr_accept.html.haml index 64f25a5118c635cdb76f9b4b9fc039cb590d770a..d4271c5551f575a2e6eb4442dd52fe15a80d9fc8 100644 --- a/app/views/merge_requests/show/_mr_accept.html.haml +++ b/app/views/merge_requests/show/_mr_accept.html.haml @@ -1,9 +1,9 @@ -- unless can?(current_user, :accept_mr, @project) +- unless @allowed_to_merge .alert - %strong Only masters can accept MR + %strong You don't have enough permissions to merge this MR -- if @merge_request.opened? && @commits.any? && can?(current_user, :accept_mr, @project) +- if @show_merge_controls .automerge_widget.can_be_merged{style: "display:none"} .alert.alert-success %span