Sha256: 0145ffc1fb9beb56c202d2026ac71c9e8a5456bf6dad5ea0efc01171d3a1e0a7
Contents?: true
Size: 945 Bytes
Versions: 3
Compression:
Stored size: 945 Bytes
Contents
# Permission 是权限。 class Unidom::Authorization::Permission < ActiveRecord::Base self.table_name = 'unidom_permissions' include Unidom::Common::Concerns::ModelExtension has_many :authorizings, class_name: 'Unidom::Authorization::Authorizing' validates :name, presence: true, length: { in: 2..self.columns_hash['name'].limit } validates :path, allow_blank: true, length: { in: 2..self.columns_hash['path'].limit } scope :path_is, ->(path) { where path: path } def authorize!(authorized, by: nil, at: Time.now) attributes = { authorized: authorized, opened_at: at } if by.present? attributes[:authorizer] = by else attributes[:authorizer_id] = Unidom::Common::NULL_UUID attributes[:authorizer_type] = '' end authorizings.create! attributes end def authorized?(authorized, at: Time.now) authorizings.authorized_is(authorized).valid_at(now: at).alive.exists? end end
Version data entries
3 entries across 3 versions & 1 rubygems