about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorStarfall <us@starfall.systems>2023-04-22 20:32:00 -0500
committerStarfall <us@starfall.systems>2023-04-22 20:32:00 -0500
commit609ee7b2979252464e63acbfd2eff3e0e3786f3e (patch)
tree6ade160c4354b803ed36ae5dae28a0ae38bcf032 /lib
parent4fe1689de43f4404eb9530fcfbcbfb26d6c1c13a (diff)
parent5b58ebb04fe197cc7aa0cfc05a4d1b2df8da0050 (diff)
Merge remote-tracking branch 'glitch/main'
Diffstat (limited to 'lib')
-rw-r--r--lib/generators/post_deployment_migration/USAGE10
-rw-r--r--lib/generators/post_deployment_migration/post_deployment_migration_generator.rb17
-rw-r--r--lib/generators/post_deployment_migration/templates/migration.erb8
-rw-r--r--lib/generators/post_deployment_migration_generator.rb17
-rw-r--r--lib/mastodon/accounts_cli.rb10
-rw-r--r--lib/templates/rails/post_deployment_migration/migration.rb8
6 files changed, 43 insertions, 27 deletions
diff --git a/lib/generators/post_deployment_migration/USAGE b/lib/generators/post_deployment_migration/USAGE
new file mode 100644
index 000000000..57f3c6aa1
--- /dev/null
+++ b/lib/generators/post_deployment_migration/USAGE
@@ -0,0 +1,10 @@
+Description:
+    Generate a Rails migration in the db/post_migrate/ dir.
+
+    Interacts with the post_deployment_migrations initializer.
+
+Example:
+    bin/rails generate post_deployment_migration IsolateChanges
+
+    Creates a migration in db/post_migrate/<timestamp>_isolate_changes.rb
+    which will have `disable_ddl_transaction!` and a `change` method included.
diff --git a/lib/generators/post_deployment_migration/post_deployment_migration_generator.rb b/lib/generators/post_deployment_migration/post_deployment_migration_generator.rb
new file mode 100644
index 000000000..adb34a289
--- /dev/null
+++ b/lib/generators/post_deployment_migration/post_deployment_migration_generator.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+require 'rails/generators/active_record'
+
+class PostDeploymentMigrationGenerator < Rails::Generators::NamedBase
+  source_root File.expand_path('templates', __dir__)
+
+  include Rails::Generators::Migration
+
+  def create_post_deployment_migration
+    migration_template 'migration.erb', "db/post_migrate/#{file_name}.rb"
+  end
+
+  def self.next_migration_number(path)
+    ActiveRecord::Generators::Base.next_migration_number(path)
+  end
+end
diff --git a/lib/generators/post_deployment_migration/templates/migration.erb b/lib/generators/post_deployment_migration/templates/migration.erb
new file mode 100644
index 000000000..fd6a02a0f
--- /dev/null
+++ b/lib/generators/post_deployment_migration/templates/migration.erb
@@ -0,0 +1,8 @@
+# frozen_string_literal: true
+
+class <%= migration_class_name %> < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]
+  disable_ddl_transaction!
+
+  def change
+  end
+end
diff --git a/lib/generators/post_deployment_migration_generator.rb b/lib/generators/post_deployment_migration_generator.rb
deleted file mode 100644
index 798c01b88..000000000
--- a/lib/generators/post_deployment_migration_generator.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# frozen_string_literal: true
-
-require 'rails/generators'
-
-module Rails
-  class PostDeploymentMigrationGenerator < Rails::Generators::NamedBase
-    def create_migration_file
-      timestamp = Time.zone.now.strftime('%Y%m%d%H%M%S')
-
-      template 'migration.rb', "db/post_migrate/#{timestamp}_#{file_name}.rb"
-    end
-
-    def migration_class_name
-      file_name.camelize
-    end
-  end
-end
diff --git a/lib/mastodon/accounts_cli.rb b/lib/mastodon/accounts_cli.rb
index a6532541e..5194cd80a 100644
--- a/lib/mastodon/accounts_cli.rb
+++ b/lib/mastodon/accounts_cli.rb
@@ -57,6 +57,7 @@ module Mastodon
     option :role
     option :reattach, type: :boolean
     option :force, type: :boolean
+    option :approve, type: :boolean
     desc 'create USERNAME', 'Create a new user account'
     long_desc <<-LONG_DESC
       Create a new user account with a given USERNAME and an
@@ -72,6 +73,8 @@ module Mastodon
       account is still in use by someone else, you can supply
       the --force option to delete the old record and reattach the
       username to the new account anyway.
+
+      With the --approve option, the account will be approved.
     LONG_DESC
     def create(username)
       role_id  = nil
@@ -89,7 +92,7 @@ module Mastodon
 
       account  = Account.new(username: username)
       password = SecureRandom.hex
-      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)
+      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)
 
       if options[:reattach]
         account = Account.find_local(username) || Account.new(username: username)
@@ -112,6 +115,8 @@ module Mastodon
           user.confirm!
         end
 
+        user.approve! if options[:approve]
+
         say('OK', :green)
         say("New password: #{password}")
       else
@@ -184,9 +189,10 @@ module Mastodon
       user.disabled = true if options[:disable]
       user.approved = true if options[:approve]
       user.otp_required_for_login = false if options[:disable_2fa]
-      user.confirm if options[:confirm]
 
       if user.save
+        user.confirm if options[:confirm]
+
         say('OK', :green)
         say("New password: #{password}") if options[:reset_password]
       else
diff --git a/lib/templates/rails/post_deployment_migration/migration.rb b/lib/templates/rails/post_deployment_migration/migration.rb
deleted file mode 100644
index 503205b84..000000000
--- a/lib/templates/rails/post_deployment_migration/migration.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-# frozen_string_literal: true
-
-class <%= migration_class_name %> < ActiveRecord::Migration[5.2]
-  disable_ddl_transaction!
-
-  def change
-  end
-end