Commit e3a9bb3e authored by Aishwarya Subramanian's avatar Aishwarya Subramanian

Display user project count on Admin Dashboard

Displays the total number of authorized projects
for individual users in the admin dashboard.
parent 5f5fe6f6
...@@ -9,6 +9,7 @@ class Admin::UsersController < Admin::ApplicationController ...@@ -9,6 +9,7 @@ class Admin::UsersController < Admin::ApplicationController
def index def index
@users = User.filter_items(params[:filter]).order_name_asc @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.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.sort_by_attribute(@sort = params[:sort])
@users = @users.page(params[:page]) @users = @users.page(params[:page])
end end
......
...@@ -4,7 +4,12 @@ ...@@ -4,7 +4,12 @@
= _('Name') = _('Name')
.table-mobile-content .table-mobile-content
= render 'user_detail', user: user = 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' } .table-mobile-header{ role: 'rowheader' }
= _('Created on') = _('Created on')
.table-mobile-content .table-mobile-content
......
...@@ -72,7 +72,8 @@ ...@@ -72,7 +72,8 @@
.table-holder .table-holder
.thead-white.text-nowrap.gl-responsive-table-row.table-row-header{ role: 'row' } .thead-white.text-nowrap.gl-responsive-table-row.table-row-header{ role: 'row' }
.table-section.section-40{ role: 'rowheader' }= _('Name') .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') .table-section.section-15{ role: 'rowheader' }= _('Last activity')
= render partial: 'admin/users/user', collection: @users = 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 ...@@ -23,6 +23,12 @@ RSpec.describe Admin::UsersController do
expect(assigns(:users)).to eq([admin]) expect(assigns(:users)).to eq([admin])
end end
it 'eager loads authorized projects association' do
get :index
expect(assigns(:users).first.association(:authorized_projects)).to be_loaded
end
end end
describe 'GET :id' do describe 'GET :id' do
......
...@@ -31,6 +31,7 @@ RSpec.describe "Admin::Users" 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(current_user.last_activity_on.strftime("%e %b, %Y"))
expect(page).to have_content(user.email) expect(page).to have_content(user.email)
expect(page).to have_content(user.name) expect(page).to have_content(user.name)
expect(page).to have_content('Projects')
expect(page).to have_button('Block') expect(page).to have_button('Block')
expect(page).to have_button('Deactivate') expect(page).to have_button('Deactivate')
expect(page).to have_button('Delete user') expect(page).to have_button('Delete user')
...@@ -48,6 +49,19 @@ RSpec.describe "Admin::Users" do ...@@ -48,6 +49,19 @@ RSpec.describe "Admin::Users" do
end end
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 describe 'search and sort' do
before do before do
create(:user, name: 'Foo Bar', last_activity_on: 3.days.ago) 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