Class: DcPolicyRole

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document, Mongoid::Timestamps
Defined in:
app/models/dc_policy_role.rb

Overview

Schema information

Collection name: dc_policy_role : User roles

_id BSON::ObjectId _id created_at Time created_at updated_at Time updated_at name String Role name system_name String System role name if required by application active Mongoid::Boolean Role is active

Documents in this model define all available user roles in the application. Roles are defined by unique name which is valid for current application or as alternative name (system_name) which can be persistent, when application is used as Rails plugin.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.choices4_rolesObject

Return all defined roles as choices for use in select field.



69
70
71
# File 'app/models/dc_policy_role.rb', line 69

def self.choices4_roles
  where(active: true).order_by(name: 1).inject([]) { |r, role| r << [ role.name, role._id] }
end

.get_role(role) ⇒ Object

Search for role when role parameter is String.



76
77
78
79
80
81
82
# File 'app/models/dc_policy_role.rb', line 76

def self.get_role(role)
  doc = DrgCms.cache_read(['dc_policy_role', role])
  return doc if doc

  doc = find_by(name: role) || find_by(system_name: role)
  DrgCms.cache_write(['dc_policy_role', role], doc)
end

Instance Method Details

#cache_clearObject

Clear cache when cache is configured



60
61
62
63
64
# File 'app/models/dc_policy_role.rb', line 60

def cache_clear
  DrgCms.cache_clear(:dc_permission)
  DrgCms.cache_clear(:dc_site)
  DrgCms.cache_clear(:dc_policy_role)
end