about summary refs log tree commit diff
path: root/app/models/invite.rb
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2019-07-26 18:55:33 +0200
committerEugen Rochko <eugen@zeonfederated.com>2019-07-26 18:55:33 +0200
commit92569ffde81a3fe768fd8773fdab5d1a927f3f88 (patch)
treed5544ac69ccea9235baf679c1988ff8e811662ef /app/models/invite.rb
parenta6b44401156524ef70a5917d17c93886c5e20a0d (diff)
Fix invites not being disabled upon account suspension (#11412)
* Disable invite links from disabled/suspended users

* Add has_many invites relationship to users

* Destroy unused invites when suspending an account
Diffstat (limited to 'app/models/invite.rb')
-rw-r--r--app/models/invite.rb4
1 files changed, 2 insertions, 2 deletions
diff --git a/app/models/invite.rb b/app/models/invite.rb
index fe2322462..02ab8e0b2 100644
--- a/app/models/invite.rb
+++ b/app/models/invite.rb
@@ -17,7 +17,7 @@
 class Invite < ApplicationRecord
   include Expireable
 
-  belongs_to :user
+  belongs_to :user, inverse_of: :invites
   has_many :users, inverse_of: :invite
 
   scope :available, -> { where(expires_at: nil).or(where('expires_at >= ?', Time.now.utc)) }
@@ -25,7 +25,7 @@ class Invite < ApplicationRecord
   before_validation :set_code
 
   def valid_for_use?
-    (max_uses.nil? || uses < max_uses) && !expired?
+    (max_uses.nil? || uses < max_uses) && !expired? && !(user.nil? || user.disabled?)
   end
 
   private