Commit 7a26a4b69ddf42c60aa406d10589a976ced0f6f3
1 parent
a442ad2b
Exists in
master
and in
4 other branches
Refactor access roles methods
Showing
9 changed files
with
18 additions
and
53 deletions
Show diff stats
app/models/project.rb
... | ... | @@ -133,10 +133,6 @@ class Project < ActiveRecord::Base |
133 | 133 | where(path: id, namespace_id: nil).last |
134 | 134 | end |
135 | 135 | end |
136 | - | |
137 | - def access_options | |
138 | - UsersProject.access_roles | |
139 | - end | |
140 | 136 | end |
141 | 137 | |
142 | 138 | def team |
... | ... | @@ -399,11 +395,6 @@ class Project < ActiveRecord::Base |
399 | 395 | http_url = [Gitlab.config.gitlab.url, "/", path_with_namespace, ".git"].join('') |
400 | 396 | end |
401 | 397 | |
402 | - def project_access_human(member) | |
403 | - project_user_relation = self.users_projects.find_by_user_id(member.id) | |
404 | - self.class.access_options.key(project_user_relation.project_access) | |
405 | - end | |
406 | - | |
407 | 398 | # Check if current branch name is marked as protected in the system |
408 | 399 | def protected_branch? branch_name |
409 | 400 | protected_branches_names.include?(branch_name) | ... | ... |
app/models/users_group.rb
... | ... | @@ -12,21 +12,10 @@ |
12 | 12 | |
13 | 13 | class UsersGroup < ActiveRecord::Base |
14 | 14 | include Notifiable |
15 | - | |
16 | - GUEST = 10 | |
17 | - REPORTER = 20 | |
18 | - DEVELOPER = 30 | |
19 | - MASTER = 40 | |
20 | - OWNER = 50 | |
15 | + include Gitlab::Access | |
21 | 16 | |
22 | 17 | def self.group_access_roles |
23 | - { | |
24 | - "Guest" => GUEST, | |
25 | - "Reporter" => REPORTER, | |
26 | - "Developer" => DEVELOPER, | |
27 | - "Master" => MASTER, | |
28 | - "Owner" => OWNER | |
29 | - } | |
18 | + Gitlab::Access.options_with_owner | |
30 | 19 | end |
31 | 20 | |
32 | 21 | attr_accessible :group_access, :user_id |
... | ... | @@ -50,7 +39,7 @@ class UsersGroup < ActiveRecord::Base |
50 | 39 | |
51 | 40 | delegate :name, :username, :email, to: :user, prefix: true |
52 | 41 | |
53 | - def human_access | |
54 | - UsersGroup.group_access_roles.key(self.group_access) | |
42 | + def access_field | |
43 | + group_access | |
55 | 44 | end |
56 | 45 | end | ... | ... |
app/models/users_project.rb
... | ... | @@ -14,11 +14,7 @@ |
14 | 14 | class UsersProject < ActiveRecord::Base |
15 | 15 | include Gitlab::ShellAdapter |
16 | 16 | include Notifiable |
17 | - | |
18 | - GUEST = 10 | |
19 | - REPORTER = 20 | |
20 | - DEVELOPER = 30 | |
21 | - MASTER = 40 | |
17 | + include Gitlab::Access | |
22 | 18 | |
23 | 19 | attr_accessible :user, :user_id, :project_access |
24 | 20 | |
... | ... | @@ -27,7 +23,7 @@ class UsersProject < ActiveRecord::Base |
27 | 23 | |
28 | 24 | validates :user, presence: true |
29 | 25 | validates :user_id, uniqueness: { scope: [:project_id], message: "already exists in project" } |
30 | - validates :project_access, inclusion: { in: [GUEST, REPORTER, DEVELOPER, MASTER] }, presence: true | |
26 | + validates :project_access, inclusion: { in: Gitlab::Access.values }, presence: true | |
31 | 27 | validates :project, presence: true |
32 | 28 | |
33 | 29 | delegate :name, :username, :email, to: :user, prefix: true |
... | ... | @@ -103,27 +99,15 @@ class UsersProject < ActiveRecord::Base |
103 | 99 | end |
104 | 100 | |
105 | 101 | def roles_hash |
106 | - { | |
107 | - guest: GUEST, | |
108 | - reporter: REPORTER, | |
109 | - developer: DEVELOPER, | |
110 | - master: MASTER | |
111 | - } | |
102 | + Gitlab::Access.sym_options | |
112 | 103 | end |
113 | 104 | |
114 | 105 | def access_roles |
115 | - { | |
116 | - "Guest" => GUEST, | |
117 | - "Reporter" => REPORTER, | |
118 | - "Developer" => DEVELOPER, | |
119 | - "Master" => MASTER | |
120 | - } | |
106 | + Gitlab::Access.options | |
121 | 107 | end |
122 | 108 | end |
123 | 109 | |
124 | - def project_access_human | |
125 | - Project.access_options.key(self.project_access) | |
110 | + def access_field | |
111 | + project_access | |
126 | 112 | end |
127 | - | |
128 | - alias_method :human_access, :project_access_human | |
129 | 113 | end | ... | ... |
app/services/system_hooks_service.rb
app/views/admin/projects/show.html.haml
... | ... | @@ -96,11 +96,12 @@ |
96 | 96 | %i.icon-edit |
97 | 97 | Manage Access |
98 | 98 | %ul.well-list.team_members |
99 | - - @project.users.each do |user| | |
99 | + - @project.users_projects.each do |users_project| | |
100 | + - user = users_project.user | |
100 | 101 | %li |
101 | 102 | %strong |
102 | 103 | = link_to user.name, admin_user_path(user) |
103 | 104 | .pull-right |
104 | - %span.light= @project.project_access_human(user) | |
105 | + %span.light= users_project.human_access | |
105 | 106 | = link_to admin_project_member_path(@project, user), confirm: remove_from_project_team_message(@project, user), method: :delete, class: "btn btn-small btn-remove" do |
106 | 107 | %i.icon-remove | ... | ... |
app/views/notify/project_access_granted_email.html.haml
app/views/notify/project_access_granted_email.text.erb
app/views/projects/team_members/_form.html.haml
... | ... | @@ -17,7 +17,7 @@ |
17 | 17 | %h6 2. Set access level for them |
18 | 18 | .control-group |
19 | 19 | = f.label :project_access, "Project Access" |
20 | - .controls= select_tag :project_access, options_for_select(Project.access_options, @user_project_relation.project_access), class: "project-access-select chosen" | |
20 | + .controls= select_tag :project_access, options_for_select(Gitlab::Access.options, @user_project_relation.project_access), class: "project-access-select chosen" | |
21 | 21 | |
22 | 22 | .form-actions |
23 | 23 | = f.submit 'Add users', class: "btn btn-create" | ... | ... |
spec/mailers/notify_spec.rb
... | ... | @@ -250,7 +250,7 @@ describe Notify do |
250 | 250 | should have_body_text /#{project.name}/ |
251 | 251 | end |
252 | 252 | it 'contains new user role' do |
253 | - should have_body_text /#{users_project.project_access_human}/ | |
253 | + should have_body_text /#{users_project.human_access}/ | |
254 | 254 | end |
255 | 255 | end |
256 | 256 | ... | ... |