Commit 643a6e5824cc8ffb6b58288b7822f42d13476c8f

Authored by Dmitriy Zaporozhets
1 parent 24e26d8b

Improve admin user show page

Show permissions for all project.
Add ability to remove user from group if not an owner
Remove unnecessary admin controller
app/assets/javascripts/admin.js.coffee
@@ -23,10 +23,16 @@ class Admin @@ -23,10 +23,16 @@ class Admin
23 e.preventDefault() 23 e.preventDefault()
24 $(this).hide() 24 $(this).hide()
25 modal.show() 25 modal.show()
26 - 26 +
27 $('.change-owner-cancel-link').bind "click", (e) -> 27 $('.change-owner-cancel-link').bind "click", (e) ->
28 e.preventDefault() 28 e.preventDefault()
29 modal.hide() 29 modal.hide()
30 $('.change-owner-link').show() 30 $('.change-owner-link').show()
31 31
  32 + $('li.users_project').bind 'ajax:success', ->
  33 + Turbolinks.visit(location.href)
  34 +
  35 + $('li.users_group').bind 'ajax:success', ->
  36 + Turbolinks.visit(location.href)
  37 +
32 @Admin = Admin 38 @Admin = Admin
app/controllers/admin/members_controller.rb
@@ -1,9 +0,0 @@ @@ -1,9 +0,0 @@
1 -class Admin::MembersController < Admin::ApplicationController  
2 - def destroy  
3 - user = User.find_by_username(params[:id])  
4 - project = Project.find_with_namespace(params[:project_id])  
5 - project.users_projects.where(user_id: user).first.destroy  
6 -  
7 - redirect_to :back  
8 - end  
9 -end  
app/models/project_team.rb
@@ -32,7 +32,15 @@ class ProjectTeam @@ -32,7 +32,15 @@ class ProjectTeam
32 end 32 end
33 33
34 def find_tm(user_id) 34 def find_tm(user_id)
35 - project.users_projects.find_by_user_id(user_id) 35 + tm = project.users_projects.find_by_user_id(user_id)
  36 +
  37 + # If user is not in project members
  38 + # we should check for group membership
  39 + if group && !tm
  40 + tm = group.users_groups.find_by_user_id(user_id)
  41 + end
  42 +
  43 + tm
36 end 44 end
37 45
38 def add_user(user, access) 46 def add_user(user, access)
app/views/admin/users/show.html.haml
@@ -95,17 +95,20 @@ @@ -95,17 +95,20 @@
95 %ul.well-list 95 %ul.well-list
96 - @user.users_groups.each do |user_group| 96 - @user.users_groups.each do |user_group|
97 - group = user_group.group 97 - group = user_group.group
98 - %li 98 + %li.users_group
99 %strong= link_to group.name, admin_group_path(group) 99 %strong= link_to group.name, admin_group_path(group)
100 .pull-right 100 .pull-right
101 %span.light= user_group.human_access 101 %span.light= user_group.human_access
  102 + - unless user_group.owner?
  103 + = 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
  104 + %i.icon-remove.icon-white
102 105
103 .ui-box 106 .ui-box
104 .title Projects (#{@projects.count}) 107 .title Projects (#{@projects.count})
105 %ul.well-list 108 %ul.well-list
106 - @projects.sort_by(&:name_with_namespace).each do |project| 109 - @projects.sort_by(&:name_with_namespace).each do |project|
107 - tm = project.team.find_tm(@user.id) 110 - tm = project.team.find_tm(@user.id)
108 - %li 111 + %li.users_project
109 = link_to admin_project_path(project), class: dom_class(project) do 112 = link_to admin_project_path(project), class: dom_class(project) do
110 - if project.namespace 113 - if project.namespace
111 = project.namespace.human_name 114 = project.namespace.human_name
@@ -119,7 +122,9 @@ @@ -119,7 +122,9 @@
119 %span.light Owner 122 %span.light Owner
120 - else 123 - else
121 %span.light= tm.human_access 124 %span.light= tm.human_access
122 - = 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  
123 - %i.icon-remove 125 +
  126 + - if tm.respond_to? :project
  127 + = 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
  128 + %i.icon-remove
124 129
125 130
config/routes.rb
@@ -89,11 +89,7 @@ Gitlab::Application.routes.draw do @@ -89,11 +89,7 @@ Gitlab::Application.routes.draw do
89 89
90 resource :logs, only: [:show] 90 resource :logs, only: [:show]
91 resource :background_jobs, controller: 'background_jobs', only: [:show] 91 resource :background_jobs, controller: 'background_jobs', only: [:show]
92 -  
93 - resources :projects, constraints: { id: /[a-zA-Z.\/0-9_\-]+/ }, only: [:index, :show] do  
94 - resources :members, only: [:destroy]  
95 - end  
96 - 92 + resources :projects, constraints: { id: /[a-zA-Z.\/0-9_\-]+/ }, only: [:index, :show]
97 root to: "dashboard#index" 93 root to: "dashboard#index"
98 end 94 end
99 95
lib/gitlab/access.rb
@@ -44,5 +44,9 @@ module Gitlab @@ -44,5 +44,9 @@ module Gitlab
44 def human_access 44 def human_access
45 Gitlab::Access.options_with_owner.key(access_field) 45 Gitlab::Access.options_with_owner.key(access_field)
46 end 46 end
  47 +
  48 + def owner?
  49 + access_field == OWNER
  50 + end
47 end 51 end
48 end 52 end