예제 #1
0
def manifest(request):

    form = forms.NewWebappForm(request.POST or None, request=request)

    features_form = forms.AppFeaturesForm(request.POST or None)
    features_form_valid = features_form.is_valid()

    if (request.method == 'POST' and form.is_valid() and
            features_form_valid):

        upload = form.cleaned_data['upload']
        addon = Webapp.from_upload(upload, is_packaged=form.is_packaged())
        file_obj = addon.latest_version.all_files[0]

        if form.is_packaged():
            validation = json.loads(upload.validation)
            escalate_reserved_permissions(
                addon, validation, addon.latest_version)

        # Set the device type.
        for device in form.get_devices():
            addon.addondevicetype_set.get_or_create(
                device_type=device.id)

        # Set the premium type, only bother if it's not free.
        premium = form.get_paid()
        if premium:
            addon.update(premium_type=premium)

        if addon.has_icon_in_manifest(file_obj):
            # Fetch the icon, do polling.
            addon.update(icon_type='image/png')
        else:
            # In this case there is no need to do any polling.
            addon.update(icon_type='')

        AddonUser(addon=addon, user=request.user).save()
        # Checking it once. Checking it twice.
        AppSubmissionChecklist.objects.create(addon=addon, terms=True,
                                              manifest=True, details=False)

        # Create feature profile.
        addon.latest_version.features.update(**features_form.cleaned_data)

        tasks.fetch_icon.delay(addon.pk, file_obj.pk)

        return redirect('submit.app.details', addon.app_slug)

    return render(request, 'submit/manifest.html',
                  {'step': 'manifest', 'features_form': features_form,
                   'form': form, 'PLATFORMS_NAMES': PLATFORMS_NAMES})
예제 #2
0
def status(request, addon_id, addon):
    appeal_form = forms.AppAppealForm(request.POST, product=addon)
    upload_form = NewWebappVersionForm(request.POST or None, is_packaged=True,
                                       addon=addon, request=request)
    publish_form = forms.PublishForm(
        request.POST if 'publish-app' in request.POST else None, addon=addon)

    if request.method == 'POST':
        if 'resubmit-app' in request.POST and appeal_form.is_valid():
            if not addon.is_rated():
                # Cannot resubmit without content ratings.
                return http.HttpResponseForbidden(
                    'This app must obtain content ratings before being '
                    'resubmitted.')

            appeal_form.save()
            create_comm_note(addon, addon.latest_version,
                             request.user, appeal_form.data['notes'],
                             note_type=comm.RESUBMISSION)
            if addon.vip_app:
                handle_vip(addon, addon.latest_version, request.user)

            messages.success(request, _('App successfully resubmitted.'))
            return redirect(addon.get_dev_url('versions'))

        elif 'upload-version' in request.POST and upload_form.is_valid():
            upload = upload_form.cleaned_data['upload']
            ver = Version.from_upload(upload, addon)

            # Update addon status now that the new version was saved.
            addon.update_status()

            res = run_validator(ver.all_files[0].file_path)
            validation_result = json.loads(res)

            # Escalate the version if it uses reserved permissions.
            escalate_reserved_permissions(addon, validation_result, ver)

            # Set all detected features as True and save them.
            keys = ['has_%s' % feature.lower()
                    for feature in validation_result['feature_profile']]
            data = defaultdict.fromkeys(keys, True)

            # Set "Smartphone-Sized Displays" if it's a mobile-only app.
            qhd_devices = (set((mkt.DEVICE_GAIA,)),
                           set((mkt.DEVICE_MOBILE,)),
                           set((mkt.DEVICE_GAIA, mkt.DEVICE_MOBILE,)))
            mobile_only = (addon.latest_version and
                           addon.latest_version.features.has_qhd)
            if set(addon.device_types) in qhd_devices or mobile_only:
                data['has_qhd'] = True

            # Update feature profile for this version.
            ver.features.update(**data)

            messages.success(request, _('New version successfully added.'))
            log.info('[Webapp:%s] New version created id=%s from upload: %s'
                     % (addon, ver.pk, upload))

            if addon.vip_app:
                handle_vip(addon, ver, request.user)

            return redirect(addon.get_dev_url('versions.edit', args=[ver.pk]))

        elif 'publish-app' in request.POST and publish_form.is_valid():
            publish_form.save()
            return redirect(addon.get_dev_url('versions'))

    ctx = {
        'addon': addon,
        'appeal_form': appeal_form,
        'is_tarako': addon.tags.filter(tag_text=QUEUE_TARAKO).exists(),
        'tarako_review': addon.additionalreview_set
                              .latest_for_queue(QUEUE_TARAKO),
        'publish_form': publish_form,
        'QUEUE_TARAKO': QUEUE_TARAKO,
        'upload_form': upload_form,
    }

    # Used in the delete version modal.
    if addon.is_packaged:
        versions = addon.versions.values('id', 'version')
        version_strings = dict((v['id'], v) for v in versions)
        version_strings['num'] = len(versions)
        ctx['version_strings'] = json.dumps(version_strings)

    if addon.status == mkt.STATUS_REJECTED:
        try:
            entry = (AppLog.objects
                     .filter(addon=addon,
                             activity_log__action=mkt.LOG.REJECT_VERSION.id)
                     .order_by('-created'))[0]
        except IndexError:
            entry = None
        # This contains the rejection reason and timestamp.
        ctx['rejection'] = entry and entry.activity_log

    if waffle.switch_is_active('preload-apps'):
        test_plan = PreloadTestPlan.objects.filter(
            addon=addon, status=mkt.STATUS_PUBLIC)
        if test_plan.exists():
            test_plan = test_plan[0]
            if (test_plan.last_submission <
                    settings.PREINSTALL_TEST_PLAN_LATEST):
                ctx['outdated_test_plan'] = True
            ctx['next_step_suffix'] = 'submit'
        else:
            ctx['next_step_suffix'] = 'home'
        ctx['test_plan'] = test_plan

    return render(request, 'developers/apps/status.html', ctx)