Exemplo n.º 1
0
    def list(self, request):
        self.serializer_class = ThreadSerializer
        profile = request.amo_user
        # We list all the threads the user has posted a note to.
        notes = profile.comm_notes.values_list('thread', flat=True)
        # We list all the threads where the user has been CC'd.
        cc = profile.comm_thread_cc.values_list('thread', flat=True)

        # This gives 404 when an app with given slug/id is not found.
        if 'app' in request.GET:
            form = PrepareForm(request.GET)
            if not form.is_valid():
                raise Http404()

            notes, cc = list(notes), list(cc)
            queryset = CommunicationThread.objects.filter(
                pk__in=notes + cc, addon=form.cleaned_data['app'])
        else:
            # We list all the threads which uses an add-on authored by the
            # user and with read permissions for add-on devs.
            notes, cc = list(notes), list(cc)
            addons = list(profile.addons.values_list('pk', flat=True))
            q_dev = Q(addon__in=addons, read_permission_developer=True)
            queryset = CommunicationThread.objects.filter(
                Q(pk__in=notes + cc) | q_dev)

        self.queryset = queryset
        return SilentListModelMixin.list(self, request)
Exemplo n.º 2
0
    def list(self, request):
        self.serializer_class = ThreadSerializer
        profile = request.amo_user
        # We list all the threads the user has posted a note to.
        notes = profile.comm_notes.values_list('thread', flat=True)
        # We list all the threads where the user has been CC'd.
        cc = profile.comm_thread_cc.values_list('thread', flat=True)

        # This gives 404 when an app with given slug/id is not found.
        if 'app' in request.GET:
            form = PrepareForm(request.GET)
            if not form.is_valid():
                raise Http404()

            notes, cc = list(notes), list(cc)
            queryset = CommunicationThread.objects.filter(pk__in=notes + cc,
                addon=form.cleaned_data['app'])
        else:
            # We list all the threads which uses an add-on authored by the
            # user and with read permissions for add-on devs.
            notes, cc = list(notes), list(cc)
            addons = list(profile.addons.values_list('pk', flat=True))
            q_dev = Q(addon__in=addons, read_permission_developer=True)
            queryset = CommunicationThread.objects.filter(
                Q(pk__in=notes + cc) | q_dev)

        self.queryset = queryset
        return SilentListModelMixin.list(self, request)
Exemplo n.º 3
0
    def list(self, request, app_slug):
        """Return list of threads for the extension."""
        form = forms.ExtensionSlugForm({'extension': app_slug})
        if not form.is_valid():
            # 404 if add-on with given slug/id not found.
            return Response('Add-on does not exist or no slug given',
                            status=status.HTTP_404_NOT_FOUND)
        elif not user_has_perm_app(request.user,
                                   form.cleaned_data['extension']):
            # 403 if user does not have auth to access add-on's comm.
            return Response('You do not have permissions for this add-on',
                            status=status.HTTP_403_FORBIDDEN)

        self.queryset = CommunicationThread.objects.filter(
            _extension=form.cleaned_data['extension'])

        return SilentListModelMixin.list(self, request)
Exemplo n.º 4
0
    def list(self, request, app_slug):
        """Return list of threads for the extension."""
        form = forms.ExtensionSlugForm({'extension': app_slug})
        if not form.is_valid():
            # 404 if add-on with given slug/id not found.
            return Response('Add-on does not exist or no slug given',
                            status=status.HTTP_404_NOT_FOUND)
        elif not user_has_perm_app(request.user,
                                   form.cleaned_data['extension']):
            # 403 if user does not have auth to access add-on's comm.
            return Response('You do not have permissions for this add-on',
                            status=status.HTTP_403_FORBIDDEN)

        self.queryset = CommunicationThread.objects.filter(
            _extension=form.cleaned_data['extension'])

        return SilentListModelMixin.list(self, request)
Exemplo n.º 5
0
    def list(self, request, app_slug):
        """Return list of threads for the app."""
        form = forms.AppSlugForm({'app': app_slug})
        if not form.is_valid():
            # 404 if app with given slug/id not found.
            return Response('App does not exist or no app slug given',
                            status=status.HTTP_404_NOT_FOUND)
        elif not user_has_perm_app(request.user, form.cleaned_data['app']):
            # 403 if user does not have auth to access app's comm.
            return Response('You do not have permissions for this app',
                            status=status.HTTP_403_FORBIDDEN)

        # Use simple serializer, which rets only ID + Version #s, if specified.
        if request.GET.get('serializer') == 'simple':
            self.serializer_class = ThreadSimpleSerializer

        self.queryset = CommunicationThread.objects.filter(
            _addon=form.cleaned_data['app']).order_by('_version__version')

        return SilentListModelMixin.list(self, request)
