2013-06-23 12:47:22 -04:00
|
|
|
class Projects::ProtectedBranchesController < Projects::ApplicationController
|
2012-02-15 15:02:33 -05:00
|
|
|
# Authorize
|
2015-04-16 08:03:37 -04:00
|
|
|
before_action :require_non_empty_project
|
|
|
|
before_action :authorize_admin_project!
|
2012-02-15 15:02:33 -05:00
|
|
|
|
2014-05-23 07:25:55 -04:00
|
|
|
layout "project_settings"
|
2012-02-15 16:51:04 -05:00
|
|
|
|
2012-02-15 15:02:33 -05:00
|
|
|
def index
|
2013-12-25 09:12:25 -05:00
|
|
|
@branches = @project.protected_branches.to_a
|
2012-02-15 15:02:33 -05:00
|
|
|
@protected_branch = @project.protected_branches.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2014-06-26 08:00:09 -04:00
|
|
|
@project.protected_branches.create(protected_branch_params)
|
2015-01-24 13:02:58 -05:00
|
|
|
redirect_to namespace_project_protected_branches_path(@project.namespace,
|
|
|
|
@project)
|
2012-02-15 15:02:33 -05:00
|
|
|
end
|
|
|
|
|
2014-12-26 05:39:12 -05:00
|
|
|
def update
|
|
|
|
protected_branch = @project.protected_branches.find(params[:id])
|
|
|
|
|
|
|
|
if protected_branch &&
|
|
|
|
protected_branch.update_attributes(
|
2015-12-14 21:53:52 -05:00
|
|
|
developers_can_push: params[:developers_can_push]
|
2014-12-26 05:39:12 -05:00
|
|
|
)
|
|
|
|
|
2014-12-26 09:37:04 -05:00
|
|
|
respond_to do |format|
|
2015-01-23 20:41:10 -05:00
|
|
|
format.json { render json: protected_branch, status: :ok }
|
2014-12-26 09:37:04 -05:00
|
|
|
end
|
|
|
|
else
|
|
|
|
respond_to do |format|
|
|
|
|
format.json { render json: protected_branch.errors, status: :unprocessable_entity }
|
|
|
|
end
|
2014-12-26 05:39:12 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-02-15 15:02:33 -05:00
|
|
|
def destroy
|
2012-02-15 16:51:04 -05:00
|
|
|
@project.protected_branches.find(params[:id]).destroy
|
|
|
|
|
|
|
|
respond_to do |format|
|
2015-01-24 13:02:58 -05:00
|
|
|
format.html { redirect_to namespace_project_protected_branches_path }
|
2012-08-10 18:07:50 -04:00
|
|
|
format.js { render nothing: true }
|
2012-02-15 16:51:04 -05:00
|
|
|
end
|
2012-02-15 15:02:33 -05:00
|
|
|
end
|
2014-06-26 08:00:09 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def protected_branch_params
|
2014-12-26 03:14:53 -05:00
|
|
|
params.require(:protected_branch).permit(:name, :developers_can_push)
|
2014-06-26 08:00:09 -04:00
|
|
|
end
|
2012-02-15 15:02:33 -05:00
|
|
|
end
|