Compare commits

...

2 Commits

Author SHA1 Message Date
Matt Jankowski
5be7d46971
Merge 53cd364043 into c442589593 2025-07-10 08:06:40 +00:00
Matt Jankowski
53cd364043 Move single user mode config to x.mastodon area 2025-07-09 07:52:23 -04:00
10 changed files with 16 additions and 20 deletions

View File

@ -148,7 +148,7 @@ class ApplicationController < ActionController::Base
end end
def single_user_mode? def single_user_mode?
@single_user_mode ||= Rails.configuration.x.single_user_mode && Account.without_internal.exists? @single_user_mode ||= Rails.configuration.x.mastodon.single_user_mode && Account.without_internal.exists?
end end
def use_seamless_external_login? def use_seamless_external_login?

View File

@ -4,7 +4,7 @@ module RegistrationHelper
extend ActiveSupport::Concern extend ActiveSupport::Concern
def allowed_registration?(remote_ip, invite) def allowed_registration?(remote_ip, invite)
!Rails.configuration.x.single_user_mode && !omniauth_only? && (registrations_open? || invite&.valid_for_use?) && !ip_blocked?(remote_ip) !Rails.configuration.x.mastodon.single_user_mode && !omniauth_only? && (registrations_open? || invite&.valid_for_use?) && !ip_blocked?(remote_ip)
end end
def registrations_open? def registrations_open?

View File

@ -40,7 +40,7 @@ class InitialStateSerializer < ActiveModel::Serializer
store[:disabled_account_id] = object.disabled_account.id.to_s if object.disabled_account store[:disabled_account_id] = object.disabled_account.id.to_s if object.disabled_account
store[:moved_to_account_id] = object.moved_to_account.id.to_s if object.moved_to_account store[:moved_to_account_id] = object.moved_to_account.id.to_s if object.moved_to_account
store[:owner] = object.owner&.id&.to_s if Rails.configuration.x.single_user_mode store[:owner] = object.owner&.id&.to_s if Rails.configuration.x.mastodon.single_user_mode
store store
end end
@ -97,10 +97,10 @@ class InitialStateSerializer < ActiveModel::Serializer
locale: I18n.locale, locale: I18n.locale,
mascot: instance_presenter.mascot&.file&.url, mascot: instance_presenter.mascot&.file&.url,
profile_directory: Setting.profile_directory, profile_directory: Setting.profile_directory,
registrations_open: Setting.registrations_mode != 'none' && !Rails.configuration.x.single_user_mode, registrations_open: Setting.registrations_mode != 'none' && !Rails.configuration.x.mastodon.single_user_mode,
repository: Mastodon::Version.repository, repository: Mastodon::Version.repository,
search_enabled: Chewy.enabled?, search_enabled: Chewy.enabled?,
single_user_mode: Rails.configuration.x.single_user_mode, single_user_mode: Rails.configuration.x.mastodon.single_user_mode,
source_url: instance_presenter.source_url, source_url: instance_presenter.source_url,
sso_redirect: sso_redirect, sso_redirect: sso_redirect,
status_page_url: Setting.status_page_url, status_page_url: Setting.status_page_url,

View File

@ -34,7 +34,7 @@ class NodeInfo::Serializer < ActiveModel::Serializer
end end
def open_registrations def open_registrations
Setting.registrations_mode != 'none' && !Rails.configuration.x.single_user_mode Setting.registrations_mode != 'none' && !Rails.configuration.x.mastodon.single_user_mode
end end
def metadata def metadata

View File

@ -122,7 +122,7 @@ class REST::InstanceSerializer < ActiveModel::Serializer
private private
def registrations_enabled? def registrations_enabled?
Setting.registrations_mode != 'none' && !Rails.configuration.x.single_user_mode Setting.registrations_mode != 'none' && !Rails.configuration.x.mastodon.single_user_mode
end end
def registrations_message def registrations_message

View File

@ -79,7 +79,7 @@ class REST::V1::InstanceSerializer < ActiveModel::Serializer
end end
def registrations def registrations
Setting.registrations_mode != 'none' && !Rails.configuration.x.single_user_mode Setting.registrations_mode != 'none' && !Rails.configuration.x.mastodon.single_user_mode
end end
def approval_required def approval_required

View File

@ -1,5 +0,0 @@
# frozen_string_literal: true
Rails.application.configure do
config.x.single_user_mode = ENV['SINGLE_USER_MODE'] == 'true'
end

