Change: #621 登録時間帯制限で、制限時間中は登録を禁止ではなく承認制にする (#628)

* Change: #621 登録時間帯制限で、制限時間中は登録を禁止ではなく承認制にする

* 管理画面のUIを改善

* Fix test

* Fix lint
This commit is contained in:
KMY(雪あすか) 2024-03-04 12:38:56 +09:00 committed by GitHub
parent 4119b8713e
commit 941705be62
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 52 additions and 33 deletions

View file

@ -1,6 +1,8 @@
# frozen_string_literal: true
module ApplicationHelper
include RegistrationLimitationHelper
DANGEROUS_SCOPES = %w(
read
write
@ -37,11 +39,11 @@ module ApplicationHelper
end
def open_registrations?
Setting.registrations_mode == 'open'
Setting.registrations_mode == 'open' && registrations_in_time?
end
def approved_registrations?
Setting.registrations_mode == 'approved'
Setting.registrations_mode == 'approved' || (Setting.registrations_mode == 'open' && !registrations_in_time?)
end
def closed_registrations?

View file

@ -2,8 +2,6 @@
module RegistrationLimitationHelper
def reach_registrations_limit?
return true unless registrations_in_time?
((Setting.registrations_limit.presence || 0).positive? && Setting.registrations_limit <= user_count_for_registration) ||
((Setting.registrations_limit_per_day.presence || 0).positive? && Setting.registrations_limit_per_day <= today_increase_user_count)
end

View file

@ -32,7 +32,7 @@ class ClosedRegistrationsModal extends ImmutablePureComponent {
<p className='prose'>
<FormattedMessage
id='closed_registrations_modal.description_when_reaching_limit'
defaultMessage='New registrations are currently temporarily restricted. Either the maximum number of registrations has been reached or it is outside the time frame available for registration. Please contact the administrator for more information or wait until the restriction is lifted.'
defaultMessage='New registrations are currently temporarily restricted. Either the maximum number of registrations has been reached for registration. Please contact the administrator for more information or wait until the restriction is lifted.'
values={{ domain: <strong>{domain}</strong> }}
/>
</p>

View file

@ -177,7 +177,7 @@
"circles.subheading": "Your circles",
"closed_registrations.other_server_instructions": "Since Mastodon is decentralized, you can create an account on another server and still interact with this one.",
"closed_registrations_modal.description": "Creating an account on {domain} is currently not possible, but please keep in mind that you do not need an account specifically on {domain} to use Mastodon.",
"closed_registrations_modal.description_when_reaching_limit": "New registrations are currently temporarily restricted. Either the maximum number of registrations has been reached or it is outside the time frame available for registration. Please contact the administrator for more information or wait until the restriction is lifted.",
"closed_registrations_modal.description_when_reaching_limit": "New registrations are currently temporarily restricted. Either the maximum number of registrations has been reached for registration. Please contact the administrator for more information or wait until the restriction is lifted.",
"closed_registrations_modal.find_another_server": "Find another server",
"closed_registrations_modal.preamble": "Mastodon is decentralized, so no matter where you create your account, you will be able to follow and interact with anyone on this server. You can even self-host it!",
"closed_registrations_modal.title": "Signing up on Mastodon",

View file

@ -171,7 +171,7 @@
"circles.subheading": "あなたのサークル",
"closed_registrations.other_server_instructions": "Mastodonは分散型なので他のサーバーにアカウントを作ってもこのサーバーとやり取りできます。",
"closed_registrations_modal.description": "現在{domain}でアカウント作成はできませんがMastodonは{domain}のアカウントでなくても利用できます。",
"closed_registrations_modal.description_when_reaching_limit": "新規登録は現在一時的に制限されています。登録の上限人数に達したか、または登録可能な時間帯の範囲外です。詳細を管理人に問い合わせるか、制限が解除されるまでお待ち下さい。",
"closed_registrations_modal.description_when_reaching_limit": "新規登録は現在一時的に制限されています。登録の上限人数に達しています。詳細を管理人に問い合わせるか、制限が解除されるまでお待ち下さい。",
"closed_registrations_modal.find_another_server": "別のサーバーを探す",
"closed_registrations_modal.preamble": "Mastodonは分散型なのでどのサーバーでアカウントを作成してもこのサーバーのユーザーを誰でもフォローして交流することができます。また自分でホスティングすることもできます",
"closed_registrations_modal.title": "Mastodonでアカウントを作成",

View file

@ -217,25 +217,37 @@ const onChangeRegistrationMode = (target: HTMLSelectElement) => {
warning_hint.style.display = target.value === 'open' ? 'inline' : 'none';
});
const toggleEnabled = (input: HTMLInputElement, value: boolean) => {
input.disabled = !value;
if (enabled) {
let element: HTMLElement | null = input;
do {
element.classList.remove('disabled');
element = element.parentElement;
} while (element && !element.classList.contains('fields-group'));
} else {
let element: HTMLElement | null = input;
do {
element.classList.add('disabled');
element = element.parentElement;
} while (element && !element.classList.contains('fields-group'));
}
};
document
.querySelectorAll<HTMLInputElement>(
'input#form_admin_settings_require_invite_text',
)
.forEach((input) => {
input.disabled = !enabled;
if (enabled) {
let element: HTMLElement | null = input;
do {
element.classList.remove('disabled');
element = element.parentElement;
} while (element && !element.classList.contains('fields-group'));
} else {
let element: HTMLElement | null = input;
do {
element.classList.add('disabled');
element = element.parentElement;
} while (element && !element.classList.contains('fields-group'));
}
toggleEnabled(input, enabled);
});
document
.querySelectorAll<HTMLInputElement>(
'#form_admin_settings_registrations_start_hour, #form_admin_settings_registrations_end_hour, #form_admin_settings_registrations_secondary_start_hour, #form_admin_settings_registrations_secondary_end_hour',
)
.forEach((input) => {
toggleEnabled(input, target.value === 'open');
});
};

View file

@ -474,7 +474,7 @@ class User < ApplicationRecord
end
def open_registrations?
Setting.registrations_mode == 'open'
Setting.registrations_mode == 'open' && registrations_in_time?
end
def external?

View file

@ -111,7 +111,7 @@ class REST::InstanceSerializer < ActiveModel::Serializer
def registrations
{
enabled: registrations_enabled?,
approval_required: Setting.registrations_mode == 'approved',
approval_required: Setting.registrations_mode == 'approved' || (Setting.registrations_mode == 'open' && !registrations_in_time?),
limit_reached: Setting.registrations_mode != 'none' && reach_registrations_limit?,
message: registrations_enabled? ? nil : registrations_message,
url: ENV.fetch('SSO_ACCOUNT_SIGN_UP', nil),

View file

@ -115,7 +115,7 @@ class REST::V1::InstanceSerializer < ActiveModel::Serializer
end
def approval_required
Setting.registrations_mode == 'approved'
Setting.registrations_mode == 'approved' || (Setting.registrations_mode == 'open' && !registrations_in_time?)
end
def invites_enabled