Commit e98d292b authored by Nicolò Maria Mezzopera's avatar Nicolò Maria Mezzopera

Merge branch '249590-project-count-admin-view' into 'master'

Display user project count on Admin Dashboard

Closes #249590

See merge request gitlab-org/gitlab!42871
parents d53f5f94 e3a9bb3e
......@@ -9,6 +9,7 @@ class Admin::UsersController < Admin::ApplicationController
def index
@users = User.filter_items(params[:filter]).order_name_asc
@users = @users.search_with_secondary_emails(params[:search_query]) if params[:search_query].present?
@users = @users.includes(:authorized_projects) # rubocop: disable CodeReuse/ActiveRecord
@users = @users.sort_by_attribute(@sort = params[:sort])
@users = @users.page(params[:page])
end
......
......@@ -4,7 +4,12 @@
= _('Name')
.table-mobile-content
= render 'user_detail', user: user
.table-section.section-25
.table-section.section-10
.table-mobile-header{ role: 'rowheader' }
= _('Projects')
.table-mobile-content.gl-str-truncated{ data: { testid: "user-project-count-#{user.id}" } }
= user.authorized_projects.length
.table-section.section-15
.table-mobile-header{ role: 'rowheader' }
= _('Created on')
.table-mobile-content
......
......@@ -72,7 +72,8 @@
.table-holder
.thead-white.text-nowrap.gl-responsive-table-row.table-row-header{ role: 'row' }
.table-section.section-40{ role: 'rowheader' }= _('Name')
.table-section.section-25{ role: 'rowheader' }= _('Created on')
.table-section.section-10{ role: 'rowheader' }= _('Projects')
.table-section.section-15{ role: 'rowheader' }= _('Created on')
.table-section.section-15{ role: 'rowheader' }= _('Last activity')
= render partial: 'admin/users/user', collection: @users
......
---
title: Display user project count on Admin Dashboard
merge_request: 42871
author:
type: added
......@@ -23,6 +23,12 @@ RSpec.describe Admin::UsersController do
expect(assigns(:users)).to eq([admin])
end
it 'eager loads authorized projects association' do
get :index
expect(assigns(:users).first.association(:authorized_projects)).to be_loaded
end
end
describe 'GET :id' do
......
......@@ -31,6 +31,7 @@ RSpec.describe "Admin::Users" do
expect(page).to have_content(current_user.last_activity_on.strftime("%e %b, %Y"))
expect(page).to have_content(user.email)
expect(page).to have_content(user.name)
expect(page).to have_content('Projects')
expect(page).to have_button('Block')
expect(page).to have_button('Deactivate')
expect(page).to have_button('Delete user')
......@@ -48,6 +49,19 @@ RSpec.describe "Admin::Users" do
end
end
context 'user project count' do
before do
project = create(:project)
project.add_maintainer(current_user)
end
it 'displays count of users projects' do
visit admin_users_path
expect(page.find("[data-testid='user-project-count-#{current_user.id}']").text).to eq("1")
end
end
describe 'search and sort' do
before do
create(:user, name: 'Foo Bar', last_activity_on: 3.days.ago)
......
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