debian-mirror-gitlab/app/controllers/projects/protected_branches_controller.rb

56 lines
1.7 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
class Projects::ProtectedBranchesController < Projects::ApplicationController
# Authorize
2015-09-11 14:41:01 +05:30
before_action :require_non_empty_project
before_action :authorize_admin_project!
2016-08-24 12:49:21 +05:30
before_action :load_protected_branch, only: [:show, :update, :destroy]
2014-09-02 18:07:02 +05:30
layout "project_settings"
def index
2016-08-24 12:49:21 +05:30
@protected_branches = @project.protected_branches.order(:name).page(params[:page])
2014-09-02 18:07:02 +05:30
@protected_branch = @project.protected_branches.new
2016-08-24 12:49:21 +05:30
gon.push({ open_branches: @project.open_branches.map { |br| { text: br.name, id: br.name, title: br.name } } })
2014-09-02 18:07:02 +05:30
end
def create
@project.protected_branches.create(protected_branch_params)
2015-04-26 12:48:37 +05:30
redirect_to namespace_project_protected_branches_path(@project.namespace,
@project)
end
2016-08-24 12:49:21 +05:30
def show
@matching_branches = @protected_branch.matching(@project.repository.branches)
end
2015-04-26 12:48:37 +05:30
2016-08-24 12:49:21 +05:30
def update
if @protected_branch && @protected_branch.update_attributes(protected_branch_params)
2015-04-26 12:48:37 +05:30
respond_to do |format|
2016-08-24 12:49:21 +05:30
format.json { render json: @protected_branch, status: :ok }
2015-04-26 12:48:37 +05:30
end
else
respond_to do |format|
2016-08-24 12:49:21 +05:30
format.json { render json: @protected_branch.errors, status: :unprocessable_entity }
2015-04-26 12:48:37 +05:30
end
end
2014-09-02 18:07:02 +05:30
end
def destroy
2016-08-24 12:49:21 +05:30
@protected_branch.destroy
2014-09-02 18:07:02 +05:30
respond_to do |format|
2015-04-26 12:48:37 +05:30
format.html { redirect_to namespace_project_protected_branches_path }
2016-06-02 11:05:42 +05:30
format.js { head :ok }
2014-09-02 18:07:02 +05:30
end
end
private
2016-08-24 12:49:21 +05:30
def load_protected_branch
@protected_branch = @project.protected_branches.find(params[:id])
end
2014-09-02 18:07:02 +05:30
def protected_branch_params
2016-08-24 12:49:21 +05:30
params.require(:protected_branch).permit(:name, :developers_can_push, :developers_can_merge)
2014-09-02 18:07:02 +05:30
end
end