Sha256: f2b93061b364a77d9f72cc6ac8f0a87f96f53ed0ec7ce3b161b76598c5bc91bb
Contents?: true
Size: 994 Bytes
Versions: 30
Compression:
Stored size: 994 Bytes
Contents
# frozen_string_literal: true module Decidim # ImpersonationLogs are created whenever an admin impersonate a managed user class ImpersonationLog < ApplicationRecord SESSION_TIME_IN_MINUTES = 30 belongs_to :admin, foreign_key: "decidim_admin_id", class_name: "Decidim::User" belongs_to :user, foreign_key: "decidim_user_id", class_name: "Decidim::User" validate :same_organization, :non_active_impersonation scope :active, -> { where(ended_at: nil, expired_at: nil) } scope :expired, -> { where(ended_at: nil).where.not(expired_at: nil) } def ended? ended_at.present? end def expired? expired_at.present? end private def same_organization return if admin&.organization == user&.organization errors.add(:admin, :invalid) end def non_active_impersonation return if ended? || expired? errors.add(:admin, :invalid) if Decidim::ImpersonationLog.where(admin: admin).active.any? end end end
Version data entries
30 entries across 30 versions & 1 rubygems