diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/mastodon/accounts_cli.rb | 41 | ||||
-rw-r--r-- | lib/simple_navigation/item_extensions.rb | 15 |
2 files changed, 44 insertions, 12 deletions
diff --git a/lib/mastodon/accounts_cli.rb b/lib/mastodon/accounts_cli.rb index 7256d1da9..29c934453 100644 --- a/lib/mastodon/accounts_cli.rb +++ b/lib/mastodon/accounts_cli.rb @@ -54,7 +54,7 @@ module Mastodon option :email, required: true option :confirmed, type: :boolean - option :role, default: 'user', enum: %w(user moderator admin) + option :role option :reattach, type: :boolean option :force, type: :boolean desc 'create USERNAME', 'Create a new user' @@ -65,8 +65,7 @@ module Mastodon With the --confirmed option, the confirmation e-mail will be skipped and the account will be active straight away. - With the --role option one of "user", "admin" or "moderator" - can be supplied. Defaults to "user" + With the --role option, the role can be supplied. With the --reattach option, the new user will be reattached to a given existing username of an old account. If the old @@ -75,9 +74,22 @@ module Mastodon username to the new account anyway. LONG_DESC def create(username) + role_id = nil + + if options[:role] + role = UserRole.find_by(name: options[:role]) + + if role.nil? + say('Cannot find user role with that name', :red) + exit(1) + end + + role_id = role.id + end + account = Account.new(username: username) password = SecureRandom.hex - user = User.new(email: options[:email], password: password, agreement: true, approved: true, admin: options[:role] == 'admin', moderator: options[:role] == 'moderator', confirmed_at: options[:confirmed] ? Time.now.utc : nil, bypass_invite_request_check: true) + user = User.new(email: options[:email], password: password, agreement: true, approved: true, role_id: role_id, confirmed_at: options[:confirmed] ? Time.now.utc : nil, bypass_invite_request_check: true) if options[:reattach] account = Account.find_local(username) || Account.new(username: username) @@ -106,14 +118,14 @@ module Mastodon user.errors.to_h.each do |key, error| say('Failure/Error: ', :red) say(key) - say(' ' + error, :red) + say(" #{error}", :red) end exit(1) end end - option :role, enum: %w(user moderator admin) + option :role option :email option :confirm, type: :boolean option :enable, type: :boolean @@ -125,8 +137,7 @@ module Mastodon long_desc <<-LONG_DESC Modify a user account. - With the --role option, update the user's role to one of "user", - "moderator" or "admin". + With the --role option, update the user's role. With the --email option, update the user's e-mail address. With the --confirm option, mark the user's e-mail as confirmed. @@ -152,8 +163,14 @@ module Mastodon end if options[:role] - user.admin = options[:role] == 'admin' - user.moderator = options[:role] == 'moderator' + role = UserRole.find_by(name: options[:role]) + + if role.nil? + say('Cannot find user role with that name', :red) + exit(1) + end + + user.role_id = role.id end password = SecureRandom.hex if options[:reset_password] @@ -172,7 +189,7 @@ module Mastodon user.errors.to_h.each do |key, error| say('Failure/Error: ', :red) say(key) - say(' ' + error, :red) + say(" #{error}", :red) end exit(1) @@ -319,7 +336,7 @@ module Mastodon unless skip_domains.empty? say('The following domains were not available during the check:', :yellow) - skip_domains.each { |domain| say(' ' + domain) } + skip_domains.each { |domain| say(" #{domain}") } end end diff --git a/lib/simple_navigation/item_extensions.rb b/lib/simple_navigation/item_extensions.rb new file mode 100644 index 000000000..28af37a18 --- /dev/null +++ b/lib/simple_navigation/item_extensions.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module SimpleNavigation + module ItemExtensions + def url + if @url.nil? && @sub_navigation + @sub_navigation.items.first.url + else + @url + end + end + end +end + +SimpleNavigation::Item.prepend(SimpleNavigation::ItemExtensions) |