]> git.openstreetmap.org Git - rails.git/blobdiff - app/models/user.rb
Refactor app/views/messages templates
[rails.git] / app / models / user.rb
index f804f4666b8c28a8e38f64a35837af2dcec65a29..1942a25cc237a784394b91f9ba64c844f36e3309 100644 (file)
@@ -115,6 +115,7 @@ class User < ApplicationRecord
 
   alias_attribute :created_at, :creation_time
 
+  after_initialize :encrypt_password
   before_save :encrypt_password
   before_save :update_tile
   after_save :spam_check
@@ -290,6 +291,12 @@ class User < ApplicationRecord
     role? "administrator"
   end
 
+  ##
+  # returns true if the user has the importer role, false otherwise
+  def importer?
+    role? "importer"
+  end
+
   ##
   # returns true if the user has the requested role
   def role?(role)
@@ -412,6 +419,18 @@ class User < ApplicationRecord
     end
   end
 
+  def deletion_allowed_at
+    unless Settings.user_account_deletion_delay.nil?
+      last_changeset = changesets.reorder(:closed_at => :desc).first
+      return last_changeset.closed_at.utc + Settings.user_account_deletion_delay.hours if last_changeset
+    end
+    creation_time.utc
+  end
+
+  def deletion_allowed?
+    deletion_allowed_at <= Time.now.utc
+  end
+
   private
 
   def encrypt_password