Class: Goldencobra::Permission

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/goldencobra/permission.rb

Constant Summary collapse

PossibleSubjectClasses =
[":all"] + ActiveRecord::Base.descendants.map(&:name)
PossibleActions =
["read", "not_read", "manage", "not_manage", "update", "not_update", "destroy", "not_destroy"]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.restricted?(item) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
37
38
39
40
# File 'app/models/goldencobra/permission.rb', line 34

def self.restricted?(item)
  @@last_permission ||= Goldencobra::Permission.reorder(:updated_at).last
  cache_key = "#{@@last_permission.try(:cache_key)}-#{item.try(:cache_key)}"
  return Rails.cache.fetch(cache_key) do
    Goldencobra::Permission.where(subject_class: item.class, subject_id: item.id).count > 0
  end
end

Instance Method Details

#set_min_sorter_idObject



42
43
44
45
46
47
48
49
# File 'app/models/goldencobra/permission.rb', line 42

def set_min_sorter_id
  last_permission = Permission.order(:created_at).last
  if last_permission.present? && ( self.sorter_id.blank? || self.sorter_id == 0 )
    self.sorter_id = last_permission.id + 1
  else
    self.sorter_id = 0
  end
end