Class: Workgroup

Inherits:
Group
  • Object
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


16
17
18
19
20
# File 'app/models/workgroup.rb', line 16

def check_last_admin_group
  if role_admin && Workgroup.where(role_admin: true).size == 1
    raise I18n.t('workgroups.error_last_admin_group')
  end
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


24
25
26
27
28
# File 'app/models/workgroup.rb', line 24

def last_admin_on_earth
  if !role_admin && !Workgroup.where(role_admin: true).where.not(id: id).exists?
    errors.add(:role_admin, I18n.t('workgroups.error_last_admin_role'))
  end
end