Commit 19f02a9b authored by Patrick Bajao's avatar Patrick Bajao

Merge branch '334296-add-user-cap-setting' into 'master'

Add user cap to group's membership settings

See merge request gitlab-org/gitlab!72006
parents 1fdaf53a 365904e8
......@@ -4,3 +4,4 @@
= render 'shared/allow_request_access', form: f
= render_if_exists 'groups/member_lock_setting', f: f, group: @group
= render_if_exists 'groups/user_caps_setting', f: f, group: @group
......@@ -71,7 +71,8 @@ module EE
def group_params_ee
[
:membership_lock,
:repository_size_limit
:repository_size_limit,
:new_user_signups_cap
].tap do |params_ee|
params_ee << { insight_attributes: [:id, :project_id, :_destroy] } if current_group&.insights_available?
params_ee << :file_template_project_id if current_group&.feature_available?(:custom_file_templates_for_namespace)
......
- return unless Feature.enabled?(:saas_user_caps, group.root_ancestor)
- user_cap_docs_link_url = help_page_path("/user/admin_area/settings/sign_up_restrictions", anchor: "user-cap")
- user_cap_docs_link_start = '<a href="%{url}" target="_blank" rel="noopener noreferrer">'.html_safe % { url: user_cap_docs_link_url }
.form-group
= f.label :new_user_signups_cap, _('User cap'), class: 'gl-font-weight-bold'
.form-text.text-muted= html_escape(_('When the number of active users exceeds this number, additional users must be %{user_cap_docs_link_start}approved by an owner%{user_cap_docs_link_end}. Leave empty if you don\'t want to enforce approvals.')) % { user_cap_docs_link_start: user_cap_docs_link_start, user_cap_docs_link_end: '</a>'.html_safe }
= f.number_field :new_user_signups_cap, min: 1, class: 'form-control form-control-sm gl-form-input gl-w-full gl-mt-3'
......@@ -615,5 +615,38 @@ RSpec.describe GroupsController do
end
end
end
context 'when `new_user_signups_cap` is specified' do
subject { put :update, params: params }
shared_examples_for 'updates the attribute' do
it 'updates the attribute' do
subject
expect(response).to have_gitlab_http_status(status)
expect(group.reload.new_user_signups_cap).to eq(result)
end
end
context 'authenticated as group owner' do
where(:new_user_signups_cap, :result, :status) do
nil | nil | :found
10 | 10 | :found
end
with_them do
let(:params) do
{ id: group.to_param, group: { new_user_signups_cap: new_user_signups_cap } }
end
before do
group.add_owner(user)
sign_in(user)
end
it_behaves_like 'updates the attribute'
end
end
end
end
end
......@@ -408,6 +408,52 @@ RSpec.describe 'Edit group settings' do
end
end
describe 'user caps settings' do
context 'when :saas_user_caps feature flag is off' do
before do
stub_feature_flags(saas_user_caps: false)
visit edit_group_path(group)
end
it 'is not visible' do
expect(page).not_to have_content('User cap')
end
end
context 'when :saas_user_caps feature flag is on', :js do
let(:user_caps_selector) { '[name="group[new_user_signups_cap]"]' }
before do
stub_feature_flags(saas_user_caps: true)
visit edit_group_path(group)
end
it 'is visible' do
expect(page).to have_content('User cap')
end
it 'will save positive numbers' do
find(user_caps_selector).set(5)
click_button 'Save changes'
wait_for_requests
expect(page).to have_content("Group 'Foo bar' was successfully updated.")
end
it 'will not allow negative number' do
find(user_caps_selector).set(-5)
click_button 'Save changes'
expect(page).to have_content('This field is required.')
wait_for_requests
expect(page).not_to have_content("Group 'Foo bar' was successfully updated.")
end
end
end
def save_permissions_group
page.within('.gs-permissions') do
click_button 'Save changes'
......
......@@ -37127,6 +37127,9 @@ msgstr ""
msgid "User and IP rate limits"
msgstr ""
msgid "User cap"
msgstr ""
msgid "User created at"
msgstr ""
......@@ -38429,6 +38432,9 @@ msgstr ""
msgid "When merge requests and commits in the default branch close, any issues they reference also close."
msgstr ""
msgid "When the number of active users exceeds this number, additional users must be %{user_cap_docs_link_start}approved by an owner%{user_cap_docs_link_end}. Leave empty if you don't want to enforce approvals."
msgstr ""
msgid "When this merge request is accepted"
msgid_plural "When these merge requests are accepted"
msgstr[0] ""
......
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