Class: Anoubis::Tenant::SystemMenu
- Inherits:
-
Core::ApplicationRecord
- Object
- ActiveRecord::Base
- Core::ApplicationRecord
- Anoubis::Tenant::SystemMenu
- Defined in:
- app/models/anoubis/tenant/system_menu.rb
Overview
Model links menu and systems. Describes if system has access to menu.
Instance Attribute Summary collapse
-
#menu ⇒ Menu
Reference to the Menu model.
-
#system ⇒ System
Reference to the System 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_system_menu ⇒ Object
Is called after create new link between system and menu.
-
#after_destroy_system_menu ⇒ Object
Is called after link between system and menu was deleted from database.
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
#menu ⇒ Menu
Returns reference to the Menu model.
17 |
# File 'app/models/anoubis/tenant/system_menu.rb', line 17 belongs_to :menu, class_name: 'Anoubis::Tenant::Menu' |
#system ⇒ System
Returns reference to the Anoubis::Tenant::System model.
12 |
# File 'app/models/anoubis/tenant/system_menu.rb', line 12 belongs_to :system, class_name: 'Anoubis::Tenant::System' |
Instance Method Details
#after_create_system_menu ⇒ Object
Is called after create new link between system and menu. If created element has parent element and link to this parent element doesn’t present in database then adds this link too.
23 24 25 26 27 |
# File 'app/models/anoubis/tenant/system_menu.rb', line 23 def if self.. != nil Anoubis::Tenant::SystemMenu.find_or_create_by(menu: self.., system: self.system) end end |
#after_destroy_system_menu ⇒ Object
Is called after link between system and menu was deleted from database. It also deletes all child links.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/models/anoubis/tenant/system_menu.rb', line 31 def ids = [] Anoubis::Tenant::Menu.where(menu_id: self.).each do |data| ids.push data.id end Anoubis::Tenant::SystemMenu.where(menu_id: ids, system_id: self.system_id).each do |data| data.destroy end ids = [] Anoubis::Tenant::Group.where(system_id: self.system_id).each do |data| ids.push data.id end Anoubis::Tenant::GroupMenu.where(menu_id: self., group_id: ids).each do |data| data.destroy end end |