Commit 24e26d8b7a4a2487600f273f7b1a6236691d2664
1 parent
afdfbd1e
Exists in
master
and in
4 other branches
Improve user block/removal from admin area
Provide UI with explanation what happens when you block or remove user When remove user - remove all groups where user is an only owner
Showing
4 changed files
with
41 additions
and
23 deletions
Show diff stats
app/controllers/admin/users_controller.rb
@@ -83,14 +83,10 @@ class Admin::UsersController < Admin::ApplicationController | @@ -83,14 +83,10 @@ class Admin::UsersController < Admin::ApplicationController | ||
83 | end | 83 | end |
84 | 84 | ||
85 | def destroy | 85 | def destroy |
86 | - # 1. Move all user groups to admin | ||
87 | - user.own_groups.each do |group| | ||
88 | - group.owner_id = User.admins.first | ||
89 | - group.save | ||
90 | - end | 86 | + # 1. Remove groups where user is the only owner |
87 | + user.solo_owned_groups.map(&:destroy) | ||
91 | 88 | ||
92 | - # 2. Remove user with all authored contenst | ||
93 | - # including personal projects | 89 | + # 2. Remove user with all authored content including personal projects |
94 | user.destroy | 90 | user.destroy |
95 | 91 | ||
96 | respond_to do |format| | 92 | respond_to do |format| |
app/models/group.rb
@@ -23,7 +23,7 @@ class Group < Namespace | @@ -23,7 +23,7 @@ class Group < Namespace | ||
23 | end | 23 | end |
24 | 24 | ||
25 | def owners | 25 | def owners |
26 | - @owners ||= (users_groups.owners.map(&:user) << owner) | 26 | + @owners ||= (users_groups.owners.map(&:user) << owner).uniq |
27 | end | 27 | end |
28 | 28 | ||
29 | def add_users(user_ids, group_access) | 29 | def add_users(user_ids, group_access) |
app/models/user.rb
@@ -135,7 +135,7 @@ class User < ActiveRecord::Base | @@ -135,7 +135,7 @@ class User < ActiveRecord::Base | ||
135 | # Remove user from all groups | 135 | # Remove user from all groups |
136 | user.users_groups.find_each do |membership| | 136 | user.users_groups.find_each do |membership| |
137 | # skip owned resources | 137 | # skip owned resources |
138 | - next if membership.group.owner == user | 138 | + next if membership.group.owners.include?(user) |
139 | 139 | ||
140 | return false unless membership.destroy | 140 | return false unless membership.destroy |
141 | end | 141 | end |
@@ -376,4 +376,10 @@ class User < ActiveRecord::Base | @@ -376,4 +376,10 @@ class User < ActiveRecord::Base | ||
376 | self.send("#{attr}=", Sanitize.clean(value)) if value.present? | 376 | self.send("#{attr}=", Sanitize.clean(value)) if value.present? |
377 | end | 377 | end |
378 | end | 378 | end |
379 | + | ||
380 | + def solo_owned_groups | ||
381 | + @solo_owned_groups ||= owned_groups.select do |group| | ||
382 | + group.owners == [self] | ||
383 | + end | ||
384 | + end | ||
379 | end | 385 | end |
app/views/admin/users/show.html.haml
@@ -10,11 +10,8 @@ | @@ -10,11 +10,8 @@ | ||
10 | = link_to edit_admin_user_path(@user), class: "btn grouped" do | 10 | = link_to edit_admin_user_path(@user), class: "btn grouped" do |
11 | %i.icon-edit | 11 | %i.icon-edit |
12 | Edit | 12 | Edit |
13 | - - unless @user == current_user | ||
14 | - - if @user.blocked? | ||
15 | - = link_to 'Unblock', unblock_admin_user_path(@user), method: :put, class: "btn grouped success" | ||
16 | - - else | ||
17 | - = link_to 'Block', block_admin_user_path(@user), confirm: 'USER WILL BE BLOCKED! Are you sure?', method: :put, class: "btn grouped btn-remove" | 13 | + - if @user.blocked? |
14 | + = link_to 'Unblock', unblock_admin_user_path(@user), method: :put, class: "btn grouped success" | ||
18 | %hr | 15 | %hr |
19 | 16 | ||
20 | .row | 17 | .row |
@@ -62,15 +59,34 @@ | @@ -62,15 +59,34 @@ | ||
62 | %strong | 59 | %strong |
63 | = link_to @user.created_by.name, [:admin, @user.created_by] | 60 | = link_to @user.created_by.name, [:admin, @user.created_by] |
64 | 61 | ||
65 | - .alert.alert-error | ||
66 | - %h4 Remove user | ||
67 | - %br | ||
68 | - %p Deleting a user has the following effects: | ||
69 | - %ul | ||
70 | - %li All user content like authored issues, snippets, comments will be removed | ||
71 | - %li User personal projects will be removed and cannot be restored | ||
72 | - %li Owned groups will be transfered to first admin | ||
73 | - = link_to 'Remove user', [:admin, @user], confirm: "USER #{@user.name} WILL BE REMOVED! Are you sure?", method: :delete, class: "btn btn-remove" | 62 | + - unless @user == current_user |
63 | + .alert | ||
64 | + %h4 Block user | ||
65 | + %br | ||
66 | + %p Blocking user has the following effects: | ||
67 | + %ul | ||
68 | + %li User will not be able to login | ||
69 | + %li User will not be able to access git repositories | ||
70 | + %li User will be removed from joined projects and groups | ||
71 | + %li Personal projects will be left | ||
72 | + %li Owned groups will be left | ||
73 | + = link_to 'Block user', block_admin_user_path(@user), confirm: 'USER WILL BE BLOCKED! Are you sure?', method: :put, class: "btn btn-remove" | ||
74 | + | ||
75 | + .alert.alert-error | ||
76 | + %h4 | ||
77 | + Remove user | ||
78 | + %br | ||
79 | + %p Deleting a user has the following effects: | ||
80 | + %ul | ||
81 | + %li All user content like authored issues, snippets, comments will be removed | ||
82 | + - rp = @user.personal_projects.count | ||
83 | + - unless rp.zero? | ||
84 | + %li #{pluralize rp, 'personal project'} will be removed and cannot be restored | ||
85 | + - if @user.solo_owned_groups.present? | ||
86 | + %li | ||
87 | + Next groups with all content will be removed: | ||
88 | + %strong #{@user.solo_owned_groups.map(&:name).join(', ')} | ||
89 | + = link_to 'Remove user', [:admin, @user], confirm: "USER #{@user.name} WILL BE REMOVED! Are you sure?", method: :delete, class: "btn btn-remove" | ||
74 | 90 | ||
75 | .span6 | 91 | .span6 |
76 | - if @user.users_groups.present? | 92 | - if @user.users_groups.present? |