summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-08-20 15:59:45 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-08-20 15:59:45 +0300
commit7a26a4b69ddf42c60aa406d10589a976ced0f6f3 (patch)
tree1cc77c7597722c0d5894abb46f6fe5cdc0a7b059
parenta442ad2b141e078fcc2899ece6068b82b5338bb8 (diff)
downloadgitlab-ce-7a26a4b69ddf42c60aa406d10589a976ced0f6f3.tar.gz
Refactor access roles methods
-rw-r--r--app/models/project.rb9
-rw-r--r--app/models/users_group.rb19
-rw-r--r--app/models/users_project.rb28
-rw-r--r--app/services/system_hooks_service.rb2
-rw-r--r--app/views/admin/projects/show.html.haml5
-rw-r--r--app/views/notify/project_access_granted_email.html.haml2
-rw-r--r--app/views/notify/project_access_granted_email.text.erb2
-rw-r--r--app/views/projects/team_members/_form.html.haml2
-rw-r--r--spec/mailers/notify_spec.rb2
9 files changed, 18 insertions, 53 deletions
diff --git a/app/models/project.rb b/app/models/project.rb
index de77bf1c666..d8e3bb6cad2 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -133,10 +133,6 @@ class Project < ActiveRecord::Base
where(path: id, namespace_id: nil).last
end
end
-
- def access_options
- UsersProject.access_roles
- end
end
def team
@@ -399,11 +395,6 @@ class Project < ActiveRecord::Base
http_url = [Gitlab.config.gitlab.url, "/", path_with_namespace, ".git"].join('')
end
- def project_access_human(member)
- project_user_relation = self.users_projects.find_by_user_id(member.id)
- self.class.access_options.key(project_user_relation.project_access)
- end
-
# Check if current branch name is marked as protected in the system
def protected_branch? branch_name
protected_branches_names.include?(branch_name)
diff --git a/app/models/users_group.rb b/app/models/users_group.rb
index b334066b8c8..3686551830d 100644
--- a/app/models/users_group.rb
+++ b/app/models/users_group.rb
@@ -12,21 +12,10 @@
class UsersGroup < ActiveRecord::Base
include Notifiable
-
- GUEST = 10
- REPORTER = 20
- DEVELOPER = 30
- MASTER = 40
- OWNER = 50
+ include Gitlab::Access
def self.group_access_roles
- {
- "Guest" => GUEST,
- "Reporter" => REPORTER,
- "Developer" => DEVELOPER,
- "Master" => MASTER,
- "Owner" => OWNER
- }
+ Gitlab::Access.options_with_owner
end
attr_accessible :group_access, :user_id
@@ -50,7 +39,7 @@ class UsersGroup < ActiveRecord::Base
delegate :name, :username, :email, to: :user, prefix: true
- def human_access
- UsersGroup.group_access_roles.key(self.group_access)
+ def access_field
+ group_access
end
end
diff --git a/app/models/users_project.rb b/app/models/users_project.rb
index 45e9305cafb..76f5685e047 100644
--- a/app/models/users_project.rb
+++ b/app/models/users_project.rb
@@ -14,11 +14,7 @@
class UsersProject < ActiveRecord::Base
include Gitlab::ShellAdapter
include Notifiable
-
- GUEST = 10
- REPORTER = 20
- DEVELOPER = 30
- MASTER = 40
+ include Gitlab::Access
attr_accessible :user, :user_id, :project_access
@@ -27,7 +23,7 @@ class UsersProject < ActiveRecord::Base
validates :user, presence: true
validates :user_id, uniqueness: { scope: [:project_id], message: "already exists in project" }
- validates :project_access, inclusion: { in: [GUEST, REPORTER, DEVELOPER, MASTER] }, presence: true
+ validates :project_access, inclusion: { in: Gitlab::Access.values }, presence: true
validates :project, presence: true
delegate :name, :username, :email, to: :user, prefix: true
@@ -103,27 +99,15 @@ class UsersProject < ActiveRecord::Base
end
def roles_hash
- {
- guest: GUEST,
- reporter: REPORTER,
- developer: DEVELOPER,
- master: MASTER
- }
+ Gitlab::Access.sym_options
end
def access_roles
- {
- "Guest" => GUEST,
- "Reporter" => REPORTER,
- "Developer" => DEVELOPER,
- "Master" => MASTER
- }
+ Gitlab::Access.options
end
end
- def project_access_human
- Project.access_options.key(self.project_access)
+ def access_field
+ project_access
end
-
- alias_method :human_access, :project_access_human
end
diff --git a/app/services/system_hooks_service.rb b/app/services/system_hooks_service.rb
index 01ddf99e97b..c872b27ba39 100644
--- a/app/services/system_hooks_service.rb
+++ b/app/services/system_hooks_service.rb
@@ -43,7 +43,7 @@ class SystemHooksService
project_id: model.project_id,
user_name: model.user.name,
user_email: model.user.email,
- project_access: model.project_access_human
+ project_access: model.human_access
})
end
end
diff --git a/app/views/admin/projects/show.html.haml b/app/views/admin/projects/show.html.haml
index 70f0c193c01..800f91d2a86 100644
--- a/app/views/admin/projects/show.html.haml
+++ b/app/views/admin/projects/show.html.haml
@@ -96,11 +96,12 @@
%i.icon-edit
Manage Access
%ul.well-list.team_members
- - @project.users.each do |user|
+ - @project.users_projects.each do |users_project|
+ - user = users_project.user
%li
%strong
= link_to user.name, admin_user_path(user)
.pull-right
- %span.light= @project.project_access_human(user)
+ %span.light= users_project.human_access
= 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
%i.icon-remove
diff --git a/app/views/notify/project_access_granted_email.html.haml b/app/views/notify/project_access_granted_email.html.haml
index b4b44eafe2c..ce34f825358 100644
--- a/app/views/notify/project_access_granted_email.html.haml
+++ b/app/views/notify/project_access_granted_email.html.haml
@@ -1,5 +1,5 @@
%p
- = "You have been granted #{@users_project.project_access_human} access to project"
+ = "You have been granted #{@users_project.human_access} access to project"
%p
= link_to project_url(@project) do
= @project.name_with_namespace
diff --git a/app/views/notify/project_access_granted_email.text.erb b/app/views/notify/project_access_granted_email.text.erb
index 077c3b8a7de..66c57def375 100644
--- a/app/views/notify/project_access_granted_email.text.erb
+++ b/app/views/notify/project_access_granted_email.text.erb
@@ -1,4 +1,4 @@
-You have been granted <%= @users_project.project_access_human %> access to project <%= @project.name_with_namespace %>
+You have been granted <%= @users_project.human_access %> access to project <%= @project.name_with_namespace %>
<%= url_for(project_url(@project)) %>
diff --git a/app/views/projects/team_members/_form.html.haml b/app/views/projects/team_members/_form.html.haml
index 8dd2faa219b..f96fa217fa3 100644
--- a/app/views/projects/team_members/_form.html.haml
+++ b/app/views/projects/team_members/_form.html.haml
@@ -17,7 +17,7 @@
%h6 2. Set access level for them
.control-group
= f.label :project_access, "Project Access"
- .controls= select_tag :project_access, options_for_select(Project.access_options, @user_project_relation.project_access), class: "project-access-select chosen"
+ .controls= select_tag :project_access, options_for_select(Gitlab::Access.options, @user_project_relation.project_access), class: "project-access-select chosen"
.form-actions
= f.submit 'Add users', class: "btn btn-create"
diff --git a/spec/mailers/notify_spec.rb b/spec/mailers/notify_spec.rb
index d89029276d8..a91bc9d75ad 100644
--- a/spec/mailers/notify_spec.rb
+++ b/spec/mailers/notify_spec.rb
@@ -250,7 +250,7 @@ describe Notify do
should have_body_text /#{project.name}/
end
it 'contains new user role' do
- should have_body_text /#{users_project.project_access_human}/
+ should have_body_text /#{users_project.human_access}/
end
end