Class: Anoubis::Tenant::Group
- Inherits:
-
Core::ApplicationRecord
- Object
- Core::ApplicationRecord
- Anoubis::Tenant::Group
- Defined in:
- app/models/anoubis/tenant/group.rb
Overview
Group model. Stores information about usser's groups
Constant Summary collapse
- VALID_IDENT_REGEX =
Group's identifier consists of lowercase alphabetic symbols.
/[a-z]\z/i
Instance Attribute Summary collapse
-
#full_ident ⇒ String
The calculated group's identification.
-
#ident ⇒ String
The group's identifier.
-
#system ⇒ System
Reference to system that owns this group.
-
#title ⇒ String
The group's title.
Instance Method Summary collapse
-
#before_destroy_group ⇒ Object
Is called before group will be deleted from database.
-
#before_save_group ⇒ Object
Is called before group will be stored in database.
-
#before_validation_group_create ⇒ Object
Is called before validation when new group is being created.
-
#before_validation_group_update ⇒ Object
Is called before validation when group is being updated.
-
#model_locale ⇒ GroupLocale
Returns model localization data from GroupLocale.
Instance Attribute Details
#full_ident ⇒ String
Returns the calculated group's identification. This identification based on System#ident and #ident.
|
|
# File 'app/models/anoubis/tenant/group.rb', line 19
|
#ident ⇒ String
Returns the group's identifier. Identifier consists of lowercase alphabetical symbols.
17 |
# File 'app/models/anoubis/tenant/group.rb', line 17 validates :ident, length: { minimum: 3, maximum: 50 }, uniqueness: { scope: [:system_id], case_sensitive: false }, format: { with: VALID_IDENT_REGEX } |
#system ⇒ System
Returns reference to system that owns this group.
24 |
# File 'app/models/anoubis/tenant/group.rb', line 24 belongs_to :system, class_name: 'Anoubis::Tenant::System' |
#title ⇒ String
Returns the group's title. Title loads from Anoubis::Tenant::GroupLocale#title based on #current_locale.
92 93 94 |
# File 'app/models/anoubis/tenant/group.rb', line 92 def title self.model_locale.title if self.model_locale end |
Instance Method Details
#before_destroy_group ⇒ Object
Is called before group will be deleted from database. Checks the ability to destroy a group. Prevents deleting group with id 1. Also destroys all associated links to User and Menu
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/models/anoubis/tenant/group.rb', line 62 def before_destroy_group # Can't destroy admin group of main system if self.ident == 'admin' && self.system_id == 1 errors.add(:base, I18n.t('anubis.groups.errors.cant_destroy_admin_group')) throw(:abort, __method__) end Anoubis::Tenant::GroupLocale.where(group_id: self.id).each do |group_locale| group_locale.destroy end unless user_groups.empty? errors.add(:base, I18n.t('anubis.groups.errors.cant_destroy_group_with_users')) throw(:abort, __method__) end # Before destroy group delete all associated links to users and menus Anoubis::Tenant::GroupMenu.where(group_id: self.id).delete_all #Anoubis::Tenant::UserGroup.where(group_id: self.id).delete_all end |
#before_save_group ⇒ Object
Is called before group will be stored in database. Changes #ident value to lower case.
55 56 57 |
# File 'app/models/anoubis/tenant/group.rb', line 55 def before_save_group self.full_ident = self.system.ident+'.'+self.ident end |
#before_validation_group_create ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'app/models/anoubis/tenant/group.rb', line 33 def before_validation_group_create if self.id if self.id == 1 self.ident = 'admin' self.system_id = 1 return true end end end |
#before_validation_group_update ⇒ Object
46 47 48 49 50 51 |
# File 'app/models/anoubis/tenant/group.rb', line 46 def before_validation_group_update if self.ident != self.ident_was && self.ident_was == 'admin' errors.add(:ident, I18n.t('tims.groups.errors.cant_change_admin_ident')) throw(:abort, __method__) end end |
#model_locale ⇒ GroupLocale
Returns model localization data from Anoubis::Tenant::GroupLocale.
86 87 88 |
# File 'app/models/anoubis/tenant/group.rb', line 86 def model_locale @model_locale ||= self.group_locales.where(locale: Anoubis::Tenant::GroupLocale.locales[self.current_locale.to_sym]).first end |