Sha256: d62317ab11c1d0cd0b3d7d9dec519fd5dfd2d585f21d0ff0c78469d1283f717b

Contents?: true

Size: 1.36 KB

Versions: 8

Compression:

Stored size: 1.36 KB

Contents

class MetaDefinition < ActiveRecord::Base
  has_many :documents, :dependent => :destroy

  validates_presence_of :label_path, :label
  validates_uniqueness_of :label_path

  acts_as_list :scope => :parent
  acts_as_tree
  path_finder :uid => 'label', :column => 'label_path'

  default_scope :order => 'position ASC'

  named_scope :by_label, lambda { |label| { :conditions => ['label = ?', label] } }

  before_save :nullify_empty_columns

  serialize :autherisation, Hash
  serialize :field_map, Hash
  serialize :flash_messages, Hash

  
  def autherisation
    super || {}
  end

  def field_map
    super || {}
  end

  def flash_messages
    super || {}
  end
  

  def allowed?(user, action)
    tokens = (autherisation[action] || Settings.documents.autherisation.send(action)).split(' ')
    tokens.each do | token |
      return true if token == 'all'
      return true if token == 'author' && self.author == user
      return true if user.has_role? token
    end
    false
  end

  # Used to find template named after label_path
  # eg. blog.post.html.erb
  def template_filename(include_extension = true)
    label_path.gsub('/', '.') + (include_extension ? '.html.erb' : '')
  end

  private

  # Prevent empty strings being saved
  def nullify_empty_columns
    %w(sort_by per_page default_state).each { |column| self.send(column+'=', nil) if self.send(column) == '' }
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
qcms-2.1.0 app/models/meta_definition.rb
qcms-2.0.0 app/models/meta_definition.rb
qcms-1.3.10 app/models/meta_definition.rb
qcms-1.3.9 app/models/meta_definition.rb
qcms-1.3.8 app/models/meta_definition.rb
qcms-1.3.7 app/models/meta_definition.rb
qcms-1.3.6 app/models/meta_definition.rb
qcms-1.3.5 app/models/meta_definition.rb