Ejemplo n.º 1
0
    def create(self, request, *args, **kwargs):
        if not waffle.switch_is_active('comm-dashboard'):
            return Response(status=status.HTTP_403_FORBIDDEN)

        thread = get_object_or_404(CommunicationThread, id=kwargs['thread_id'])

        # Validate note.
        form = forms.CreateCommNoteForm(request.DATA)
        if not form.is_valid():
            return Response(form.errors, status=status.HTTP_400_BAD_REQUEST)
        note_type = form.cleaned_data['note_type']

        if (note_type == comm.DEVELOPER_COMMENT
                and not request.user.addonuser_set.filter(
                    addon=thread.addon).exists()):
            # Developer comment only for developers.
            return Response('Only developers can make developer comments',
                            status=status.HTTP_403_FORBIDDEN)
        elif (note_type == comm.REVIEWER_COMMENT
              and not acl.check_reviewer(request)):
            # Reviewer comment only for reviewers.
            return Response('Only reviewers can make reviewer comments',
                            status=status.HTTP_403_FORBIDDEN)

        # Create notes.
        thread, note = create_comm_note(thread.addon,
                                        thread.version,
                                        self.request.user,
                                        form.cleaned_data['body'],
                                        note_type=note_type)

        return Response(NoteSerializer(note, context={
            'request': request
        }).data,
                        status=status.HTTP_201_CREATED)
Ejemplo n.º 2
0
    def create(self, request, *args, **kwargs):
        thread = get_object_or_404(CommunicationThread, id=kwargs['thread_id'])

        # Validate note.
        form = forms.CreateCommNoteForm(request.DATA)
        if not form.is_valid():
            return Response(form.errors, status=status.HTTP_400_BAD_REQUEST)
        note_type = form.cleaned_data['note_type']

        if not self._has_create_perms(request, thread, request.user,
                                      note_type):
            return Response(
                'Only developers can make developer comments. '
                'Only reviewers can make reviewer comments.',
                status=status.HTTP_403_FORBIDDEN)

        # Create notes.
        thread, note = create_comm_note(thread.addon,
                                        thread.version,
                                        self.request.user,
                                        form.cleaned_data['body'],
                                        note_type=note_type)

        return Response(NoteSerializer(note, context={
            'request': request
        }).data,
                        status=status.HTTP_201_CREATED)
Ejemplo n.º 3
0
    def create(self, request, *args, **kwargs):
        thread = get_object_or_404(CommunicationThread, id=kwargs['thread_id'])

        # Validate note.
        form = forms.CreateCommNoteForm(request.DATA)
        if not form.is_valid():
            return Response(form.errors, status=status.HTTP_400_BAD_REQUEST)

        # Create notes.
        thread, note = create_comm_note(
            thread.addon, thread.version, self.request.amo_user,
            form.cleaned_data['body'],
            note_type=form.cleaned_data['note_type'])
        self.attach_as_reply(note)

        return Response(
            NoteSerializer(note, context={'request': request}).data,
            status=status.HTTP_201_CREATED)