Commit 24e26d8b authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

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
parent afdfbd1e
......@@ -83,14 +83,10 @@ class Admin::UsersController < Admin::ApplicationController
end
def destroy
# 1. Move all user groups to admin
user.own_groups.each do |group|
group.owner_id = User.admins.first
group.save
end
# 1. Remove groups where user is the only owner
user.solo_owned_groups.map(&:destroy)
# 2. Remove user with all authored contenst
# including personal projects
# 2. Remove user with all authored content including personal projects
user.destroy
respond_to do |format|
......
......@@ -23,7 +23,7 @@ class Group < Namespace
end
def owners
@owners ||= (users_groups.owners.map(&:user) << owner)
@owners ||= (users_groups.owners.map(&:user) << owner).uniq
end
def add_users(user_ids, group_access)
......
......@@ -135,7 +135,7 @@ class User < ActiveRecord::Base
# Remove user from all groups
user.users_groups.find_each do |membership|
# skip owned resources
next if membership.group.owner == user
next if membership.group.owners.include?(user)
return false unless membership.destroy
end
......@@ -376,4 +376,10 @@ class User < ActiveRecord::Base
self.send("#{attr}=", Sanitize.clean(value)) if value.present?
end
end
def solo_owned_groups
@solo_owned_groups ||= owned_groups.select do |group|
group.owners == [self]
end
end
end
......@@ -10,11 +10,8 @@
= 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 success"
- else
= link_to 'Block', block_admin_user_path(@user), confirm: 'USER WILL BE BLOCKED! Are you sure?', method: :put, class: "btn grouped btn-remove"
- if @user.blocked?
= link_to 'Unblock', unblock_admin_user_path(@user), method: :put, class: "btn grouped success"
%hr
.row
......@@ -62,15 +59,34 @@
%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"
- unless @user == current_user
.alert
%h4 Block user
%br
%p Blocking user has the following effects:
%ul
%li User will not be able to login
%li User will not be able to access git repositories
%li User will be removed from joined projects and groups
%li Personal projects will be left
%li Owned groups will be left
= link_to 'Block user', block_admin_user_path(@user), confirm: 'USER WILL BE BLOCKED! Are you sure?', method: :put, class: "btn btn-remove"
.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
- rp = @user.personal_projects.count
- unless rp.zero?
%li #{pluralize rp, 'personal project'} will be removed and cannot be restored
- if @user.solo_owned_groups.present?
%li
Next groups with all content will be removed:
%strong #{@user.solo_owned_groups.map(&:name).join(', ')}
= 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?
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment