From def44618ef99c989bf4bbe5d9d24075fbaa8079c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A2u=20Cao?= Date: Wed, 6 Sep 2023 12:16:00 +0200 Subject: [PATCH] Comments --- app/models/user.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/models/user.rb b/app/models/user.rb index d5db570..d0969a0 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -11,7 +11,10 @@ class User < ApplicationRecord has_one_attached :avatar + # # Relations + # + has_many :invitations, dependent: :destroy has_one :invitation, inverse_of: :invitee, foreign_key: 'invited_user_id' has_one :inviter, through: :invitation, source: :user @@ -26,6 +29,10 @@ class User < ApplicationRecord has_many :remote_storage_authorizations + # + # Validations + # + validates_uniqueness_of :cn, scope: :ou validates_length_of :cn, minimum: 3 validates_format_of :cn, with: /\A([a-z0-9\-])*\z/, @@ -47,10 +54,19 @@ class User < ApplicationRecord validates_uniqueness_of :nostr_pubkey, allow_blank: true validate :acceptable_avatar + + # + # Scopes + # + scope :confirmed, -> { where.not(confirmed_at: nil) } scope :pending, -> { where(confirmed_at: nil) } scope :all_except, -> (user) { where.not(id: user) } + # + # Encrypted database columns + # + has_encrypted :ln_login, :ln_password # Include default devise modules. Others available are: