Class: Workgroup
- Inherits:
-
Group
- Object
- ActiveRecord::Base
- ApplicationRecord
- Group
- Workgroup
- Includes:
- CustomFields
- Defined in:
- app/models/workgroup.rb
Instance Attribute Summary
Attributes included from CustomFields
Attributes inherited from Group
Instance Method Summary collapse
-
#check_last_admin_group ⇒ Object
protected
Check before destroy a group, if this is the last group with admin role.
-
#last_admin_on_earth ⇒ Object
protected
add validation check on update Return an error if this is the last group with admin role and role_admin should set to false.
Methods inherited from Group
#deleted?, #mark_as_deleted, #member?, #non_members
Methods included from MarkAsDeletedWithName
Instance Method Details
#check_last_admin_group ⇒ Object (protected)
Check before destroy a group, if this is the last group with admin role
15 16 17 18 19 |
# File 'app/models/workgroup.rb', line 15 def check_last_admin_group return unless role_admin && Workgroup.where(role_admin: true).size == 1 raise I18n.t('workgroups.error_last_admin_group') end |
#last_admin_on_earth ⇒ Object (protected)
add validation check on update Return an error if this is the last group with admin role and role_admin should set to false
23 24 25 26 27 |
# File 'app/models/workgroup.rb', line 23 def last_admin_on_earth return unless !role_admin && !Workgroup.where(role_admin: true).where.not(id: id).exists? errors.add(:role_admin, I18n.t('workgroups.error_last_admin_role')) end |