Class: Anoubis::Tenant::SystemMenu

Inherits:
Core::ApplicationRecord show all
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

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

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

Returns reference to the Menu model.

Returns:

  • (Menu)

    reference to the Menu model



17
# File 'app/models/anoubis/tenant/system_menu.rb', line 17

belongs_to :menu, class_name: 'Anoubis::Tenant::Menu'

#systemSystem

Returns reference to the Anoubis::Tenant::System model.

Returns:



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_menuObject

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 after_create_system_menu
  if self.menu.menu_id != nil
    Anoubis::Tenant::SystemMenu.find_or_create_by(menu: self.menu.menu, system: self.system)
  end
end

#after_destroy_system_menuObject

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 after_destroy_system_menu
  ids = []

  Anoubis::Tenant::Menu.where(menu_id: self.menu_id).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.menu_id, group_id: ids).each do |data|
    data.destroy
  end
end