View File

@ -3,6 +3,7 @@ shared:
experimental_features: <%= ENV.fetch('EXPERIMENTAL_FEATURES', nil) %> experimental_features: <%= ENV.fetch('EXPERIMENTAL_FEATURES', nil) %>
limited_federation_mode: <%= (ENV.fetch('LIMITED_FEDERATION_MODE', nil) || ENV.fetch('WHITELIST_MODE', nil)) == 'true' %> limited_federation_mode: <%= (ENV.fetch('LIMITED_FEDERATION_MODE', nil) || ENV.fetch('WHITELIST_MODE', nil)) == 'true' %>
self_destruct_value: <%= ENV.fetch('SELF_DESTRUCT', nil)&.to_json %> self_destruct_value: <%= ENV.fetch('SELF_DESTRUCT', nil)&.to_json %>
single_user_mode: <%= ENV.fetch('SINGLE_USER_MODE', nil) == 'true' %>
software_update_url: <%= ENV.fetch('UPDATE_CHECK_URL', 'https://api.joinmastodon.org/update-check')&.to_json %> software_update_url: <%= ENV.fetch('UPDATE_CHECK_URL', 'https://api.joinmastodon.org/update-check')&.to_json %>
source: source:
base_url: <%= ENV.fetch('SOURCE_BASE_URL', nil)&.to_json %> base_url: <%= ENV.fetch('SOURCE_BASE_URL', nil)&.to_json %>

View File

@ -68,18 +68,18 @@ RSpec.describe ApplicationController do
describe 'helper_method :single_user_mode?' do describe 'helper_method :single_user_mode?' do
it 'returns false if it is in single_user_mode but there is no account' do it 'returns false if it is in single_user_mode but there is no account' do
allow(Rails.configuration.x).to receive(:single_user_mode).and_return(true) allow(Rails.configuration.x.mastodon).to receive(:single_user_mode).and_return(true)
expect(controller.view_context.single_user_mode?).to be false expect(controller.view_context.single_user_mode?).to be false
end end
it 'returns false if there is an account but it is not in single_user_mode' do it 'returns false if there is an account but it is not in single_user_mode' do
allow(Rails.configuration.x).to receive(:single_user_mode).and_return(false) allow(Rails.configuration.x.mastodon).to receive(:single_user_mode).and_return(false)
Fabricate(:account) Fabricate(:account)
expect(controller.view_context.single_user_mode?).to be false expect(controller.view_context.single_user_mode?).to be false
end end
it 'returns true if it is in single_user_mode and there is an account' do it 'returns true if it is in single_user_mode and there is an account' do
allow(Rails.configuration.x).to receive(:single_user_mode).and_return(true) allow(Rails.configuration.x.mastodon).to receive(:single_user_mode).and_return(true)
Fabricate(:account) Fabricate(:account)
expect(controller.view_context.single_user_mode?).to be true expect(controller.view_context.single_user_mode?).to be true
end end

View File

@ -9,7 +9,7 @@ RSpec.describe Auth::RegistrationsController do
context 'when in single user mode and open for registration' do context 'when in single user mode and open for registration' do
before do before do
Setting.registrations_mode = 'open' Setting.registrations_mode = 'open'
allow(Rails.configuration.x).to receive(:single_user_mode).and_return(true) allow(Rails.configuration.x.mastodon).to receive(:single_user_mode).and_return(true)
end end
it 'redirects to root' do it 'redirects to root' do
@ -17,21 +17,21 @@ RSpec.describe Auth::RegistrationsController do
get path get path
expect(response).to redirect_to '/' expect(response).to redirect_to '/'
expect(Rails.configuration.x).to have_received(:single_user_mode) expect(Rails.configuration.x.mastodon).to have_received(:single_user_mode)
end end
end end
context 'when registrations closed and not in single user mode' do context 'when registrations closed and not in single user mode' do
before do before do
Setting.registrations_mode = 'none' Setting.registrations_mode = 'none'
allow(Rails.configuration.x).to receive(:single_user_mode).and_return(false) allow(Rails.configuration.x.mastodon).to receive(:single_user_mode).and_return(false)
end end
it 'redirects to root' do it 'redirects to root' do
get path get path
expect(response).to redirect_to '/' expect(response).to redirect_to '/'
expect(Rails.configuration.x).to have_received(:single_user_mode) expect(Rails.configuration.x.mastodon).to have_received(:single_user_mode)
end end
end end
end end