summaryrefslogtreecommitdiff
path: root/lib/api/branches.rb
diff options
context:
space:
mode:
authorDouwe Maan <douwe@selenight.nl>2016-08-16 17:49:53 -0500
committerDouwe Maan <douwe@selenight.nl>2016-08-16 17:49:53 -0500
commite07c27fee427195d8d89f6278d0fc12dfeec3588 (patch)
treec4676e5e953aecef8bf2bb715619027cd556c9cc /lib/api/branches.rb
parent029b7d2e9266246feff2f165a10b16be1d7fe88e (diff)
parent415159c28da1aec00bb383d46aad67a9de75faae (diff)
downloadgitlab-ce-e07c27fee427195d8d89f6278d0fc12dfeec3588.tar.gz
Merge branch 'master' into 4273-slash-commands
# Conflicts: # app/services/issues/create_service.rb
Diffstat (limited to 'lib/api/branches.rb')
-rw-r--r--lib/api/branches.rb29
1 files changed, 17 insertions, 12 deletions
diff --git a/lib/api/branches.rb b/lib/api/branches.rb
index a77afe634f6..b615703df93 100644
--- a/lib/api/branches.rb
+++ b/lib/api/branches.rb
@@ -61,22 +61,27 @@ module API
name: @branch.name
}
- unless developers_can_merge.nil?
- protected_branch_params.merge!({
- merge_access_level_attributes: {
- access_level: developers_can_merge ? Gitlab::Access::DEVELOPER : Gitlab::Access::MASTER
- }
- })
+ # If `developers_can_merge` is switched off, _all_ `DEVELOPER`
+ # merge_access_levels need to be deleted.
+ if developers_can_merge == false
+ protected_branch.merge_access_levels.where(access_level: Gitlab::Access::DEVELOPER).destroy_all
end
- unless developers_can_push.nil?
- protected_branch_params.merge!({
- push_access_level_attributes: {
- access_level: developers_can_push ? Gitlab::Access::DEVELOPER : Gitlab::Access::MASTER
- }
- })
+ # If `developers_can_push` is switched off, _all_ `DEVELOPER`
+ # push_access_levels need to be deleted.
+ if developers_can_push == false
+ protected_branch.push_access_levels.where(access_level: Gitlab::Access::DEVELOPER).destroy_all
end
+ protected_branch_params.merge!(
+ merge_access_levels_attributes: [{
+ access_level: developers_can_merge ? Gitlab::Access::DEVELOPER : Gitlab::Access::MASTER
+ }],
+ push_access_levels_attributes: [{
+ access_level: developers_can_push ? Gitlab::Access::DEVELOPER : Gitlab::Access::MASTER
+ }]
+ )
+
if protected_branch
service = ProtectedBranches::UpdateService.new(user_project, current_user, protected_branch_params)
service.execute(protected_branch)