Commit afdfbd1e8a5865ebb2494c7d55220248a4981b77
1 parent
79f0858a
Exists in
master
and in
4 other branches
Add description to user removal block. Transfer owned groups to admin before remove
Showing
2 changed files
with
23 additions
and
7 deletions
Show diff stats
app/controllers/admin/users_controller.rb
| ... | ... | @@ -83,9 +83,14 @@ class Admin::UsersController < Admin::ApplicationController |
| 83 | 83 | end |
| 84 | 84 | |
| 85 | 85 | def destroy |
| 86 | - if user.personal_projects.count > 0 | |
| 87 | - redirect_to admin_users_path, alert: "User is a project owner and can't be removed." and return | |
| 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 | |
| 88 | 90 | end |
| 91 | + | |
| 92 | + # 2. Remove user with all authored contenst | |
| 93 | + # including personal projects | |
| 89 | 94 | user.destroy |
| 90 | 95 | |
| 91 | 96 | respond_to do |format| | ... | ... |
app/views/admin/users/show.html.haml
| ... | ... | @@ -7,15 +7,14 @@ |
| 7 | 7 | %span.cred (Admin) |
| 8 | 8 | |
| 9 | 9 | .pull-right |
| 10 | - = link_to edit_admin_user_path(@user), class: "btn grouped btn-small" do | |
| 10 | + = link_to edit_admin_user_path(@user), class: "btn grouped" do | |
| 11 | 11 | %i.icon-edit |
| 12 | 12 | Edit |
| 13 | 13 | - unless @user == current_user |
| 14 | 14 | - if @user.blocked? |
| 15 | - = link_to 'Unblock', unblock_admin_user_path(@user), method: :put, class: "btn grouped btn-small success" | |
| 15 | + = link_to 'Unblock', unblock_admin_user_path(@user), method: :put, class: "btn grouped success" | |
| 16 | 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-small btn-remove" | |
| 18 | - = link_to 'Destroy', [:admin, @user], confirm: "USER #{@user.name} WILL BE REMOVED! Are you sure?", method: :delete, class: "btn grouped btn-small btn-remove" | |
| 17 | + = link_to 'Block', block_admin_user_path(@user), confirm: 'USER WILL BE BLOCKED! Are you sure?', method: :put, class: "btn grouped btn-remove" | |
| 19 | 18 | %hr |
| 20 | 19 | |
| 21 | 20 | .row |
| ... | ... | @@ -63,6 +62,17 @@ |
| 63 | 62 | %strong |
| 64 | 63 | = link_to @user.created_by.name, [:admin, @user.created_by] |
| 65 | 64 | |
| 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" | |
| 74 | + | |
| 75 | + .span6 | |
| 66 | 76 | - if @user.users_groups.present? |
| 67 | 77 | .ui-box |
| 68 | 78 | .title Groups: |
| ... | ... | @@ -74,7 +84,6 @@ |
| 74 | 84 | .pull-right |
| 75 | 85 | %span.light= user_group.human_access |
| 76 | 86 | |
| 77 | - .span6 | |
| 78 | 87 | .ui-box |
| 79 | 88 | .title Projects (#{@projects.count}) |
| 80 | 89 | %ul.well-list |
| ... | ... | @@ -96,3 +105,5 @@ |
| 96 | 105 | %span.light= tm.human_access |
| 97 | 106 | = link_to admin_project_member_path(project, tm.user), confirm: remove_from_project_team_message(project, @user), method: :delete, class: "btn btn-small btn-remove" do |
| 98 | 107 | %i.icon-remove |
| 108 | + | |
| 109 | + | ... | ... |