summaryrefslogtreecommitdiff
path: root/app/services/protected_refs/access_level_params.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-07-13 21:10:15 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-07-13 21:10:15 +0000
commita269fb8e7cca24b826dd3f53485641ffce93bbee (patch)
tree81a7c4f56feba26bb6244c8a3a76123533f68aa8 /app/services/protected_refs/access_level_params.rb
parent7e064974b92de60a3ef4642905e8af98a364a7a0 (diff)
downloadgitlab-ce-a269fb8e7cca24b826dd3f53485641ffce93bbee.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services/protected_refs/access_level_params.rb')
-rw-r--r--app/services/protected_refs/access_level_params.rb37
1 files changed, 37 insertions, 0 deletions
diff --git a/app/services/protected_refs/access_level_params.rb b/app/services/protected_refs/access_level_params.rb
new file mode 100644
index 00000000000..59fc17868d1
--- /dev/null
+++ b/app/services/protected_refs/access_level_params.rb
@@ -0,0 +1,37 @@
+# frozen_string_literal: true
+
+module ProtectedRefs
+ 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::MAINTAINER 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
+
+ProtectedRefs::AccessLevelParams.prepend_mod_with('ProtectedRefs::AccessLevelParams')