Commit 9c574464a6051536ee83a93e8270a7dd9d85da33
1 parent
17ea019f
Exists in
master
and in
4 other branches
Add functional in admin section
Showing
7 changed files
with
103 additions
and
16 deletions
Show diff stats
app/controllers/admin/groups_controller.rb
1 | 1 | class Admin::GroupsController < AdminController |
2 | - before_filter :group, only: [:edit, :show, :update, :destroy, :project_update] | |
2 | + before_filter :group, only: [:edit, :show, :update, :destroy, :project_update, :project_teams_update] | |
3 | 3 | |
4 | 4 | def index |
5 | 5 | @groups = Group.order('name ASC') |
... | ... | @@ -12,6 +12,8 @@ class Admin::GroupsController < AdminController |
12 | 12 | @projects = @projects.not_in_group(@group) if @group.projects.present? |
13 | 13 | @projects = @projects.all |
14 | 14 | @projects.reject!(&:empty_repo?) |
15 | + | |
16 | + @users = User.active | |
15 | 17 | end |
16 | 18 | |
17 | 19 | def new |
... | ... | @@ -65,6 +67,13 @@ class Admin::GroupsController < AdminController |
65 | 67 | redirect_to :back, notice: 'Group was successfully updated.' |
66 | 68 | end |
67 | 69 | |
70 | + def project_teams_update | |
71 | + @group.projects.each do |p| | |
72 | + p.add_users_ids_to_team(params[:user_ids], params[:project_access]) | |
73 | + end | |
74 | + redirect_to [:admin, @group], notice: 'Users was successfully added.' | |
75 | + end | |
76 | + | |
68 | 77 | def destroy |
69 | 78 | @group.destroy |
70 | 79 | ... | ... |
app/models/project.rb
... | ... | @@ -82,6 +82,7 @@ class Project < ActiveRecord::Base |
82 | 82 | scope :public_only, where(private_flag: false) |
83 | 83 | scope :without_user, ->(user) { where("id NOT IN (:ids)", ids: user.projects.map(&:id) ) } |
84 | 84 | scope :not_in_group, ->(group) { where("id NOT IN (:ids)", ids: group.project_ids ) } |
85 | + scope :in_group, ->(group) { where(namespace_id: group.id) } | |
85 | 86 | scope :sorted_by_activity, ->() { order("(SELECT max(events.created_at) FROM events WHERE events.project_id = projects.id) DESC") } |
86 | 87 | scope :personal, ->(user) { where(namespace_id: user.namespace_id) } |
87 | 88 | scope :joined, ->(user) { where("namespace_id != ?", user.namespace_id) } | ... | ... |
app/models/users_project.rb
... | ... | @@ -33,6 +33,8 @@ class UsersProject < ActiveRecord::Base |
33 | 33 | |
34 | 34 | delegate :name, :email, to: :user, prefix: true |
35 | 35 | |
36 | + scope :in_project, ->(project) { where(project_id: project.id) } | |
37 | + | |
36 | 38 | class << self |
37 | 39 | def import_team(source_project, target_project) |
38 | 40 | UsersProject.without_repository_callback do | ... | ... |
app/views/admin/groups/show.html.haml
... | ... | @@ -44,25 +44,54 @@ |
44 | 44 | %div |
45 | 45 | = f.submit 'Change Owner', class: "btn danger" |
46 | 46 | = link_to "Cancel", "#", class: "btn change-owner-cancel-link" |
47 | -%fieldset | |
48 | - %legend Projects (#{@group.projects.count}) | |
49 | - %table | |
50 | - %thead | |
47 | + | |
48 | +- if @group.projects.any? | |
49 | + %fieldset | |
50 | + %legend Projects (#{@group.projects.count}) | |
51 | + %table | |
52 | + %thead | |
53 | + %tr | |
54 | + %th Project name | |
55 | + %th Path | |
56 | + %th Users | |
57 | + %th.cred Danger Zone! | |
58 | + - @group.projects.each do |project| | |
59 | + %tr | |
60 | + %td | |
61 | + = link_to project.name_with_namespace, [:admin, project] | |
62 | + %td | |
63 | + %span.monospace= project.path_with_namespace + ".git" | |
64 | + %td= project.users.count | |
65 | + %td.bgred | |
66 | + = link_to 'Transfer project to global namespace', remove_project_admin_group_path(@group, project_id: project.id), confirm: 'Remove project from group and move to global namespace. Are you sure?', method: :delete, class: "btn danger small" | |
67 | + | |
68 | + = form_tag project_teams_update_admin_group_path(@group), id: "new_team_member", class: "bulk_import", method: :put do | |
69 | + %table.zebra-striped | |
70 | + %thead | |
71 | + %tr | |
72 | + %th Users | |
73 | + %th Project Access: | |
74 | + | |
75 | + - @group.users.each do |u| | |
76 | + %tr{class: "user_#{u.id}"} | |
77 | + %td.name= link_to u.name, admin_user_path(u) | |
78 | + %td.projects_access | |
79 | + - u.projects.in_group(@group).each do |p| | |
80 | + - u_p = u.users_projects.in_project(p).first | |
81 | + = "#{p.name} (#{link_to u_p.project_access_human, edit_admin_team_member_path(u_p) })".html_safe | |
51 | 82 | %tr |
52 | - %th Project name | |
53 | - %th Path | |
54 | - %th Users | |
55 | - %th.cred Danger Zone! | |
56 | - - @group.projects.each do |project| | |
83 | + %td.input= select_tag :user_ids, options_from_collection_for_select(@users , :id, :name), multiple: true, data: {placeholder: 'Select users'}, class: 'chosen span5' | |
84 | + %td= select_tag :project_access, options_for_select(Project.access_options), {class: "project-access-select chosen span3"} | |
85 | + | |
57 | 86 | %tr |
87 | + %td= submit_tag 'Add user to projects in group', class: "btn primary" | |
58 | 88 | %td |
59 | - = link_to project.name_with_namespace, [:admin, project] | |
60 | - %td | |
61 | - %span.monospace= project.path_with_namespace + ".git" | |
62 | - %td= project.users.count | |
63 | - %td.bgred | |
64 | - = link_to 'Transfer project to global namespace', remove_project_admin_group_path(@group, project_id: project.id), confirm: 'Remove project from group and move to global namespace. Are you sure?', method: :delete, class: "btn danger small" | |
89 | + Read more about project permissions | |
90 | + %strong= link_to "here", help_permissions_path, class: "vlink" | |
65 | 91 | |
92 | +- else | |
93 | + %fieldset | |
94 | + %legend Group is empty | |
66 | 95 | |
67 | 96 | = form_tag project_update_admin_group_path(@group), class: "bulk_import", method: :put do |
68 | 97 | %fieldset | ... | ... |
config/routes.rb
features/admin/groups.feature
1 | 1 | Feature: Admin Groups |
2 | 2 | Background: |
3 | 3 | Given I sign in as an admin |
4 | + And I have group with projects | |
5 | + And Create gitlab user "John" | |
4 | 6 | And I visit admin groups page |
5 | 7 | |
6 | 8 | Scenario: Create a group |
... | ... | @@ -8,3 +10,8 @@ Feature: Admin Groups |
8 | 10 | And submit form with new group info |
9 | 11 | Then I should be redirected to group page |
10 | 12 | And I should see newly created group |
13 | + | |
14 | + Scenario: Add user into projects in group | |
15 | + When I visit admin group page | |
16 | + When I select user "John" from user list as "Reporter" | |
17 | + Then I should see "John" in team list in every project as "Reporter" | ... | ... |
features/steps/admin/admin_groups.rb
... | ... | @@ -3,10 +3,26 @@ class AdminGroups < Spinach::FeatureSteps |
3 | 3 | include SharedPaths |
4 | 4 | include SharedActiveTab |
5 | 5 | |
6 | + When 'I visit admin group page' do | |
7 | + visit admin_group_path(current_group) | |
8 | + end | |
9 | + | |
6 | 10 | When 'I click new group link' do |
7 | 11 | click_link "New Group" |
8 | 12 | end |
9 | 13 | |
14 | + And 'I have group with projects' do | |
15 | + @group = create(:group) | |
16 | + @project = create(:project, group: @group) | |
17 | + @event = create(:closed_issue_event, project: @project) | |
18 | + | |
19 | + @project.add_access current_user, :admin | |
20 | + end | |
21 | + | |
22 | + And 'Create gitlab user "John"' do | |
23 | + create(:user, :name => "John") | |
24 | + end | |
25 | + | |
10 | 26 | And 'submit form with new group info' do |
11 | 27 | fill_in 'group_name', :with => 'gitlab' |
12 | 28 | click_button "Create group" |
... | ... | @@ -19,5 +35,27 @@ class AdminGroups < Spinach::FeatureSteps |
19 | 35 | Then 'I should be redirected to group page' do |
20 | 36 | current_path.should == admin_group_path(Group.last) |
21 | 37 | end |
38 | + | |
39 | + When 'I select user "John" from user list as "Reporter"' do | |
40 | + user = User.find_by_name("John") | |
41 | + within "#new_team_member" do | |
42 | + select user.name, :from => "user_ids" | |
43 | + select "Reporter", :from => "project_access" | |
44 | + end | |
45 | + click_button "Add user to projects in group" | |
46 | + end | |
47 | + | |
48 | + Then 'I should see "John" in team list in every project as "Reporter"' do | |
49 | + user = User.find_by_name("John") | |
50 | + projects_with_access = find(".user_#{user.id} .projects_access") | |
51 | + projects_with_access.should have_link("Reporter") | |
52 | + end | |
53 | + | |
54 | + protected | |
55 | + | |
56 | + def current_group | |
57 | + @group ||= Group.first | |
58 | + end | |
59 | + | |
22 | 60 | end |
23 | 61 | ... | ... |