* Change: #621 登録時間帯制限で、制限時間中は登録を禁止ではなく承認制にする * 管理画面のUIを改善 * Fix test * Fix lint
This commit is contained in:
parent
4119b8713e
commit
941705be62
13 changed files with 52 additions and 33 deletions
|
@ -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?
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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でアカウントを作成",
|
||||
|
|
|
@ -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');
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -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?
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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: ドメインがブロックされた理由を表示
|
||||
|
|
|
@ -485,18 +485,21 @@ RSpec.describe Auth::RegistrationsController do
|
|||
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
|
||||
|
|
|
@ -86,6 +86,10 @@ describe ApplicationHelper do
|
|||
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')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue