Skip to content

Commit

Permalink
Change: #621 登録時間帯制限で、制限時間中は登録を禁止ではなく承認制にする
Browse files Browse the repository at this point in the history
  • Loading branch information
kmycode committed Mar 3, 2024
1 parent 76b2419 commit b88b9a6
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 19 deletions.
6 changes: 4 additions & 2 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

module ApplicationHelper
include RegistrationLimitationHelper

DANGEROUS_SCOPES = %w(
read
write
Expand Down Expand Up @@ -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?
Expand Down
2 changes: 0 additions & 2 deletions app/helpers/registration_limitation_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/mastodon/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/mastodon/locales/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -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でアカウントを作成",
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/rest/instance_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/rest/v1/instance_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions config/locales/simple_form.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions config/locales/simple_form.ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: マストドンでの連絡方法
Expand Down Expand Up @@ -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: ドメインがブロックされた理由を表示
Expand Down
5 changes: 4 additions & 1 deletion spec/controllers/auth/registrations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -485,18 +485,21 @@ def create_other_user
user = User.find_by(email: '[email protected]')
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: '[email protected]')
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
Expand Down

0 comments on commit b88b9a6

Please sign in to comment.