Skip to content

Commit

Permalink
adds EmployPersonMutation
Browse files Browse the repository at this point in the history
  • Loading branch information
timegrid committed Apr 28, 2024
1 parent dedaac7 commit 13e8ed0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions georga/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2199,6 +2199,9 @@ def permitted(cls, person, user, action):
# persons can be read by themself
Q(pk=user.pk),
])
case 'employ':
# subscribers can be employed by organization admin
return Q(organizations_subscribed__id__in=user.admin_organization_ids)
case 'update' | 'delete':
# persons can be updated/deleted by themself
return Q(pk=user.pk)
Expand Down
26 changes: 26 additions & 0 deletions georga/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -1584,6 +1584,11 @@ class PersonTokenModelForm(PersonModelForm):
])


class PersonEmployModelForm(PersonModelForm):
organization = ModelChoiceField(queryset=Organization.objects)
employed = BooleanField(required=False)


# mutations
class CreatePersonMutation(UUIDDjangoModelFormMutation):
class Meta:
Expand Down Expand Up @@ -1765,6 +1770,26 @@ class Meta:
permissions = [login_required, object_permits_user("update")]


class EmployPersonMutation(UUIDDjangoModelFormMutation):
class Meta:
form_class = PersonEmployModelForm
only_fields = ['id', 'organization', 'employed']
permissions = [staff_member_required, object_permits_user('employ')]

@classmethod
def perform_mutate(cls, form, info):
person = form.instance
organization = Organization.objects.get(uuid=form.data.get('organization'))
employed = form.data.get('employed')
if organization.id not in info.context.user.admin_organization_ids:
raise PermissionDenied()
if employed:
person.organizations_employed.add(organization.id)
else:
person.organizations_employed.remove(organization.id)
return cls(person=person, errors=[])


# PersonProperty --------------------------------------------------------------

# fields
Expand Down Expand Up @@ -2990,6 +3015,7 @@ class MutationType(ObjectType):
reset_person_password = ResetPersonPasswordMutation.Field()
change_person_password = ChangePersonPasswordMutation.Field()
update_person_profile = UpdatePersonProfileMutation.Field()
employ_person = EmployPersonMutation.Field()
# PersonProperty
create_person_property = CreatePersonPropertyMutation.Field()
update_person_property = UpdatePersonPropertyMutation.Field()
Expand Down

0 comments on commit 13e8ed0

Please sign in to comment.