Exemplo n.º 6
0
    def list(self, request, app_slug):
        """Return list of threads for the app."""
        form = forms.AppSlugForm({'app': app_slug})
        if not form.is_valid():
            # 404 if app with given slug/id not found.
            return Response('App does not exist or no app slug given',
                            status=status.HTTP_404_NOT_FOUND)
        elif not user_has_perm_app(request.user, form.cleaned_data['app']):
            # 403 if user does not have auth to access app's comm.
            return Response('You do not have permissions for this app',
                            status=status.HTTP_403_FORBIDDEN)

        # Use simple serializer, which rets only ID + Version #s, if specified.
        if request.GET.get('serializer') == 'simple':
            self.serializer_class = ThreadSimpleSerializer

        self.queryset = CommunicationThread.objects.filter(
            _addon=form.cleaned_data['app']).order_by('_version__version')

        return SilentListModelMixin.list(self, request)
Exemplo n.º 7
0
    def list(self, request):
        self.serializer_class = ThreadSerializer
        profile = request.user
        # We list all the threads where the user has been CC'd.
        cc = list(profile.comm_thread_cc.values_list('thread', flat=True))

        # This gives 404 when an app with given slug/id is not found.
        data = {}
        if 'app' in request.GET:
            form = forms.AppSlugForm(request.GET)
            if not form.is_valid():
                return Response('App does not exist or no app slug given',
                                status=status.HTTP_404_NOT_FOUND)
            elif not user_has_perm_app(profile, form.cleaned_data['app']):
                return Response('You do not have permissions for this app',
                                status=status.HTTP_403_FORBIDDEN)

            queryset = CommunicationThread.objects.filter(
                _addon=form.cleaned_data['app'])

            # Thread IDs and version numbers from same app.
            data['app_threads'] = list(queryset.order_by('_version__version')
                .values('id', '_version__version'))
            for app_thread in data['app_threads']:
                app_thread['version__version'] = app_thread.pop(
                    '_version__version')
        else:
            # We list all the threads that user is developer of or
            # is subscribed/CC'ed to.
            addons = list(profile.addons.values_list('pk', flat=True))
            q_dev = Q(_addon__in=addons, read_permission_developer=True)
            queryset = CommunicationThread.objects.filter(
                Q(pk__in=cc) | q_dev)

        self.queryset = queryset
        res = SilentListModelMixin.list(self, request)
        if res.data:
            res.data.update(data)

        return res
Exemplo n.º 8
0
    def list(self, request):
        """Deprecated by CommAppViewSet and ThreadViewSetV2."""
        self.serializer_class = ThreadSerializer
        profile = request.user
        # We list all the threads where the user has been CC'd.
        cc = list(profile.comm_thread_cc.values_list('thread', flat=True))

        # This gives 404 when an app with given slug/id is not found.
        data = {}
        if 'app' in request.GET:
            form = forms.AppSlugForm(request.GET)
            if not form.is_valid():
                return Response('App does not exist or no app slug given',
                                status=status.HTTP_404_NOT_FOUND)
            elif not user_has_perm_app(profile, form.cleaned_data['app']):
                return Response('You do not have permissions for this app',
                                status=status.HTTP_403_FORBIDDEN)

            queryset = CommunicationThread.objects.filter(
                _addon=form.cleaned_data['app'])

            # Thread IDs and version numbers from same app.
            data['app_threads'] = list(
                queryset.order_by('_version__version').values(
                    'id', '_version__version'))
            for app_thread in data['app_threads']:
                app_thread['version__version'] = app_thread.pop(
                    '_version__version')
        else:
            # We list all the threads that user is developer of or
            # is subscribed/CC'ed to.
            queryset = CommunicationThread.objects.filter(_addon__isnull=False,
                                                          pk__in=cc)

        self.queryset = queryset
        res = SilentListModelMixin.list(self, request)
        if res.data:
            res.data.update(data)

        return res
