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,14 +59,33 @@ ...@@ -62,14 +59,33 @@
%strong %strong
= link_to @user.created_by.name, [:admin, @user.created_by] = link_to @user.created_by.name, [:admin, @user.created_by]
- 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 .alert.alert-error
%h4 Remove user %h4
Remove user
%br %br
%p Deleting a user has the following effects: %p Deleting a user has the following effects:
%ul %ul
%li All user content like authored issues, snippets, comments will be removed %li All user content like authored issues, snippets, comments will be removed
%li User personal projects will be removed and cannot be restored - rp = @user.personal_projects.count
%li Owned groups will be transfered to first admin - 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" = link_to 'Remove user', [:admin, @user], confirm: "USER #{@user.name} WILL BE REMOVED! Are you sure?", method: :delete, class: "btn btn-remove"
.span6 .span6
......
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