Commit 0455391a authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Improve branch-removal logic

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent e089b11b
...@@ -4,8 +4,7 @@ class Projects::BranchesController < Projects::ApplicationController ...@@ -4,8 +4,7 @@ class Projects::BranchesController < Projects::ApplicationController
before_filter :require_non_empty_project before_filter :require_non_empty_project
before_filter :authorize_code_access! before_filter :authorize_code_access!
before_filter :authorize_push!, only: [:create] before_filter :authorize_push!, only: [:create, :destroy]
before_filter :authorize_admin_project!, only: [:destroy]
def index def index
@branches = Kaminari.paginate_array(@repository.branches).page(params[:page]).per(30) @branches = Kaminari.paginate_array(@repository.branches).page(params[:page]).per(30)
...@@ -22,11 +21,7 @@ class Projects::BranchesController < Projects::ApplicationController ...@@ -22,11 +21,7 @@ class Projects::BranchesController < Projects::ApplicationController
end end
def destroy def destroy
branch = @repository.find_branch(params[:id]) DeleteBranchService.new.execute(project, params[:id], current_user)
if branch && @repository.rm_branch(branch.name)
Event.create_ref_event(@project, current_user, branch, 'rm')
end
respond_to do |format| respond_to do |format|
format.html { redirect_to project_branches_path(@project) } format.html { redirect_to project_branches_path(@project) }
......
...@@ -8,6 +8,10 @@ class DeleteBranchService ...@@ -8,6 +8,10 @@ class DeleteBranchService
return error('No such branch') return error('No such branch')
end end
if branch_name == repository.root_ref
return error('Cannot remove HEAD branch')
end
# Dont allow remove of protected branch # Dont allow remove of protected branch
if project.protected_branch?(branch_name) if project.protected_branch?(branch_name)
return error('Protected branch cant be removed') return error('Protected branch cant be removed')
......
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
%i.icon-copy %i.icon-copy
Compare Compare
- if can?(current_user, :admin_project, @project) && branch.name != @repository.root_ref - if can_remove_branch?(@project, branch.name)
= link_to project_branch_path(@project, branch.name), class: 'btn btn-grouped btn-small remove-row', method: :delete, data: { confirm: 'Removed branch cannot be restored. Are you sure?'}, remote: true do = link_to project_branch_path(@project, branch.name), class: 'btn btn-grouped btn-small btn-remove remove-row', method: :delete, data: { confirm: 'Removed branch cannot be restored. Are you sure?'}, remote: true do
%i.icon-trash %i.icon-trash
- if commit - if commit
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment