Class: Anoubis::Tenant::GroupMenu
- Inherits:
-
Core::ApplicationRecord
- Object
- ActiveRecord::Base
- Core::ApplicationRecord
- Anoubis::Tenant::GroupMenu
- Defined in:
- app/models/anoubis/tenant/group_menu.rb
Overview
Instance Attribute Summary collapse
-
#access ⇒ 'not', ...
Group access to menu element.
-
#group ⇒ Group
Reference to the Group model.
-
#menu ⇒ Menu
Reference to the Menu model.
Attributes inherited from Core::ApplicationRecord
#can_delete, #can_edit, #can_new, #created_at, #current_user, #need_refresh, #redis, #sys_title, #updated_at
Instance Method Summary collapse
-
#after_create_group_menu ⇒ Object
Is called after new link between menu and group was created.
-
#after_destroy_group_menu ⇒ Object
Is called after link between menu and group had been deleted from database.
-
#after_modify_group_menu ⇒ Object
Deletes all user’s keys that belong this menu element in Redis database.
-
#before_update_group_menu ⇒ Object
Is called before link between menu and group will be updated.
-
#before_validation_group_menu ⇒ Object
Is called before validation when the link between menu and group is being created or updated.
Methods inherited from Core::ApplicationRecord
#after_initialize_core_anubis_model, #can_destroy?, #current_locale, #current_locale=, #default_locale, #get_locale, #get_locale_field, get_where, #is_field_localized, #new_uuid, redis, #redis_prefix, redis_prefix, #set_locale_field
Instance Attribute Details
#access ⇒ 'not', ...
Returns group access to menu element.
-
‘not’ — menu element doesn’t available for this group
-
‘read’ — group has access to menu element only for read data
-
‘write’ — group has access to menu element for read and write data
-
‘disable’ — group hasn’t access to menu element.
29 |
# File 'app/models/anoubis/tenant/group_menu.rb', line 29 enum access: { not: 0, read: 20, write: 40, disable: 60 } |
#group ⇒ Group
Returns reference to the Anoubis::Tenant::Group model.
15 |
# File 'app/models/anoubis/tenant/group_menu.rb', line 15 belongs_to :group, :class_name => 'Anoubis::Tenant::Group' |
Instance Method Details
#after_create_group_menu ⇒ Object
Is called after new link between menu and group was created. If new element has parent with link that doesn’t present in database then adds this link to database with #access defined as ‘read’.
46 47 48 49 50 51 52 53 |
# File 'app/models/anoubis/tenant/group_menu.rb', line 46 def if self.. != nil Anoubis::Tenant::GroupMenu.find_or_create_by(menu_id: self.., group_id: self.group_id) do || .access = Anoubis::Tenant::GroupMenu.accesses[:read] end end self. end |
#after_destroy_group_menu ⇒ Object
Is called after link between menu and group had been deleted from database. It also deletes all child links.
66 67 68 69 70 71 72 73 |
# File 'app/models/anoubis/tenant/group_menu.rb', line 66 def Anoubis::Tenant::Menu.select(:id).where(menu_id: self.).each do || Anoubis::Tenant::GroupMenu.where(menu_id: .id, group_id: self.group_id).each do || .destroy end end self. end |
#after_modify_group_menu ⇒ Object
Deletes all user’s keys that belong this menu element in Redis database.
77 78 79 80 81 82 83 |
# File 'app/models/anoubis/tenant/group_menu.rb', line 77 def if self.redis self.redis.keys(self.redis_prefix + '*_'+self..mode).each do |data| self.redis.del data end end end |
#before_update_group_menu ⇒ Object
58 59 60 61 62 |
# File 'app/models/anoubis/tenant/group_menu.rb', line 58 def self. = self. if self. self.group_id = self.group_id_was if self.group_id_changed? self. end |
#before_validation_group_menu ⇒ Object
35 36 37 38 39 40 41 |
# File 'app/models/anoubis/tenant/group_menu.rb', line 35 def if !Anoubis::Tenant::SystemMenu.where(system_id: self.group.system_id, menu_id: self.).first errors.add(:base, I18n.t('anubis.group_menus.errors.no_access')) throw(:abort, __method__) end self.access = Anoubis::Tenant::GroupMenu.accesses[:read] if !self.access end |