about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorpluralcafe-docker <git@plural.cafe>2018-10-13 01:09:02 +0000
committerpluralcafe-docker <git@plural.cafe>2018-10-13 01:09:02 +0000
commit7c96ee7815c216d6ac3b748d7dd6959376d3914e (patch)
treefd36bade02afa1536198e7f3beafb208973b68c5 /lib
parentf9275cb762a311cbf298b3929552a153703c0726 (diff)
parent70d346ea951ebfa002225759310d72882a435a5c (diff)
Merge branch 'glitch'
Diffstat (limited to 'lib')
-rw-r--r--lib/cli.rb4
-rw-r--r--lib/mastodon/accounts_cli.rb26
-rw-r--r--lib/mastodon/migration_helpers.rb10
-rw-r--r--lib/mastodon/settings_cli.rb26
-rw-r--r--lib/tasks/mastodon.rake25
5 files changed, 59 insertions, 32 deletions
diff --git a/lib/cli.rb b/lib/cli.rb
index 14a91c2db..208df660f 100644
--- a/lib/cli.rb
+++ b/lib/cli.rb
@@ -5,6 +5,7 @@ require_relative 'mastodon/media_cli'
 require_relative 'mastodon/emoji_cli'
 require_relative 'mastodon/accounts_cli'
 require_relative 'mastodon/feeds_cli'
+require_relative 'mastodon/settings_cli'
 
 module Mastodon
   class CLI < Thor
@@ -19,5 +20,8 @@ module Mastodon
 
     desc 'feeds SUBCOMMAND ...ARGS', 'Manage feeds'
     subcommand 'feeds', Mastodon::FeedsCLI
+
+    desc 'settings SUBCOMMAND ...ARGS', 'Manage dynamic settings'
+    subcommand 'settings', Mastodon::SettingsCLI
   end
 end
diff --git a/lib/mastodon/accounts_cli.rb b/lib/mastodon/accounts_cli.rb
index 65c1b395a..704cf474b 100644
--- a/lib/mastodon/accounts_cli.rb
+++ b/lib/mastodon/accounts_cli.rb
@@ -83,7 +83,8 @@ module Mastodon
         end
       end
 
-      user.account = account
+      account.suspended = false
+      user.account      = account
 
       if user.save
         if options[:confirmed]
@@ -170,11 +171,32 @@ module Mastodon
         exit(1)
       end
 
-      say("Deleting user with #{account.statuses_count}, this might take a while...")
+      say("Deleting user with #{account.statuses_count} statuses, this might take a while...")
       SuspendAccountService.new.call(account, remove_user: true)
       say('OK', :green)
     end
 
+    desc 'backup USERNAME', 'Request a backup for a user'
+    long_desc <<-LONG_DESC
+      Request a new backup for an account with a given USERNAME.
+
+      The backup will be created in Sidekiq asynchronously, and
+      the user will receive an e-mail with a link to it once
+      it's done.
+    LONG_DESC
+    def backup(username)
+      account = Account.find_local(username)
+
+      if account.nil?
+        say('No user with such username', :red)
+        exit(1)
+      end
+
+      backup = account.user.backups.create!
+      BackupWorker.perform_async(backup.id)
+      say('OK', :green)
+    end
+
     option :dry_run, type: :boolean
     desc 'cull', 'Remove remote accounts that no longer exist'
     long_desc <<-LONG_DESC
diff --git a/lib/mastodon/migration_helpers.rb b/lib/mastodon/migration_helpers.rb
index 5c135685f..f5dc7e1c6 100644
--- a/lib/mastodon/migration_helpers.rb
+++ b/lib/mastodon/migration_helpers.rb
@@ -342,8 +342,8 @@ module Mastodon
 
       say "Migrating #{table_name}.#{column} (~#{total.to_i} rows)"
 
-      started_time = Time.now
-      last_time = Time.now
+      started_time = Time.zone.now
+      last_time = Time.zone.now
       migrated = 0
       loop do
         stop_row = nil
@@ -375,13 +375,13 @@ module Mastodon
         end
 
         migrated += batch_size
-        if Time.now - last_time > 1
+        if Time.zone.now - last_time > 1
           status = "Migrated #{migrated} rows"
 
           percentage = 100.0 * migrated / total
           status += " (~#{sprintf('%.2f', percentage)}%, "
 
-          remaining_time = (100.0 - percentage) * (Time.now - started_time) / percentage
+          remaining_time = (100.0 - percentage) * (Time.zone.now - started_time) / percentage
 
           status += "#{(remaining_time / 60).to_i}:"
           status += sprintf('%02d', remaining_time.to_i % 60)
@@ -397,7 +397,7 @@ module Mastodon
           status += ')'
 
           say status, true
-          last_time = Time.now
+          last_time = Time.zone.now
         end
 
         # There are no more rows left to update.
diff --git a/lib/mastodon/settings_cli.rb b/lib/mastodon/settings_cli.rb
new file mode 100644
index 000000000..87c321013
--- /dev/null
+++ b/lib/mastodon/settings_cli.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+require_relative '../../config/boot'
+require_relative '../../config/environment'
+require_relative 'cli_helper'
+
+module Mastodon
+  class RegistrationsCLI < Thor
+    desc 'open', 'Open registrations'
+    def open
+      Setting.open_registrations = true
+      say('OK', :green)
+    end
+
+    desc 'close', 'Close registrations'
+    def close
+      Setting.open_registrations = false
+      say('OK', :green)
+    end
+  end
+
+  class SettingsCLI < Thor
+    desc 'registrations SUBCOMMAND ...ARGS', 'Manage state of registrations'
+    subcommand 'registrations', RegistrationsCLI
+  end
+end
diff --git a/lib/tasks/mastodon.rake b/lib/tasks/mastodon.rake
index ec8800819..ee9657b0e 100644
--- a/lib/tasks/mastodon.rake
+++ b/lib/tasks/mastodon.rake
@@ -1,7 +1,5 @@
 # frozen_string_literal: true
 
-require 'optparse'
-require 'colorize'
 require 'tty-command'
 require 'tty-prompt'
 
@@ -390,25 +388,6 @@ namespace :mastodon do
     end
   end
 
-  namespace :push do
-    desc 'Unsubscribes from PuSH updates of feeds nobody follows locally'
-    task clear: :environment do
-      Pubsubhubbub::UnsubscribeWorker.push_bulk(Account.remote.without_followers.where.not(subscription_expires_at: nil).pluck(:id))
-    end
-  end
-
-  namespace :settings do
-    desc 'Open registrations on this instance'
-    task open_registrations: :environment do
-      Setting.open_registrations = true
-    end
-
-    desc 'Close registrations on this instance'
-    task close_registrations: :environment do
-      Setting.open_registrations = false
-    end
-  end
-
   namespace :webpush do
     desc 'Generate VAPID key'
     task generate_vapid_key: :environment do
@@ -427,7 +406,3 @@ def disable_log_stdout!
   HttpLog.configuration.logger = dev_null
   Paperclip.options[:log]      = false
 end
-
-def prepare_for_options!
-  2.times { ARGV.shift }
-end