Class: Collavre::Label

Inherits:
ApplicationRecord show all
Defined in:
app/models/collavre/label.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_sti_class(type_name) ⇒ Object

Resolve short STI class names to namespaced versions Use constantize to always get fresh class reference after hot reload



19
20
21
22
# File 'app/models/collavre/label.rb', line 19

def self.find_sti_class(type_name)
  type_name = "Collavre::#{type_name}" unless type_name.start_with?("Collavre::")
  type_name.constantize
end

Instance Method Details

#readable_by?(user) ⇒ Boolean

Check if user has permission to read this label If linked to a Creative, delegates to Creative’s permission system Otherwise falls back to owner-based or public (nil owner) visibility

Returns:

  • (Boolean)


29
30
31
32
33
34
35
36
37
# File 'app/models/collavre/label.rb', line 29

def readable_by?(user)
  return true if owner_id.present? && owner_id == user&.id

  if creative_id.present? && creative
    creative.has_permission?(user, :read)
  else
    owner_id.nil?
  end
end