Add ability to require invite request text (#15326)
Fixes #15273 Co-authored-by: Claire <claire.github-309c@sitedethib.com>lolsob-rspec
parent
5749bd73ca
commit
64eaaff345
|
@ -67,10 +67,36 @@ const onEnableBootstrapTimelineAccountsChange = (target) => {
|
||||||
|
|
||||||
delegate(document, '#form_admin_settings_enable_bootstrap_timeline_accounts', 'change', ({ target }) => onEnableBootstrapTimelineAccountsChange(target));
|
delegate(document, '#form_admin_settings_enable_bootstrap_timeline_accounts', 'change', ({ target }) => onEnableBootstrapTimelineAccountsChange(target));
|
||||||
|
|
||||||
|
const onChangeRegistrationMode = (target) => {
|
||||||
|
const enabled = target.value === 'approved';
|
||||||
|
|
||||||
|
[].forEach.call(document.querySelectorAll('#form_admin_settings_require_invite_text'), (input) => {
|
||||||
|
input.disabled = !enabled;
|
||||||
|
if (enabled) {
|
||||||
|
let element = input;
|
||||||
|
do {
|
||||||
|
element.classList.remove('disabled');
|
||||||
|
element = element.parentElement;
|
||||||
|
} while (element && !element.classList.contains('fields-group'));
|
||||||
|
} else {
|
||||||
|
let element = input;
|
||||||
|
do {
|
||||||
|
element.classList.add('disabled');
|
||||||
|
element = element.parentElement;
|
||||||
|
} while (element && !element.classList.contains('fields-group'));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
delegate(document, '#form_admin_settings_registrations_mode', 'change', ({ target }) => onChangeRegistrationMode(target));
|
||||||
|
|
||||||
ready(() => {
|
ready(() => {
|
||||||
const domainBlockSeverityInput = document.getElementById('domain_block_severity');
|
const domainBlockSeverityInput = document.getElementById('domain_block_severity');
|
||||||
if (domainBlockSeverityInput) onDomainBlockSeverityChange(domainBlockSeverityInput);
|
if (domainBlockSeverityInput) onDomainBlockSeverityChange(domainBlockSeverityInput);
|
||||||
|
|
||||||
const enableBootstrapTimelineAccounts = document.getElementById('form_admin_settings_enable_bootstrap_timeline_accounts');
|
const enableBootstrapTimelineAccounts = document.getElementById('form_admin_settings_enable_bootstrap_timeline_accounts');
|
||||||
if (enableBootstrapTimelineAccounts) onEnableBootstrapTimelineAccountsChange(enableBootstrapTimelineAccounts);
|
if (enableBootstrapTimelineAccounts) onEnableBootstrapTimelineAccountsChange(enableBootstrapTimelineAccounts);
|
||||||
|
|
||||||
|
const registrationMode = document.getElementById('form_admin_settings_registrations_mode');
|
||||||
|
if (registrationMode) onChangeRegistrationMode(registrationMode);
|
||||||
});
|
});
|
||||||
|
|
|
@ -377,11 +377,6 @@ code {
|
||||||
box-shadow: none;
|
box-shadow: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
&:focus:invalid:not(:placeholder-shown),
|
|
||||||
&:required:invalid:not(:placeholder-shown) {
|
|
||||||
border-color: lighten($error-red, 12%);
|
|
||||||
}
|
|
||||||
|
|
||||||
&:required:valid {
|
&:required:valid {
|
||||||
border-color: $valid-value-color;
|
border-color: $valid-value-color;
|
||||||
}
|
}
|
||||||
|
@ -397,6 +392,16 @@ code {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
input[type=text],
|
||||||
|
input[type=number],
|
||||||
|
input[type=email],
|
||||||
|
input[type=password] {
|
||||||
|
&:focus:invalid:not(:placeholder-shown),
|
||||||
|
&:required:invalid:not(:placeholder-shown) {
|
||||||
|
border-color: lighten($error-red, 12%);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.input.field_with_errors {
|
.input.field_with_errors {
|
||||||
label {
|
label {
|
||||||
color: lighten($error-red, 12%);
|
color: lighten($error-red, 12%);
|
||||||
|
|
|
@ -35,6 +35,7 @@ class Form::AdminSettings
|
||||||
show_domain_blocks
|
show_domain_blocks
|
||||||
show_domain_blocks_rationale
|
show_domain_blocks_rationale
|
||||||
noindex
|
noindex
|
||||||
|
require_invite_text
|
||||||
).freeze
|
).freeze
|
||||||
|
|
||||||
BOOLEAN_KEYS = %i(
|
BOOLEAN_KEYS = %i(
|
||||||
|
@ -51,6 +52,7 @@ class Form::AdminSettings
|
||||||
trends
|
trends
|
||||||
trendable_by_default
|
trendable_by_default
|
||||||
noindex
|
noindex
|
||||||
|
require_invite_text
|
||||||
).freeze
|
).freeze
|
||||||
|
|
||||||
UPLOAD_KEYS = %i(
|
UPLOAD_KEYS = %i(
|
||||||
|
|
|
@ -82,7 +82,8 @@ class User < ApplicationRecord
|
||||||
has_many :webauthn_credentials, dependent: :destroy
|
has_many :webauthn_credentials, dependent: :destroy
|
||||||
|
|
||||||
has_one :invite_request, class_name: 'UserInviteRequest', inverse_of: :user, dependent: :destroy
|
has_one :invite_request, class_name: 'UserInviteRequest', inverse_of: :user, dependent: :destroy
|
||||||
accepts_nested_attributes_for :invite_request, reject_if: ->(attributes) { attributes['text'].blank? }
|
accepts_nested_attributes_for :invite_request, reject_if: ->(attributes) { attributes['text'].blank? && !Setting.require_invite_text }
|
||||||
|
validates :invite_request, presence: true, on: :create, if: -> { Setting.require_invite_text }
|
||||||
|
|
||||||
validates :locale, inclusion: I18n.available_locales.map(&:to_s), if: :locale?
|
validates :locale, inclusion: I18n.available_locales.map(&:to_s), if: :locale?
|
||||||
validates_with BlacklistedEmailValidator, on: :create
|
validates_with BlacklistedEmailValidator, on: :create
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
- if approved_registrations?
|
- if approved_registrations?
|
||||||
.fields-group
|
.fields-group
|
||||||
= f.simple_fields_for :invite_request do |invite_request_fields|
|
= f.simple_fields_for :invite_request do |invite_request_fields|
|
||||||
= invite_request_fields.input :text, as: :text, wrapper: :with_block_label, required: false
|
= invite_request_fields.input :text, as: :text, wrapper: :with_block_label, required: Setting.require_invite_text
|
||||||
|
|
||||||
.fields-group
|
.fields-group
|
||||||
= f.input :agreement, as: :boolean, wrapper: :with_label, label: t('auth.checkbox_agreement_html', rules_path: about_more_path, terms_path: terms_path), required: true, disabled: closed_registrations?
|
= f.input :agreement, as: :boolean, wrapper: :with_label, label: t('auth.checkbox_agreement_html', rules_path: about_more_path, terms_path: terms_path), required: true, disabled: closed_registrations?
|
||||||
|
|
|
@ -43,6 +43,12 @@
|
||||||
|
|
||||||
%hr.spacer/
|
%hr.spacer/
|
||||||
|
|
||||||
|
.fields-group
|
||||||
|
= f.input :require_invite_text, as: :boolean, wrapper: :with_label, label: t('admin.settings.registrations.require_invite_text.title'), hint: t('admin.settings.registrations.require_invite_text.desc_html'), disabled: !approved_registrations?
|
||||||
|
.fields-group
|
||||||
|
|
||||||
|
%hr.spacer/
|
||||||
|
|
||||||
.fields-group
|
.fields-group
|
||||||
= f.input :enable_bootstrap_timeline_accounts, as: :boolean, wrapper: :with_label, label: t('admin.settings.enable_bootstrap_timeline_accounts.title')
|
= f.input :enable_bootstrap_timeline_accounts, as: :boolean, wrapper: :with_label, label: t('admin.settings.enable_bootstrap_timeline_accounts.title')
|
||||||
.fields-group
|
.fields-group
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
- if approved_registrations? && !@invite.present?
|
- if approved_registrations? && !@invite.present?
|
||||||
.fields-group
|
.fields-group
|
||||||
= f.simple_fields_for :invite_request, resource.invite_request || resource.build_invite_request do |invite_request_fields|
|
= f.simple_fields_for :invite_request, resource.invite_request || resource.build_invite_request do |invite_request_fields|
|
||||||
= invite_request_fields.input :text, as: :text, wrapper: :with_block_label, required: false
|
= invite_request_fields.input :text, as: :text, wrapper: :with_block_label, required: Setting.require_invite_text
|
||||||
|
|
||||||
= f.input :invite_code, as: :hidden
|
= f.input :invite_code, as: :hidden
|
||||||
|
|
||||||
|
|
|
@ -586,6 +586,9 @@ en:
|
||||||
min_invite_role:
|
min_invite_role:
|
||||||
disabled: No one
|
disabled: No one
|
||||||
title: Allow invitations by
|
title: Allow invitations by
|
||||||
|
require_invite_text:
|
||||||
|
desc_html: When registrations require manual approval, make the “Why do you want to join?” invite request text mandatory rather than optional
|
||||||
|
title: Require new users to fill an invite request text
|
||||||
registrations_mode:
|
registrations_mode:
|
||||||
modes:
|
modes:
|
||||||
approved: Approval required for sign up
|
approved: Approval required for sign up
|
||||||
|
|
|
@ -70,6 +70,7 @@ defaults: &defaults
|
||||||
spam_check_enabled: true
|
spam_check_enabled: true
|
||||||
show_domain_blocks: 'disabled'
|
show_domain_blocks: 'disabled'
|
||||||
show_domain_blocks_rationale: 'disabled'
|
show_domain_blocks_rationale: 'disabled'
|
||||||
|
require_invite_text: false
|
||||||
|
|
||||||
development:
|
development:
|
||||||
<<: *defaults
|
<<: *defaults
|
||||||
|
|
Loading…
Reference in New Issue