summaryrefslogtreecommitdiff
path: root/app/services
diff options
context:
space:
mode:
authorTimothy Andrew <mail@timothyandrew.net>2016-07-07 16:18:07 +0530
committerTimothy Andrew <mail@timothyandrew.net>2016-07-29 15:20:39 +0530
commitab6096c17261605d835a4a8edae21f31d90026df (patch)
tree0a4490cc0a62b86bf240fbc5bdff709b2e8d11b0 /app/services
parentf8a04e15371815ad39e2c66056db4ab0439555f4 (diff)
downloadgitlab-ce-ab6096c17261605d835a4a8edae21f31d90026df.tar.gz
Add "No One Can Push" to the protected branches UI.
1. Move to dropdowns instead of checkboxes. One each for "Allowed to Push" and "Allowed to Merge" 2. Refactor the `ProtectedBranches` coffeescript class into `ProtectedBranchesAccessSelect`. 3. Modify the backend to accept the new parameters.
Diffstat (limited to 'app/services')
-rw-r--r--app/services/protected_branches/base_service.rb20
-rw-r--r--app/services/protected_branches/create_service.rb28
2 files changed, 27 insertions, 21 deletions
diff --git a/app/services/protected_branches/base_service.rb b/app/services/protected_branches/base_service.rb
index d4be8698a5f..3a7c35327fe 100644
--- a/app/services/protected_branches/base_service.rb
+++ b/app/services/protected_branches/base_service.rb
@@ -1,17 +1,21 @@
module ProtectedBranches
class BaseService < ::BaseService
def set_access_levels!
- if params[:developers_can_push] == '0'
- @protected_branch.push_access_level.masters!
- elsif params[:developers_can_push] == '1'
- @protected_branch.push_access_level.developers!
- end
-
- if params[:developers_can_merge] == '0'
+ case params[:allowed_to_merge]
+ when 'masters'
@protected_branch.merge_access_level.masters!
- elsif params[:developers_can_merge] == '1'
+ when 'developers'
@protected_branch.merge_access_level.developers!
end
+
+ case params[:allowed_to_push]
+ when 'masters'
+ @protected_branch.push_access_level.masters!
+ when 'developers'
+ @protected_branch.push_access_level.developers!
+ when 'no_one'
+ @protected_branch.push_access_level.no_one!
+ end
end
end
end
diff --git a/app/services/protected_branches/create_service.rb b/app/services/protected_branches/create_service.rb
index 743f7bd2ce1..ab462f3054e 100644
--- a/app/services/protected_branches/create_service.rb
+++ b/app/services/protected_branches/create_service.rb
@@ -1,19 +1,21 @@
-class ProtectedBranches::CreateService < BaseService
- attr_reader :protected_branch
+module ProtectedBranches
+ class CreateService < BaseService
+ attr_reader :protected_branch
- def execute
- ProtectedBranch.transaction do
- @protected_branch = project.protected_branches.new(name: params[:name])
- @protected_branch.save!
+ def execute
+ ProtectedBranch.transaction do
+ @protected_branch = project.protected_branches.new(name: params[:name])
+ @protected_branch.save!
- @protected_branch.create_push_access_level!
- @protected_branch.create_merge_access_level!
+ @protected_branch.create_push_access_level!
+ @protected_branch.create_merge_access_level!
- set_access_levels!
- end
+ set_access_levels!
+ end
- true
- rescue ActiveRecord::RecordInvalid
- false
+ true
+ rescue ActiveRecord::RecordInvalid
+ false
+ end
end
end