diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2017-12-07 15:53:50 +0300 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2017-12-07 15:53:50 +0300 |
commit | 28c983db2353d7428f44dad2f8495e1028e360d1 (patch) | |
tree | 8b558c894f2e7f7efd85db37e6a9392d04ba0c95 /app/services | |
parent | 0054e1567b87795cc907232a4c1e9388be5c11a5 (diff) | |
parent | 1d47ae1365e259406233764885891923bebc555c (diff) |
Merge branch 'jej/per-user-protected-branches-api-ce' into 'master'
CE backport of "ProtectedBranches API handles per user/group granularity"
See merge request gitlab-org/gitlab-ce!15747
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/protected_branches/access_level_params.rb | 33 | ||||
-rw-r--r-- | app/services/protected_branches/api_service.rb | 24 |
2 files changed, 57 insertions, 0 deletions
diff --git a/app/services/protected_branches/access_level_params.rb b/app/services/protected_branches/access_level_params.rb new file mode 100644 index 00000000000..253ae8b0124 --- /dev/null +++ b/app/services/protected_branches/access_level_params.rb @@ -0,0 +1,33 @@ +module ProtectedBranches + class AccessLevelParams + attr_reader :type, :params + + def initialize(type, params) + @type = type + @params = params_with_default(params) + end + + def access_levels + ce_style_access_level + end + + private + + def params_with_default(params) + params[:"#{type}_access_level"] ||= Gitlab::Access::MASTER if use_default_access_level?(params) + params + end + + def use_default_access_level?(params) + true + end + + def ce_style_access_level + access_level = params[:"#{type}_access_level"] + + return [] unless access_level + + [{ access_level: access_level }] + end + end +end diff --git a/app/services/protected_branches/api_service.rb b/app/services/protected_branches/api_service.rb new file mode 100644 index 00000000000..4b40200644b --- /dev/null +++ b/app/services/protected_branches/api_service.rb @@ -0,0 +1,24 @@ +module ProtectedBranches + class ApiService < BaseService + def create + @push_params = AccessLevelParams.new(:push, params) + @merge_params = AccessLevelParams.new(:merge, params) + + verify_params! + + protected_branch_params = { + name: params[:name], + push_access_levels_attributes: @push_params.access_levels, + merge_access_levels_attributes: @merge_params.access_levels + } + + ::ProtectedBranches::CreateService.new(@project, @current_user, protected_branch_params).execute + end + + private + + def verify_params! + # EE-only + end + end +end |