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!
|
2014-09-02 18:07:02 +05:30
|
|
|
|
|
|
|
layout "project_settings"
|
|
|
|
|
|
|
|
def index
|
|
|
|
@branches = @project.protected_branches.to_a
|
|
|
|
@protected_branch = @project.protected_branches.new
|
|
|
|
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
|
|
|
|
|
|
|
|
def update
|
|
|
|
protected_branch = @project.protected_branches.find(params[:id])
|
|
|
|
|
|
|
|
if protected_branch &&
|
|
|
|
protected_branch.update_attributes(
|
2015-12-23 02:04:40 +05:30
|
|
|
developers_can_push: params[:developers_can_push]
|
2015-04-26 12:48:37 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.json { render json: protected_branch, status: :ok }
|
|
|
|
end
|
|
|
|
else
|
|
|
|
respond_to do |format|
|
|
|
|
format.json { render json: protected_branch.errors, status: :unprocessable_entity }
|
|
|
|
end
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@project.protected_branches.find(params[:id]).destroy
|
|
|
|
|
|
|
|
respond_to do |format|
|
2015-04-26 12:48:37 +05:30
|
|
|
format.html { redirect_to namespace_project_protected_branches_path }
|
2014-09-02 18:07:02 +05:30
|
|
|
format.js { render nothing: true }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def protected_branch_params
|
2015-04-26 12:48:37 +05:30
|
|
|
params.require(:protected_branch).permit(:name, :developers_can_push)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|