Class: Anoubis::Sso::Client::GroupMenu

Inherits:
ApplicationRecord
  • Object
show all
Defined in:
app/models/anoubis/sso/client/group_menu.rb

Overview

Model links Menu and Group. Describes group access to menu.

Instance Attribute Summary collapse

Instance Method Summary collapse

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.

Returns:

  • ('not', 'read', 'write', 'disable')

    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/sso/client/group_menu.rb', line 29

enum access: { not: 0, read: 20, write: 40, disable: 60 }

#groupGroup

Returns reference to the Anoubis::Sso::Client::Group model.

Returns:



15
# File 'app/models/anoubis/sso/client/group_menu.rb', line 15

belongs_to :group, :class_name => 'Anoubis::Sso::Client::Group'

Returns reference to the Menu model.

Returns:

  • (Menu)

    reference to the Menu model



20
# File 'app/models/anoubis/sso/client/group_menu.rb', line 20

belongs_to :menu, :class_name => 'Anoubis::Sso::Client::Menu'

Instance Method Details

#after_create_sso_client_group_menuObject

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’.



42
43
44
45
46
47
48
49
# File 'app/models/anoubis/sso/client/group_menu.rb', line 42

def after_create_sso_client_group_menu
  if self.menu.menu_id != nil
    Anoubis::Sso::Client::GroupMenu.find_or_create_by(menu_id: self.menu.menu_id, group_id: self.group_id) do |menu|
      menu.access = 'read'
    end
  end
  self.after_modify_sso_client_group_menu
end

#after_destroy_sso_client_group_menuObject

Is called after link between menu and group had been deleted from database. It also deletes all child links.



62
63
64
65
66
67
68
69
# File 'app/models/anoubis/sso/client/group_menu.rb', line 62

def after_destroy_sso_client_group_menu
  Anoubis::Sso::Client::Menu.select(:id).where(menu_id: self.menu_id).each do |menu|
    Anoubis::Sso::Client::GroupMenu.where(menu_id: menu.id, group_id: self.group_id).each do |group_menu|
      group_menu.destroy
    end
  end
  self.after_modify_sso_client_group_menu
end

#after_modify_sso_client_group_menuObject

Deletes all user’s keys that belong this menu element in Redis database.



73
74
75
76
77
78
79
# File 'app/models/anoubis/sso/client/group_menu.rb', line 73

def after_modify_sso_client_group_menu
  if self.redis
    self.redis.keys(self.redis_prefix + '*_' + self.menu.mode).each do |data|
      self.redis.del data
    end
  end
end

#before_update_sso_client_group_menuObject

Is called before link between menu and group will be updated. Procedure prevents changing #menu and #group value.



54
55
56
57
58
# File 'app/models/anoubis/sso/client/group_menu.rb', line 54

def before_update_sso_client_group_menu
  self.menu_id = self.menu_id_was if self.menu_id_changed?
  self.group_id = self.group_id_was if self.group_id_changed?
  self.after_modify_sso_client_group_menu
end

#before_validation_sso_client_group_menuObject

Is called before validation when the link between menu and group is being created or updated. Procedure checks if group belongs a system that has access to this menu element. If #access doesn’t defined then #access sets to ‘read’



35
36
37
# File 'app/models/anoubis/sso/client/group_menu.rb', line 35

def before_validation_sso_client_group_menu
  self.access = 'read' if !self.access
end

#get_localized_menu(field) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'app/models/anoubis/sso/client/group_menu.rb', line 93

def get_localized_menu(field)
  loc_field = (field.to_s + '_locale').to_sym
  begin
    self[loc_field] = JSON.parse(self[loc_field]) if self[loc_field]
  rescue

  end

  begin
    result = self.get_locale_field loc_field.to_s
  rescue
    result = eval('self.menu.' + field.to_s)
  end

  result
end

#page_titleObject



85
86
87
# File 'app/models/anoubis/sso/client/group_menu.rb', line 85

def page_title
  self.get_localized_menu 'page_title'
end

#short_titleObject



89
90
91
# File 'app/models/anoubis/sso/client/group_menu.rb', line 89

def short_title
  self.get_localized_menu 'short_title'
end

#titleObject



81
82
83
# File 'app/models/anoubis/sso/client/group_menu.rb', line 81

def title
  self.get_localized_menu 'title'
end