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,10 +133,6 @@ class Project < ActiveRecord::Base | ||
| 133 | where(path: id, namespace_id: nil).last | 133 | where(path: id, namespace_id: nil).last |
| 134 | end | 134 | end |
| 135 | end | 135 | end |
| 136 | - | ||
| 137 | - def access_options | ||
| 138 | - UsersProject.access_roles | ||
| 139 | - end | ||
| 140 | end | 136 | end |
| 141 | 137 | ||
| 142 | def team | 138 | def team |
| @@ -399,11 +395,6 @@ class Project < ActiveRecord::Base | @@ -399,11 +395,6 @@ class Project < ActiveRecord::Base | ||
| 399 | http_url = [Gitlab.config.gitlab.url, "/", path_with_namespace, ".git"].join('') | 395 | http_url = [Gitlab.config.gitlab.url, "/", path_with_namespace, ".git"].join('') |
| 400 | end | 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 | # Check if current branch name is marked as protected in the system | 398 | # Check if current branch name is marked as protected in the system |
| 408 | def protected_branch? branch_name | 399 | def protected_branch? branch_name |
| 409 | protected_branches_names.include?(branch_name) | 400 | protected_branches_names.include?(branch_name) |
app/models/users_group.rb
| @@ -12,21 +12,10 @@ | @@ -12,21 +12,10 @@ | ||
| 12 | 12 | ||
| 13 | class UsersGroup < ActiveRecord::Base | 13 | class UsersGroup < ActiveRecord::Base |
| 14 | include Notifiable | 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 | def self.group_access_roles | 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 | end | 19 | end |
| 31 | 20 | ||
| 32 | attr_accessible :group_access, :user_id | 21 | attr_accessible :group_access, :user_id |
| @@ -50,7 +39,7 @@ class UsersGroup < ActiveRecord::Base | @@ -50,7 +39,7 @@ class UsersGroup < ActiveRecord::Base | ||
| 50 | 39 | ||
| 51 | delegate :name, :username, :email, to: :user, prefix: true | 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 | end | 44 | end |
| 56 | end | 45 | end |
app/models/users_project.rb
| @@ -14,11 +14,7 @@ | @@ -14,11 +14,7 @@ | ||
| 14 | class UsersProject < ActiveRecord::Base | 14 | class UsersProject < ActiveRecord::Base |
| 15 | include Gitlab::ShellAdapter | 15 | include Gitlab::ShellAdapter |
| 16 | include Notifiable | 16 | include Notifiable |
| 17 | - | ||
| 18 | - GUEST = 10 | ||
| 19 | - REPORTER = 20 | ||
| 20 | - DEVELOPER = 30 | ||
| 21 | - MASTER = 40 | 17 | + include Gitlab::Access |
| 22 | 18 | ||
| 23 | attr_accessible :user, :user_id, :project_access | 19 | attr_accessible :user, :user_id, :project_access |
| 24 | 20 | ||
| @@ -27,7 +23,7 @@ class UsersProject < ActiveRecord::Base | @@ -27,7 +23,7 @@ class UsersProject < ActiveRecord::Base | ||
| 27 | 23 | ||
| 28 | validates :user, presence: true | 24 | validates :user, presence: true |
| 29 | validates :user_id, uniqueness: { scope: [:project_id], message: "already exists in project" } | 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 | validates :project, presence: true | 27 | validates :project, presence: true |
| 32 | 28 | ||
| 33 | delegate :name, :username, :email, to: :user, prefix: true | 29 | delegate :name, :username, :email, to: :user, prefix: true |
| @@ -103,27 +99,15 @@ class UsersProject < ActiveRecord::Base | @@ -103,27 +99,15 @@ class UsersProject < ActiveRecord::Base | ||
| 103 | end | 99 | end |
| 104 | 100 | ||
| 105 | def roles_hash | 101 | def roles_hash |
| 106 | - { | ||
| 107 | - guest: GUEST, | ||
| 108 | - reporter: REPORTER, | ||
| 109 | - developer: DEVELOPER, | ||
| 110 | - master: MASTER | ||
| 111 | - } | 102 | + Gitlab::Access.sym_options |
| 112 | end | 103 | end |
| 113 | 104 | ||
| 114 | def access_roles | 105 | def access_roles |
| 115 | - { | ||
| 116 | - "Guest" => GUEST, | ||
| 117 | - "Reporter" => REPORTER, | ||
| 118 | - "Developer" => DEVELOPER, | ||
| 119 | - "Master" => MASTER | ||
| 120 | - } | 106 | + Gitlab::Access.options |
| 121 | end | 107 | end |
| 122 | end | 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 | end | 112 | end |
| 127 | - | ||
| 128 | - alias_method :human_access, :project_access_human | ||
| 129 | end | 113 | end |
app/services/system_hooks_service.rb
| @@ -43,7 +43,7 @@ class SystemHooksService | @@ -43,7 +43,7 @@ class SystemHooksService | ||
| 43 | project_id: model.project_id, | 43 | project_id: model.project_id, |
| 44 | user_name: model.user.name, | 44 | user_name: model.user.name, |
| 45 | user_email: model.user.email, | 45 | user_email: model.user.email, |
| 46 | - project_access: model.project_access_human | 46 | + project_access: model.human_access |
| 47 | }) | 47 | }) |
| 48 | end | 48 | end |
| 49 | end | 49 | end |
app/views/admin/projects/show.html.haml
| @@ -96,11 +96,12 @@ | @@ -96,11 +96,12 @@ | ||
| 96 | %i.icon-edit | 96 | %i.icon-edit |
| 97 | Manage Access | 97 | Manage Access |
| 98 | %ul.well-list.team_members | 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 | %li | 101 | %li |
| 101 | %strong | 102 | %strong |
| 102 | = link_to user.name, admin_user_path(user) | 103 | = link_to user.name, admin_user_path(user) |
| 103 | .pull-right | 104 | .pull-right |
| 104 | - %span.light= @project.project_access_human(user) | 105 | + %span.light= users_project.human_access |
| 105 | = 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 | = 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 | %i.icon-remove | 107 | %i.icon-remove |
app/views/notify/project_access_granted_email.html.haml
| 1 | %p | 1 | %p |
| 2 | - = "You have been granted #{@users_project.project_access_human} access to project" | 2 | + = "You have been granted #{@users_project.human_access} access to project" |
| 3 | %p | 3 | %p |
| 4 | = link_to project_url(@project) do | 4 | = link_to project_url(@project) do |
| 5 | = @project.name_with_namespace | 5 | = @project.name_with_namespace |
app/views/notify/project_access_granted_email.text.erb
| 1 | 1 | ||
| 2 | -You have been granted <%= @users_project.project_access_human %> access to project <%= @project.name_with_namespace %> | 2 | +You have been granted <%= @users_project.human_access %> access to project <%= @project.name_with_namespace %> |
| 3 | 3 | ||
| 4 | <%= url_for(project_url(@project)) %> | 4 | <%= url_for(project_url(@project)) %> |
app/views/projects/team_members/_form.html.haml
| @@ -17,7 +17,7 @@ | @@ -17,7 +17,7 @@ | ||
| 17 | %h6 2. Set access level for them | 17 | %h6 2. Set access level for them |
| 18 | .control-group | 18 | .control-group |
| 19 | = f.label :project_access, "Project Access" | 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 | .form-actions | 22 | .form-actions |
| 23 | = f.submit 'Add users', class: "btn btn-create" | 23 | = f.submit 'Add users', class: "btn btn-create" |
spec/mailers/notify_spec.rb
| @@ -250,7 +250,7 @@ describe Notify do | @@ -250,7 +250,7 @@ describe Notify do | ||
| 250 | should have_body_text /#{project.name}/ | 250 | should have_body_text /#{project.name}/ |
| 251 | end | 251 | end |
| 252 | it 'contains new user role' do | 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 | end | 254 | end |
| 255 | end | 255 | end |
| 256 | 256 |