diff --git a/app/models/user.rb b/app/models/user.rb index 72f7490043..6bd3c85a30 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -112,7 +112,7 @@ class User < ApplicationRecord validates_with RegistrationFormTimeValidator, on: :create validates :website, absence: true, on: :create validates :confirm_password, absence: true, on: :create - validates :date_of_birth, presence: true, date_of_birth: true, on: :create, if: -> { Setting.min_age.present? } + validates :date_of_birth, presence: true, date_of_birth: true, on: :create, if: -> { Setting.min_age.present? && !bypass_registration_checks? } validate :validate_role_elevation scope :account_not_suspended, -> { joins(:account).merge(Account.without_suspended) } @@ -144,7 +144,7 @@ class User < ApplicationRecord delegate :can?, to: :role attr_reader :invite_code, :date_of_birth - attr_writer :external, :bypass_invite_request_check, :current_account + attr_writer :external, :bypass_registration_checks, :current_account def self.those_who_can(*any_of_privileges) matching_role_ids = UserRole.that_can(*any_of_privileges).map(&:id) @@ -501,8 +501,8 @@ class User < ApplicationRecord !!@external end - def bypass_invite_request_check? - @bypass_invite_request_check + def bypass_registration_checks? + @bypass_registration_checks end def sanitize_role @@ -549,7 +549,7 @@ class User < ApplicationRecord end def invite_text_required? - Setting.require_invite_text && !open_registrations? && !invited? && !external? && !bypass_invite_request_check? + Setting.require_invite_text && !open_registrations? && !invited? && !external? && !bypass_registration_checks? end def trigger_webhooks diff --git a/lib/mastodon/cli/accounts.rb b/lib/mastodon/cli/accounts.rb index 41127741ef..1b33f56055 100644 --- a/lib/mastodon/cli/accounts.rb +++ b/lib/mastodon/cli/accounts.rb @@ -79,7 +79,14 @@ module Mastodon::CLI account = Account.new(username: username) password = SecureRandom.hex - user = User.new(email: options[:email], password: password, agreement: true, role_id: role_id, confirmed_at: options[:confirmed] ? Time.now.utc : nil, bypass_invite_request_check: true) + user = User.new( + email: options[:email], + password: password, + agreement: true, + role_id: role_id, + confirmed_at: options[:confirmed] ? Time.now.utc : nil, + bypass_registration_checks: true + ) if options[:reattach] account = Account.find_local(username) || Account.new(username: username) diff --git a/lib/tasks/mastodon.rake b/lib/tasks/mastodon.rake index 61dba4eb52..99f4b86b73 100644 --- a/lib/tasks/mastodon.rake +++ b/lib/tasks/mastodon.rake @@ -552,7 +552,7 @@ namespace :mastodon do password = SecureRandom.hex(16) owner_role = UserRole.find_by(name: 'Owner') - user = User.new(email: email, password: password, confirmed_at: Time.now.utc, account_attributes: { username: username }, bypass_invite_request_check: true, role: owner_role) + user = User.new(email: email, password: password, confirmed_at: Time.now.utc, account_attributes: { username: username }, bypass_registration_checks: true, role: owner_role) user.save(validate: false) user.approve! diff --git a/spec/lib/mastodon/cli/accounts_spec.rb b/spec/lib/mastodon/cli/accounts_spec.rb index f6cc28297a..238f72f834 100644 --- a/spec/lib/mastodon/cli/accounts_spec.rb +++ b/spec/lib/mastodon/cli/accounts_spec.rb @@ -70,6 +70,25 @@ RSpec.describe Mastodon::CLI::Accounts do end end + context 'with min_age setting' do + let(:options) { { email: 'tootctl@example.com', confirmed: true } } + + before do + Setting.min_age = 42 + end + + it_behaves_like 'a new user with given email address and username' + + it 'creates a new user with confirmed status' do + expect { subject } + .to output_results('New password') + + user = User.find_by(email: options[:email]) + + expect(user.confirmed?).to be(true) + end + end + context 'with --confirmed option' do let(:options) { { email: 'tootctl@example.com', confirmed: true } }