forgeplus/app/controllers/protected_branches_controll...

44 lines
1.1 KiB
Ruby
Raw Normal View History

2020-12-03 15:24:40 +08:00
class ProtectedBranchesController < ApplicationController
2020-12-04 11:06:12 +08:00
include OperateProjectAbilityAble
2020-12-03 15:24:40 +08:00
before_action :require_login
before_action :load_repository
2020-12-04 11:06:12 +08:00
before_action :authorizate_user_can_edit_project!
2020-12-03 15:24:40 +08:00
def index
scope = @repository.protected_branches
2020-12-03 15:24:40 +08:00
@total_count = scope.size
@protected_branches = paginate(scope)
end
def create
@protected_branch = ProtectedBranches::CreateService.call(@repository, @owner, params)
2020-12-04 11:06:12 +08:00
render_protected_branch_json
2020-12-03 15:24:40 +08:00
end
def update
@protected_branch = ProtectedBranches::UpdateService.call(@repository, @owner, params)
end
def destroy
ProtectedBranches::DestroyService.call(@repository, @owner, params[:branch_name])
render_ok
end
2020-12-04 11:06:12 +08:00
def show
@protected_branch = ProtectedBranches::GetService.call(@repository, @owner, params)
end
2020-12-04 16:18:27 +08:00
def edit
@branch, @protected_branch = ProtectedBranches::EditService.call(@repository, @owner, params[:branch_name])
end
2020-12-03 15:24:40 +08:00
private
def render_protected_branch_json
2020-12-04 11:06:12 +08:00
@protected_branch.persisted? ? @protected_branch : render_error('创建失败!')
2020-12-03 15:24:40 +08:00
end
end