Sha256: 79f810983a67f77e1297f09870b6e6dad214143076eed1b863d2290deb2202f5

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

class Authorization < ActiveRecord::Base
  belongs_to :operator, :class_name => ::VIGILANTE_CONFIG['current_user_class'].to_s, inverse_of: :authorizations, optional: true
  belongs_to :ability

  has_many :authorization_extents, :dependent => :delete_all
  accepts_nested_attributes_for :authorization_extents, :reject_if => proc { |x| x[:extent].blank? && x[:extent_objid].blank? }, :allow_destroy => true


  def match_extent(extent_object)
    extents_count = authorization_extents.count
    return true if extents_count == 0 && extent_object.blank?

    return false if ((extents_count == 0 && extent_object.present?) ||
                     (extents_count > 0  && extent_object.blank?))

    authorization_extents.each do |extent|
      return true if extent.match_extent(extent_object)
    end
    false
  end


  def add_extent(extent_object)
    unless extent_object.nil? || match_extent(extent_object)
      new_extent = authorization_extents.build
      new_extent.set_extent(extent_object)
      new_extent.save
    end
  end
  
  def has_extent?
    authorization_extents.count > 0
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vigilante-1.0.19 app/models/authorization.rb