Skip to content
Snippets Groups Projects

WIP: Project option to require allow collaboration on merge requests

4 unresolved threads
Compare and Show latest version
9 files
+ 90
51
Compare changes
  • Side-by-side
  • Inline
Files
9
@@ -666,9 +666,10 @@ def validate_fork
end
def validate_collaboration
return true unless target_project.merge_requests_require_allow_collaboration?
return true unless must_allow_collaboration?
return true unless for_fork?
return true unless source_and_target_projects_not_private?
# TODO: Can merge request authors be changed?
return true if can_allow_collaboration?(author)
errors.add :base, 'Target project requires merge requests to allow commits from members who can merge to the target branch'
@@ -834,7 +835,7 @@ def can_cancel_auto_merge?(current_user)
def can_remove_source_branch?(current_user)
!protected_source_branch? &&
!source_project.root_ref?(source_branch) &&
can_push_to_source_branch? &&
can_push_to_source_project?(current_user) &&
diff_head_sha == source_branch_head.try(:sha)
end
@@ -1428,17 +1429,21 @@ def source_and_target_projects_not_private?
source_project.visibility_level > Gitlab::VisibilityLevel::PRIVATE
end
def can_allow_collaboration?(user)
def can_allow_collaboration?(current_user)
collaborative_push_possible? &&
can_push_to_source_branch?
can_push_to_source_project?(current_user)
end
def must_allow_collaboration?
target_project.merge_requests_require_allow_collaboration?
end
def can_toggle_collaboration?(user)
can_allow_collaboration?(user) && !must_allow_collaboration?
def can_toggle_collaboration?(current_user)
can_allow_collaboration?(current_user) && !must_allow_collaboration?
end
def should_allow_collaboration?(current_user)
can_allow_collaboration?(current_user) && must_allow_collaboration?
end
def squash_in_progress?
@@ -1476,7 +1481,7 @@ def protected_source_branch?
ProtectedBranch.protected?(source_project, source_branch)
end
def can_push_to_source_branch?
Ability.allowed?(author, :push_code, source_project)
def can_push_to_source_project?(current_user)
Ability.allowed?(current_user, :push_code, source_project)
end
end
Loading