Exemplo n.º 9
0
    def list(self, request):
        self.serializer_class = ThreadSerializer
        profile = request.amo_user
        # We list all the threads the user has posted a note to.
        notes = profile.comm_notes.values_list('thread', flat=True)
        # We list all the threads where the user has been CC'd.
        cc = profile.comm_thread_cc.values_list('thread', flat=True)

        # This gives 404 when an app with given slug/id is not found.
        data = {}
        if 'app' in request.GET:
            form = forms.AppSlugForm(request.GET)
            if not form.is_valid():
                raise Http404()

            notes, cc = list(notes), list(cc)
            # TODO: use CommunicationThread.with_perms once other PR merged in.
            queryset = CommunicationThread.objects.filter(
                pk__in=notes + cc, addon=form.cleaned_data['app'])

            # Thread IDs and version numbers from same app.
            data['app_threads'] = list(
                queryset.order_by('version__version').values(
                    'id', 'version__version'))
        else:
            # We list all the threads which uses an add-on authored by the
            # user and with read permissions for add-on devs.
            notes, cc = list(notes), list(cc)
            addons = list(profile.addons.values_list('pk', flat=True))
            q_dev = Q(addon__in=addons, read_permission_developer=True)
            queryset = CommunicationThread.objects.filter(
                Q(pk__in=notes + cc) | q_dev)

        self.queryset = queryset
        res = SilentListModelMixin.list(self, request)
        if res.data:
            res.data.update(data)

        return res
Exemplo n.º 10
0
    def list(self, request):
        self.serializer_class = ThreadSerializer
        profile = request.amo_user
        # We list all the threads the user has posted a note to.
        notes = list(profile.comm_notes.values_list('thread', flat=True))
        # We list all the threads where the user has been CC'd.
        cc = list(profile.comm_thread_cc.values_list('thread', flat=True))

        # This gives 404 when an app with given slug/id is not found.
        data = {}
        if 'app' in request.GET:
            form = forms.AppSlugForm(request.GET)
            if not form.is_valid():
                return Response('App does not exist or no app slug given',
                                status=status.HTTP_404_NOT_FOUND)
            elif not user_has_perm_app(profile, form.cleaned_data['app']):
                return Response('You do not have permissions for this app',
                                status=status.HTTP_403_FORBIDDEN)

            queryset = CommunicationThread.objects.filter(
                addon=form.cleaned_data['app'])

            # Thread IDs and version numbers from same app.
            data['app_threads'] = list(queryset.order_by('version__version')
                .values('id', 'version__version'))
        else:
            # We list all the threads which uses an add-on authored by the
            # user and with read permissions for add-on devs.
            addons = list(profile.addons.values_list('pk', flat=True))
            q_dev = Q(addon__in=addons, read_permission_developer=True)
            queryset = CommunicationThread.objects.filter(
                Q(pk__in=notes + cc) | q_dev)

        self.queryset = queryset
        res = SilentListModelMixin.list(self, request)
        if res.data:
            res.data.update(data)

        return res
Exemplo n.º 11
0
    def list(self, request):
        self.serializer_class = ThreadSerializer
        profile = request.amo_user
        # We list all the threads the user has posted a note to.
        notes = profile.comm_notes.values_list('thread', flat=True)
        # We list all the threads where the user has been CC'd.
        cc = profile.comm_thread_cc.values_list('thread', flat=True)

        # This gives 404 when an app with given slug/id is not found.
        data = {}
        if 'app' in request.GET:
            form = forms.AppSlugForm(request.GET)
            if not form.is_valid():
                raise Http404()

            notes, cc = list(notes), list(cc)
            # TODO: use CommunicationThread.with_perms once other PR merged in.
            queryset = CommunicationThread.objects.filter(pk__in=notes + cc,
                addon=form.cleaned_data['app'])

            # Thread IDs and version numbers from same app.
            data['app_threads'] = list(queryset.order_by('version__version')
                .values('id', 'version__version'))
        else:
            # We list all the threads which uses an add-on authored by the
            # user and with read permissions for add-on devs.
            notes, cc = list(notes), list(cc)
            addons = list(profile.addons.values_list('pk', flat=True))
            q_dev = Q(addon__in=addons, read_permission_developer=True)
            queryset = CommunicationThread.objects.filter(
                Q(pk__in=notes + cc) | q_dev)

        self.queryset = queryset
        res = SilentListModelMixin.list(self, request)
        if res.data:
            res.data.update(data)

        return res
Exemplo n.º 12
0
    def list(self, request):
        """List all the threads where the user has been CC'd."""
        cc = list(request.user.comm_thread_cc.values_list('thread', flat=True))
        self.queryset = CommunicationThread.objects.filter(pk__in=cc)

        return SilentListModelMixin.list(self, request)
Exemplo n.º 13
0
    def list(self, request):
        """List all the threads where the user has been CC'd."""
        cc = list(request.user.comm_thread_cc.values_list('thread', flat=True))
        self.queryset = CommunicationThread.objects.filter(pk__in=cc)

        return SilentListModelMixin.list(self, request)