def mutate_and_get_payload(cls, root, info, user, id, **kwargs): _, lookup_id = from_global_id(id) try: invitation = Invitation.objects.get(id=lookup_id) except Invitation.DoesNotExist as e: return cls(error=InterfaceErrorType.from_exception(e)) InvitationSystemFacade.cancel_invitation(invitation, user) return cls(invitation=invitation)
def mutate_and_get_payload(cls, root, info, **input): user_id = from_global_id(input['id'])[1] # make sure only superuser or the user himself is allowed if info.context.user.pk != int( user_id) and not info.context.user.is_superuser: return cls(error=AuthErrors.PERMISSION_DENIED_ERROR) return super().mutate_and_get_payload(root, info, **input)
def mutate_and_get_payload(cls, root, info, user, id, **kwargs): _, lookup_id = from_global_id(id) try: invitation = Invitation.objects.get(id=lookup_id) except Invitation.DoesNotExist as e: return cls(error=InterfaceErrorType.from_exception(e)) checked = InvitationSystemFacade.check_invitation(invitation, user) if not checked['is_valid']: return cls(error=InterfaceErrorType(id='INVITATION_NOT_VALID', data=checked['error'])) InvitationSystemFacade.reject_invitation(invitation, user) return cls()
def resolve_invitation(self, info, **kwargs): if ('id' in kwargs and 'token' in kwargs) or ('id' not in kwargs and 'token' not in kwargs): raise Exception( 'One of each inputs are required: id or token (both at the same time is not valid also)' ) try: if 'id' in kwargs: _, lookup_id = from_global_id(kwargs['id']) invitation = Invitation.objects.get(id=lookup_id) else: invitation = Invitation.objects.get(accept_token=kwargs['token']) info.context.checked_invitation = InvitationSystemFacade.check_invitation( invitation, info.context.user ) except Invitation.DoesNotExist: return None return invitation
def _get_lookup_id(cls, global_id): _, lookup_id = from_global_id(global_id) return lookup_id