Skip to content

Commit d0cd778

Browse files
authored
Admission-based registrations mode (mastodon#10250)
Fix mastodon#6856 Fix mastodon#6951
1 parent c4ef714 commit d0cd778

92 files changed

Lines changed: 282 additions & 249 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/controllers/accounts_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ def hashtag_scope
8989
end
9090
end
9191

92-
def set_account
93-
@account = Account.find_local!(params[:username])
92+
def username_param
93+
params[:username]
9494
end
9595

9696
def older_url

app/controllers/admin/accounts_controller.rb

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
module Admin
44
class AccountsController < BaseController
5-
before_action :set_account, only: [:show, :subscribe, :unsubscribe, :redownload, :remove_avatar, :remove_header, :enable, :unsilence, :unsuspend, :memorialize]
5+
before_action :set_account, only: [:show, :subscribe, :unsubscribe, :redownload, :remove_avatar, :remove_header, :enable, :unsilence, :unsuspend, :memorialize, :approve, :reject]
66
before_action :require_remote_account!, only: [:subscribe, :unsubscribe, :redownload]
7-
before_action :require_local_account!, only: [:enable, :memorialize]
7+
before_action :require_local_account!, only: [:enable, :memorialize, :approve, :reject]
88

99
def index
1010
authorize :account, :index?
@@ -45,6 +45,18 @@ def enable
4545
redirect_to admin_account_path(@account.id)
4646
end
4747

48+
def approve
49+
authorize @account.user, :approve?
50+
@account.user.approve!
51+
redirect_to admin_accounts_path(pending: '1')
52+
end
53+
54+
def reject
55+
authorize @account.user, :reject?
56+
SuspendAccountService.new.call(@account, including_user: true, destroy: true)
57+
redirect_to admin_accounts_path(pending: '1')
58+
end
59+
4860
def unsilence
4961
authorize @account, :unsilence?
5062
@account.unsilence!
@@ -114,6 +126,7 @@ def filter_params
114126
:remote,
115127
:by_domain,
116128
:active,
129+
:pending,
117130
:silenced,
118131
:suspended,
119132
:username,

app/controllers/admin/dashboard_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def index
1010
@interactions_week = Redis.current.get("activity:interactions:#{current_week}") || 0
1111
@relay_enabled = Relay.enabled.exists?
1212
@single_user_mode = Rails.configuration.x.single_user_mode
13-
@registrations_enabled = Setting.open_registrations
13+
@registrations_enabled = Setting.registrations_mode != 'none'
1414
@deletions_enabled = Setting.open_deletion
1515
@invites_enabled = Setting.min_invite_role == 'user'
1616
@search_enabled = Chewy.enabled?

app/controllers/admin/settings_controller.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class SettingsController < BaseController
1010
site_description
1111
site_extended_description
1212
site_terms
13-
open_registrations
13+
registrations_mode
1414
closed_registrations_message
1515
open_deletion
1616
timeline_preview
@@ -30,7 +30,6 @@ class SettingsController < BaseController
3030
).freeze
3131

3232
BOOLEAN_SETTINGS = %w(
33-
open_registrations
3433
open_deletion
3534
timeline_preview
3635
show_staff_badge

app/controllers/api/base_controller.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ def require_user!
7373
elsif current_user.disabled?
7474
render json: { error: 'Your login is currently disabled' }, status: 403
7575
elsif !current_user.confirmed?
76-
render json: { error: 'Email confirmation is not completed' }, status: 403
76+
render json: { error: 'Your login is missing a confirmed e-mail address' }, status: 403
77+
elsif !current_user.approved?
78+
render json: { error: 'Your login is currently pending approval' }, status: 403
7779
else
7880
set_user_activity
7981
end

app/controllers/api/v1/accounts_controller.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ def account_params
8080
end
8181

8282
def check_enabled_registrations
83-
forbidden if single_user_mode? || !Setting.open_registrations
83+
forbidden if single_user_mode? || !allowed_registrations?
84+
end
85+
86+
def allowed_registrations?
87+
Setting.registrations_mode != 'none'
8488
end
8589
end

app/controllers/auth/registrations_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def check_enabled_registrations
6565
end
6666

6767
def allowed_registrations?
68-
Setting.open_registrations || @invite&.valid_for_use?
68+
Setting.registrations_mode != 'none' || @invite&.valid_for_use?
6969
end
7070

7171
def invite_code

app/controllers/concerns/account_controller_concern.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@ module AccountControllerConcern
77

88
included do
99
layout 'public'
10+
1011
before_action :set_account
12+
before_action :check_account_approval
13+
before_action :check_account_suspension
1114
before_action :set_instance_presenter
1215
before_action :set_link_headers
13-
before_action :check_account_suspension
1416
end
1517

1618
private
1719

1820
def set_account
19-
@account = Account.find_local!(params[:account_username])
21+
@account = Account.find_local!(username_param)
2022
end
2123

2224
def set_instance_presenter
@@ -33,6 +35,10 @@ def set_link_headers
3335
)
3436
end
3537

38+
def username_param
39+
params[:account_username]
40+
end
41+
3642
def webfinger_account_link
3743
[
3844
webfinger_account_url,
@@ -58,6 +64,10 @@ def webfinger_account_url
5864
webfinger_url(resource: @account.to_webfinger_s)
5965
end
6066

67+
def check_account_approval
68+
not_found if @account.user_pending?
69+
end
70+
6171
def check_account_suspension
6272
gone if @account.suspended?
6373
end

app/helpers/admin/filter_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
module Admin::FilterHelper
4-
ACCOUNT_FILTERS = %i(local remote by_domain active silenced suspended username display_name email ip staff).freeze
4+
ACCOUNT_FILTERS = %i(local remote by_domain active pending silenced suspended username display_name email ip staff).freeze
55
REPORT_FILTERS = %i(resolved account_id target_account_id).freeze
66
INVITE_FILTER = %i(available expired).freeze
77
CUSTOM_EMOJI_FILTERS = %i(local remote by_domain shortcode).freeze

app/helpers/application_helper.rb

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,23 @@ def show_landing_strip?
2020
end
2121

2222
def open_registrations?
23-
Setting.open_registrations
23+
Setting.registrations_mode == 'open'
24+
end
25+
26+
def approved_registrations?
27+
Setting.registrations_mode == 'approved'
28+
end
29+
30+
def closed_registrations?
31+
Setting.registrations_mode == 'none'
32+
end
33+
34+
def available_sign_up_path
35+
if closed_registrations?
36+
'https://joinmastodon.org/#getting-started'
37+
else
38+
new_user_registration_path
39+
end
2440
end
2541

2642
def open_deletion?

0 commit comments

Comments
 (0)