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
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user