Class: Workgroup

Inherits:
Group show all
Includes:
CustomFields
Defined in:
app/models/workgroup.rb

Instance Attribute Summary

Attributes included from CustomFields

#custom_fields

Attributes inherited from Group

#user_tokens

Instance Method Summary collapse

Methods inherited from Group

#deleted?, #mark_as_deleted, #member?, #non_members

Methods included from MarkAsDeletedWithName

#mark_as_deleted

Instance Method Details

#check_last_admin_groupObject (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_earthObject (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