def members(self, request, *args, **kwargs):
        organization = self.get_object()
        data = merge_dicts(request.data, request.query_params.dict(),
                           {'organization': organization.pk})

        if request.method == 'POST' and 'username' not in data:
            data['username'] = None

        if request.method == 'DELETE':
            data['remove'] = True

        if request.method == 'PUT' and 'role' not in data:
            data['role'] = None

        serializer = OrganizationMemberSerializer(data=data)

        if serializer.is_valid():
            serializer.save()

        else:
            return Response(data=serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)

        self.etag_data = json.dumps(data)
        resp_status = status.HTTP_201_CREATED if request.method == 'POST' \
            else status.HTTP_200_OK

        return Response(status=resp_status, data=serializer.data())
示例#2
0
    def share(self, request, *args, **kwargs):
        self.object = self.get_object()
        data = merge_dicts(request.data.dict(), {'project': self.object.pk})

        remove = data.get("remove")
        if remove and remove is not isinstance(remove, bool):
            remove = strtobool(remove)

        if remove:
            serializer = RemoveUserFromProjectSerializer(data=data)
        else:
            serializer = ShareProjectSerializer(data=data)
        if serializer.is_valid():
            serializer.save()
            email_msg = data.get('email_msg')
            if email_msg:
                # send out email message.
                user = serializer.instance.user
                send_mail(SHARE_PROJECT_SUBJECT.format(self.object.name),
                          email_msg,
                          DEFAULT_FROM_EMAIL,
                          (user.email, ))
        else:
            return Response(data=serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)
        return Response(status=status.HTTP_204_NO_CONTENT)
示例#3
0
    def members(self, request, *args, **kwargs):
        organization = self.get_object()
        data = merge_dicts(request.data, request.query_params.dict(),
                           {'organization': organization.pk})

        if request.method == 'POST' and 'username' not in data:
            data['username'] = None

        if request.method == 'DELETE':
            data['remove'] = True

        if request.method == 'PUT' and 'role' not in data:
            data['role'] = None

        serializer = OrganizationMemberSerializer(data=data)

        username = kwargs.get('user')
        if serializer.is_valid():
            serializer.save()
            organization = serializer.validated_data.get('organization')
            data = OrganizationSerializer(organization,
                                          context={
                                              'request': request
                                          }).data
            cache.set(f'{ORG_PROFILE_CACHE}{username}', data)

        else:
            return Response(data=serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)

        self.etag_data = json.dumps(data)
        resp_status = status.HTTP_201_CREATED if request.method == 'POST' \
            else status.HTTP_200_OK

        return Response(status=resp_status, data=serializer.data())
示例#4
0
    def share(self, request, *args, **kwargs):
        self.object = self.get_object()
        data = merge_dicts(request.data.dict(), {'project': self.object.pk})

        remove = data.get("remove")
        if remove and remove is not isinstance(remove, bool):
            remove = strtobool(remove)

        if remove:
            serializer = RemoveUserFromProjectSerializer(data=data)
        else:
            serializer = ShareProjectSerializer(data=data)
        if serializer.is_valid():
            serializer.save()
            email_msg = data.get('email_msg')
            if email_msg:
                # send out email message.
                user = serializer.instance.user
                send_mail(SHARE_PROJECT_SUBJECT.format(self.object.name),
                          email_msg,
                          DEFAULT_FROM_EMAIL,
                          (user.email, ))
        else:
            return Response(data=serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)
        return Response(status=status.HTTP_204_NO_CONTENT)
    def members(self, request, *args, **kwargs):
        organization = self.get_object()
        data = merge_dicts(request.data,
                           request.query_params.dict(),
                           {'organization': organization.pk})

        if request.method == 'POST' and 'username' not in data:
            data['username'] = None

        if request.method == 'DELETE':
            data['remove'] = True

        if request.method == 'PUT' and 'role' not in data:
            data['role'] = None

        serializer = OrganizationMemberSerializer(data=data)

        if serializer.is_valid():
            serializer.save()

        else:
            return Response(data=serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)

        self.etag_data = json.dumps(data)
        resp_status = status.HTTP_201_CREATED if request.method == 'POST' \
            else status.HTTP_200_OK

        return Response(status=resp_status, data=serializer.data())
