Commit f062cb0d authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'vij-sm-pending-user-count-fe' into 'master'

Display pending user count when modifying user cap

See merge request gitlab-org/gitlab!66654
parents 9ac3a67a 9ceeb7b5
...@@ -11,7 +11,7 @@ import { ...@@ -11,7 +11,7 @@ import {
} from '@gitlab/ui'; } from '@gitlab/ui';
import { toSafeInteger } from 'lodash'; import { toSafeInteger } from 'lodash';
import csrf from '~/lib/utils/csrf'; import csrf from '~/lib/utils/csrf';
import { __, s__, sprintf } from '~/locale'; import { __, n__, s__, sprintf } from '~/locale';
import SignupCheckbox from './signup_checkbox.vue'; import SignupCheckbox from './signup_checkbox.vue';
const DENYLIST_TYPE_RAW = 'raw'; const DENYLIST_TYPE_RAW = 'raw';
...@@ -51,6 +51,7 @@ export default { ...@@ -51,6 +51,7 @@ export default {
'supportedSyntaxLinkUrl', 'supportedSyntaxLinkUrl',
'emailRestrictions', 'emailRestrictions',
'afterSignUpText', 'afterSignUpText',
'pendingUserCount',
], ],
data() { data() {
return { return {
...@@ -105,8 +106,9 @@ export default { ...@@ -105,8 +106,9 @@ export default {
canUsersBeAccidentallyApproved() { canUsersBeAccidentallyApproved() {
const hasUserCapBeenToggledOff = const hasUserCapBeenToggledOff =
this.requireAdminApprovalAfterUserSignup && !this.form.requireAdminApproval; this.requireAdminApprovalAfterUserSignup && !this.form.requireAdminApproval;
const currentlyPendingUsers = this.pendingUserCount > 0;
return this.hasUserCapBeenIncreased || hasUserCapBeenToggledOff; return (this.hasUserCapBeenIncreased || hasUserCapBeenToggledOff) && currentlyPendingUsers;
}, },
signupEnabledHelpText() { signupEnabledHelpText() {
const text = sprintf( const text = sprintf(
...@@ -132,13 +134,39 @@ export default { ...@@ -132,13 +134,39 @@ export default {
return text; return text;
}, },
approveUsersModal() {
const { pendingUserCount } = this;
return {
id: 'signup-settings-modal',
text: n__(
'ApplicationSettings|By making this change, you will automatically approve %d user with the pending approval status.',
'ApplicationSettings|By making this change, you will automatically approve %d users with the pending approval status.',
pendingUserCount,
),
actionPrimary: {
text: n__(
'ApplicationSettings|Approve %d user',
'ApplicationSettings|Approve %d users',
pendingUserCount,
),
attributes: {
variant: 'confirm',
},
},
actionCancel: {
text: __('Cancel'),
},
title: s__('ApplicationSettings|Approve users in the pending approval status?'),
};
},
}, },
watch: { watch: {
showModal(value) { showModal(value) {
if (value === true) { if (value === true) {
this.$refs[this.$options.modal.id].show(); this.$refs[this.approveUsersModal.id].show();
} else { } else {
this.$refs[this.$options.modal.id].hide(); this.$refs[this.approveUsersModal.id].hide();
} }
}, },
}, },
...@@ -196,22 +224,6 @@ export default { ...@@ -196,22 +224,6 @@ export default {
afterSignUpTextGroupLabel: s__('ApplicationSettings|After sign up text'), afterSignUpTextGroupLabel: s__('ApplicationSettings|After sign up text'),
afterSignUpTextGroupDescription: s__('ApplicationSettings|Markdown enabled'), afterSignUpTextGroupDescription: s__('ApplicationSettings|Markdown enabled'),
}, },
modal: {
id: 'signup-settings-modal',
actionPrimary: {
text: s__('ApplicationSettings|Approve users'),
attributes: {
variant: 'confirm',
},
},
actionCancel: {
text: __('Cancel'),
},
title: s__('ApplicationSettings|Approve all users in the pending approval status?'),
text: s__(
'ApplicationSettings|By making this change, you will automatically approve all users in pending approval status.',
),
},
}; };
</script> </script>
...@@ -403,15 +415,15 @@ export default { ...@@ -403,15 +415,15 @@ export default {
</gl-button> </gl-button>
<gl-modal <gl-modal
:ref="$options.modal.id" :ref="approveUsersModal.id"
:modal-id="$options.modal.id" :modal-id="approveUsersModal.id"
:action-cancel="$options.modal.actionCancel" :action-cancel="approveUsersModal.actionCancel"
:action-primary="$options.modal.actionPrimary" :action-primary="approveUsersModal.actionPrimary"
:title="$options.modal.title" :title="approveUsersModal.title"
@primary="submitForm" @primary="submitForm"
@hide="modalHideHandler" @hide="modalHideHandler"
> >
{{ $options.modal.text }} {{ approveUsersModal.text }}
</gl-modal> </gl-modal>
</form> </form>
</template> </template>
...@@ -313,15 +313,43 @@ RSpec.describe 'Admin updates EE-only settings' do ...@@ -313,15 +313,43 @@ RSpec.describe 'Admin updates EE-only settings' do
end end
end end
it 'changes the user cap to unlimited' do context 'with a user cap assigned' do
visit general_admin_application_settings_path before do
current_settings.update_attribute(:new_user_signups_cap, 5)
end
page.within('#js-signup-settings') do it 'changes the user cap to unlimited' do
fill_in 'application_setting[new_user_signups_cap]', with: nil visit general_admin_application_settings_path
click_button 'Save changes' page.within('#js-signup-settings') do
fill_in 'application_setting[new_user_signups_cap]', with: nil
click_button 'Save changes'
expect(current_settings.new_user_signups_cap).to be_nil expect(current_settings.new_user_signups_cap).to be_nil
end
end
context 'with pending users' do
before do
create(:user, :blocked_pending_approval)
end
it 'displays a modal confirmation when removing the cap' do
visit general_admin_application_settings_path
page.within('#js-signup-settings') do
fill_in 'application_setting[new_user_signups_cap]', with: nil
click_button 'Save changes'
end
page.within('.modal') do
click_button 'Approve 1 user'
end
expect(current_settings.new_user_signups_cap).to be_nil
end
end end
end end
end end
......
...@@ -3963,14 +3963,18 @@ msgstr "" ...@@ -3963,14 +3963,18 @@ msgstr ""
msgid "ApplicationSettings|Allowed domains for sign-ups" msgid "ApplicationSettings|Allowed domains for sign-ups"
msgstr "" msgstr ""
msgid "ApplicationSettings|Approve all users in the pending approval status?" msgid "ApplicationSettings|Approve %d user"
msgstr "" msgid_plural "ApplicationSettings|Approve %d users"
msgstr[0] ""
msgstr[1] ""
msgid "ApplicationSettings|Approve users" msgid "ApplicationSettings|Approve users in the pending approval status?"
msgstr "" msgstr ""
msgid "ApplicationSettings|By making this change, you will automatically approve all users in pending approval status." msgid "ApplicationSettings|By making this change, you will automatically approve %d user with the pending approval status."
msgstr "" msgid_plural "ApplicationSettings|By making this change, you will automatically approve %d users with the pending approval status."
msgstr[0] ""
msgstr[1] ""
msgid "ApplicationSettings|Denied domains for sign-ups" msgid "ApplicationSettings|Denied domains for sign-ups"
msgstr "" msgstr ""
......
...@@ -192,22 +192,27 @@ describe('Signup Form', () => { ...@@ -192,22 +192,27 @@ describe('Signup Form', () => {
describe('form submit button confirmation modal for side-effect of adding possibly unwanted new users', () => { describe('form submit button confirmation modal for side-effect of adding possibly unwanted new users', () => {
it.each` it.each`
requireAdminApprovalAction | userCapAction | buttonEffect requireAdminApprovalAction | userCapAction | pendingUserCount | buttonEffect
${'unchanged from true'} | ${'unchanged'} | ${'submits form'} ${'unchanged from true'} | ${'unchanged'} | ${0} | ${'submits form'}
${'unchanged from false'} | ${'unchanged'} | ${'submits form'} ${'unchanged from false'} | ${'unchanged'} | ${0} | ${'submits form'}
${'toggled off'} | ${'unchanged'} | ${'shows confirmation modal'} ${'toggled off'} | ${'unchanged'} | ${1} | ${'shows confirmation modal'}
${'toggled on'} | ${'unchanged'} | ${'submits form'} ${'toggled off'} | ${'unchanged'} | ${0} | ${'submits form'}
${'unchanged from false'} | ${'increased'} | ${'shows confirmation modal'} ${'toggled on'} | ${'unchanged'} | ${0} | ${'submits form'}
${'unchanged from true'} | ${'increased'} | ${'shows confirmation modal'} ${'unchanged from false'} | ${'increased'} | ${1} | ${'shows confirmation modal'}
${'toggled off'} | ${'increased'} | ${'shows confirmation modal'} ${'unchanged from true'} | ${'increased'} | ${0} | ${'submits form'}
${'toggled on'} | ${'increased'} | ${'shows confirmation modal'} ${'toggled off'} | ${'increased'} | ${1} | ${'shows confirmation modal'}
${'toggled on'} | ${'decreased'} | ${'submits form'} ${'toggled off'} | ${'increased'} | ${0} | ${'submits form'}
${'unchanged from false'} | ${'changed from limited to unlimited'} | ${'shows confirmation modal'} ${'toggled on'} | ${'increased'} | ${1} | ${'shows confirmation modal'}
${'unchanged from false'} | ${'changed from unlimited to limited'} | ${'submits form'} ${'toggled on'} | ${'increased'} | ${0} | ${'submits form'}
${'unchanged from false'} | ${'unchanged from unlimited'} | ${'submits form'} ${'toggled on'} | ${'decreased'} | ${0} | ${'submits form'}
${'toggled on'} | ${'decreased'} | ${1} | ${'submits form'}
${'unchanged from false'} | ${'changed from limited to unlimited'} | ${1} | ${'shows confirmation modal'}
${'unchanged from false'} | ${'changed from limited to unlimited'} | ${0} | ${'submits form'}
${'unchanged from false'} | ${'changed from unlimited to limited'} | ${0} | ${'submits form'}
${'unchanged from false'} | ${'unchanged from unlimited'} | ${0} | ${'submits form'}
`( `(
'$buttonEffect if require admin approval for new sign-ups is $requireAdminApprovalAction and the user cap is $userCapAction', '$buttonEffect if require admin approval for new sign-ups is $requireAdminApprovalAction and the user cap is $userCapAction and pending user count is $pendingUserCount',
async ({ requireAdminApprovalAction, userCapAction, buttonEffect }) => { async ({ requireAdminApprovalAction, userCapAction, pendingUserCount, buttonEffect }) => {
let isModalDisplayed; let isModalDisplayed;
switch (buttonEffect) { switch (buttonEffect) {
...@@ -224,7 +229,9 @@ describe('Signup Form', () => { ...@@ -224,7 +229,9 @@ describe('Signup Form', () => {
const isFormSubmittedWhenClickingFormSubmitButton = !isModalDisplayed; const isFormSubmittedWhenClickingFormSubmitButton = !isModalDisplayed;
const injectedProps = {}; const injectedProps = {
pendingUserCount,
};
const USER_CAP_DEFAULT = 5; const USER_CAP_DEFAULT = 5;
...@@ -310,6 +317,7 @@ describe('Signup Form', () => { ...@@ -310,6 +317,7 @@ describe('Signup Form', () => {
await mountComponent({ await mountComponent({
injectedProps: { injectedProps: {
newUserSignupsCap: INITIAL_USER_CAP, newUserSignupsCap: INITIAL_USER_CAP,
pendingUserCount: 5,
}, },
stubs: { GlButton, GlModal: stubComponent(GlModal) }, stubs: { GlButton, GlModal: stubComponent(GlModal) },
}); });
......
...@@ -17,6 +17,7 @@ export const rawMockData = { ...@@ -17,6 +17,7 @@ export const rawMockData = {
supportedSyntaxLinkUrl: '/supported/syntax/link', supportedSyntaxLinkUrl: '/supported/syntax/link',
emailRestrictions: 'user1@domain.com, user2@domain.com', emailRestrictions: 'user1@domain.com, user2@domain.com',
afterSignUpText: 'Congratulations on your successful sign-up!', afterSignUpText: 'Congratulations on your successful sign-up!',
pendingUserCount: '0',
}; };
export const mockData = { export const mockData = {
...@@ -38,4 +39,5 @@ export const mockData = { ...@@ -38,4 +39,5 @@ export const mockData = {
supportedSyntaxLinkUrl: '/supported/syntax/link', supportedSyntaxLinkUrl: '/supported/syntax/link',
emailRestrictions: 'user1@domain.com, user2@domain.com', emailRestrictions: 'user1@domain.com, user2@domain.com',
afterSignUpText: 'Congratulations on your successful sign-up!', afterSignUpText: 'Congratulations on your successful sign-up!',
pendingUserCount: '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