Add `--reset-password` option to `tootctl accounts modify` (#13126)

rebase/4.0.0rc2
ThibG 2020-02-22 01:29:14 +01:00 committed by GitHub
parent 0f07218e53
commit ca7ee9f1cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 0 deletions

View File

@ -120,6 +120,7 @@ module Mastodon
option :disable, type: :boolean option :disable, type: :boolean
option :disable_2fa, type: :boolean option :disable_2fa, type: :boolean
option :approve, type: :boolean option :approve, type: :boolean
option :reset_password, type: :boolean
desc 'modify USERNAME', 'Modify a user' desc 'modify USERNAME', 'Modify a user'
long_desc <<-LONG_DESC long_desc <<-LONG_DESC
Modify a user account. Modify a user account.
@ -138,6 +139,9 @@ module Mastodon
With the --disable-2fa option, the two-factor authentication With the --disable-2fa option, the two-factor authentication
requirement for the user can be removed. requirement for the user can be removed.
With the --reset-password option, the user's password is replaced by
a randomly-generated one, printed in the output.
LONG_DESC LONG_DESC
def modify(username) def modify(username)
user = Account.find_local(username)&.user user = Account.find_local(username)&.user
@ -152,6 +156,8 @@ module Mastodon
user.moderator = options[:role] == 'moderator' user.moderator = options[:role] == 'moderator'
end end
password = SecureRandom.hex if options[:reset_password]
user.password = password if options[:reset_password]
user.email = options[:email] if options[:email] user.email = options[:email] if options[:email]
user.disabled = false if options[:enable] user.disabled = false if options[:enable]
user.disabled = true if options[:disable] user.disabled = true if options[:disable]
@ -161,6 +167,7 @@ module Mastodon
if user.save if user.save
say('OK', :green) say('OK', :green)
say("New password: #{password}") if options[:reset_password]
else else
user.errors.to_h.each do |key, error| user.errors.to_h.each do |key, error|
say('Failure/Error: ', :red) say('Failure/Error: ', :red)