Commit 6b16f8a7 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'improve/user_removal' of /home/git/repositories/gitlab/gitlabhq

parents 2358489f eb4272e2
...@@ -23,10 +23,16 @@ class Admin ...@@ -23,10 +23,16 @@ class Admin
e.preventDefault() e.preventDefault()
$(this).hide() $(this).hide()
modal.show() modal.show()
$('.change-owner-cancel-link').bind "click", (e) -> $('.change-owner-cancel-link').bind "click", (e) ->
e.preventDefault() e.preventDefault()
modal.hide() modal.hide()
$('.change-owner-link').show() $('.change-owner-link').show()
$('li.users_project').bind 'ajax:success', ->
Turbolinks.visit(location.href)
$('li.users_group').bind 'ajax:success', ->
Turbolinks.visit(location.href)
@Admin = Admin @Admin = Admin
class Admin::MembersController < Admin::ApplicationController
def destroy
user = User.find_by_username(params[:id])
project = Project.find_with_namespace(params[:project_id])
project.users_projects.where(user_id: user).first.destroy
redirect_to :back
end
end
...@@ -83,9 +83,10 @@ class Admin::UsersController < Admin::ApplicationController ...@@ -83,9 +83,10 @@ class Admin::UsersController < Admin::ApplicationController
end end
def destroy def destroy
if user.personal_projects.count > 0 # 1. Remove groups where user is the only owner
redirect_to admin_users_path, alert: "User is a project owner and can't be removed." and return user.solo_owned_groups.map(&:destroy)
end
# 2. Remove user with all authored content 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)
......
...@@ -32,7 +32,15 @@ class ProjectTeam ...@@ -32,7 +32,15 @@ class ProjectTeam
end end
def find_tm(user_id) def find_tm(user_id)
project.users_projects.find_by_user_id(user_id) tm = project.users_projects.find_by_user_id(user_id)
# If user is not in project members
# we should check for group membership
if group && !tm
tm = group.users_groups.find_by_user_id(user_id)
end
tm
end end
def add_user(user, access) def add_user(user, 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
...@@ -7,15 +7,11 @@ ...@@ -7,15 +7,11 @@
%span.cred (Admin) %span.cred (Admin)
.pull-right .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 %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 btn-small 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"
%hr %hr
.row .row
...@@ -63,24 +59,56 @@ ...@@ -63,24 +59,56 @@
%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
%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? - if @user.users_groups.present?
.ui-box .ui-box
.title Groups: .title Groups:
%ul.well-list %ul.well-list
- @user.users_groups.each do |user_group| - @user.users_groups.each do |user_group|
- group = user_group.group - group = user_group.group
%li %li.users_group
%strong= link_to group.name, admin_group_path(group) %strong= link_to group.name, admin_group_path(group)
.pull-right .pull-right
%span.light= user_group.human_access %span.light= user_group.human_access
- unless user_group.owner?
= link_to group_users_group_path(group, user_group), confirm: remove_user_from_group_message(group, @user), method: :delete, remote: true, class: "btn-tiny btn btn-remove", title: 'Remove user from group' do
%i.icon-remove.icon-white
.span6
.ui-box .ui-box
.title Projects (#{@projects.count}) .title Projects (#{@projects.count})
%ul.well-list %ul.well-list
- @projects.sort_by(&:name_with_namespace).each do |project| - @projects.sort_by(&:name_with_namespace).each do |project|
- tm = project.team.find_tm(@user.id) - tm = project.team.find_tm(@user.id)
%li %li.users_project
= link_to admin_project_path(project), class: dom_class(project) do = link_to admin_project_path(project), class: dom_class(project) do
- if project.namespace - if project.namespace
= project.namespace.human_name = project.namespace.human_name
...@@ -94,5 +122,9 @@ ...@@ -94,5 +122,9 @@
%span.light Owner %span.light Owner
- else - else
%span.light= tm.human_access %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 - if tm.respond_to? :project
= link_to project_team_member_path(project, @user), confirm: remove_from_project_team_message(project, @user), remote: true, method: :delete, class: "btn-tiny btn btn-remove", title: 'Remove user from project' do
%i.icon-remove
...@@ -89,11 +89,7 @@ Gitlab::Application.routes.draw do ...@@ -89,11 +89,7 @@ Gitlab::Application.routes.draw do
resource :logs, only: [:show] resource :logs, only: [:show]
resource :background_jobs, controller: 'background_jobs', only: [:show] resource :background_jobs, controller: 'background_jobs', only: [:show]
resources :projects, constraints: { id: /[a-zA-Z.\/0-9_\-]+/ }, only: [:index, :show]
resources :projects, constraints: { id: /[a-zA-Z.\/0-9_\-]+/ }, only: [:index, :show] do
resources :members, only: [:destroy]
end
root to: "dashboard#index" root to: "dashboard#index"
end end
......
...@@ -44,5 +44,9 @@ module Gitlab ...@@ -44,5 +44,9 @@ module Gitlab
def human_access def human_access
Gitlab::Access.options_with_owner.key(access_field) Gitlab::Access.options_with_owner.key(access_field)
end end
def owner?
access_field == OWNER
end
end end
end end
...@@ -75,13 +75,6 @@ describe Admin::ProjectsController, "routing" do ...@@ -75,13 +75,6 @@ describe Admin::ProjectsController, "routing" do
end end
end end
# DELETE /admin/projects/:project_id/members/:id(.:format) admin/projects/members#destroy {id: /[^\/]+/, project_id: /[^\/]+/}
describe Admin::MembersController, "routing" do
it "to #destroy" do
delete("/admin/projects/test/members/1").should route_to('admin/members#destroy', project_id: 'test', id: '1')
end
end
# admin_hook_test GET /admin/hooks/:hook_id/test(.:format) admin/hooks#test # admin_hook_test GET /admin/hooks/:hook_id/test(.:format) admin/hooks#test
# admin_hooks GET /admin/hooks(.:format) admin/hooks#index # admin_hooks GET /admin/hooks(.:format) admin/hooks#index
# POST /admin/hooks(.:format) admin/hooks#create # POST /admin/hooks(.:format) admin/hooks#create
......
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