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 ...@@ -83,14 +83,10 @@ class Admin::UsersController < Admin::ApplicationController
end end
def destroy def destroy
# 1. Move all user groups to admin # 1. Remove groups where user is the only owner
user.own_groups.each do |group| user.solo_owned_groups.map(&:destroy)
group.owner_id = User.admins.first
group.save
end
# 2. Remove user with all authored contenst # 2. Remove user with all authored content including personal projects
# including personal projects
user.destroy user.destroy
respond_to do |format| respond_to do |format|
......
...@@ -23,7 +23,7 @@ class Group < Namespace ...@@ -23,7 +23,7 @@ class Group < Namespace
end end
def owners def owners
@owners ||= (users_groups.owners.map(&:user) << owner) @owners ||= (users_groups.owners.map(&:user) << owner).uniq
end end
def add_users(user_ids, group_access) def add_users(user_ids, group_access)
......
...@@ -135,7 +135,7 @@ class User < ActiveRecord::Base ...@@ -135,7 +135,7 @@ class User < ActiveRecord::Base
# Remove user from all groups # Remove user from all groups
user.users_groups.find_each do |membership| user.users_groups.find_each do |membership|
# skip owned resources # skip owned resources
next if membership.group.owner == user next if membership.group.owners.include?(user)
return false unless membership.destroy return false unless membership.destroy
end end
...@@ -376,4 +376,10 @@ class User < ActiveRecord::Base ...@@ -376,4 +376,10 @@ class User < ActiveRecord::Base
self.send("#{attr}=", Sanitize.clean(value)) if value.present? self.send("#{attr}=", Sanitize.clean(value)) if value.present?
end end
end end
def solo_owned_groups
@solo_owned_groups ||= owned_groups.select do |group|
group.owners == [self]
end
end
end end
...@@ -10,11 +10,8 @@ ...@@ -10,11 +10,8 @@
= link_to edit_admin_user_path(@user), class: "btn grouped" do = link_to edit_admin_user_path(@user), class: "btn grouped" do
%i.icon-edit %i.icon-edit
Edit Edit
- unless @user == current_user - if @user.blocked?
- if @user.blocked? = link_to 'Unblock', unblock_admin_user_path(@user), method: :put, class: "btn grouped 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-remove"
%hr %hr
.row .row
...@@ -62,15 +59,34 @@ ...@@ -62,15 +59,34 @@
%strong %strong
= link_to @user.created_by.name, [:admin, @user.created_by] = link_to @user.created_by.name, [:admin, @user.created_by]
.alert.alert-error - unless @user == current_user
%h4 Remove user .alert
%br %h4 Block user
%p Deleting a user has the following effects: %br
%ul %p Blocking user has the following effects:
%li All user content like authored issues, snippets, comments will be removed %ul
%li User personal projects will be removed and cannot be restored %li User will not be able to login
%li Owned groups will be transfered to first admin %li User will not be able to access git repositories
= link_to 'Remove user', [:admin, @user], confirm: "USER #{@user.name} WILL BE REMOVED! Are you sure?", method: :delete, class: "btn btn-remove" %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 .span6
- if @user.users_groups.present? - 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