2013-06-23 16:47:22 +00:00
|
|
|
class Projects::ProtectedBranchesController < Projects::ApplicationController
|
2012-02-15 20:02:33 +00:00
|
|
|
# Authorize
|
2015-04-16 12:03:37 +00:00
|
|
|
before_action :require_non_empty_project
|
|
|
|
before_action :authorize_admin_project!
|
2016-06-16 07:33:30 +00:00
|
|
|
before_action :load_protected_branch, only: [:show, :update, :destroy]
|
2016-07-07 07:36:28 +00:00
|
|
|
before_action :load_protected_branches, only: [:index, :create]
|
2012-02-15 20:02:33 +00:00
|
|
|
|
2014-05-23 11:25:55 +00:00
|
|
|
layout "project_settings"
|
2012-02-15 21:51:04 +00:00
|
|
|
|
2012-02-15 20:02:33 +00:00
|
|
|
def index
|
|
|
|
@protected_branch = @project.protected_branches.new
|
2016-07-14 03:42:16 +00:00
|
|
|
gon.push({ open_branches: @project.open_branches.map { |br| { text: br.name, id: br.name, title: br.name } },
|
|
|
|
push_access_levels: ProtectedBranch::PushAccessLevel.human_access_levels.map { |id, text| { id: id, text: text } },
|
|
|
|
merge_access_levels: ProtectedBranch::MergeAccessLevel.human_access_levels.map { |id, text| { id: id, text: text } } })
|
2012-02-15 20:02:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2016-07-07 07:36:28 +00:00
|
|
|
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
|
2012-02-15 20:02:33 +00:00
|
|
|
end
|
|
|
|
|
2016-06-16 07:33:30 +00:00
|
|
|
def show
|
|
|
|
@matching_branches = @protected_branch.matching(@project.repository.branches)
|
|
|
|
end
|
2014-12-26 10:39:12 +00:00
|
|
|
|
2016-06-16 07:33:30 +00:00
|
|
|
def update
|
2016-07-07 07:36:28 +00:00
|
|
|
service = ProtectedBranches::UpdateService.new(@project, current_user, params[:id], protected_branch_params)
|
|
|
|
|
|
|
|
if service.execute
|
2014-12-26 14:37:04 +00:00
|
|
|
respond_to do |format|
|
2016-07-07 07:36:28 +00:00
|
|
|
format.json { render json: service.protected_branch, status: :ok }
|
2014-12-26 14:37:04 +00:00
|
|
|
end
|
|
|
|
else
|
|
|
|
respond_to do |format|
|
2016-07-07 07:36:28 +00:00
|
|
|
format.json { render json: service.protected_branch.errors, status: :unprocessable_entity }
|
2014-12-26 14:37:04 +00:00
|
|
|
end
|
2014-12-26 10:39:12 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-02-15 20:02:33 +00:00
|
|
|
def destroy
|
2016-06-16 07:33:30 +00:00
|
|
|
@protected_branch.destroy
|
2012-02-15 21:51:04 +00:00
|
|
|
|
|
|
|
respond_to do |format|
|
2015-01-24 18:02:58 +00:00
|
|
|
format.html { redirect_to namespace_project_protected_branches_path }
|
2016-03-16 01:16:25 +00:00
|
|
|
format.js { head :ok }
|
2012-02-15 21:51:04 +00:00
|
|
|
end
|
2012-02-15 20:02:33 +00:00
|
|
|
end
|
2014-06-26 12:00:09 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
2016-06-16 07:33:30 +00:00
|
|
|
def load_protected_branch
|
|
|
|
@protected_branch = @project.protected_branches.find(params[:id])
|
|
|
|
end
|
|
|
|
|
2014-06-26 12:00:09 +00:00
|
|
|
def protected_branch_params
|
2016-07-07 10:48:07 +00:00
|
|
|
params.require(:protected_branch).permit(:name, :allowed_to_push, :allowed_to_merge)
|
2014-06-26 12:00:09 +00:00
|
|
|
end
|
2016-07-07 07:36:28 +00:00
|
|
|
|
|
|
|
def load_protected_branches
|
|
|
|
@protected_branches = @project.protected_branches.order(:name).page(params[:page])
|
|
|
|
end
|
2012-02-15 20:02:33 +00:00
|
|
|
end
|