Beispiel #1
0
    def post(self, request, pk, *args, **kwargs):
        log.info(u'Received IARC pingback for app:%s' % pk)

        if request.content_type != 'application/json':
            log.info(u'IARC pingback not of content-type "application/json"')
            return Response({
                'detail': "Endpoint only accepts 'application/json'."
            }, status=status.HTTP_415_UNSUPPORTED_MEDIA_TYPE)

        app = self.get_object()

        # Verify token.
        data = request.DATA[0]
        if app.iarc_token() != data.get('token'):
            log.info(u'Token mismatch in IARC pingback for app:%s' % app.id)
            return Response({'detail': 'Token mismatch'},
                            status=status.HTTP_400_BAD_REQUEST)

        if data.get('ratings'):
            log.info(u'Setting content ratings from IARC pingback for app:%s' %
                     app.id)
            # We found a rating, so store the id and code for future use.
            if 'submission_id' in data and 'security_code' in data:
                app.set_iarc_info(data['submission_id'], data['security_code'])

            # Update status if incomplete status.
            # Do this before set_content_ratings to not prematurely trigger
            # a refresh.
            log.info('Checking app:%s completeness after IARC pingback.'
                     % app.id)
            if (app.has_incomplete_status() and
                app.is_fully_complete(ignore_ratings=True)):
                log.info('Updating app status from IARC pingback for app:%s' %
                         app.id)
                # Don't call update to prevent recursion in update_status.
                app.update(status=amo.STATUS_PENDING)
            elif app.has_incomplete_status():
                log.info('Reasons for app:%s incompleteness after IARC '
                         'pingback: %s' % (app.id, app.completion_errors()))

            app.set_descriptors(data.get('descriptors', []))
            app.set_interactives(data.get('interactives', []))
            # Set content ratings last since it triggers a refresh on Content
            # Ratings page. We want descriptors and interactives visible by
            # the time it's refreshed.
            app.set_content_ratings(data.get('ratings', {}))

            remove_iarc_exclusions(app)

        return Response('ok')
Beispiel #2
0
    def save(self, app, *args, **kwargs):
        iarc_id = self.cleaned_data['submission_id']
        iarc_code = self.cleaned_data['security_code']

        # Generate XML.
        xml = lib.iarc.utils.render_xml('get_app_info.xml', {
            'submission_id': iarc_id,
            'security_code': iarc_code
        })

        # Process that shizzle.
        client = lib.iarc.client.get_iarc_client('services')
        resp = client.Get_App_Info(XMLString=xml)

        # Handle response.
        data = lib.iarc.utils.IARC_XML_Parser().parse_string(resp)

        if data.get('rows'):
            row = data['rows'][0]

            if 'submission_id' not in row:
                # [{'ActionStatus': 'No records found. Please try another
                #                   'criteria.', 'rowId: 1}].
                msg = _('Invalid submission ID or security code.')
                self._errors['submission_id'] = self.error_class([msg])
                raise forms.ValidationError(msg)

            # We found a rating, so store the id and code for future use.
            app.set_iarc_info(iarc_id, iarc_code)
            app.set_descriptors(row.get('descriptors', []))
            app.set_interactives(row.get('interactives', []))
            app.set_content_ratings(row.get('ratings', {}))

            remove_iarc_exclusions(app)
        else:
            msg = _('Invalid submission ID or security code.')
            self._errors['submission_id'] = self.error_class([msg])
            raise forms.ValidationError(msg)
Beispiel #3
0
    def save(self, app, *args, **kwargs):
        iarc_id = self.cleaned_data['submission_id']
        iarc_code = self.cleaned_data['security_code']

        # Generate XML.
        xml = lib.iarc.utils.render_xml(
            'get_app_info.xml',
            {'submission_id': iarc_id, 'security_code': iarc_code})

        # Process that shizzle.
        client = lib.iarc.client.get_iarc_client('services')
        resp = client.Get_App_Info(XMLString=xml)

        # Handle response.
        data = lib.iarc.utils.IARC_XML_Parser().parse_string(resp)

        if data.get('rows'):
            row = data['rows'][0]

            if 'submission_id' not in row:
                # [{'ActionStatus': 'No records found. Please try another
                #                   'criteria.', 'rowId: 1}].
                msg = _('Invalid submission ID or security code.')
                self._errors['submission_id'] = self.error_class([msg])
                raise forms.ValidationError(msg)

            # We found a rating, so store the id and code for future use.
            app.set_iarc_info(iarc_id, iarc_code)
            app.set_descriptors(row.get('descriptors', []))
            app.set_interactives(row.get('interactives', []))
            app.set_content_ratings(row.get('ratings', {}))

            remove_iarc_exclusions(app)
        else:
            msg = _('Invalid submission ID or security code.')
            self._errors['submission_id'] = self.error_class([msg])
            raise forms.ValidationError(msg)