Commit 137ab2c0 authored by Krasimir Angelov's avatar Krasimir Angelov Committed by Enrique Alcantara

Make seat usage available only for top-level groups

Update Groups::SeatUsageController to respond with 404 Not Found if the
group is not top-level group, in order to match API -
https://gitlab.com/gitlab-org/gitlab/-/blob/fa74a193238b237b11577f79298e1203dbc48de9/ee/lib/ee/api/members.rb#L68.
parent 4ea549d0
# frozen_string_literal: true
class Groups::SeatUsageController < Groups::ApplicationController
before_action :verify_top_level_group
before_action :authorize_admin_group_member!
before_action :verify_namespace_plan_check_enabled
before_action :seat_usage_export_enabled?, if: -> { request.format.csv? }
before_action :verify_seat_usage_export_enabled, if: -> { request.format.csv? }
layout "group_settings"
......@@ -36,7 +37,11 @@ class Groups::SeatUsageController < Groups::ApplicationController
"seat-usage-export-#{Time.current.to_s(:number)}.csv"
end
def seat_usage_export_enabled?
def verify_top_level_group
not_found unless group.root?
end
def verify_seat_usage_export_enabled
not_found unless Feature.enabled?(:seat_usage_export, group, default_enabled: :yaml)
end
end
......@@ -12,8 +12,8 @@ RSpec.describe Groups::SeatUsageController do
stub_application_setting(check_namespace_plan: true)
end
def get_show(format: :html)
get :show, params: { group_id: group }, format: format
def get_show(format: :html, group_id: group)
get :show, params: { group_id: group_id }, format: format
end
subject { response }
......@@ -34,9 +34,26 @@ RSpec.describe Groups::SeatUsageController do
expect(response).to have_gitlab_http_status(:ok)
expect(response).to render_template(:show)
end
it 'responds with 404 Not Found if the group is not top-level group' do
subgroup = create(:group, :private, :nested)
subgroup.add_owner(user)
get_show(group_id: subgroup)
expect(response).to have_gitlab_http_status(:not_found)
end
end
context 'when csv format' do
it 'responds with 404 Not Found if the group is not top-level group' do
subgroup = create(:group, :private, :nested)
subgroup.add_owner(user)
get_show(group_id: subgroup, format: :csv)
expect(response).to have_gitlab_http_status(:not_found)
end
context 'when seat_usage_export feature flag is disabled' do
before do
stub_feature_flags(seat_usage_export: false)
......
......@@ -29,7 +29,6 @@ const providedFields = {
namespaceName: 'Test Group Name',
namespaceId: '1000',
seatUsageExportPath: '/groups/test_group/-/seat_usage.csv',
};
const fakeStore = ({ initialState, initialGetters }) =>
......@@ -75,7 +74,7 @@ describe('Subscription Seats', () => {
const findPageHeadingText = () => findPageHeading().find('[data-testid="heading-info-text"]');
const findPageHeadingBadge = () => findPageHeading().find(GlBadge);
const findExportButton= () => wrapper.findByTestId('export-button');
const findExportButton = () => wrapper.findByTestId('export-button');
const findSearchBox = () => wrapper.findComponent(FilterSortContainerRoot);
const findPagination = () => wrapper.findComponent(GlPagination);
......
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