def post(self, request, *args, **kwargs): org = request.user.active_organization org.reset_token() logger.debug(f'New token for organization {org.pk} is {org.token}') invite_url = '{}?token={}'.format(reverse('user-signup'), org.token) serializer = OrganizationInviteSerializer(data={'invite_url': invite_url, 'token': org.token}) serializer.is_valid() return Response(serializer.data, status=201)
def get(self, request, *args, **kwargs): org = get_object_with_check_and_log(self.request, Organization, pk=request.user.active_organization_id) self.check_object_permissions(self.request, org) invite_url = '{}?token={}'.format(reverse('user-signup'), org.token) if hasattr(settings, 'FORCE_SCRIPT_NAME') and settings.FORCE_SCRIPT_NAME: invite_url = invite_url.replace(settings.FORCE_SCRIPT_NAME, '', 1) serializer = OrganizationInviteSerializer(data={'invite_url': invite_url, 'token': org.token}) serializer.is_valid() return Response(serializer.data, status=200)
def post(self, request, *args, **kwargs): org = get_object_with_check_and_log( self.request, Organization, pk=request.user.active_organization_id) self.check_object_permissions(self.request, org) org.reset_token() logger.debug(f'New token for organization {org.pk} is {org.token}') invite_url = '{}?token={}'.format(reverse('user-signup'), org.token) serializer = OrganizationInviteSerializer(data={ 'invite_url': invite_url, 'token': org.token }) serializer.is_valid() return Response(serializer.data, status=201)
class OrganizationResetTokenAPI(APIView): permission_required = all_permissions.organizations_invite parser_classes = (JSONParser, ) @swagger_auto_schema(tags=["Invites"], operation_summary='Reset organization token', responses={200: OrganizationInviteSerializer()}) def post(self, request, *args, **kwargs): org = request.user.active_organization org.reset_token() logger.debug(f'New token for organization {org.pk} is {org.token}') invite_url = '{}?token={}'.format(reverse('user-signup'), org.token) serializer = OrganizationInviteSerializer(data={ 'invite_url': invite_url, 'token': org.token }) serializer.is_valid() return Response(serializer.data, status=201)
class OrganizationInviteAPI(APIView): parser_classes = (JSONParser, ) permission_required = all_permissions.organizations_change @swagger_auto_schema(tags=["Invites"], operation_summary='Get organization invite link', responses={200: OrganizationInviteSerializer()}) def get(self, request, *args, **kwargs): org = get_object_with_check_and_log( self.request, Organization, pk=request.user.active_organization_id) self.check_object_permissions(self.request, org) invite_url = '{}?token={}'.format(reverse('user-signup'), org.token) serializer = OrganizationInviteSerializer(data={ 'invite_url': invite_url, 'token': org.token }) serializer.is_valid() return Response(serializer.data, status=200)
class OrganizationResetTokenAPI(APIView): parser_classes = (JSONParser, ) permission_classes = (IsAuthenticated, ) @swagger_auto_schema(tags=["Invites"], operation_summary='Reset organization token', responses={200: OrganizationInviteSerializer()}) def post(self, request, *args, **kwargs): org = get_object_with_check_and_log( self.request, Organization, pk=request.user.active_organization_id) self.check_object_permissions(self.request, org) org.reset_token() logger.debug(f'New token for organization {org.pk} is {org.token}') invite_url = '{}?token={}'.format(reverse('user-signup'), org.token) serializer = OrganizationInviteSerializer(data={ 'invite_url': invite_url, 'token': org.token }) serializer.is_valid() return Response(serializer.data, status=201)
return super(OrganizationAPI, self).patch(request, *args, **kwargs) @swagger_auto_schema(auto_schema=None) def post(self, request, *args, **kwargs): return super(OrganizationAPI, self).post(request, *args, **kwargs) @swagger_auto_schema(auto_schema=None) def put(self, request, *args, **kwargs): return super(OrganizationAPI, self).put(request, *args, **kwargs) @method_decorator(name='get', decorator=swagger_auto_schema( tags=["Invites"], operation_summary='Get organization invite link', operation_description='Get a link to use to invite a new member to an organization in Label Studio Enterprise.', responses={200: OrganizationInviteSerializer()} )) class OrganizationInviteAPI(APIView): parser_classes = (JSONParser,) permission_required = all_permissions.organizations_change def get(self, request, *args, **kwargs): org = get_object_with_check_and_log(self.request, Organization, pk=request.user.active_organization_id) self.check_object_permissions(self.request, org) invite_url = '{}?token={}'.format(reverse('user-signup'), org.token) if hasattr(settings, 'FORCE_SCRIPT_NAME') and settings.FORCE_SCRIPT_NAME: invite_url = invite_url.replace(settings.FORCE_SCRIPT_NAME, '', 1) serializer = OrganizationInviteSerializer(data={'invite_url': invite_url, 'token': org.token}) serializer.is_valid() return Response(serializer.data, status=200)