Sha256: efd5b4ed0187129128767f8a429507ff0a4c1cd5d82db2b1b0f7ed50cc5bbc12

Contents?: true

Size: 1.31 KB

Versions: 3

Compression:

Stored size: 1.31 KB

Contents

module Adminpanel
  class Permission < ActiveRecord::Base
    include Adminpanel::Base
    include ApplicationHelper

    enum action: [
                  :to_read,
                  :to_publish,
                  :to_create,
                  :to_update,
                  :to_destroy,
                  :to_manage
                ]

    belongs_to :role, touch: true

    # validates_presence_of :action
    validates_presence_of :role_id
    validates_presence_of :resource

    def name
      "#{I18n.t("#{self.class.name.demodulize.downcase}.#{self.action}")} #{symbol_class(self['resource']).display_name}"
    end

    def self.form_attributes
      [
        {
          'role_id' => {
            'type' => 'belongs_to',
            'label' => I18n.t('permission.role'),
            'model' => 'Adminpanel::Role',
            # 'remote_resource' => false
          }
        },
        {
          'action' => {
            'type' => 'enum_field',
            'label' => I18n.t('permission.action'),
          }
        },
        {
          'resource' => {
            'type' => 'resource_select',
            'label' => I18n.t('permission.resource'),
          }
        },
      ]
    end

    def self.display_name
      I18n.t('model.Permission') # singular
    end

    def self.icon
      'gavel' # fa-{icon}
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
adminpanel-2.4.0 app/models/adminpanel/permission.rb
adminpanel-2.3.1 app/models/adminpanel/permission.rb
adminpanel-2.3.0 app/models/adminpanel/permission.rb