2013-06-23 12:47:22 -04:00
|
|
|
class Projects::ProtectedBranchesController < Projects::ApplicationController
|
2012-02-15 15:02:33 -05:00
|
|
|
# Authorize
|
|
|
|
before_filter :require_non_empty_project
|
2014-05-23 07:25:55 -04:00
|
|
|
before_filter :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)
|
2012-02-15 15:02:33 -05:00
|
|
|
redirect_to project_protected_branches_path(@project)
|
|
|
|
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(
|
|
|
|
developers_can_push: params[:developers_can_push]
|
|
|
|
)
|
|
|
|
|
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|
|
|
|
|
format.html { redirect_to 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
|