Sha256: 9d316256e6f7daddf39308f60f515e5e6117ae225cb0fb08d3a521ad1b688759

Contents?: true

Size: 902 Bytes

Versions: 32

Compression:

Stored size: 902 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) }

    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

32 entries across 32 versions & 2 rubygems

Version Path
decidim-core-0.8.4 app/models/decidim/impersonation_log.rb
decidim-core-0.8.3 app/models/decidim/impersonation_log.rb
decidim-core-0.8.2 app/models/decidim/impersonation_log.rb
decidim-core-0.8.1 app/models/decidim/impersonation_log.rb
decidim-core-0.8.0 app/models/decidim/impersonation_log.rb
decidim-core-0.7.4 app/models/decidim/impersonation_log.rb
decidim-core-0.7.3 app/models/decidim/impersonation_log.rb
decidim-core-0.7.2 app/models/decidim/impersonation_log.rb
decidim-core-0.7.1 app/models/decidim/impersonation_log.rb
decidim-core-0.7.0 app/models/decidim/impersonation_log.rb
decidim-core-0.6.8 app/models/decidim/impersonation_log.rb
decidim-0.6.8 decidim-core/app/models/decidim/impersonation_log.rb
decidim-core-0.6.7 app/models/decidim/impersonation_log.rb
decidim-0.6.7 decidim-core/app/models/decidim/impersonation_log.rb
decidim-core-0.6.6 app/models/decidim/impersonation_log.rb
decidim-0.6.6 decidim-core/app/models/decidim/impersonation_log.rb
decidim-core-0.6.5 app/models/decidim/impersonation_log.rb
decidim-0.6.5 decidim-core/app/models/decidim/impersonation_log.rb
decidim-core-0.6.4 app/models/decidim/impersonation_log.rb
decidim-0.6.4 decidim-core/app/models/decidim/impersonation_log.rb