Class: ArPermission
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- ArPermission
- Defined in:
- app/models/ar_permission.rb
Overview
Schema information
Table name: ar_permission : Table permissions
id Integer id created_at Time created_at updated_at Time updated_at table_name String Permission is valid for table is_default Boolean This is default permission for all tables in database active Boolean Permission is active ar_policy_rules Embedded: ArPolicyRule Defined policy rules
ar_permissions table define permissions for accessing single table when in edit mode. They define table and user role that can view, edit or delete documents in a table. Document marked as default is the top level document and defines general permissions valid for all tables. It usually states that admiin can delete all documents and guest has no access.
Rules can also be namespaced. If you have an isolated application which is using its own set of tables, you can start table names with same (3 letter) prefix and add a permission rule like ar_*.
Constant Summary collapse
- NO_ACCESS =
User has no access
0- CAN_VIEW =
User can view documents
1- CAN_CREATE =
User can create new documents
2- CAN_EDIT =
User can edit his own documents
4- CAN_EDIT_ALL =
User can edit all documents in table
8- CAN_DELETE =
User can delete his own documents
16- CAN_DELETE_ALL =
User can delete all documents in table
32- CAN_ADMIN =
User can admin table (same as can_delete_all, but can see documents which do not belong to current site)
64- SUPERADMIN =
User is superadmin. Basicly same as admin.
128
Class Method Summary collapse
-
.choices_for_permissions ⇒ Object
Returns values for permissions ready to be used in select field.
-
.choices_for_site_permissions ⇒ Object
Returns values for site_permissions ready to be used in select field.
-
.permission_name_for_value(value) ⇒ Object
Will return translated permission name for value.
- .permissions_for(table_name, result = {}) ⇒ Object
-
.permissions_for_table(table_name) ⇒ Object
Will return permissions for table.
- .site_permission_name_for_value(value) ⇒ Object
-
.site_permissions ⇒ Object
Will return choices for permissions prepared for usega in select input field.
-
.table_permissions ⇒ Object
Will return choices for permissions prepared for usega in select input field.
- .values_for_permissions_for_key(key) ⇒ Object
Instance Method Summary collapse
-
#cache_clear ⇒ Object
Clear cache if cache is configured.
Class Method Details
.choices_for_permissions ⇒ Object
Returns values for permissions ready to be used in select field.
Example (as used in AgileRails form):
20:
name: permission
type: select
eval: ArPermission.values_for_permissions
132 133 134 |
# File 'app/models/ar_permission.rb', line 132 def self. 'helpers.label.ar_policy_rule.choices_for_permission' end |
.choices_for_site_permissions ⇒ Object
Returns values for site_permissions ready to be used in select field.
Example (as used in AgileRails form):
20:
name: permission
type: select
eval: ArPermission.values_for_site_permissions
145 146 147 |
# File 'app/models/ar_permission.rb', line 145 def self. 'helpers.label.ar_policy_rule.choices_for_sites_permission' end |
.permission_name_for_value(value) ⇒ Object
Will return translated permission name for value.
Parameters: [value] Integer. Permission value
Example (as used in AgileRails form):
data_set:
columns:
2:
name: permission
eval: ArPermission.permission_name_for_value
Returns: String. Name (description) for value
172 173 174 |
# File 'app/models/ar_permission.rb', line 172 def self.(value) .reduce('error') { |r, v| break v.first if v.last.to_i == value.to_i } end |
.permissions_for(table_name, result = {}) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 |
# File 'app/models/ar_permission.rb', line 111 def self.(table_name, result = {}) #:nodoc: = if table_name == '*' find_by(is_default: true) else find_by(table_name: table_name, active: true) end if ..each { |rule| result[rule.ar_role_id] = rule. } end result end |
.permissions_for_table(table_name) ⇒ Object
Will return permissions for table
102 103 104 105 106 |
# File 'app/models/ar_permission.rb', line 102 def self.(table_name) result = ('*') result = ("#{table_name[0,3]}*", result) (table_name, result) end |
.site_permission_name_for_value(value) ⇒ Object
176 177 178 |
# File 'app/models/ar_permission.rb', line 176 def self.(value) .reduce('error') { |r, v| break v.first if v.last.to_i == value.to_i } end |
.site_permissions ⇒ Object
Will return choices for permissions prepared for usega in select input field. This will return english only comments so it is not used.
95 96 97 |
# File 'app/models/ar_permission.rb', line 95 def self. #:nodoc: [['NO_ACCESS', 0], ['CAN_VIEW', 1], ['CAN_EDIT', 2]] end |
.table_permissions ⇒ Object
Will return choices for permissions prepared for usega in select input field. This will return english only comments so it is not used.
86 87 88 89 |
# File 'app/models/ar_permission.rb', line 86 def self. #:nodoc: [['NO_ACCESS', 0], ['CAN_VIEW', 1], ['CAN_CREATE', 2], ['CAN_EDIT', 4], ['CAN_EDIT_ALL', 8], ['CAN_DELETE', 16], ['CAN_DELETE_ALL', 32], ['CAN_ADMIN', 64], ['SUPERADMIN', 128]] end |
.values_for_permissions_for_key(key) ⇒ Object
150 151 152 153 154 |
# File 'app/models/ar_permission.rb', line 150 def self.(key) c = I18n.t(key) c = I18n.t(key, locale: 'en') if c.class == Hash || c.match(/translation missing/i) c.split(',').map { |e| (ar = e.split(':'); [ar.first, ar.last.to_i]) } end |
Instance Method Details
#cache_clear ⇒ Object
Clear cache if cache is configured
78 79 80 |
# File 'app/models/ar_permission.rb', line 78 def cache_clear Agile.cache_clear(:ar_permission) end |