From 6777634043097d7cd9893ddfaf50763e1f6a8921 Mon Sep 17 00:00:00 2001 From: Eugenia Grieff Date: Thu, 31 Oct 2024 13:06:17 +0100 Subject: [PATCH 1/2] Add with_highest_role_planner field to users_statistics table Add specs Changelog: added EE: true --- app/models/users_statistics.rb | 2 ++ app/views/admin/dashboard/_stats_users_table.html.haml | 7 +++++++ ..._add_with_highest_role_planner_to_users_statistics.rb | 9 +++++++++ db/schema_migrations/20241029130136 | 1 + db/structure.sql | 3 ++- ee/app/models/ee/users_statistics.rb | 1 + .../views/admin/dashboard/_stats_users_table.html.haml | 7 +++++++ ee/spec/features/admin/admin_dashboard_spec.rb | 7 ++++--- ee/spec/models/ee/users_statistics_spec.rb | 6 +++--- locale/gitlab.pot | 3 +++ spec/factories/users_statistics.rb | 1 + spec/models/users_statistics_spec.rb | 6 ++++-- 12 files changed, 44 insertions(+), 9 deletions(-) create mode 100644 db/migrate/20241029130136_add_with_highest_role_planner_to_users_statistics.rb create mode 100644 db/schema_migrations/20241029130136 diff --git a/app/models/users_statistics.rb b/app/models/users_statistics.rb index a314ae8920bcc5..6b2261a0591aa4 100644 --- a/app/models/users_statistics.rb +++ b/app/models/users_statistics.rb @@ -7,6 +7,7 @@ def active [ without_groups_and_projects, with_highest_role_guest, + with_highest_role_planner, with_highest_role_reporter, with_highest_role_developer, with_highest_role_maintainer, @@ -34,6 +35,7 @@ def highest_role_stats { without_groups_and_projects: without_groups_and_projects_stats, with_highest_role_guest: batch_count_for_access_level(Gitlab::Access::GUEST), + with_highest_role_planner: batch_count_for_access_level(Gitlab::Access::PLANNER), with_highest_role_reporter: batch_count_for_access_level(Gitlab::Access::REPORTER), with_highest_role_developer: batch_count_for_access_level(Gitlab::Access::DEVELOPER), with_highest_role_maintainer: batch_count_for_access_level(Gitlab::Access::MAINTAINER), diff --git a/app/views/admin/dashboard/_stats_users_table.html.haml b/app/views/admin/dashboard/_stats_users_table.html.haml index 218f91fd3a6bcd..32c444ac700311 100644 --- a/app/views/admin/dashboard/_stats_users_table.html.haml +++ b/app/views/admin/dashboard/_stats_users_table.html.haml @@ -6,6 +6,13 @@ %td.gl-text-right{ class: '!gl-p-5' } = @users_statistics&.without_groups_and_projects = render_if_exists 'admin/dashboard/minimal_access_stats_row', users_statistics: @users_statistics + %tr + %td{ class: '!gl-p-5' } + = s_('AdminArea|Users with highest role') + %strong + = s_('AdminArea|Planner') + %td.gl-text-right{ class: '!gl-p-5' } + = @users_statistics&.with_highest_role_planner %tr %td{ class: '!gl-p-5' } = s_('AdminArea|Users with highest role') diff --git a/db/migrate/20241029130136_add_with_highest_role_planner_to_users_statistics.rb b/db/migrate/20241029130136_add_with_highest_role_planner_to_users_statistics.rb new file mode 100644 index 00000000000000..b208b69374659a --- /dev/null +++ b/db/migrate/20241029130136_add_with_highest_role_planner_to_users_statistics.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddWithHighestRolePlannerToUsersStatistics < Gitlab::Database::Migration[2.2] + milestone '17.7' + + def change + add_column :users_statistics, :with_highest_role_planner, :integer, default: 0, null: false + end +end diff --git a/db/schema_migrations/20241029130136 b/db/schema_migrations/20241029130136 new file mode 100644 index 00000000000000..7b372520ca7f39 --- /dev/null +++ b/db/schema_migrations/20241029130136 @@ -0,0 +1 @@ +fdbb03606a5f6f61031e54b407ee60f5074d5130bf856959a0f3b010d5413654 \ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index 6fdd10467b7ba1..590204bc3a2bc9 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -21060,7 +21060,8 @@ CREATE TABLE users_statistics ( bots integer DEFAULT 0 NOT NULL, blocked integer DEFAULT 0 NOT NULL, with_highest_role_minimal_access integer DEFAULT 0 NOT NULL, - with_highest_role_guest_with_custom_role integer DEFAULT 0 NOT NULL + with_highest_role_guest_with_custom_role integer DEFAULT 0 NOT NULL, + with_highest_role_planner integer DEFAULT 0 NOT NULL ); CREATE SEQUENCE users_statistics_id_seq diff --git a/ee/app/models/ee/users_statistics.rb b/ee/app/models/ee/users_statistics.rb index 140cc774e90f76..e3513095452d4d 100644 --- a/ee/app/models/ee/users_statistics.rb +++ b/ee/app/models/ee/users_statistics.rb @@ -32,6 +32,7 @@ def base_non_billable def base_billable_users [ + with_highest_role_planner, with_highest_role_reporter, with_highest_role_developer, with_highest_role_maintainer, diff --git a/ee/app/views/admin/dashboard/_stats_users_table.html.haml b/ee/app/views/admin/dashboard/_stats_users_table.html.haml index eb1b0459e2223e..0ae710d2c9cd27 100644 --- a/ee/app/views/admin/dashboard/_stats_users_table.html.haml +++ b/ee/app/views/admin/dashboard/_stats_users_table.html.haml @@ -7,6 +7,13 @@ = render_if_exists 'admin/dashboard/without_group_or_project_row', users_statistics: @users_statistics unless exclude_guests_from_active_count = render_if_exists 'admin/dashboard/minimal_access_stats_row', users_statistics: @users_statistics = render_if_exists 'admin/dashboard/elevated_role_stats_row', users_statistics: @users_statistics + %tr + %td{ class: '!gl-p-5' } + = s_('AdminArea|Users with highest role') + %strong + = s_('AdminArea|Planner') + %td.gl-text-right{ class: '!gl-p-5' } + = @users_statistics&.with_highest_role_planner %tr %td{ class: '!gl-p-5' } = s_('AdminArea|Users with highest role') diff --git a/ee/spec/features/admin/admin_dashboard_spec.rb b/ee/spec/features/admin/admin_dashboard_spec.rb index 43525023b3ca3e..4afc70da1ea423 100644 --- a/ee/spec/features/admin/admin_dashboard_spec.rb +++ b/ee/spec/features/admin/admin_dashboard_spec.rb @@ -61,15 +61,16 @@ expect(page).to have_content("Users without a Group and Project 23") expect(page).to have_content("Users with highest role Guest 5") + expect(page).to have_content("Users with highest role Planner 7") expect(page).to have_content("Users with highest role Reporter 9") expect(page).to have_content("Users with highest role Developer 21") expect(page).to have_content("Users with highest role Maintainer 6") expect(page).to have_content("Users with highest role Owner 5") expect(page).to have_content("Bots 2") - expect(page).to have_content("Billable users 69") - expect(page).to have_content("Active users (total billable + total non-billable) 71") + expect(page).to have_content("Billable users 76") + expect(page).to have_content("Active users (total billable + total non-billable) 78") expect(page).to have_content("Blocked users 7") - expect(page).to have_content("Total users (active users + blocked users) 78") + expect(page).to have_content("Total users (active users + blocked users) 85") end end diff --git a/ee/spec/models/ee/users_statistics_spec.rb b/ee/spec/models/ee/users_statistics_spec.rb index b111c5ade1f450..84435d686fc522 100644 --- a/ee/spec/models/ee/users_statistics_spec.rb +++ b/ee/spec/models/ee/users_statistics_spec.rb @@ -9,7 +9,7 @@ describe '#billable' do it 'sums users statistics values excluding blocked users and bots' do - expect(users_statistics.billable).to eq(74) + expect(users_statistics.billable).to eq(81) end context 'when there is an ultimate license' do @@ -18,14 +18,14 @@ end it 'excludes blocked users, bots, guest users, users without a group or project and minimal access users' do - expect(users_statistics.billable).to eq(43) + expect(users_statistics.billable).to eq(50) end end end describe '#active' do it 'includes minimal access roles' do - expect(users_statistics.active).to eq(76) + expect(users_statistics.active).to eq(83) end end diff --git a/locale/gitlab.pot b/locale/gitlab.pot index 7b46ee6a2156a7..68bb8e12c43723 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -3758,6 +3758,9 @@ msgstr "" msgid "AdminArea|Owner" msgstr "" +msgid "AdminArea|Planner" +msgstr "" + msgid "AdminArea|Projects" msgstr "" diff --git a/spec/factories/users_statistics.rb b/spec/factories/users_statistics.rb index 07699dc38b2e82..ea53ade722eebe 100644 --- a/spec/factories/users_statistics.rb +++ b/spec/factories/users_statistics.rb @@ -4,6 +4,7 @@ factory :users_statistics do without_groups_and_projects { 23 } with_highest_role_guest { 5 } + with_highest_role_planner { 7 } with_highest_role_reporter { 9 } with_highest_role_developer { 21 } with_highest_role_maintainer { 6 } diff --git a/spec/models/users_statistics_spec.rb b/spec/models/users_statistics_spec.rb index d1ca9ff5125258..26630ace9bae20 100644 --- a/spec/models/users_statistics_spec.rb +++ b/spec/models/users_statistics_spec.rb @@ -36,6 +36,7 @@ before do create_list(:user_highest_role, 1) create_list(:user_highest_role, 2, :guest) + create_list(:user_highest_role, 2, :planner) create_list(:user_highest_role, 2, :reporter) create_list(:user_highest_role, 2, :developer) create_list(:user_highest_role, 2, :maintainer) @@ -51,6 +52,7 @@ expect(described_class.create_current_stats!).to have_attributes( without_groups_and_projects: 1, with_highest_role_guest: 2, + with_highest_role_planner: 2, with_highest_role_reporter: 2, with_highest_role_developer: 2, with_highest_role_maintainer: 2, @@ -72,13 +74,13 @@ describe '#active' do it 'sums users statistics values without the value for blocked' do - expect(users_statistics.active).to eq(71) + expect(users_statistics.active).to eq(78) end end describe '#total' do it 'sums all users statistics values' do - expect(users_statistics.total).to eq(78) + expect(users_statistics.total).to eq(85) end end end -- GitLab From b77993cf30939eaabc2ff787113f4253b97c551b Mon Sep 17 00:00:00 2001 From: Eugenia Grieff Date: Tue, 3 Dec 2024 12:47:35 +0100 Subject: [PATCH 2/2] Fix feature specs in admin/dashboard_spec.rb --- spec/features/admin/dashboard_spec.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/spec/features/admin/dashboard_spec.rb b/spec/features/admin/dashboard_spec.rb index a7ad3a05c35302..67e7cd6dc94c3c 100644 --- a/spec/features/admin/dashboard_spec.rb +++ b/spec/features/admin/dashboard_spec.rb @@ -36,6 +36,7 @@ expect(page).to have_content('Users without a Group and Project 23') expect(page).to have_content('Users with highest role Guest 5') + expect(page).to have_content('Users with highest role Planner 7') expect(page).to have_content('Users with highest role Reporter 9') expect(page).to have_content('Users with highest role Developer 21') expect(page).to have_content('Users with highest role Maintainer 6') @@ -43,13 +44,13 @@ expect(page).to have_content('Bots 2') if Gitlab.ee? - expect(page).to have_content('Billable users 69') + expect(page).to have_content('Billable users 76') else - expect(page).not_to have_content('Billable users 69') + expect(page).not_to have_content('Billable users 76') end expect(page).to have_content('Blocked users 7') - expect(page).to have_content('Total users (active users + blocked users) 78') + expect(page).to have_content('Total users (active users + blocked users) 85') end end -- GitLab