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:
authorTimothy Andrew <mail@timothyandrew.net>2016-07-07 10:36:28 +0300
committerTimothy Andrew <mail@timothyandrew.net>2016-07-29 12:50:39 +0300
commit134fe5af83167f95205a080f7932452de7d77496 (patch)
tree6f253ad95afc8fc0525c6501ce9345294dd1ff45 /app/controllers/projects/protected_branches_controller.rb
parent21bece443d5f871680a3d7649c2d16861035196d (diff)
Use the `{Push,Merge}AccessLevel` models in the UI.
1. Improve error handling while creating protected branches. 2. Modify coffeescript code so that the "Developers can *" checkboxes send a '1' or '0' even when using AJAX. This lets us keep the backend code simpler. 3. Use services for both creating and updating protected branches. Destruction is taken care of with `dependent: :destroy`
Diffstat (limited to 'app/controllers/projects/protected_branches_controller.rb')
-rw-r--r--app/controllers/projects/protected_branches_controller.rb24
1 files changed, 17 insertions, 7 deletions
diff --git a/app/controllers/projects/protected_branches_controller.rb b/app/controllers/projects/protected_branches_controller.rb
index 10dca47fded..fdbe0044d3c 100644
--- a/app/controllers/projects/protected_branches_controller.rb
+++ b/app/controllers/projects/protected_branches_controller.rb
@@ -3,19 +3,23 @@ class Projects::ProtectedBranchesController < Projects::ApplicationController
before_action :require_non_empty_project
before_action :authorize_admin_project!
before_action :load_protected_branch, only: [:show, :update, :destroy]
+ before_action :load_protected_branches, only: [:index, :create]
layout "project_settings"
def index
- @protected_branches = @project.protected_branches.order(:name).page(params[:page])
@protected_branch = @project.protected_branches.new
gon.push({ open_branches: @project.open_branches.map { |br| { text: br.name, id: br.name, title: br.name } } })
end
def create
- @project.protected_branches.create(protected_branch_params)
- redirect_to namespace_project_protected_branches_path(@project.namespace,
- @project)
+ service = ProtectedBranches::CreateService.new(@project, current_user, protected_branch_params)
+ if service.execute
+ redirect_to namespace_project_protected_branches_path(@project.namespace, @project)
+ else
+ @protected_branch = service.protected_branch
+ render :index
+ end
end
def show
@@ -23,13 +27,15 @@ class Projects::ProtectedBranchesController < Projects::ApplicationController
end
def update
- if @protected_branch && @protected_branch.update_attributes(protected_branch_params)
+ service = ProtectedBranches::UpdateService.new(@project, current_user, params[:id], protected_branch_params)
+
+ if service.execute
respond_to do |format|
- format.json { render json: @protected_branch, status: :ok }
+ format.json { render json: service.protected_branch, status: :ok }
end
else
respond_to do |format|
- format.json { render json: @protected_branch.errors, status: :unprocessable_entity }
+ format.json { render json: service.protected_branch.errors, status: :unprocessable_entity }
end
end
end
@@ -52,4 +58,8 @@ class Projects::ProtectedBranchesController < Projects::ApplicationController
def protected_branch_params
params.require(:protected_branch).permit(:name, :developers_can_push, :developers_can_merge)
end
+
+ def load_protected_branches
+ @protected_branches = @project.protected_branches.order(:name).page(params[:page])
+ end
end