2013-07-16 15:19:07 -04:00
|
|
|
class Projects::BranchesController < Projects::ApplicationController
|
|
|
|
# Authorize
|
|
|
|
before_filter :authorize_read_project!
|
|
|
|
before_filter :require_non_empty_project
|
|
|
|
|
2013-07-17 01:26:00 -04:00
|
|
|
before_filter :authorize_code_access!
|
|
|
|
before_filter :authorize_push!, only: [:create]
|
|
|
|
before_filter :authorize_admin_project!, only: [:destroy]
|
2013-07-16 15:19:07 -04:00
|
|
|
|
|
|
|
def index
|
|
|
|
@branches = Kaminari.paginate_array(@repository.branches).page(params[:page]).per(30)
|
|
|
|
end
|
|
|
|
|
2013-08-05 10:59:58 -04:00
|
|
|
def recent
|
|
|
|
@branches = @repository.recent_branches
|
|
|
|
end
|
|
|
|
|
2013-07-16 15:19:07 -04:00
|
|
|
def create
|
2013-07-17 08:11:03 -04:00
|
|
|
@repository.add_branch(params[:branch_name], params[:ref])
|
|
|
|
|
|
|
|
if new_branch = @repository.find_branch(params[:branch_name])
|
|
|
|
Event.create_ref_event(@project, current_user, new_branch, 'add')
|
|
|
|
end
|
2013-07-16 17:09:23 -04:00
|
|
|
|
|
|
|
redirect_to project_branches_path(@project)
|
2013-07-16 15:19:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2013-07-17 08:11:03 -04:00
|
|
|
branch = @repository.find_branch(params[:id])
|
2013-07-16 15:43:14 -04:00
|
|
|
|
2013-07-17 08:11:03 -04:00
|
|
|
if branch && @repository.rm_branch(branch.name)
|
|
|
|
Event.create_ref_event(@project, current_user, branch, 'rm')
|
2013-07-16 15:43:14 -04:00
|
|
|
end
|
2013-07-16 15:19:07 -04:00
|
|
|
|
|
|
|
respond_to do |format|
|
2013-07-16 17:09:23 -04:00
|
|
|
format.html { redirect_to project_branches_path(@project) }
|
2013-07-16 15:19:07 -04:00
|
|
|
format.js { render nothing: true }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|