-
Notifications
You must be signed in to change notification settings - Fork 117
/
Copy pathrepository_protected_branches_controller.rb
80 lines (63 loc) · 2.17 KB
/
repository_protected_branches_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
class RepositoryProtectedBranchesController < RedmineGitHostingController
include RedmineGitHosting::GitoliteAccessor::Methods
before_action :check_xitolite_permissions
before_action :find_repository_protected_branch, except: %i[index new create sort]
accept_api_auth :index, :show
def index
@repository_protected_branches = @repository.protected_branches.all
render_with_api
end
def new
@protected_branch = @repository.protected_branches.new
end
def create
@protected_branch = @repository.protected_branches.new
@protected_branch.safe_attributes = params[:repository_protected_branche]
return unless @protected_branch.save
check_members
flash[:notice] = l(:notice_protected_branch_created)
call_use_case_and_redirect
end
def update
@protected_branch.safe_attributes = params[:repository_protected_branche]
return unless @protected_branch.save
check_members
flash[:notice] = l(:notice_protected_branch_updated)
call_use_case_and_redirect
end
def destroy
return unless @protected_branch.destroy
flash[:notice] = l(:notice_protected_branch_deleted)
call_use_case_and_redirect
end
def clone
@protected_branch = RepositoryProtectedBranche.clone_from(params[:id])
render 'new'
end
def sort
params[:protected_branch].each_with_index do |id, index|
@repository.protected_branches.where(id: id).update_all(position: index + 1)
end
# Update Gitolite repository
call_use_case
head :ok
end
private
def set_current_tab
@tab = 'repository_protected_branches'
end
def find_repository_protected_branch
@protected_branch = @repository.protected_branches.find(params[:id])
rescue ActiveRecord::RecordNotFound
render_404
end
def call_use_case(opts = {})
options = opts.merge(message: "Update branch permissions for repository : '#{@repository.gitolite_repository_name}'")
gitolite_accessor.update_repository(@repository, options)
end
def check_members
member_manager = RepositoryProtectedBranches::MemberManager.new(@protected_branch)
member_manager.add_users(params[:user_ids])
member_manager.add_groups(params[:group_ids])
end
end