Exemplo n.º 1
0
    def create(self, request, **kwargs):
        """
        Override create method to add new organisation to authenticated user
        """
        user = request.user
        serializer = OrganisationSerializerFull(data=request.data)
        if serializer.is_valid():
            org = serializer.save()
            user.add_organisation(org, OrganisationRole.ADMIN)

            return Response(serializer.data, status.HTTP_201_CREATED)
        else:
            return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Exemplo n.º 2
0
 def update_subscription(self, request, pk):
     serializer = self.get_serializer(data=request.data)
     serializer.is_valid(raise_exception=True)
     serializer.save()
     return Response(
         OrganisationSerializerFull(instance=self.get_object()).data,
         status=status.HTTP_200_OK)
Exemplo n.º 3
0
def join_organisation(request, invite_hash):
    invite = get_object_or_404(Invite, hash=invite_hash)

    try:
        request.user.join_organisation(invite)
    except InvalidInviteError as e:
        error_data = {'detail': str(e)}
        return Response(data=error_data, status=status.HTTP_400_BAD_REQUEST)

    if invite.organisation.over_plan_seats_limit():
        Thread(target=FFAdminUser.send_organisation_over_limit_alert,
               args=[invite.organisation]).start()

    return Response(OrganisationSerializerFull(invite.organisation,
                                               context={
                                                   'request': request
                                               }).data,
                    status=status.HTTP_200_OK)
Exemplo n.º 4
0
def join_organisation_from_link(request, hash):
    invite = get_object_or_404(InviteLink, hash=hash)

    if invite.is_expired:
        return Response(data={"detail": "Invite has expired."})

    request.user.add_organisation(
        invite.organisation, role=OrganisationRole(invite.role)
    )

    if invite.organisation.over_plan_seats_limit():
        Thread(
            target=FFAdminUser.send_organisation_over_limit_alert,
            args=[invite.organisation],
        ).start()

    return Response(
        OrganisationSerializerFull(
            invite.organisation, context={"request": request}
        ).data,
        status=status.HTTP_200_OK,
    )