diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 2a189ea6024fb0..a9212a7fb6f649 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true module ApplicationHelper + include RegistrationLimitationHelper + DANGEROUS_SCOPES = %w( read write @@ -37,11 +39,11 @@ def show_landing_strip? 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? diff --git a/app/helpers/registration_limitation_helper.rb b/app/helpers/registration_limitation_helper.rb index 4ac04450aa5716..56523b816cdf54 100644 --- a/app/helpers/registration_limitation_helper.rb +++ b/app/helpers/registration_limitation_helper.rb @@ -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 diff --git a/app/javascript/mastodon/features/closed_registrations_modal/index.jsx b/app/javascript/mastodon/features/closed_registrations_modal/index.jsx index a8565f47975959..3938c5b1f60e0d 100644 --- a/app/javascript/mastodon/features/closed_registrations_modal/index.jsx +++ b/app/javascript/mastodon/features/closed_registrations_modal/index.jsx @@ -32,7 +32,7 @@ class ClosedRegistrationsModal extends ImmutablePureComponent {

{domain} }} />

diff --git a/app/javascript/mastodon/locales/en.json b/app/javascript/mastodon/locales/en.json index 2fa6aa87095848..8ad552775d00b4 100644 --- a/app/javascript/mastodon/locales/en.json +++ b/app/javascript/mastodon/locales/en.json @@ -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", diff --git a/app/javascript/mastodon/locales/ja.json b/app/javascript/mastodon/locales/ja.json index 18904cc033c527..0bc4adf2a7ebd5 100644 --- a/app/javascript/mastodon/locales/ja.json +++ b/app/javascript/mastodon/locales/ja.json @@ -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でアカウントを作成", diff --git a/app/javascript/packs/admin.tsx b/app/javascript/packs/admin.tsx index 9fee5605659663..6674b2951fba71 100644 --- a/app/javascript/packs/admin.tsx +++ b/app/javascript/packs/admin.tsx @@ -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( '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( + '#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'); }); }; diff --git a/app/models/user.rb b/app/models/user.rb index 6924ad0a170ff5..288904a56c0c1c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -474,7 +474,7 @@ def sign_up_email_requires_approval? end def open_registrations? - Setting.registrations_mode == 'open' + Setting.registrations_mode == 'open' && registrations_in_time? end def external? diff --git a/app/serializers/rest/instance_serializer.rb b/app/serializers/rest/instance_serializer.rb index c3070b6852f4fc..b47699a0c84689 100644 --- a/app/serializers/rest/instance_serializer.rb +++ b/app/serializers/rest/instance_serializer.rb @@ -111,7 +111,7 @@ def configuration 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), diff --git a/app/serializers/rest/v1/instance_serializer.rb b/app/serializers/rest/v1/instance_serializer.rb index 57a1e807137158..4895c28c8c6e5d 100644 --- a/app/serializers/rest/v1/instance_serializer.rb +++ b/app/serializers/rest/v1/instance_serializer.rb @@ -115,7 +115,7 @@ def registrations end def approval_required - Setting.registrations_mode == 'approved' + Setting.registrations_mode == 'approved' || (Setting.registrations_mode == 'open' && !registrations_in_time?) end def invites_enabled diff --git a/config/locales/simple_form.en.yml b/config/locales/simple_form.en.yml index 8fdb6664af4d99..8aced089f61fca 100644 --- a/config/locales/simple_form.en.yml +++ b/config/locales/simple_form.en.yml @@ -357,8 +357,8 @@ en: registrations_limit: User registration limit registrations_limit_per_day: User registration limit per day registrations_mode: Who can sign-up - registrations_end_hour: Registration end hour (UTC 0-24) - registrations_start_hour: Registration start hour (UTC 0-24) + registrations_end_hour: Registration-without-approval end hour (UTC 0-24) + registrations_start_hour: Registration-without-approval start hour (UTC 0-24) registrations_secondary_end_hour: Secondary registration end hour (UTC 0-24) If input 0, secondary hour is disabled. registrations_secondary_start_hour: Secondary registration start hour (UTC 0-24) require_invite_text: Require a reason to join diff --git a/config/locales/simple_form.ja.yml b/config/locales/simple_form.ja.yml index c8bf127b97489c..2fae3f630e221a 100644 --- a/config/locales/simple_form.ja.yml +++ b/config/locales/simple_form.ja.yml @@ -116,8 +116,8 @@ ja: receive_other_servers_emoji_reaction: 負荷の原因になります。人が少ない場合にのみ有効にすることをおすすめします。 registrations_limit: 現在のユーザー数がこれを超過すると、管理者がこの数値を増やさない限り新規登録できません。0を指定すると、この制限を無効化します。 registrations_limit_per_day: 本日登録されたユーザー数がこれを超過すると、UTC時刻で翌日0時にならない限り新規登録できません。0を指定すると、この制限を無効化します。 - registrations_end_hour: 新規登録可能な時間帯の開始時間を指定します。これより前の時間に登録することはできません。終了時間より後にすることはできません。 - registrations_start_hour: 新規登録可能な時間帯の終了時間を指定します。これより後の時間に登録することはできません。開始時間より前にすることはできません。 + registrations_end_hour: 新規登録が承認なしで可能な時間帯の開始時間を指定します。これより前の時間に登録することはできません。終了時間より後にすることはできません。この時間帯から外れた新規登録には、別途承認が必要となります。 + registrations_start_hour: 新規登録が承認なしで可能な時間帯の終了時間を指定します。これより後の時間に登録することはできません。開始時間より前にすることはできません。この時間帯から外れた新規登録には、別途承認が必要となります。 require_invite_text: アカウント登録が承認制の場合、登録の際の申請事由の入力を必須にします site_contact_email: 法律またはサポートに関する問い合わせ先 site_contact_username: マストドンでの連絡方法 @@ -368,10 +368,10 @@ ja: registrations_limit: 登録ユーザー数上限 (現在 %{count} 名) registrations_limit_per_day: 1日あたり登録ユーザー数上限 (現在 %{count} 名) registrations_mode: 新規登録が可能な人 - registrations_end_hour: 登録受付終了時間 A (UTC 0〜24) - registrations_start_hour: 登録受付開始時間 A (UTC 0〜24) - registrations_secondary_end_hour: 登録受付終了時間 B (UTC 0〜24) ここで0を指定した場合、時間Bの設定は無効化されます - registrations_secondary_start_hour: 登録受付開始時間 B (UTC 0〜24) + registrations_end_hour: 登録に承認を必要としない時間帯の終了時刻 A (UTC 0〜24) + registrations_start_hour: 登録に承認を必要としない時間帯の開始時刻 A (UTC 0〜24) + registrations_secondary_end_hour: 登録に承認を必要としない時間帯の終了時刻 B (UTC 0〜24) ここで0を指定した場合、時間Bの設定は無効化されます + registrations_secondary_start_hour: 登録に承認を必要としない時間帯の開始時刻 B (UTC 0〜24) require_invite_text: 申請事由の入力を必須にする show_domain_blocks: ドメインブロックを表示 show_domain_blocks_rationale: ドメインがブロックされた理由を表示 diff --git a/spec/controllers/auth/registrations_controller_spec.rb b/spec/controllers/auth/registrations_controller_spec.rb index ffd14af93cc5de..a30fffe6d1d1f6 100644 --- a/spec/controllers/auth/registrations_controller_spec.rb +++ b/spec/controllers/auth/registrations_controller_spec.rb @@ -485,18 +485,21 @@ def create_other_user user = User.find_by(email: 'test@example.com') expect(user).to_not be_nil expect(user.locale).to eq(accept_language) + expect(user.approved?).to be true end else it 'does not create user' do subject user = User.find_by(email: 'test@example.com') - expect(user).to be_nil + expect(user).to_not be_nil + expect(user.approved?).to be false end end end end it_behaves_like 'registration with time', 'time range is not set', 0, 24, 0, 0, true + it_behaves_like 'registration with time', 'time range is default values', 0, 0, 0, 0, true it_behaves_like 'registration with time', 'time range is set', 9, 12, 0, 0, true it_behaves_like 'registration with time', 'time range is out of range', 12, 15, 0, 0, false it_behaves_like 'registration with time', 'time range is invalid', 20, 15, 0, 0, true diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index ef1463e64c8660..b2ffb65c909314 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -86,6 +86,10 @@ def current_theme = 'default' describe 'open_registrations?' do it 'returns true when open for registrations' do allow(Setting).to receive(:[]).with('registrations_mode').and_return('open') + allow(Setting).to receive(:[]).with('registrations_start_hour').and_return(0) + allow(Setting).to receive(:[]).with('registrations_end_hour').and_return(0) + allow(Setting).to receive(:[]).with('registrations_secondary_start_hour').and_return(0) + allow(Setting).to receive(:[]).with('registrations_secondary_end_hour').and_return(0) expect(helper.open_registrations?).to be true expect(Setting).to have_received(:[]).with('registrations_mode')