Sha256: 1f527f1a1dd0884ff91f4093a8afd61cb92136d03d45ed7b74a0fbca22316465

Contents?: true

Size: 1.14 KB

Versions: 19

Compression:

Stored size: 1.14 KB

Contents

class Cms::Fortress::Role < ActiveRecord::Base
  # set_table_name :cms_fortress_roles
  self.table_name = "cms_fortress_roles"
  # attr_accessible :description, :name
  has_many :users
  has_many :role_details
  belongs_to :site, class_name: "Comfy::Cms::Site", foreign_key: :site_id
  accepts_nested_attributes_for :role_details, allow_destroy: true

  def load_defaults
    # load user custom roles
    if File.exist?(file = File.join(Rails.root, "config", "roles.yml"))
      load_from_file(file)
    else
      errors[:base] << I18n.t('cms.fortress.admin.errors.missing_roles_yaml_file')
      raise Cms::Fortress::Error::MissingRoleConfigurationFile
    end
  end

  private

  def load_from_file(file)
    data = YAML.load_file(file)
    data.each do |k,v|
      v.each do |m|
        description = m.split('.').map(&:humanize).join(' - ')
        role_details.build(
          :name       => description,
          :command    => "#{k}.#{m}",
          :can_create => true,
          :can_update => true,
          :can_delete => true,
          :can_view   => true
        ) unless role_details.map(&:command).include?("#{k}.#{m}")
      end
    end

  end
end


Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
cms-fortress-1.3.15 app/models/cms/fortress/role.rb
cms-fortress-1.3.14 app/models/cms/fortress/role.rb
cms-fortress-1.3.13 app/models/cms/fortress/role.rb
cms-fortress-1.3.12 app/models/cms/fortress/role.rb
cms-fortress-1.3.11 app/models/cms/fortress/role.rb
cms-fortress-1.3.10 app/models/cms/fortress/role.rb
cms-fortress-1.3.9 app/models/cms/fortress/role.rb
cms-fortress-1.3.8 app/models/cms/fortress/role.rb
cms-fortress-1.3.7 app/models/cms/fortress/role.rb
cms-fortress-1.3.6 app/models/cms/fortress/role.rb
cms-fortress-1.3.5 app/models/cms/fortress/role.rb
cms-fortress-1.3.4 app/models/cms/fortress/role.rb
cms-fortress-1.3.3 app/models/cms/fortress/role.rb
cms-fortress-1.3.2 app/models/cms/fortress/role.rb
cms-fortress-1.3.1 app/models/cms/fortress/role.rb
cms-fortress-1.3.0 app/models/cms/fortress/role.rb
cms-fortress-1.3.0.rc3 app/models/cms/fortress/role.rb
cms-fortress-1.3.0.rc2 app/models/cms/fortress/role.rb
cms-fortress-1.3.0.rc1 app/models/cms/fortress/role.rb