2013-06-23 16:47:22 +00:00
|
|
|
class Projects::ProtectedBranchesController < Projects::ApplicationController
|
2017-03-03 17:41:15 +00:00
|
|
|
include RepositorySettingsRedirect
|
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]
|
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
|
2017-02-21 21:37:00 +00:00
|
|
|
redirect_to_repository_settings(@project)
|
2012-02-15 20:02:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2016-08-16 05:09:13 +00:00
|
|
|
@protected_branch = ::ProtectedBranches::CreateService.new(@project, current_user, protected_branch_params).execute
|
2017-01-30 19:21:02 +00:00
|
|
|
unless @protected_branch.persisted?
|
2017-02-21 21:37:00 +00:00
|
|
|
flash[:alert] = @protected_branches.errors.full_messages.join(', ').html_safe
|
2016-07-07 07:36:28 +00:00
|
|
|
end
|
2017-02-21 21:37:00 +00:00
|
|
|
redirect_to_repository_settings(@project)
|
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-08-16 05:09:13 +00:00
|
|
|
@protected_branch = ::ProtectedBranches::UpdateService.new(@project, current_user, protected_branch_params).execute(@protected_branch)
|
2016-07-07 07:36:28 +00:00
|
|
|
|
2016-07-29 06:13:07 +00:00
|
|
|
if @protected_branch.valid?
|
2014-12-26 14:37:04 +00:00
|
|
|
respond_to do |format|
|
2016-07-29 06:13:07 +00:00
|
|
|
format.json { render json: @protected_branch, status: :ok }
|
2014-12-26 14:37:04 +00:00
|
|
|
end
|
|
|
|
else
|
|
|
|
respond_to do |format|
|
2016-07-29 06:13:07 +00:00
|
|
|
format.json { render json: @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|
|
2017-02-21 21:37:00 +00:00
|
|
|
format.html { redirect_to_repository_settings(@project) }
|
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-29 06:13:07 +00:00
|
|
|
params.require(:protected_branch).permit(:name,
|
2016-08-16 05:09:13 +00:00
|
|
|
merge_access_levels_attributes: [:access_level, :id],
|
|
|
|
push_access_levels_attributes: [:access_level, :id])
|
2014-06-26 12:00:09 +00:00
|
|
|
end
|
2012-02-15 20:02:33 +00:00
|
|
|
end
|