Commit 946b4ced authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Improve variables in mr widget

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 8893ac4b
......@@ -139,14 +139,13 @@ class Projects::MergeRequestsController < Projects::ApplicationController
@merge_request.check_if_can_be_merged
end
@allowed_to_merge = allowed_to_merge?
closes_issues
render partial: "projects/merge_requests/widget/show.html.haml", layout: false
end
def automerge
return access_denied! unless allowed_to_merge?
return access_denied! unless @merge_request.can_be_merged_by?(current_user)
if @merge_request.automergeable?
AutoMergeWorker.perform_async(@merge_request.id, current_user.id, params)
......@@ -255,8 +254,6 @@ class Projects::MergeRequestsController < Projects::ApplicationController
@commits = @merge_request.commits
@merge_request_diff = @merge_request.merge_request_diff
@allowed_to_merge = allowed_to_merge?
@show_merge_controls = @merge_request.open? && @commits.any? && @allowed_to_merge
@source_branch = @merge_request.source_project.repository.find_branch(@merge_request.source_branch).try(:name)
if @merge_request.locked_long_ago?
......@@ -265,19 +262,11 @@ class Projects::MergeRequestsController < Projects::ApplicationController
end
end
def allowed_to_merge?
allowed_to_push_code?(project, @merge_request.target_branch)
end
def invalid_mr
# Render special view for MR with removed source or target branch
render 'invalid'
end
def allowed_to_push_code?(project, branch)
::Gitlab::GitAccess.new(current_user, project).can_push_to_branch?(branch)
end
def merge_request_params
params.require(:merge_request).permit(
:title, :assignee_id, :source_project_id, :source_branch,
......
......@@ -413,4 +413,8 @@ class MergeRequest < ActiveRecord::Base
def branch_missing?
!source_branch_exists? || !target_branch_exists?
end
def can_be_merged_by?(user)
::Gitlab::GitAccess.new(user, project).can_push_to_branch?(target_branch)
end
end
......@@ -15,7 +15,7 @@
= render 'projects/merge_requests/widget/open/conflicts'
- elsif @merge_request.work_in_progress?
= render 'projects/merge_requests/widget/open/wip'
- elsif !@allowed_to_merge
- elsif !@merge_request.can_be_merged_by?(current_user)
= render 'projects/merge_requests/widget/open/not_allowed'
- elsif @merge_request.can_be_merged?
= render 'projects/merge_requests/widget/open/accept'
......
- if @allowed_to_merge
- if @merge_request.can_be_merged_by?(current_user)
%h4
This merge request contains merge conflicts that must be resolved.
You can try it manually on the
......
- if @allowed_to_merge
- if @merge_request.can_be_merged_by?(current_user)
%h4
This merge request cannot be accepted because it is marked as Work In Progress.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment