Example #1
0
 def test_tarako_enabled(self):
     tag = Tag(tag_text='tarako')
     tag.save_tag(self.app)
     #WebappIndexer.index_ids([self.app.pk])
     res = self.summary()
     text = 'Tarako enabled'
     assert text in pq(res.content)('.column-b dd').eq(6).text()
Example #2
0
 def test_tarako_enabled(self):
     tag = Tag(tag_text='tarako')
     tag.save_tag(self.app)
     #WebappIndexer.index_ids([self.app.pk])
     res = self.summary()
     text = 'Tarako enabled'
     assert text in pq(res.content)('.column-b dd').eq(6).text()
Example #3
0
 def destroy(self, request, pk, tag_text, **kwargs):
     if tag_text == 'tarako':
         app = self.get_object()
         Tag(tag_text=tag_text).remove_tag(app)
         return response.Response(status=status.HTTP_204_NO_CONTENT)
     else:
         return response.Response(status=status.HTTP_403_FORBIDDEN)
Example #4
0
    def save(self, commit=False):
        form = super(WebsiteForm, self).save(commit=False)

        keywords_new = self.cleaned_data['keywords']
        keywords_old = [
            slugify(keyword, spaces=True)
            for keyword in self.instance.keywords.values_list('tag_text',
                                                              flat=True)
        ]
        for k in set(keywords_new) - set(keywords_old):
            Tag(tag_text=k).save_tag(self.instance)
        for k in set(keywords_old) - set(keywords_new):
            Tag(tag_text=k).remove_tag(self.instance)

        form.save()
        return form
Example #5
0
def homescreen_factory(self):
    # Homescreens may not be added to feed collections.
    homescreen = app_factory(name=u'Elegant Waffle',
                             description=u'homescreen runner',
                             created=self.days_ago(5),
                             manifest_url='http://h.testmanifest.com')
    Tag(tag_text='homescreen').save_tag(homescreen)
    return homescreen
Example #6
0
 def test_q_is_tag_misspelled(self):
     Tag(tag_text='whatsapp').save_tag(self.webapp)
     self.webapp.save()
     self.refresh('webapp')
     res = self.anon.get(self.url, data={'q': 'whatsupp'})
     eq_(res.status_code, 200)
     obj = res.json['objects'][0]
     eq_(obj['slug'], self.webapp.app_slug)
Example #7
0
    def test_not_blocked(self):
        """Make sure Tag Manager filters right for not blocked tags."""
        tag1 = Tag(tag_text='abc', blocked=False)
        tag1.save()
        tag2 = Tag(tag_text='swearword', blocked=True)
        tag2.save()

        eq_(Tag.objects.all().count(), 2)
        eq_(Tag.objects.not_blocked().count(), 1)
        eq_(Tag.objects.not_blocked()[0], tag1)
Example #8
0
    def save(self, addon, commit=True):
        if (self.cleaned_data.get('DELETE')
                and 'upload_hash' not in self.changed_data and self.promo.id):
            self.promo.delete()
        elif self.promo and 'upload_hash' in self.changed_data:
            self.promo.delete()
        elif self.cleaned_data.get('upload_hash'):
            super(AdminSettingsForm, self).save(addon, True)

        updates = {
            'vip_app': self.cleaned_data.get('vip_app'),
            'priority_review': self.cleaned_data.get('priority_review'),
        }
        contact = self.cleaned_data.get('mozilla_contact')
        if contact is not None:
            updates['mozilla_contact'] = contact
        addon.update(**updates)

        tags_new = self.cleaned_data['tags']
        tags_old = [slugify(t, spaces=True) for t in self.get_tags(addon)]

        add_tags = set(tags_new) - set(tags_old)
        del_tags = set(tags_old) - set(tags_new)

        # Add new tags.
        for t in add_tags:
            Tag(tag_text=t).save_tag(addon)

        # Remove old tags.
        for t in del_tags:
            Tag(tag_text=t).remove_tag(addon)

        geodata = addon.geodata
        geodata.banner_regions = self.cleaned_data.get('banner_regions')
        geodata.banner_message = self.cleaned_data.get('banner_message')
        geodata.save()

        uses_flash = self.cleaned_data.get('flash')
        af = addon.get_latest_file()
        if af is not None:
            af.update(uses_flash=bool(uses_flash))

        index_webapps.delay([addon.id])

        return addon
Example #9
0
 def test_indexable(self):
     homescreen = app_factory(name=u'Elegant Waffle',
                              description=u'homescreen runner',
                              created=self.days_ago(5),
                              manifest_url='http://h.testmanifest.com')
     Tag(tag_text='homescreen').save_tag(homescreen)
     homescreen.save()
     q = WebappIndexer.get_indexable()
     eq_(list(q), [self.app])
Example #10
0
    def save(self, addon, commit=False):
        # We ignore `commit`, since we need it to be `False` so we can save
        # the ManyToMany fields on our own.
        addonform = super(AppFormBasic, self).save(commit=False)
        addonform.save()

        if 'manifest_url' in self.changed_data:
            before_url = self.old_manifest_url
            after_url = self.cleaned_data['manifest_url']

            # If a non-admin edited the manifest URL, add to Re-review Queue.
            if not acl.action_allowed(self.request, 'Admin', '%'):
                log.info(u'[Webapp:%s] (Re-review) Manifest URL changed '
                         u'from %s to %s'
                         % (self.instance, before_url, after_url))

                msg = (_(u'Manifest URL changed from {before_url} to '
                         u'{after_url}')
                       .format(before_url=before_url, after_url=after_url))

                RereviewQueue.flag(self.instance,
                                   mkt.LOG.REREVIEW_MANIFEST_URL_CHANGE, msg)

            # Refetch the new manifest.
            log.info('Manifest %s refreshed for %s'
                     % (addon.manifest_url, addon))
            update_manifests.delay([self.instance.id])

        tags_new = self.cleaned_data['tags']
        tags_old = [slugify(t, spaces=True) for t in self.get_tags(addon)]

        add_tags = set(tags_new) - set(tags_old)
        del_tags = set(tags_old) - set(tags_new)

        # Add new tags.
        for t in add_tags:
            Tag(tag_text=t).save_tag(addon)

        # Remove old tags.
        for t in del_tags:
            Tag(tag_text=t).remove_tag(addon)

        return addonform
Example #11
0
    def save(self, *args, **kw):
        if self.data['notes']:
            create_comm_note(self.instance, self.instance.versions.latest(),
                             self.request.user, self.data['notes'],
                             note_type=comm.SUBMISSION)
        self.instance = super(AppDetailsBasicForm, self).save(commit=True)

        for tag_text in self.cleaned_data['tags']:
            Tag(tag_text=tag_text).save_tag(self.instance)

        return self.instance
Example #12
0
    def test_removing_all_tags(self):
        Tag(tag_text='tag one').save_tag(self.webapp)
        eq_(self.webapp.tags.count(), 1)

        self.data.update({'tags': ''})
        form = forms.AdminSettingsForm(self.data, **self.kwargs)
        assert form.is_valid(), form.errors
        form.save(self.webapp)

        eq_(self.webapp.tags.count(), 0)
        self.assertSetEqual(
            self.webapp.tags.values_list('tag_text', flat=True), [])
Example #13
0
    def test_removing_all_tags(self):
        Tag(tag_text='tag one').save_tag(self.app)
        eq_(self.app.tags.count(), 1)

        self.data.update({'tags': ''})
        self.post()
        assert self.form.is_valid(), self.form.errors
        self.form.save(self.app)

        eq_(self.app.tags.count(), 0)
        self.assertSetEqual(self.app.tags.values_list('tag_text', flat=True),
                            [])
Example #14
0
 def make_homescreen(self):
     self.homescreen = app_factory(name=u'Elegant Waffle',
                                   description=u'homescreen runner',
                                   created=self.days_ago(5),
                                   manifest_url='http://h.testmanifest.com')
     Tag(tag_text='homescreen').save_tag(self.homescreen)
     self.homescreen.addondevicetype_set.create(
         device_type=mkt.DEVICE_GAIA.id)
     self.homescreen.update(categories=['health-fitness', 'productivity'])
     self.homescreen.update_version()
     HomescreenIndexer.index_ids([self.homescreen.pk], no_delay=True)
     self.refresh(('webapp', 'website', 'extension', 'homescreen'))
     return self.homescreen
Example #15
0
 def make_homescreen(self):
     post_request_task._start_queuing_tasks()
     self.homescreen = app_factory(name=u'Elegant Waffle',
                                   description=u'homescreen runner',
                                   created=self.days_ago(5),
                                   manifest_url='http://h.testmanifest.com')
     Tag(tag_text='homescreen').save_tag(self.homescreen)
     self.homescreen.addondevicetype_set.create(
         device_type=mkt.DEVICE_GAIA.id)
     self.homescreen.update_version()
     self.homescreen.update(categories=['health-fitness', 'productivity'])
     post_request_task._send_tasks_and_stop_queuing()
     self.refresh(('webapp', 'extension', 'homescreen'))
     return self.homescreen
Example #16
0
    def save(self, *args, **kw):
        if self.data['notes']:
            create_comm_note(self.instance, self.instance.versions.latest(),
                             self.request.user, self.data['notes'],
                             note_type=comm.SUBMISSION)
        self.instance = super(AppDetailsBasicForm, self).save(commit=True)
        uses_flash = self.cleaned_data.get('flash')
        af = self.instance.get_latest_file()
        if af is not None:
            af.update(uses_flash=bool(uses_flash))

        for tag_text in self.cleaned_data['tags']:
            Tag(tag_text=tag_text).save_tag(self.instance)

        return self.instance
Example #17
0
    def test_not_blocked(self):
        """Make sure Tag Manager filters right for not blocked tags."""
        tag1 = Tag(tag_text="abc", blocked=False)
        tag1.save()
        tag2 = Tag(tag_text="swearword", blocked=True)
        tag2.save()

        eq_(Tag.objects.all().count(), 2)
        eq_(Tag.objects.not_blocked().count(), 1)
        eq_(Tag.objects.not_blocked()[0], tag1)
Example #18
0
    def test_is_tarako(self):
        Tag(tag_text='tarako').save_tag(self.webapp)
        self.webapp.save()
        self.refresh('webapp')

        res = self.client.get(self.url, {'is_tarako': True})
        eq_(res.status_code, 200)
        obj = res.json['objects'][0]
        eq_(obj['slug'], self.webapp.app_slug)

        res = self.client.get(self.url, {'is_tarako': False})
        eq_(res.status_code, 200)
        objs = res.json['objects']
        eq_(len(objs), 0)

        res = self.client.get(self.url, {'is_tarako': None})
        eq_(res.status_code, 200)
        obj = res.json['objects'][0]
        eq_(obj['slug'], self.webapp.app_slug)
Example #19
0
 def add_tag(self, tag_text):
     Tag(tag_text=tag_text).save_tag(self.app)
Example #20
0
 def test_tv_featured(self):
     Tag(tag_text='featured-tv').save_tag(self.app)
     self.app.save()
     self.refresh('webapp')
     res = self.serialize(self.app)
     ok_(res['tv_featured'])
Example #21
0
def tarako_failed(review):
    """Remove the tarako tag from the app."""
    tag = Tag(tag_text='tarako')
    tag.remove_tag(review.app)
    WebappIndexer.index_ids([review.app.pk])
Example #22
0
def tarako_passed(review):
    """Add the tarako tag to the app."""
    tag = Tag(tag_text='tarako')
    tag.save_tag(review.app)
    WebappIndexer.index_ids([review.app.pk])
Example #23
0
 def test_tv_featured(self):
     Tag(tag_text='featured-tv').save_tag(self.website)
     self.website.save()
     self.refresh('website')
     res = self.serialize(self.website)
     ok_(res['tv_featured'])
Example #24
0
def tarako_passed(review):
    """Add the tarako tag to the app."""
    tag = Tag(tag_text='tarako')
    tag.save_tag(review.app)
    WebappIndexer.index_ids([review.app.pk])
Example #25
0
def tarako_failed(review):
    """Remove the tarako tag from the app."""
    tag = Tag(tag_text='tarako')
    tag.remove_tag(review.app)
    WebappIndexer.index_ids([review.app.pk])
Example #26
0
def _review(request, addon, version):

    if (not settings.ALLOW_SELF_REVIEWS
            and not acl.action_allowed(request, 'Admin', '%')
            and addon.has_author(request.user)):
        messages.warning(request, _('Self-reviews are not allowed.'))
        return redirect(reverse('reviewers.home'))

    if (addon.status == amo.STATUS_BLOCKED
            and not acl.action_allowed(request, 'Apps', 'ReviewEscalated')):
        messages.warning(
            request, _('Only senior reviewers can review blocklisted apps.'))
        return redirect(reverse('reviewers.home'))

    attachment_formset = CommAttachmentFormSet(data=request.POST or None,
                                               files=request.FILES or None,
                                               prefix='attachment')
    form = forms.get_review_form(data=request.POST or None,
                                 files=request.FILES or None,
                                 request=request,
                                 addon=addon,
                                 version=version,
                                 attachment_formset=attachment_formset)
    postdata = request.POST if request.method == 'POST' else None
    all_forms = [form, attachment_formset]

    if version:
        features_list = [unicode(f) for f in version.features.to_list()]
        appfeatures_form = AppFeaturesForm(data=postdata,
                                           instance=version.features)
        all_forms.append(appfeatures_form)
    else:
        appfeatures_form = None
        features_list = None

    queue_type = form.helper.review_type
    redirect_url = reverse('reviewers.apps.queue_%s' % queue_type)
    is_admin = acl.action_allowed(request, 'Apps', 'Edit')

    if request.method == 'POST' and all(f.is_valid() for f in all_forms):

        old_types = set(o.id for o in addon.device_types)
        new_types = set(form.cleaned_data.get('device_override'))

        old_features = set(features_list)
        new_features = set(
            unicode(f) for f in appfeatures_form.instance.to_list())

        if form.cleaned_data.get('action') == 'public':
            if old_types != new_types:
                # The reviewer overrode the device types. We need to not
                # publish this app immediately.
                if addon.publish_type == amo.PUBLISH_IMMEDIATE:
                    addon.update(publish_type=amo.PUBLISH_PRIVATE)

                # And update the device types to what the reviewer set.
                AddonDeviceType.objects.filter(addon=addon).delete()
                for device in form.cleaned_data.get('device_override'):
                    addon.addondevicetype_set.create(device_type=device)

                # Log that the reviewer changed the device types.
                added_devices = new_types - old_types
                removed_devices = old_types - new_types
                msg = _(
                    u'Device(s) changed by '
                    u'reviewer: {0}'
                ).format(', '.join([
                    _(u'Added {0}').format(unicode(amo.DEVICE_TYPES[d].name))
                    for d in added_devices
                ] + [
                    _(u'Removed {0}').format(unicode(amo.DEVICE_TYPES[d].name))
                    for d in removed_devices
                ]))

                log_reviewer_action(addon, request.user, msg,
                                    amo.LOG.REVIEW_DEVICE_OVERRIDE)

            if old_features != new_features:
                # The reviewer overrode the requirements. We need to not
                # publish this app immediately.
                if addon.publish_type == amo.PUBLISH_IMMEDIATE:
                    addon.update(publish_type=amo.PUBLISH_PRIVATE)

                appfeatures_form.save(mark_for_rereview=False)

                # Log that the reviewer changed the minimum requirements.
                added_features = new_features - old_features
                removed_features = old_features - new_features

                fmt = ', '.join(
                    [_(u'Added {0}').format(f) for f in added_features] +
                    [_(u'Removed {0}').format(f) for f in removed_features])
                # L10n: {0} is the list of requirements changes.
                msg = _(u'Requirements changed by reviewer: {0}').format(fmt)

                log_reviewer_action(addon, request.user, msg,
                                    amo.LOG.REVIEW_FEATURES_OVERRIDE)

        score = form.helper.process()

        if form.cleaned_data.get('notify'):
            # TODO: bug 741679 for implementing notifications in Marketplace.
            EditorSubscription.objects.get_or_create(user=request.user,
                                                     addon=addon)

        is_tarako = form.cleaned_data.get('is_tarako', False)
        if is_tarako:
            Tag(tag_text='tarako').save_tag(addon)
        else:
            Tag(tag_text='tarako').remove_tag(addon)

        # Success message.
        if score:
            score = ReviewerScore.objects.filter(user=request.user)[0]
            # L10N: {0} is the type of review. {1} is the points they earned.
            #       {2} is the points they now have total.
            success = _(
                u'"{0}" successfully processed (+{1} points, {2} total).'.
                format(unicode(amo.REVIEWED_CHOICES[score.note_key]),
                       score.score, ReviewerScore.get_total(request.user)))
        else:
            success = _('Review successfully processed.')
        messages.success(request, success)

        return redirect(redirect_url)

    canned = CannedResponse.objects.all()
    actions = form.helper.actions.items()

    try:
        if not version:
            raise Version.DoesNotExist
        show_diff = (addon.versions.exclude(id=version.id).filter(
            files__isnull=False,
            created__lt=version.created,
            files__status=amo.STATUS_PUBLIC).latest())
    except Version.DoesNotExist:
        show_diff = None

    # The actions we should show a minimal form from.
    actions_minimal = [k for (k, a) in actions if not a.get('minimal')]

    # We only allow the user to check/uncheck files for "pending"
    allow_unchecking_files = form.helper.review_type == "pending"

    versions = (Version.with_deleted.filter(
        addon=addon).order_by('-created').transform(
            Version.transformer_activity).transform(Version.transformer))

    product_attrs = {
        'product':
        json.dumps(product_as_dict(request, addon, False, 'reviewer'),
                   cls=JSONEncoder),
        'manifest_url':
        addon.manifest_url,
    }

    pager = paginate(request, versions, 10)

    num_pages = pager.paginator.num_pages
    count = pager.paginator.count

    ctx = context(request,
                  version=version,
                  product=addon,
                  pager=pager,
                  num_pages=num_pages,
                  count=count,
                  form=form,
                  canned=canned,
                  is_admin=is_admin,
                  status_types=amo.STATUS_CHOICES,
                  show_diff=show_diff,
                  allow_unchecking_files=allow_unchecking_files,
                  actions=actions,
                  actions_minimal=actions_minimal,
                  tab=queue_type,
                  product_attrs=product_attrs,
                  attachment_formset=attachment_formset,
                  appfeatures_form=appfeatures_form)

    if features_list is not None:
        ctx['feature_list'] = features_list

    return render(request, 'reviewers/review.html', ctx)
Example #27
0
 def remove_tag(self, tag_text):
     Tag(tag_text=tag_text).remove_tag(self.app)