diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index 7703ae8b249500ca7e6b6995f3afbec45a6478d6..eeedc764078d09f474a1fbe894778a6abb380167 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -83,9 +83,14 @@ class Admin::UsersController < Admin::ApplicationController end def destroy - if user.personal_projects.count > 0 - redirect_to admin_users_path, alert: "User is a project owner and can't be removed." and return + # 1. Move all user groups to admin + user.own_groups.each do |group| + group.owner_id = User.admins.first + group.save end + + # 2. Remove user with all authored contenst + # including personal projects user.destroy respond_to do |format| diff --git a/app/views/admin/users/show.html.haml b/app/views/admin/users/show.html.haml index 9b1718dc53d9588d7d4e9d9d7c3a8a293b2b64f7..d1b882072e8cbf32ec4c9fd66fdf78b67e4cf04a 100644 --- a/app/views/admin/users/show.html.haml +++ b/app/views/admin/users/show.html.haml @@ -7,15 +7,14 @@ %span.cred (Admin) .pull-right - = link_to edit_admin_user_path(@user), class: "btn grouped btn-small" do + = link_to edit_admin_user_path(@user), class: "btn grouped" do %i.icon-edit Edit - unless @user == current_user - if @user.blocked? - = link_to 'Unblock', unblock_admin_user_path(@user), method: :put, class: "btn grouped btn-small success" + = link_to 'Unblock', unblock_admin_user_path(@user), method: :put, class: "btn grouped success" - else - = 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" - = link_to 'Destroy', [:admin, @user], confirm: "USER #{@user.name} WILL BE REMOVED! Are you sure?", method: :delete, class: "btn grouped btn-small btn-remove" + = link_to 'Block', block_admin_user_path(@user), confirm: 'USER WILL BE BLOCKED! Are you sure?', method: :put, class: "btn grouped btn-remove" %hr .row @@ -63,6 +62,17 @@ %strong = link_to @user.created_by.name, [:admin, @user.created_by] + .alert.alert-error + %h4 Remove user + %br + %p Deleting a user has the following effects: + %ul + %li All user content like authored issues, snippets, comments will be removed + %li User personal projects will be removed and cannot be restored + %li Owned groups will be transfered to first admin + = link_to 'Remove user', [:admin, @user], confirm: "USER #{@user.name} WILL BE REMOVED! Are you sure?", method: :delete, class: "btn btn-remove" + + .span6 - if @user.users_groups.present? .ui-box .title Groups: @@ -74,7 +84,6 @@ .pull-right %span.light= user_group.human_access - .span6 .ui-box .title Projects (#{@projects.count}) %ul.well-list @@ -96,3 +105,5 @@ %span.light= tm.human_access = 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 %i.icon-remove + +