summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-06-17 14:17:32 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-06-18 17:47:52 +0300
commite940fbc7c1b322c15f5d5ae878fbd3117e9b98f9 (patch)
tree385370e2caea4e562a563613581cc64258e5b9e0 /app
parentfa877b63126c84cb304228cf37b61d186d5e4477 (diff)
downloadgitlab-ce-e940fbc7c1b322c15f5d5ae878fbd3117e9b98f9.tar.gz
Add UsersGroup relation to be respected by abilities and Project#team
Diffstat (limited to 'app')
-rw-r--r--app/controllers/groups_controller.rb4
-rw-r--r--app/models/ability.rb4
-rw-r--r--app/models/project_team.rb24
-rw-r--r--app/models/users_group.rb2
-rw-r--r--app/models/users_project.rb4
-rw-r--r--app/services/system_hooks_service.rb2
-rw-r--r--app/views/groups/_new_group_member.html.haml4
-rw-r--r--app/views/groups/_new_member.html.haml6
-rw-r--r--app/views/groups/_people_filter.html.haml14
-rw-r--r--app/views/groups/people.html.haml18
10 files changed, 55 insertions, 27 deletions
diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb
index 9cbe6ec44f2..a191aff2b6b 100644
--- a/app/controllers/groups_controller.rb
+++ b/app/controllers/groups_controller.rb
@@ -64,11 +64,11 @@ class GroupsController < ApplicationController
def people
@project = group.projects.find(params[:project_id]) if params[:project_id]
- @users_groups = group.users_groups
-
if @project
+ @members = @project.users_projects
@team_member = @project.users_projects.new
else
+ @members = group.users_groups
@team_member = UsersGroup.new
end
end
diff --git a/app/models/ability.rb b/app/models/ability.rb
index 0199012d6fc..70a4435e699 100644
--- a/app/models/ability.rb
+++ b/app/models/ability.rb
@@ -50,6 +50,10 @@ class Ability
rules << project_admin_rules
end
+ if project.group && project.group.owners.include?(user)
+ rules << project_admin_rules
+ end
+
rules.flatten
end
diff --git a/app/models/project_team.rb b/app/models/project_team.rb
index f3e5c0e5354..d84d46431f5 100644
--- a/app/models/project_team.rb
+++ b/app/models/project_team.rb
@@ -47,23 +47,23 @@ class ProjectTeam
end
def members
- project.users_projects
+ fetch_members
end
def guests
- members.guests.map(&:user)
+ @guests ||= fetch_members(:guests)
end
def reporters
- members.reporters.map(&:user)
+ @reporters ||= fetch_members(:reporters)
end
def developers
- members.developers.map(&:user)
+ @developers ||= fetch_members(:developers)
end
def masters
- members.masters.map(&:user)
+ @masters ||= fetch_members(:masters)
end
def import(source_project)
@@ -96,4 +96,18 @@ class ProjectTeam
rescue
false
end
+
+ private
+
+ def fetch_members(level = nil)
+ project_members = project.users_projects
+ group_members = project.group.users_groups
+
+ if level
+ project_members = project_members.send(level)
+ group_members = group_members.send(level)
+ end
+
+ (project_members + group_members).map(&:user).uniq
+ end
end
diff --git a/app/models/users_group.rb b/app/models/users_group.rb
index 146b788c004..e9caa3fe705 100644
--- a/app/models/users_group.rb
+++ b/app/models/users_group.rb
@@ -35,7 +35,7 @@ class UsersGroup < ActiveRecord::Base
delegate :name, :username, :email, to: :user, prefix: true
- def human_group_access
+ def human_access
UsersGroup.group_access_roles.index(self.group_access)
end
end
diff --git a/app/models/users_project.rb b/app/models/users_project.rb
index 935ecede42c..4c58b009380 100644
--- a/app/models/users_project.rb
+++ b/app/models/users_project.rb
@@ -129,9 +129,7 @@ class UsersProject < ActiveRecord::Base
Project.access_options.key(self.project_access)
end
- def repo_access_human
- self.class.access_roles.invert[self.project_access]
- end
+ alias_method :human_access, :project_access_human
def skip_git?
!!@skip_git
diff --git a/app/services/system_hooks_service.rb b/app/services/system_hooks_service.rb
index a52d13d5237..01ddf99e97b 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.repo_access_human
+ project_access: model.project_access_human
})
end
end
diff --git a/app/views/groups/_new_group_member.html.haml b/app/views/groups/_new_group_member.html.haml
index 77dfda7e1d4..bc1b12f257d 100644
--- a/app/views/groups/_new_group_member.html.haml
+++ b/app/views/groups/_new_group_member.html.haml
@@ -1,8 +1,8 @@
= form_for @team_member, as: :team_member, url: team_members_group_path(@group) do |f|
%fieldset
- %legend= "New Team member(s) for projects in #{@group.name}"
+ %legend= "New Group member(s) for #{@group.name}"
- %h6 1. Choose people you want in the team
+ %h6 1. Choose people you want in the group
.clearfix
= f.label :user_ids, "People"
.input= users_select_tag(:user_ids, multiple: true)
diff --git a/app/views/groups/_new_member.html.haml b/app/views/groups/_new_member.html.haml
index 4a762ed39ed..70c3e8cd248 100644
--- a/app/views/groups/_new_member.html.haml
+++ b/app/views/groups/_new_member.html.haml
@@ -1,8 +1,8 @@
= form_for @team_member, as: :team_member, url: project_team_members_path(@project, @team_member) do |f|
%fieldset
- %legend= "New Team member(s) for #{@project.name}"
+ %legend= "New Project member(s) for #{@project.name}"
- %h6 1. Choose people you want in the team
+ %h6 1. Choose people you want in the project
.clearfix
= f.label :user_ids, "People"
.input= users_select_tag(:user_ids, multiple: true)
@@ -14,5 +14,5 @@
.form-actions
= hidden_field_tag :redirect_to, people_group_path(@group, project_id: @project.id)
- = f.submit 'Add', class: "btn btn-save"
+ = f.submit 'Add users into project', class: "btn btn-create"
diff --git a/app/views/groups/_people_filter.html.haml b/app/views/groups/_people_filter.html.haml
index ee63743eb4f..598b1e7b979 100644
--- a/app/views/groups/_people_filter.html.haml
+++ b/app/views/groups/_people_filter.html.haml
@@ -1,6 +1,15 @@
+%fieldset
+ %legend Group members:
+ %ul.nav.nav-pills.nav-stacked
+ %li{class: ("active" if params[:project_id].blank?)}
+ = link_to people_group_path(@group) do
+ #{@group.name} Group
+ %small.pull-right= @group.users.count
+
+
= form_tag people_group_path(@group), method: 'get' do
%fieldset
- %legend Projects:
+ %legend Project members:
%ul.nav.nav-pills.nav-stacked
- @projects.each do |project|
%li{class: ("active" if params[:project_id] == project.id.to_s)}
@@ -10,7 +19,4 @@
- if @projects.blank?
%p.nothing_here_message This group has no projects yet
- %fieldset
- %hr
- = link_to "Reset", people_group_path(@group), class: 'btn pull-right'
diff --git a/app/views/groups/people.html.haml b/app/views/groups/people.html.haml
index 965a761db1e..b55e1b1379e 100644
--- a/app/views/groups/people.html.haml
+++ b/app/views/groups/people.html.haml
@@ -6,12 +6,18 @@
= render (@project ? "new_member" : "new_group_member")
.ui-box
%h5.title
- #{@group.name} Team
- %small
- (#{@users_groups.count})
+ - if @project
+ #{@project.name} Project Members
+ %small
+ (#{@members.count})
+ - else
+ #{@group.name} Group Members
+ %small
+ (#{@members.count})
%ul.well-list
- - @users_groups.each do |users_group|
- - user = users_group.user
+ - @members.each do |member|
+ - user = member.user
+ - next unless user
%li
= image_tag gravatar_icon(user.email, 16), class: "avatar s16"
%strong= user.name
@@ -21,5 +27,5 @@
- if @group.owners.include?(user)
%span.label.label-info Group Owner
- else
- = users_group.human_group_access
+ = member.human_access