summaryrefslogtreecommitdiff
path: root/lib/api
diff options
context:
space:
mode:
authorTimothy Andrew <mail@timothyandrew.net>2016-07-25 20:14:53 +0530
committerTimothy Andrew <mail@timothyandrew.net>2016-07-29 15:20:39 +0530
commit01d190a84ad9b8e4a40cbdec8a55946bac38ab76 (patch)
tree74b06499ba066a8e6d4b9c0bf13b6a5166501980 /lib/api
parent88fd401d599f94bc4ea572cd47afa7d12c484db2 (diff)
downloadgitlab-ce-01d190a84ad9b8e4a40cbdec8a55946bac38ab76.tar.gz
Have the `branches` API work with the new protected branches data model.
1. The new data model moves from `developers_can_{push,merge}` to `allowed_to_{push,merge}`. 2. The API interface has not been changed. It still accepts `developers_can_push` and `developers_can_merge` as options. These attributes are inferred from the new data model. 3. Modify the protected branch create/update services to translate from the API interface to our current data model.
Diffstat (limited to 'lib/api')
-rw-r--r--lib/api/branches.rb29
-rw-r--r--lib/api/entities.rb6
2 files changed, 21 insertions, 14 deletions
diff --git a/lib/api/branches.rb b/lib/api/branches.rb
index 66b853eb342..4133a1f7a6b 100644
--- a/lib/api/branches.rb
+++ b/lib/api/branches.rb
@@ -35,6 +35,10 @@ module API
# Protect a single branch
#
+ # Note: The internal data model moved from `developers_can_{merge,push}` to `allowed_to_{merge,push}`
+ # in `gitlab-org/gitlab-ce!5081`. The API interface has not been changed (to maintain compatibility),
+ # but it works with the changed data model to infer `developers_can_merge` and `developers_can_push`.
+ #
# Parameters:
# id (required) - The ID of a project
# branch (required) - The name of the branch
@@ -49,18 +53,19 @@ module API
@branch = user_project.repository.find_branch(params[:branch])
not_found!('Branch') unless @branch
protected_branch = user_project.protected_branches.find_by(name: @branch.name)
- developers_can_push = to_boolean(params[:developers_can_push])
- developers_can_merge = to_boolean(params[:developers_can_merge])
-
- if protected_branch
- protected_branch.developers_can_push = developers_can_push unless developers_can_push.nil?
- protected_branch.developers_can_merge = developers_can_merge unless developers_can_merge.nil?
- protected_branch.save
- else
- user_project.protected_branches.create(name: @branch.name,
- developers_can_push: developers_can_push || false,
- developers_can_merge: developers_can_merge || false)
- end
+ protected_branch_params = {
+ name: @branch.name,
+ developers_can_push: params[:developers_can_push],
+ developers_can_merge: params[:developers_can_merge]
+ }
+
+ service = if protected_branch
+ ProtectedBranches::UpdateService.new(user_project, current_user, protected_branch.id, protected_branch_params)
+ else
+ ProtectedBranches::CreateService.new(user_project, current_user, protected_branch_params)
+ end
+
+ service.execute
present @branch, with: Entities::RepoBranch, project: user_project
end
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index e76e7304674..e51bee5c846 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -126,11 +126,13 @@ module API
end
expose :developers_can_push do |repo_branch, options|
- options[:project].developers_can_push_to_protected_branch? repo_branch.name
+ project = options[:project]
+ project.protected_branches.matching(repo_branch.name).any? { |protected_branch| protected_branch.push_access_level.developers? }
end
expose :developers_can_merge do |repo_branch, options|
- options[:project].developers_can_merge_to_protected_branch? repo_branch.name
+ project = options[:project]
+ project.protected_branches.matching(repo_branch.name).any? { |protected_branch| protected_branch.merge_access_level.developers? }
end
end