From 048f5998001dcda45b2629a5a800f63d8481ebd2 Mon Sep 17 00:00:00 2001
From: Angelo Gulina <agulina@gitlab.com>
Date: Tue, 18 Feb 2025 16:51:17 +0100
Subject: [PATCH] Update seats related notifications

When Restricted Access is active, seats related notifications copy
and interaction should change accordingly.

Changelog: changed
EE: true
---
 app/views/layouts/_page.html.haml             |  3 +-
 .../all_seats_used_alert_component.html.haml  |  2 +-
 ee/app/helpers/seat_count_alert_helper.rb     | 16 ++++++++++
 .../header/_all_seats_used_alert.html.haml    |  1 -
 .../header/_seat_count_alert.html.haml        | 29 ++++++++++---------
 .../helpers/seat_count_alert_helper_spec.rb   | 20 ++++++++++++-
 locale/gitlab.pot                             |  6 ++++
 7 files changed, 58 insertions(+), 19 deletions(-)
 delete mode 100644 ee/app/views/layouts/header/_all_seats_used_alert.html.haml

diff --git a/app/views/layouts/_page.html.haml b/app/views/layouts/_page.html.haml
index 4d4d1a38fd4ea..4d5ab713b7b76 100644
--- a/app/views/layouts/_page.html.haml
+++ b/app/views/layouts/_page.html.haml
@@ -35,8 +35,7 @@
       = dispensable_render "shared/gitlab_version/security_patch_upgrade_alert"
       = dispensable_render "shared/service_ping_consent"
       = dispensable_render_if_exists "layouts/header/ee_subscribable_banner"
-      = dispensable_render_if_exists "layouts/header/seat_count_alert"
-      = dispensable_render_if_exists "layouts/header/all_seats_used_alert", context: context
+      = dispensable_render_if_exists "layouts/header/seat_count_alert", context: context
       = dispensable_render_if_exists "shared/namespace_user_cap_reached_alert"
       = dispensable_render_if_exists "shared/new_user_signups_cap_reached_alert"
       = dispensable_render_if_exists "shared/silent_mode_banner"
