about summary refs log tree commit diff
path: root/app/models
diff options
context:
space:
mode:
authorMatt Jankowski <mjankowski@thoughtbot.com>2017-05-07 21:32:52 -0400
committerEugen Rochko <eugen@zeonfederated.com>2017-05-08 03:32:52 +0200
commitbba537a7bebe11be4b1e4a7e126a34cd27b73678 (patch)
tree940ae93f632bfa1cd99d525d0fde9bb3523fe5c7 /app/models
parent0291b73de7e2fca7f5c137de4427800c02d7a233 (diff)
Improve allowed language handling (#2897)
* Dont allow empty value in user allowed languages

* Sanitize language input to reject blank values in array
Diffstat (limited to 'app/models')
-rw-r--r--app/models/user.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/app/models/user.rb b/app/models/user.rb
index f8e8a2efa..dfecb2339 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -52,6 +52,8 @@ class User < ApplicationRecord
   scope :admins,    -> { where(admin: true) }
   scope :confirmed, -> { where.not(confirmed_at: nil) }
 
+  before_validation :sanitize_languages
+
   def confirmed?
     confirmed_at.present?
   end
@@ -77,4 +79,10 @@ class User < ApplicationRecord
   def setting_auto_play_gif
     settings.auto_play_gif
   end
+
+  private
+
+  def sanitize_languages
+    allowed_languages.reject!(&:blank?)
+  end
 end