Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/services')
-rw-r--r--app/services/protected_branches/base_service.rb17
-rw-r--r--app/services/protected_branches/create_service.rb19
-rw-r--r--app/services/protected_branches/update_service.rb21
3 files changed, 57 insertions, 0 deletions
diff --git a/app/services/protected_branches/base_service.rb b/app/services/protected_branches/base_service.rb
new file mode 100644
index 00000000000..d4be8698a5f
--- /dev/null
+++ b/app/services/protected_branches/base_service.rb
@@ -0,0 +1,17 @@
+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'
+ @protected_branch.merge_access_level.masters!
+ elsif params[:developers_can_merge] == '1'
+ @protected_branch.merge_access_level.developers!
+ end
+ end
+ end
+end
diff --git a/app/services/protected_branches/create_service.rb b/app/services/protected_branches/create_service.rb
new file mode 100644
index 00000000000..743f7bd2ce1
--- /dev/null
+++ b/app/services/protected_branches/create_service.rb
@@ -0,0 +1,19 @@
+class ProtectedBranches::CreateService < BaseService
+ attr_reader :protected_branch
+
+ 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!
+
+ set_access_levels!
+ end
+
+ true
+ rescue ActiveRecord::RecordInvalid
+ false
+ end
+end
diff --git a/app/services/protected_branches/update_service.rb b/app/services/protected_branches/update_service.rb
new file mode 100644
index 00000000000..ed59b06b79a
--- /dev/null
+++ b/app/services/protected_branches/update_service.rb
@@ -0,0 +1,21 @@
+module ProtectedBranches
+ class UpdateService < BaseService
+ attr_reader :protected_branch
+
+ def initialize(project, current_user, id, params = {})
+ super(project, current_user, params)
+ @id = id
+ end
+
+ def execute
+ ProtectedBranch.transaction do
+ @protected_branch = ProtectedBranch.find(@id)
+ set_access_levels!
+ end
+
+ true
+ rescue ActiveRecord::RecordInvalid
+ false
+ end
+ end
+end