diff options
author | Starfall <us@starfall.systems> | 2022-07-25 18:53:31 -0500 |
---|---|---|
committer | Starfall <us@starfall.systems> | 2022-07-25 18:53:31 -0500 |
commit | 5b9419060d79eda85c40a12c567dd0e1e44a7ecb (patch) | |
tree | f5e21930844f7c11ae40b9097a78a32916ba5dba /lib | |
parent | a137fecf94d25a03ef7224843c1afd0c30f428e6 (diff) | |
parent | 3a7c641dd4db1d67b172f731518b472d58dd2262 (diff) |
Merge remote-tracking branch 'glitch/main'
Diffstat (limited to 'lib')
-rw-r--r-- | lib/mastodon/accounts_cli.rb | 41 | ||||
-rw-r--r-- | lib/simple_navigation/item_extensions.rb | 15 | ||||
-rw-r--r-- | lib/tasks/tests.rake | 18 |
3 files changed, 61 insertions, 13 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) diff --git a/lib/tasks/tests.rake b/lib/tasks/tests.rake index 0f3b44a74..65bff6a8e 100644 --- a/lib/tasks/tests.rake +++ b/lib/tasks/tests.rake @@ -38,10 +38,26 @@ namespace :tests do puts 'Instance actor does not have a private key' exit(1) end + + unless Account.find_by(username: 'user', domain: nil).custom_filters.map { |filter| filter.keywords.pluck(:keyword) } == [['test'], ['take']] + puts 'CustomFilterKeyword records not created as expected' + exit(1) + end + end + + desc 'Populate the database with test data for 2.4.3' + task populate_v2_4_3: :environment do # rubocop:disable Naming/VariableNumber + ActiveRecord::Base.connection.execute(<<~SQL) + INSERT INTO "custom_filters" + (id, account_id, phrase, context, whole_word, irreversible, created_at, updated_at) + VALUES + (1, 2, 'test', '{ "home", "public" }', true, true, now(), now()), + (2, 2, 'take', '{ "home" }', false, false, now(), now()); + SQL end desc 'Populate the database with test data for 2.4.0' - task populate_v2_4: :environment do + task populate_v2_4: :environment do # rubocop:disable Naming/VariableNumber ActiveRecord::Base.connection.execute(<<~SQL) INSERT INTO "settings" (id, thing_type, thing_id, var, value, created_at, updated_at) |