Sha256: c0f039924f785a26b94a32c2358409caeac6f5cd5a590d879fcc86ade90f99f5
Contents?: true
Size: 1.48 KB
Versions: 10
Compression:
Stored size: 1.48 KB
Contents
# frozen_string_literal: true module Maquina module Blockeable extend ActiveSupport::Concern included do |base| if base.eql?(Maquina::User) define_method(:memberships_blocked?) do return false if management? return @memberships_blocked if !@memberships_blocked.nil? @memberships_blocked = !memberships.includes(:organization).where(blocked_at: nil).where(maquina_organizations: {active: true}).exists? end end if has_attribute?(:blocked_at) && has_attribute?(:temporary_blocked_at) define_method(:blocked?) do temporary_blocked_until = nil if Maquina.configuration.temporary_block.present? && temporary_blocked_at.present? temporary_blocked_until = temporary_blocked_at.since(Maquina.configuration.temporary_block) end blocked_at.present? || (temporary_blocked_until.present? && temporary_blocked_until > Time.zone.now) || (respond_to?(:memberships_blocked?) && memberships_blocked?) end scope :unblocked, -> { where(blocked_at: nil).where("(coalesce(temporary_blocked_at + interval '? minutes', now())) <= now()", Maquina.configuration.temporary_block&.in_minutes&.to_i || 0) } elsif has_attribute(:blocked_at) define_method(:blocked?) do blocked_at.present? || (respond_to?(:memberships_blocked?) && memberships_blocked?) end scope :unblocked, -> { where(blocked_at: nil) } end end end end
Version data entries
10 entries across 10 versions & 1 rubygems