]> git.openstreetmap.org Git - rails.git/blobdiff - app/models/user.rb
Merge remote-tracking branch 'upstream/pull/3345'
[rails.git] / app / models / user.rb
index 123ef3230e39fd025dc3e06bd1c1a2e219486d8c..7a0d069927fa5da20e6aeecee4a52a841d76b1e2 100644 (file)
@@ -87,7 +87,7 @@ class User < ApplicationRecord
   scope :active, -> { where(:status => %w[active confirmed]) }
   scope :identifiable, -> { where(:data_public => true) }
 
-  has_one_attached :avatar
+  has_one_attached :avatar, :service => Settings.avatar_storage
 
   validates :display_name, :presence => true, :length => 3..255,
                            :exclusion => %w[new terms save confirm confirm-email go_public reset-password forgot-password suspended]
@@ -172,8 +172,10 @@ class User < ApplicationRecord
     end
 
     # Used in test suite, not something that we would normally need to do.
-    event :deactivate do
-      transitions :from => :active, :to => :pending
+    if Rails.env.test?
+      event :deactivate do
+        transitions :from => :active, :to => :pending
+      end
     end
 
     # To confirm an account is used to override the spam scoring
@@ -181,10 +183,21 @@ class User < ApplicationRecord
       transitions :from => [:pending, :active, :suspended], :to => :confirmed
     end
 
+    # To unconfirm an account is to make it subject to future spam scoring again
+    event :unconfirm do
+      transitions :from => :confirmed, :to => :active
+    end
+
+    # Accounts can be automatically suspended by spam_check
     event :suspend do
       transitions :from => [:pending, :active], :to => :suspended
     end
 
+    # Unsuspending an account moves it back to active without overriding the spam scoring
+    event :unsuspend do
+      transitions :from => :suspended, :to => :active
+    end
+
     # Mark the account as deleted but keep all data intact
     event :hide do
       transitions :from => [:pending, :active, :confirmed, :suspended], :to => :deleted