示例#6
0
    def share(self, request, *args, **kwargs):
        self.object = self.get_object()
        data = merge_dicts(request.data.items(), {'team': self.object.pk})

        if data.get("remove"):
            serializer = RemoveTeamFromProjectSerializer(data=data)
        else:
            serializer = ShareTeamProjectSerializer(data=data)

        if serializer.is_valid():
            serializer.save()
        else:
            return Response(data=serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)

        return Response(status=status.HTTP_204_NO_CONTENT)
示例#7
0
    def share(self, request, *args, **kwargs):
        self.object = self.get_object()
        data = merge_dicts(request.data.items(), {'team': self.object.pk})

        remove = data.get("remove")
        if remove and remove is not isinstance(remove, bool):
            remove = strtobool(remove)

        if remove:
            serializer = RemoveTeamFromProjectSerializer(data=data)
        else:
            serializer = ShareTeamProjectSerializer(data=data)

        if serializer.is_valid():
            serializer.save()
        else:
            return Response(data=serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)

        return Response(status=status.HTTP_204_NO_CONTENT)
    def _create_user_profile(self, extra_post_data={}):
        self.profile_data = merge_dicts(self.profile_data, extra_post_data)
        user, created = User.objects.get_or_create(
            username=self.profile_data['username'],
            first_name=self.profile_data['first_name'],
            last_name=self.profile_data['last_name'],
            email=self.profile_data['email'])
        user.set_password(self.profile_data['password1'])
        user.save()
        new_profile, created = UserProfile.objects.get_or_create(
            user=user, name=self.profile_data['first_name'],
            city=self.profile_data['city'],
            country=self.profile_data['country'],
            organization=self.profile_data['organization'],
            home_page=self.profile_data['home_page'],
            twitter=self.profile_data['twitter'],
            require_auth=False
        )

        return new_profile
示例#9
0
    def _create_user_profile(self, extra_post_data={}):
        self.profile_data = merge_dicts(self.profile_data, extra_post_data)
        user, created = User.objects.get_or_create(
            username=self.profile_data['username'],
            first_name=self.profile_data['first_name'],
            last_name=self.profile_data['last_name'],
            email=self.profile_data['email'])
        user.set_password(self.profile_data['password1'])
        user.save()
        new_profile, created = UserProfile.objects.get_or_create(
            user=user, name=self.profile_data['first_name'],
            city=self.profile_data['city'],
            country=self.profile_data['country'],
            organization=self.profile_data['organization'],
            home_page=self.profile_data['home_page'],
            twitter=self.profile_data['twitter'],
            require_auth=False
        )

        return new_profile
示例#10
0
 def _login_user_and_profile(self, extra_post_data={}):
     post_data = {
         'username': '******',
         'email': '*****@*****.**',
         'password1': 'bobbob',
         'password2': 'bobbob',
         'first_name': 'Bob',
         'last_name': 'User',
         'city': 'Bobville',
         'country': 'US',
         'organization': 'Bob Inc.',
         'home_page': 'bob.com',
         'twitter': 'boberama'
     }
     url = '/accounts/register/'
     post_data = merge_dicts(post_data, extra_post_data)
     self.response = self.client.post(url, post_data)
     try:
         self.user = User.objects.get(username=post_data['username'])
     except User.DoesNotExist:
         pass
示例#11
0
 def _login_user_and_profile(self, extra_post_data={}):
     post_data = {
         'username': '******',
         'email': '*****@*****.**',
         'password1': 'bobbob',
         'password2': 'bobbob',
         'first_name': 'Bob',
         'last_name': 'User',
         'city': 'Bobville',
         'country': 'US',
         'organization': 'Bob Inc.',
         'home_page': 'bob.com',
         'twitter': 'boberama'
     }
     url = '/accounts/register/'
     post_data = merge_dicts(post_data, extra_post_data)
     self.response = self.client.post(url, post_data)
     try:
         self.user = User.objects.get(username=post_data['username'])
     except User.DoesNotExist:
         pass