diff --git a/ee/app/components/namespaces/block_seat_overages/all_seats_used_alert_component.html.haml b/ee/app/components/namespaces/block_seat_overages/all_seats_used_alert_component.html.haml
index 945f00b249fe4..4f10200358a26 100644
--- a/ee/app/components/namespaces/block_seat_overages/all_seats_used_alert_component.html.haml
+++ b/ee/app/components/namespaces/block_seat_overages/all_seats_used_alert_component.html.haml
@@ -1,4 +1,4 @@
-%div{ class: [@content_class, '!gl-pt-5'] }
+%div
   = render Pajamas::AlertComponent.new(alert_options: { class: 'js-all-seats-used',
                                                         data: { dismiss_endpoint: group_callouts_path,
                                                         feature_id: EE::Users::GroupCalloutsHelper::ALL_SEATS_USED_ALERT,
diff --git a/ee/app/helpers/seat_count_alert_helper.rb b/ee/app/helpers/seat_count_alert_helper.rb
index 3f92bf4de1cc1..f47f62c682154 100644
--- a/ee/app/helpers/seat_count_alert_helper.rb
+++ b/ee/app/helpers/seat_count_alert_helper.rb
@@ -16,4 +16,20 @@ def total_seat_count
   def namespace
     @seat_count_data[:namespace]
   end
+
+  def seat_count_text
+    if namespace.block_seat_overages?
+      return _('Once you reach the number of seats in your subscription, you can no longer ' \
+        'invite or add users to the namespace.')
+    end
+
+    _('Even if you reach the number of seats in your subscription, you can continue to add users, ' \
+      'and GitLab will bill you for the overage.')
+  end
+
+  def seat_count_help_page_link
+    return help_page_path('user/group/manage.md', anchor: 'turn-on-restricted-access') if namespace.block_seat_overages?
+
+    help_page_path('subscriptions/quarterly_reconciliation.md')
+  end
 end
diff --git a/ee/app/views/layouts/header/_all_seats_used_alert.html.haml b/ee/app/views/layouts/header/_all_seats_used_alert.html.haml
deleted file mode 100644
index b54114bda9a93..0000000000000
--- a/ee/app/views/layouts/header/_all_seats_used_alert.html.haml
+++ /dev/null
@@ -1 +0,0 @@
-= render Namespaces::BlockSeatOverages::AllSeatsUsedAlertComponent.new(context: context, content_class: full_content_class, current_user: current_user)
diff --git a/ee/app/views/layouts/header/_seat_count_alert.html.haml b/ee/app/views/layouts/header/_seat_count_alert.html.haml
index 92b94c4955467..db40a8099aeea 100644
--- a/ee/app/views/layouts/header/_seat_count_alert.html.haml
+++ b/ee/app/views/layouts/header/_seat_count_alert.html.haml
@@ -1,14 +1,15 @@
-- return unless show_seat_count_alert?
-
-= render Pajamas::AlertComponent.new(alert_options: { class: 'js-approaching-seat-count-threshold',
-  data: { dismiss_endpoint: group_callouts_path,
-          feature_id: Users::GroupCalloutsHelper::APPROACHING_SEAT_COUNT_THRESHOLD,
-          group_id: namespace.id }},
-  title: _('%{group_name} is approaching the limit of available seats') % { group_name: namespace.name },
-  close_button_options: { data: { testid: 'approaching-seat-count-threshold-alert-dismiss' }}) do |c|
-  - c.with_body do
-    = n_('Your subscription has %{remaining_seat_count} out of %{total_seat_count} seat remaining.', 'Your subscription has %{remaining_seat_count} out of %{total_seat_count} seats remaining.', total_seat_count) % { remaining_seat_count: remaining_seat_count, total_seat_count: total_seat_count }
-    = _('Even if you reach the number of seats in your subscription, you can continue to add users, and GitLab will bill you for the overage.')
-    = link_to _('Learn more.'), help_page_path('subscriptions/quarterly_reconciliation.md'), target: '_blank', rel: 'noopener noreferrer'
-  - c.with_actions do
-    = link_button_to _('View seat usage'), usage_quotas_path(namespace, anchor: 'seats-quota-tab'), class: 'gl-alert-action', variant: :confirm
+- if show_seat_count_alert?
+  = render Pajamas::AlertComponent.new(alert_options: { class: 'js-approaching-seat-count-threshold',
+    data: { dismiss_endpoint: group_callouts_path,
+            feature_id: Users::GroupCalloutsHelper::APPROACHING_SEAT_COUNT_THRESHOLD,
+            group_id: namespace.id }},
+    title: _('%{group_name} is approaching the limit of available seats') % { group_name: namespace.name },
+    close_button_options: { data: { testid: 'approaching-seat-count-threshold-alert-dismiss' }}) do |c|
+    - c.with_body do
+      = n_('Your subscription has %{remaining_seat_count} out of %{total_seat_count} seat remaining.', 'Your subscription has %{remaining_seat_count} out of %{total_seat_count} seats remaining.', total_seat_count) % { remaining_seat_count: remaining_seat_count, total_seat_count: total_seat_count }
+      = seat_count_text
+      = link_to _('Learn more.'), seat_count_help_page_link, target: '_blank', rel: 'noopener noreferrer'
+    - c.with_actions do
+      = link_button_to _('View seat usage'), usage_quotas_path(namespace, anchor: 'seats-quota-tab'), class: 'gl-alert-action', variant: :confirm
+- else
+  = render Namespaces::BlockSeatOverages::AllSeatsUsedAlertComponent.new(context: context, content_class: full_content_class, current_user: current_user)
diff --git a/ee/spec/helpers/seat_count_alert_helper_spec.rb b/ee/spec/helpers/seat_count_alert_helper_spec.rb
index 15991eafc255c..ae6ac463afe82 100644
--- a/ee/spec/helpers/seat_count_alert_helper_spec.rb
+++ b/ee/spec/helpers/seat_count_alert_helper_spec.rb
@@ -2,7 +2,7 @@
 
 require 'spec_helper'
 
-RSpec.describe SeatCountAlertHelper, :saas do
+RSpec.describe SeatCountAlertHelper, :saas, feature_category: :seat_cost_management do
   let(:user) { create(:user) }
 
   let(:seat_count_data) do
@@ -63,4 +63,22 @@
       end
     end
   end
+
+  describe '#seat_count_text' do
+    let(:namespace) { create(:group) }
+
+    it 'returns the correct copy' do
+      expect(helper.seat_count_text).to eq('Even if you reach the number of seats in your subscription, ' \
+        'you can continue to add users, and GitLab will bill you for the overage.')
+    end
+
+    context 'when restricted access is active' do
+      it 'returns the correct copy' do
+        namespace.namespace_settings.update!(seat_control: :block_overages)
+
+        expect(helper.seat_count_text).to eq('Once you reach the number of seats in your subscription, ' \
+          'you can no longer invite or add users to the namespace.')
+      end
+    end
+  end
 end
diff --git a/locale/gitlab.pot b/locale/gitlab.pot
index 7a4b83239ca7c..2ec0ae0b9a1ac 100644
--- a/locale/gitlab.pot
+++ b/locale/gitlab.pot
@@ -40161,6 +40161,9 @@ msgstr ""
 msgid "Once imported, repositories can be mirrored over SSH. Read more %{link_start}here%{link_end}."
 msgstr ""
 
+msgid "Once you reach the number of seats in your subscription, you can no longer invite or add users to the namespace."
+msgstr ""
+
 msgid "One and only one of %{params} is required"
 msgstr ""
 
@@ -43285,6 +43288,9 @@ msgstr ""
 msgid "Pipeline|Variable"
 msgstr ""
 
+msgid "Pipeline|Variable type"
+msgstr ""
+
 msgid "Pipeline|Variables"
 msgstr ""
 
-- 
GitLab