about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorThibaut Girka <thib@sitedethib.com>2019-05-04 16:37:26 +0200
committerThibaut Girka <thib@sitedethib.com>2019-05-04 16:37:26 +0200
commit33c80e07838d932efc6214cb1642cefaeb624b67 (patch)
tree51cae2d9096888cc27ae38ec4b0ceceb1853bb73 /lib
parent2c2f649200ba5b742ba9d17ac5ba553c752b59aa (diff)
parentc88d9e524b02cba895de9bdb7cba0e29e37703d5 (diff)
Merge branch 'master' into glitch-soc/merge-upstream
Conflicts:
- app/models/media_attachment.rb
Diffstat (limited to 'lib')
-rw-r--r--lib/cli.rb4
-rw-r--r--lib/mastodon/accounts_cli.rb7
-rw-r--r--lib/mastodon/cache_cli.rb19
-rw-r--r--lib/mastodon/version.rb2
-rw-r--r--lib/paperclip/blurhash_transcoder.rb16
5 files changed, 46 insertions, 2 deletions
diff --git a/lib/cli.rb b/lib/cli.rb
index b56c6e76f..5780e3e87 100644
--- a/lib/cli.rb
+++ b/lib/cli.rb
@@ -9,6 +9,7 @@ require_relative 'mastodon/search_cli'
 require_relative 'mastodon/settings_cli'
 require_relative 'mastodon/statuses_cli'
 require_relative 'mastodon/domains_cli'
+require_relative 'mastodon/cache_cli'
 require_relative 'mastodon/version'
 
 module Mastodon
@@ -41,6 +42,9 @@ module Mastodon
     desc 'domains SUBCOMMAND ...ARGS', 'Manage account domains'
     subcommand 'domains', Mastodon::DomainsCLI
 
+    desc 'cache SUBCOMMAND ...ARGS', 'Manage cache'
+    subcommand 'cache', Mastodon::CacheCLI
+
     option :dry_run, type: :boolean
     desc 'self-destruct', 'Erase the server from the federation'
     long_desc <<~LONG_DESC
diff --git a/lib/mastodon/accounts_cli.rb b/lib/mastodon/accounts_cli.rb
index 9dc84f1b5..3131647f3 100644
--- a/lib/mastodon/accounts_cli.rb
+++ b/lib/mastodon/accounts_cli.rb
@@ -73,7 +73,7 @@ module Mastodon
     def create(username)
       account  = Account.new(username: username)
       password = SecureRandom.hex
-      user     = User.new(email: options[:email], password: password, agreement: true, admin: options[:role] == 'admin', moderator: options[:role] == 'moderator', confirmed_at: options[:confirmed] ? Time.now.utc : nil)
+      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)
 
       if options[:reattach]
         account = Account.find_local(username) || Account.new(username: username)
@@ -115,6 +115,7 @@ module Mastodon
     option :enable, type: :boolean
     option :disable, type: :boolean
     option :disable_2fa, type: :boolean
+    option :approve, type: :boolean
     desc 'modify USERNAME', 'Modify a user'
     long_desc <<-LONG_DESC
       Modify a user account.
@@ -128,6 +129,9 @@ module Mastodon
       With the --disable option, lock the user out of their account. The
       --enable option is the opposite.
 
+      With the --approve option, the account will be approved, if it was
+      previously not due to not having open registrations.
+
       With the --disable-2fa option, the two-factor authentication
       requirement for the user can be removed.
     LONG_DESC
@@ -147,6 +151,7 @@ module Mastodon
       user.email = options[:email] if options[:email]
       user.disabled = false if options[:enable]
       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]
 
diff --git a/lib/mastodon/cache_cli.rb b/lib/mastodon/cache_cli.rb
new file mode 100644
index 000000000..e9b6667b3
--- /dev/null
+++ b/lib/mastodon/cache_cli.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+require_relative '../../config/boot'
+require_relative '../../config/environment'
+require_relative 'cli_helper'
+
+module Mastodon
+  class CacheCLI < Thor
+    def self.exit_on_failure?
+      true
+    end
+
+    desc 'clear', 'Clear out the cache storage'
+    def clear
+      Rails.cache.clear
+      say('OK', :green)
+    end
+  end
+end
diff --git a/lib/mastodon/version.rb b/lib/mastodon/version.rb
index 8172aeb94..c825e7629 100644
--- a/lib/mastodon/version.rb
+++ b/lib/mastodon/version.rb
@@ -13,7 +13,7 @@ module Mastodon
     end
 
     def patch
-      0
+      1
     end
 
     def pre
diff --git a/lib/paperclip/blurhash_transcoder.rb b/lib/paperclip/blurhash_transcoder.rb
new file mode 100644
index 000000000..08925a6dd
--- /dev/null
+++ b/lib/paperclip/blurhash_transcoder.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+module Paperclip
+  class BlurhashTranscoder < Paperclip::Processor
+    def make
+      return @file unless options[:style] == :small
+
+      pixels   = convert(':source RGB:-', source: File.expand_path(@file.path)).unpack('C*')
+      geometry = options.fetch(:file_geometry_parser).from_file(@file)
+
+      attachment.instance.blurhash = Blurhash.encode(geometry.width, geometry.height, pixels, options[:blurhash] || {})
+
+      @file
+    end
+  end
+end