示例#1
0
 def test_manifest_fetch_3x_fail(self, retry, fetch):
     def die(self):
         raise RuntimeError()
     fetch.side_effect = die
     update_manifests(ids=(self.addon.pk,), retries={self.addon.pk: 2})
     assert not retry.called
     assert RereviewQueue.objects.filter(addon=self.addon).exists()
示例#2
0
 def test_manifest_fetch_4th_attempt(self, notify, retry, fetch):
     fetch.side_effect = RuntimeError
     update_manifests(ids=(self.addon.pk, ), retries={self.addon.pk: 3})
     # We already tried 3 times before, this is the 4th and last attempt,
     # we shouldn't retry anymore, instead we should just add the app to
     # the re-review queue. We shouldn't notify the developer either at this
     # step, it should have been done before already.
     assert not notify.called
     assert not retry.called
     assert RereviewQueue.objects.filter(addon=self.addon).exists()
示例#3
0
 def test_manifest_fetch_fail(self, retry, fetch):
     def die(self):
         raise RuntimeError()
     fetch.side_effect = die
     update_manifests(ids=(self.addon.pk,))
     retry.assert_called_with(
         args=([self.addon.pk,],),
         kwargs={'check_hash': True,
                 'retries': {self.addon.pk: 1}},
         countdown=3600)
示例#4
0
 def test_manifest_fetch_4th_attempt(self, notify, retry, fetch):
     fetch.side_effect = RuntimeError
     update_manifests(ids=(self.addon.pk,), retries={self.addon.pk: 3})
     # We already tried 3 times before, this is the 4th and last attempt,
     # we shouldn't retry anymore, instead we should just add the app to
     # the re-review queue. We shouldn't notify the developer either at this
     # step, it should have been done before already.
     assert not notify.called
     assert not retry.called
     assert RereviewQueue.objects.filter(addon=self.addon).exists()
示例#5
0
 def test_manifest_fetch_fail(self, retry, fetch):
     later = datetime.datetime.now() + datetime.timedelta(seconds=3600)
     fetch.side_effect = RuntimeError
     update_manifests(ids=(self.addon.pk,))
     retry.assert_called()
     # Not using assert_called_with b/c eta is a datetime.
     eq_(retry.call_args[1]["args"], ([self.addon.pk],))
     eq_(retry.call_args[1]["kwargs"], {"check_hash": True, "retries": {self.addon.pk: 1}})
     self.assertCloseToNow(retry.call_args[1]["eta"], later)
     eq_(retry.call_args[1]["max_retries"], 5)
     eq_(len(mail.outbox), 0)
示例#6
0
 def test_manifest_fetch_fail(self, retry, fetch):
     later = datetime.datetime.now() + datetime.timedelta(seconds=3600)
     fetch.side_effect = RuntimeError
     update_manifests(ids=(self.addon.pk,))
     retry.assert_called()
     # Not using assert_called_with b/c eta is a datetime.
     eq_(retry.call_args[1]['args'], ([self.addon.pk],))
     eq_(retry.call_args[1]['kwargs'], {'check_hash': True,
                                        'retries': {self.addon.pk: 1}})
     self.assertCloseToNow(retry.call_args[1]['eta'], later)
     eq_(retry.call_args[1]['max_retries'], 4)
示例#7
0
 def test_manifest_fetch_fail(self, retry, fetch):
     later = datetime.datetime.now() + datetime.timedelta(seconds=3600)
     fetch.side_effect = RuntimeError
     update_manifests(ids=(self.addon.pk,))
     retry.assert_called()
     # Not using assert_called_with b/c eta is a datetime.
     eq_(retry.call_args[1]['args'], ([self.addon.pk],))
     eq_(retry.call_args[1]['kwargs'], {'check_hash': True,
                                        'retries': {self.addon.pk: 1}})
     self.assertCloseToNow(retry.call_args[1]['eta'], later)
     eq_(retry.call_args[1]['max_retries'], 5)
     eq_(len(mail.outbox), 0)
示例#8
0
    def test_manifest_fetch_3rd_attempt(self, retry, fetch):
        fetch.side_effect = RuntimeError
        update_manifests(ids=(self.addon.pk, ), retries={self.addon.pk: 2})
        # We already tried twice before, this is the 3rd attempt,
        # We should notify the developer that something is wrong.
        eq_(len(mail.outbox), 1)
        msg = mail.outbox[0]
        ok_(msg.subject.startswith('Issue with your app'))
        expected = u'Failed to get manifest from %s' % self.addon.manifest_url
        ok_(expected in msg.body)
        ok_(settings.MKT_SUPPORT_EMAIL in msg.body)

        # We should have scheduled a retry.
        assert retry.called

        # We shouldn't have put the app in the rereview queue yet.
        assert not RereviewQueue.objects.filter(addon=self.addon).exists()
示例#9
0
    def test_manifest_fetch_3rd_attempt(self, retry, fetch):
        fetch.side_effect = RuntimeError
        update_manifests(ids=(self.addon.pk,), retries={self.addon.pk: 2})
        # We already tried twice before, this is the 3rd attempt,
        # We should notify the developer that something is wrong.
        eq_(len(mail.outbox), 1)
        msg = mail.outbox[0]
        ok_(msg.subject.startswith('Issue with your app'))
        expected = u'Failed to get manifest from %s' % self.addon.manifest_url
        ok_(expected in msg.body)
        ok_(settings.MKT_SUPPORT_EMAIL in msg.body)

        # We should have scheduled a retry.
        assert retry.called

        # We shouldn't have put the app in the rereview queue yet.
        assert not RereviewQueue.objects.filter(addon=self.addon).exists()
示例#10
0
 def test_manifest_fetch_3x_fail(self, retry, fetch):
     fetch.side_effect = RuntimeError
     update_manifests(ids=(self.addon.pk, ), retries={self.addon.pk: 2})
     assert not retry.called
     assert RereviewQueue.objects.filter(addon=self.addon).exists()
示例#11
0
 def test_update_manifest(self, retry, fetch):
     fetch.return_value = '{}'
     update_manifests(ids=(self.addon.pk, ))
     assert not retry.called
示例#12
0
 def _run(self, _get_content_hash, **kw):
     # Will run the task and will act depending upon how you've set hash.
     _get_content_hash.return_value = self._hash
     update_manifests(ids=(self.addon.pk, ), **kw)
示例#13
0
文件: views.py 项目: ngokevin/zamboni
def addons_section(request, addon_id, addon, section, editable=False):
    models = {
        "basic": AppFormBasic,
        "media": AppFormMedia,
        "details": AppFormDetails,
        "support": AppFormSupport,
        "technical": AppFormTechnical,
        "admin": forms.AdminSettingsForm,
    }

    is_dev = acl.check_addon_ownership(request, addon, dev=True)

    if section not in models:
        raise http.Http404()

    version = addon.current_version or addon.latest_version

    tags, previews, restricted_tags = [], [], []
    cat_form = appfeatures = appfeatures_form = version_form = None
    formdata = request.POST if request.method == "POST" else None

    # Permissions checks.
    # Only app owners can edit any of the details of their apps.
    # Users with 'Apps:Configure' can edit the admin settings.
    if (section != "admin" and not is_dev) or (
        section == "admin"
        and not acl.action_allowed(request, "Apps", "Configure")
        and not acl.action_allowed(request, "Apps", "ViewConfiguration")
    ):
        raise PermissionDenied

    if section == "basic":
        cat_form = CategoryForm(formdata, product=addon, request=request)
        # Only show/use the release notes form for hosted apps, packaged apps
        # can do that from the version edit page.
        if not addon.is_packaged:
            version_form = AppVersionForm(formdata, instance=version)

    elif section == "media":
        previews = PreviewFormSet(request.POST or None, prefix="files", queryset=addon.get_previews())

    elif section == "technical":
        # Only show/use the features form for hosted apps, packaged apps
        # can do that from the version edit page.
        if not addon.is_packaged:
            appfeatures = version.features
            appfeatures_form = AppFeaturesForm(formdata, instance=appfeatures)

    elif section == "admin":
        tags = addon.tags.not_blacklisted().values_list("tag_text", flat=True)
        restricted_tags = addon.tags.filter(restricted=True)

    # Get the slug before the form alters it to the form data.
    valid_slug = addon.app_slug
    if editable:
        if request.method == "POST":

            if section == "admin" and not acl.action_allowed(request, "Apps", "Configure"):
                raise PermissionDenied

            form = models[section](formdata, request.FILES, instance=addon, version=version, request=request)

            all_forms = [form, previews]
            for additional_form in (appfeatures_form, cat_form, version_form):
                if additional_form:
                    all_forms.append(additional_form)

            if all(not f or f.is_valid() for f in all_forms):
                if cat_form:
                    cat_form.save()

                addon = form.save(addon)

                if appfeatures_form:
                    appfeatures_form.save()

                if version_form:
                    # We are re-using version_form without displaying all its
                    # fields, so we need to override the boolean fields,
                    # otherwise they'd be considered empty and therefore False.
                    version_form.cleaned_data["publish_immediately"] = version_form.fields[
                        "publish_immediately"
                    ].initial
                    version_form.save()

                if "manifest_url" in form.changed_data:
                    addon.update(app_domain=addon.domain_from_url(addon.manifest_url))
                    update_manifests([addon.pk])

                if previews:
                    for preview in previews.forms:
                        preview.save(addon)

                editable = False
                if section == "media":
                    amo.log(amo.LOG.CHANGE_ICON, addon)
                else:
                    amo.log(amo.LOG.EDIT_PROPERTIES, addon)

                valid_slug = addon.app_slug
        else:
            form = models[section](instance=addon, version=version, request=request)
    else:
        form = False

    data = {
        "addon": addon,
        "version": version,
        "form": form,
        "editable": editable,
        "tags": tags,
        "restricted_tags": restricted_tags,
        "cat_form": cat_form,
        "version_form": version_form,
        "preview_form": previews,
        "valid_slug": valid_slug,
    }

    if appfeatures_form and appfeatures:
        data.update(
            {
                "appfeatures": appfeatures,
                "feature_list": [unicode(f) for f in appfeatures.to_list()],
                "appfeatures_form": appfeatures_form,
            }
        )

    return render(request, "developers/apps/edit/%s.html" % section, data)
示例#14
0
文件: views.py 项目: j-barron/zamboni
def addons_section(request, addon_id, addon, section, editable=False):
    models = {
        'basic': AppFormBasic,
        'media': AppFormMedia,
        'details': AppFormDetails,
        'support': AppFormSupport,
        'technical': AppFormTechnical,
        'admin': forms.AdminSettingsForm
    }

    is_dev = acl.check_addon_ownership(request, addon, dev=True)

    if section not in models:
        raise http.Http404()

    version = addon.current_version or addon.latest_version

    tags, previews, restricted_tags = [], [], []
    cat_form = appfeatures = appfeatures_form = version_form = None
    formdata = request.POST if request.method == 'POST' else None

    # Permissions checks.
    # Only app owners can edit any of the details of their apps.
    # Users with 'Apps:Configure' can edit the admin settings.
    if (section != 'admin' and not is_dev) or (
            section == 'admin'
            and not acl.action_allowed(request, 'Apps', 'Configure')
            and not acl.action_allowed(request, 'Apps', 'ViewConfiguration')):
        raise PermissionDenied

    if section == 'basic':
        cat_form = CategoryForm(formdata, product=addon, request=request)
        # Only show/use the release notes form for hosted apps, packaged apps
        # can do that from the version edit page.
        if not addon.is_packaged:
            version_form = AppVersionForm(formdata, instance=version)

    elif section == 'media':
        previews = PreviewFormSet(request.POST or None,
                                  prefix='files',
                                  queryset=addon.get_previews())

    elif section == 'technical':
        # Only show/use the features form for hosted apps, packaged apps
        # can do that from the version edit page.
        if not addon.is_packaged:
            appfeatures = version.features
            appfeatures_form = AppFeaturesForm(formdata, instance=appfeatures)

    elif section == 'admin':
        tags = addon.tags.not_blacklisted().values_list('tag_text', flat=True)
        restricted_tags = addon.tags.filter(restricted=True)

    # Get the slug before the form alters it to the form data.
    valid_slug = addon.app_slug
    if editable:
        if request.method == 'POST':

            if (section == 'admin'
                    and not acl.action_allowed(request, 'Apps', 'Configure')):
                raise PermissionDenied

            form = models[section](formdata,
                                   request.FILES,
                                   instance=addon,
                                   version=version,
                                   request=request)

            all_forms = [form, previews]
            for additional_form in (appfeatures_form, cat_form, version_form):
                if additional_form:
                    all_forms.append(additional_form)

            if all(not f or f.is_valid() for f in all_forms):
                if cat_form:
                    cat_form.save()

                addon = form.save(addon)

                if appfeatures_form:
                    appfeatures_form.save()

                if version_form:
                    # We are re-using version_form without displaying all its
                    # fields, so we need to override the boolean fields,
                    # otherwise they'd be considered empty and therefore False.
                    version_form.cleaned_data['publish_immediately'] = (
                        version_form.fields['publish_immediately'].initial)
                    version_form.save()

                if 'manifest_url' in form.changed_data:
                    addon.update(
                        app_domain=addon.domain_from_url(addon.manifest_url))
                    update_manifests([addon.pk])

                if previews:
                    for preview in previews.forms:
                        preview.save(addon)

                editable = False
                if section == 'media':
                    amo.log(amo.LOG.CHANGE_ICON, addon)
                else:
                    amo.log(amo.LOG.EDIT_PROPERTIES, addon)

                valid_slug = addon.app_slug
        else:
            form = models[section](instance=addon,
                                   version=version,
                                   request=request)
    else:
        form = False

    data = {
        'addon': addon,
        'version': version,
        'form': form,
        'editable': editable,
        'tags': tags,
        'restricted_tags': restricted_tags,
        'cat_form': cat_form,
        'version_form': version_form,
        'preview_form': previews,
        'valid_slug': valid_slug,
    }

    if appfeatures_form and appfeatures:
        data.update({
            'appfeatures': appfeatures,
            'feature_list': [unicode(f) for f in appfeatures.to_list()],
            'appfeatures_form': appfeatures_form
        })

    return render(request, 'developers/apps/edit/%s.html' % section, data)
示例#15
0
def addons_section(request, addon_id, addon, section, editable=False,
                   webapp=False):
    basic = AppFormBasic if webapp else addon_forms.AddonFormBasic
    models = {'basic': basic,
              'media': AppFormMedia,
              'details': AppFormDetails,
              'support': AppFormSupport,
              'technical': AppFormTechnical,
              'admin': forms.AdminSettingsForm}

    is_dev = acl.check_addon_ownership(request, addon, dev=True)

    if section not in models:
        raise http.Http404()

    version = addon.current_version or addon.latest_version

    tags, previews, restricted_tags = [], [], []
    cat_form = appfeatures = appfeatures_form = None

    # Permissions checks.
    # Only app owners can edit any of the details of their apps.
    # Users with 'Apps:Configure' can edit the admin settings.
    if (section != 'admin' and not is_dev) or (section == 'admin' and
        not acl.action_allowed(request, 'Apps', 'Configure') and
        not acl.action_allowed(request, 'Apps', 'ViewConfiguration')):
        raise PermissionDenied

    if section == 'basic':
        cat_form = CategoryForm(request.POST or None, product=addon,
                                request=request)

    elif section == 'media':
        previews = PreviewFormSet(
            request.POST or None, prefix='files',
            queryset=addon.get_previews())

    elif section == 'technical':
        # Only show the list of features if app isn't packaged.
        if (waffle.switch_is_active('buchets') and not addon.is_packaged and
                section == 'technical'):
            appfeatures = version.features
            formdata = request.POST if request.method == 'POST' else None
            appfeatures_form = AppFeaturesForm(formdata, instance=appfeatures)

    elif section == 'admin':
        tags = addon.tags.not_blacklisted().values_list('tag_text', flat=True)
        restricted_tags = addon.tags.filter(restricted=True)

    # Get the slug before the form alters it to the form data.
    valid_slug = addon.app_slug
    if editable:
        if request.method == 'POST':

            if (section == 'admin' and
                not acl.action_allowed(request, 'Apps', 'Configure')):
                raise PermissionDenied

            form = models[section](request.POST, request.FILES,
                                   instance=addon, request=request)

            all_forms = [form, previews]
            if appfeatures_form:
                all_forms.append(appfeatures_form)
            if cat_form:
                all_forms.append(cat_form)
            if all(not f or f.is_valid() for f in all_forms):
                if cat_form:
                    cat_form.save()

                addon = form.save(addon)

                if appfeatures_form:
                    appfeatures_form.save()

                if 'manifest_url' in form.changed_data:
                    addon.update(
                        app_domain=addon.domain_from_url(addon.manifest_url))
                    update_manifests([addon.pk])

                if previews:
                    for preview in previews.forms:
                        preview.save(addon)

                editable = False
                if section == 'media':
                    amo.log(amo.LOG.CHANGE_ICON, addon)
                else:
                    amo.log(amo.LOG.EDIT_PROPERTIES, addon)

                valid_slug = addon.app_slug
        else:
            form = models[section](instance=addon, request=request)
    else:
        form = False

    data = {'addon': addon,
            'webapp': webapp,
            'version': version,
            'form': form,
            'editable': editable,
            'tags': tags,
            'restricted_tags': restricted_tags,
            'cat_form': cat_form,
            'preview_form': previews,
            'valid_slug': valid_slug, }

    if appfeatures_form and appfeatures:
        data.update({
            'appfeatures': appfeatures,
            'feature_list': [unicode(f) for f in appfeatures.to_list()],
            'appfeatures_form': appfeatures_form
        })

    return jingo.render(request,
                        'developers/apps/edit/%s.html' % section, data)
示例#16
0
文件: views.py 项目: patilkr/zamboni
def addons_section(request, addon_id, addon, section, editable=False):
    basic = AppFormBasic
    models = {'basic': basic,
              'media': AppFormMedia,
              'details': AppFormDetails,
              'support': AppFormSupport,
              'technical': AppFormTechnical,
              'admin': forms.AdminSettingsForm}

    is_dev = acl.check_addon_ownership(request, addon, dev=True)

    if section not in models:
        raise http.Http404()

    version = addon.current_version or addon.latest_version

    tags, previews, restricted_tags = [], [], []
    cat_form = appfeatures = appfeatures_form = version_form = None
    formdata = request.POST if request.method == 'POST' else None

    # Permissions checks.
    # Only app owners can edit any of the details of their apps.
    # Users with 'Apps:Configure' can edit the admin settings.
    if (section != 'admin' and not is_dev) or (section == 'admin' and
        not acl.action_allowed(request, 'Apps', 'Configure') and
        not acl.action_allowed(request, 'Apps', 'ViewConfiguration')):
        raise PermissionDenied

    if section == 'basic':
        cat_form = CategoryForm(formdata, product=addon, request=request)
        # Only show/use the release notes form for hosted apps, packaged apps
        # can do that from the version edit page.
        if not addon.is_packaged:
            version_form = AppVersionForm(formdata, instance=version)

    elif section == 'media':
        previews = PreviewFormSet(
            request.POST or None, prefix='files',
            queryset=addon.get_previews())

    elif section == 'technical':
        # Only show/use the features form for hosted apps, packaged apps
        # can do that from the version edit page.
        if not addon.is_packaged:
            appfeatures = version.features
            appfeatures_form = AppFeaturesForm(formdata, instance=appfeatures)

    elif section == 'admin':
        tags = addon.tags.not_blacklisted().values_list('tag_text', flat=True)
        restricted_tags = addon.tags.filter(restricted=True)

    # Get the slug before the form alters it to the form data.
    valid_slug = addon.app_slug
    if editable:
        if request.method == 'POST':

            if (section == 'admin' and
                not acl.action_allowed(request, 'Apps', 'Configure')):
                raise PermissionDenied

            form = models[section](formdata, request.FILES,
                                   instance=addon, request=request)

            all_forms = [form, previews]
            for additional_form in (appfeatures_form, cat_form, version_form):
                if additional_form:
                    all_forms.append(additional_form)

            if all(not f or f.is_valid() for f in all_forms):
                if cat_form:
                    cat_form.save()

                addon = form.save(addon)

                if appfeatures_form:
                    appfeatures_form.save()

                if version_form:
                    # We are re-using version_form without displaying all its
                    # fields, so we need to override the boolean fields,
                    # otherwise they'd be considered empty and therefore False.
                    version_form.cleaned_data['publish_immediately'] = (
                        version_form.fields['publish_immediately'].initial)
                    version_form.save()

                if 'manifest_url' in form.changed_data:
                    addon.update(
                        app_domain=addon.domain_from_url(addon.manifest_url))
                    update_manifests([addon.pk])

                if previews:
                    for preview in previews.forms:
                        preview.save(addon)

                editable = False
                if section == 'media':
                    amo.log(amo.LOG.CHANGE_ICON, addon)
                else:
                    amo.log(amo.LOG.EDIT_PROPERTIES, addon)

                valid_slug = addon.app_slug
        else:
            form = models[section](instance=addon, request=request)
    else:
        form = False

    data = {'addon': addon,
            'version': version,
            'form': form,
            'editable': editable,
            'tags': tags,
            'restricted_tags': restricted_tags,
            'cat_form': cat_form,
            'version_form': version_form,
            'preview_form': previews,
            'valid_slug': valid_slug, }

    if appfeatures_form and appfeatures:
        data.update({
            'appfeatures': appfeatures,
            'feature_list': [unicode(f) for f in appfeatures.to_list()],
            'appfeatures_form': appfeatures_form
        })

    return render(request, 'developers/apps/edit/%s.html' % section, data)
示例#17
0
 def test_update_manifest(self, retry, fetch):
     def f(self):
         return '{}'
     fetch.side_effect = f
     update_manifests(ids=(self.addon.pk,))
     assert not retry.called
示例#18
0
 def _run(self, _get_content_hash):
     # Will run the task and will act depending upon how you've set hash.
     _get_content_hash.side_effect = self._write
     update_manifests(ids=(self.addon.pk,))
示例#19
0
 def _run(self, _get_content_hash, **kw):
     # Will run the task and will act depending upon how you've set hash.
     _get_content_hash.return_value = self._hash
     update_manifests(ids=(self.addon.pk,), **kw)
示例#20
0
 def test_error(self, _get_content_hash):
     _get_content_hash.side_effect = Exception()
     update_manifests(ids=(self.addon.pk,))
     eq_(ActivityLog.objects.for_addons(self.addon).count(), 0)
示例#21
0
文件: views.py 项目: dbialer/zamboni
def addons_section(request, addon_id, addon, section, editable=False, webapp=False):
    basic = AppFormBasic if webapp else addon_forms.AddonFormBasic
    models = {
        "basic": basic,
        "media": AppFormMedia,
        "details": AppFormDetails,
        "support": AppFormSupport,
        "technical": addon_forms.AddonFormTechnical,
        "admin": forms.AdminSettingsForm,
    }

    if section not in models:
        raise http.Http404()

    tags = previews = restricted_tags = []
    cat_form = device_type_form = region_form = None

    if section == "basic":
        tags = addon.tags.not_blacklisted().values_list("tag_text", flat=True)
        cat_form = CategoryForm(request.POST or None, product=addon, request=request)
        restricted_tags = addon.tags.filter(restricted=True)
        device_type_form = DeviceTypeForm(request.POST or None, addon=addon)

    elif section == "media":
        previews = PreviewFormSet(request.POST or None, prefix="files", queryset=addon.get_previews())

    elif section == "details" and settings.REGION_STORES:
        region_form = RegionForm(request.POST or None, product=addon)

    elif (
        section == "admin"
        and not acl.action_allowed(request, "Apps", "Configure")
        and not acl.action_allowed(request, "Apps", "ViewConfiguration")
    ):
        return http.HttpResponseForbidden()

    # Get the slug before the form alters it to the form data.
    valid_slug = addon.app_slug
    if editable:
        if request.method == "POST":

            if section == "admin" and not acl.action_allowed(request, "Apps", "Configure"):
                return http.HttpResponseForbidden()

            form = models[section](request.POST, request.FILES, instance=addon, request=request)
            if (
                form.is_valid()
                and (not previews or previews.is_valid())
                and (not region_form or region_form.is_valid())
            ):

                if region_form:
                    region_form.save()

                addon = form.save(addon)

                if "manifest_url" in form.changed_data:
                    addon.update(app_domain=addon.domain_from_url(addon.manifest_url))
                    update_manifests([addon.pk])

                if previews:
                    for preview in previews.forms:
                        preview.save(addon)

                editable = False
                if section == "media":
                    amo.log(amo.LOG.CHANGE_ICON, addon)
                else:
                    amo.log(amo.LOG.EDIT_PROPERTIES, addon)

                valid_slug = addon.app_slug
            if cat_form:
                if cat_form.is_valid():
                    cat_form.save()
                    addon.save()
                else:
                    editable = True
            if device_type_form:
                if device_type_form.is_valid():
                    device_type_form.save(addon)
                    addon.save()
                else:
                    editable = True
        else:
            form = models[section](instance=addon, request=request)
    else:
        form = False

    data = {
        "addon": addon,
        "webapp": webapp,
        "form": form,
        "editable": editable,
        "tags": tags,
        "restricted_tags": restricted_tags,
        "cat_form": cat_form,
        "preview_form": previews,
        "valid_slug": valid_slug,
        "device_type_form": device_type_form,
        "region_form": region_form,
    }

    return jingo.render(request, "developers/apps/edit/%s.html" % section, data)
示例#22
0
def addons_section(request,
                   addon_id,
                   addon,
                   section,
                   editable=False,
                   webapp=False):
    basic = AppFormBasic if webapp else addon_forms.AddonFormBasic
    models = {
        'basic': basic,
        'media': AppFormMedia,
        'details': AppFormDetails,
        'support': AppFormSupport,
        'technical': AppFormTechnical,
        'admin': forms.AdminSettingsForm
    }

    is_dev = acl.check_addon_ownership(request, addon, dev=True)

    if section not in models:
        raise http.Http404()

    version = addon.current_version or addon.latest_version

    tags, previews, restricted_tags = [], [], []
    cat_form = appfeatures = appfeatures_form = None

    # Permissions checks.
    # Only app owners can edit any of the details of their apps.
    # Users with 'Apps:Configure' can edit the admin settings.
    if (section != 'admin' and not is_dev) or (
            section == 'admin'
            and not acl.action_allowed(request, 'Apps', 'Configure')
            and not acl.action_allowed(request, 'Apps', 'ViewConfiguration')):
        raise PermissionDenied

    if section == 'basic':
        cat_form = CategoryForm(request.POST or None,
                                product=addon,
                                request=request)

    elif section == 'media':
        previews = PreviewFormSet(request.POST or None,
                                  prefix='files',
                                  queryset=addon.get_previews())

    elif section == 'technical':
        # Only show the list of features if app isn't packaged.
        if (waffle.switch_is_active('buchets') and not addon.is_packaged
                and section == 'technical'):
            appfeatures = version.features
            formdata = request.POST if request.method == 'POST' else None
            appfeatures_form = AppFeaturesForm(formdata, instance=appfeatures)

    elif section == 'admin':
        tags = addon.tags.not_blacklisted().values_list('tag_text', flat=True)
        restricted_tags = addon.tags.filter(restricted=True)

    # Get the slug before the form alters it to the form data.
    valid_slug = addon.app_slug
    if editable:
        if request.method == 'POST':

            if (section == 'admin'
                    and not acl.action_allowed(request, 'Apps', 'Configure')):
                raise PermissionDenied

            form = models[section](request.POST,
                                   request.FILES,
                                   instance=addon,
                                   request=request)

            all_forms = [form, previews]
            if appfeatures_form:
                all_forms.append(appfeatures_form)
            if cat_form:
                all_forms.append(cat_form)
            if all(not f or f.is_valid() for f in all_forms):
                if cat_form:
                    cat_form.save()

                addon = form.save(addon)

                if appfeatures_form:
                    appfeatures_form.save()

                if 'manifest_url' in form.changed_data:
                    addon.update(
                        app_domain=addon.domain_from_url(addon.manifest_url))
                    update_manifests([addon.pk])

                if previews:
                    for preview in previews.forms:
                        preview.save(addon)

                editable = False
                if section == 'media':
                    amo.log(amo.LOG.CHANGE_ICON, addon)
                else:
                    amo.log(amo.LOG.EDIT_PROPERTIES, addon)

                valid_slug = addon.app_slug
        else:
            form = models[section](instance=addon, request=request)
    else:
        form = False

    data = {
        'addon': addon,
        'webapp': webapp,
        'version': version,
        'form': form,
        'editable': editable,
        'tags': tags,
        'restricted_tags': restricted_tags,
        'cat_form': cat_form,
        'preview_form': previews,
        'valid_slug': valid_slug,
    }

    if appfeatures_form and appfeatures:
        data.update({
            'appfeatures': appfeatures,
            'feature_list': [unicode(f) for f in appfeatures.to_list()],
            'appfeatures_form': appfeatures_form
        })

    return jingo.render(request, 'developers/apps/edit/%s.html' % section,
                        data)
示例#23
0
文件: views.py 项目: flyun/zamboni
def addons_section(request,
                   addon_id,
                   addon,
                   section,
                   editable=False,
                   webapp=False):
    basic = AppFormBasic if webapp else addon_forms.AddonFormBasic
    models = {
        'basic': basic,
        'media': AppFormMedia,
        'details': AppFormDetails,
        'support': AppFormSupport,
        'technical': AppFormTechnical,
        'admin': forms.AdminSettingsForm
    }

    is_dev = acl.check_addon_ownership(request, addon, dev=True)

    if section not in models:
        raise http.Http404()

    tags = image_assets = previews = restricted_tags = []
    cat_form = None

    # Permissions checks.
    # Only app owners can edit any of the details of their apps.
    # Users with 'Apps:Configure' can edit the admin settings.
    if (section != 'admin' and not is_dev) or (
            section == 'admin'
            and not acl.action_allowed(request, 'Apps', 'Configure')
            and not acl.action_allowed(request, 'Apps', 'ViewConfiguration')):
        raise PermissionDenied

    if section == 'basic':
        tags = addon.tags.not_blacklisted().values_list('tag_text', flat=True)
        cat_form = CategoryForm(request.POST or None,
                                product=addon,
                                request=request)
        restricted_tags = addon.tags.filter(restricted=True)

    elif section == 'media':
        image_assets = ImageAssetFormSet(request.POST or None,
                                         prefix='images',
                                         app=addon)
        previews = PreviewFormSet(request.POST or None,
                                  prefix='files',
                                  queryset=addon.get_previews())

    # Get the slug before the form alters it to the form data.
    valid_slug = addon.app_slug
    if editable:
        if request.method == 'POST':

            if (section == 'admin'
                    and not acl.action_allowed(request, 'Apps', 'Configure')):
                raise PermissionDenied

            form = models[section](request.POST,
                                   request.FILES,
                                   instance=addon,
                                   request=request)
            if (form.is_valid() and (not previews or previews.is_valid())
                    and (not image_assets or image_assets.is_valid())):

                addon = form.save(addon)

                if 'manifest_url' in form.changed_data:
                    addon.update(
                        app_domain=addon.domain_from_url(addon.manifest_url))
                    update_manifests([addon.pk])

                if previews:
                    for preview in previews.forms:
                        preview.save(addon)

                if image_assets:
                    image_assets.save()

                editable = False
                if section == 'media':
                    amo.log(amo.LOG.CHANGE_ICON, addon)
                else:
                    amo.log(amo.LOG.EDIT_PROPERTIES, addon)

                valid_slug = addon.app_slug
            if cat_form:
                if cat_form.is_valid():
                    cat_form.save()
                    addon.save()
                else:
                    editable = True
        else:
            form = models[section](instance=addon, request=request)
    else:
        form = False

    data = {
        'addon': addon,
        'webapp': webapp,
        'form': form,
        'editable': editable,
        'tags': tags,
        'restricted_tags': restricted_tags,
        'image_sizes': APP_IMAGE_SIZES,
        'cat_form': cat_form,
        'preview_form': previews,
        'image_asset_form': image_assets,
        'valid_slug': valid_slug,
    }

    return jingo.render(request, 'developers/apps/edit/%s.html' % section,
                        data)
示例#24
0
def addons_section(request, addon_id, addon, section, editable=False,
                   webapp=False):
    basic = AppFormBasic if webapp else addon_forms.AddonFormBasic
    models = {'basic': basic,
              'media': AppFormMedia,
              'details': AppFormDetails,
              'support': AppFormSupport,
              'technical': AppFormTechnical,
              'admin': forms.AdminSettingsForm}

    if section not in models:
        raise http.Http404()

    tags = image_assets = previews = restricted_tags = []
    cat_form = None

    if section == 'basic':
        tags = addon.tags.not_blacklisted().values_list('tag_text', flat=True)
        cat_form = CategoryForm(request.POST or None, product=addon,
                                request=request)
        restricted_tags = addon.tags.filter(restricted=True)

    elif section == 'media':
        image_assets = ImageAssetFormSet(
            request.POST or None, prefix='images', app=addon)
        previews = PreviewFormSet(
            request.POST or None, prefix='files',
            queryset=addon.get_previews())

    elif (section == 'admin' and
          not acl.action_allowed(request, 'Apps', 'Configure') and
          not acl.action_allowed(request, 'Apps', 'ViewConfiguration')):
        raise PermissionDenied

    # Get the slug before the form alters it to the form data.
    valid_slug = addon.app_slug
    if editable:
        if request.method == 'POST':

            if (section == 'admin' and
                not acl.action_allowed(request, 'Apps', 'Configure')):
                raise PermissionDenied

            form = models[section](request.POST, request.FILES,
                                   instance=addon, request=request)
            if (form.is_valid()
                and (not previews or previews.is_valid())
                and (not image_assets or image_assets.is_valid())):

                addon = form.save(addon)

                if 'manifest_url' in form.changed_data:
                    addon.update(
                        app_domain=addon.domain_from_url(addon.manifest_url))
                    update_manifests([addon.pk])

                if previews:
                    for preview in previews.forms:
                        preview.save(addon)

                if image_assets:
                    image_assets.save()

                editable = False
                if section == 'media':
                    amo.log(amo.LOG.CHANGE_ICON, addon)
                else:
                    amo.log(amo.LOG.EDIT_PROPERTIES, addon)

                valid_slug = addon.app_slug
            if cat_form:
                if cat_form.is_valid():
                    cat_form.save()
                    addon.save()
                else:
                    editable = True
        else:
            form = models[section](instance=addon, request=request)
    else:
        form = False

    data = {'addon': addon,
            'webapp': webapp,
            'form': form,
            'editable': editable,
            'tags': tags,
            'restricted_tags': restricted_tags,
            'image_sizes': APP_IMAGE_SIZES,
            'cat_form': cat_form,
            'preview_form': previews,
            'image_asset_form': image_assets,
            'valid_slug': valid_slug, }

    return jingo.render(request,
                        'developers/apps/edit/%s.html' % section, data)
示例#25
0
 def _run(self, _get_content_hash):
     # Will run the task and will act depending upon how you've set hash.
     _get_content_hash.side_effect = self._write
     update_manifests(ids=(self.addon.pk, ))
示例#26
0
 def test_update_manifest(self, retry, fetch):
     fetch.return_value = '{}'
     update_manifests(ids=(self.addon.pk,))
     assert not retry.called
示例#27
0
 def test_error(self, _get_content_hash):
     _get_content_hash.side_effect = Exception()
     update_manifests(ids=(self.addon.pk, ))
     eq_(ActivityLog.objects.for_apps(self.addon).count(), 0)
示例#28
0
def addons_section(request,
                   addon_id,
                   addon,
                   section,
                   editable=False,
                   webapp=False):
    basic = AppFormBasic if webapp else addon_forms.AddonFormBasic
    models = {
        'basic': basic,
        'media': AppFormMedia,
        'details': AppFormDetails,
        'support': AppFormSupport,
        'technical': addon_forms.AddonFormTechnical,
        'admin': forms.AdminSettingsForm
    }

    if section not in models:
        raise http.Http404()

    tags = previews = restricted_tags = []
    cat_form = device_type_form = None

    if section == 'basic':
        tags = addon.tags.not_blacklisted().values_list('tag_text', flat=True)
        cat_form = addon_forms.CategoryFormSet(request.POST or None,
                                               addon=addon,
                                               request=request)
        restricted_tags = addon.tags.filter(restricted=True)
        device_type_form = addon_forms.DeviceTypeForm(request.POST or None,
                                                      addon=addon)

    elif section == 'media':
        previews = PreviewFormSet(request.POST or None,
                                  prefix='files',
                                  queryset=addon.get_previews())

    elif (section == 'admin'
          and not acl.action_allowed(request, 'Apps', 'Configure')
          and not acl.action_allowed(request, 'Apps', 'ViewConfiguration')):
        return http.HttpResponseForbidden()

    # Get the slug before the form alters it to the form data.
    valid_slug = addon.app_slug
    if editable:
        if request.method == 'POST':

            if (section == 'admin'
                    and not acl.action_allowed(request, 'Apps', 'Configure')):
                return http.HttpResponseForbidden()

            form = models[section](request.POST,
                                   request.FILES,
                                   instance=addon,
                                   request=request)
            if form.is_valid() and (not previews or previews.is_valid()):

                addon = form.save(addon)

                if 'manifest_url' in form.changed_data:
                    addon.update(
                        app_domain=addon.domain_from_url(addon.manifest_url))
                    update_manifests([addon.pk])

                if previews:
                    for preview in previews.forms:
                        preview.save(addon)

                editable = False
                if section == 'media':
                    amo.log(amo.LOG.CHANGE_ICON, addon)
                else:
                    amo.log(amo.LOG.EDIT_PROPERTIES, addon)

                valid_slug = addon.app_slug
            if cat_form:
                if cat_form.is_valid():
                    cat_form.save()
                    addon.save()
                else:
                    editable = True
            if device_type_form:
                if device_type_form.is_valid():
                    device_type_form.save(addon)
                    addon.save()
                else:
                    editable = True
        else:
            form = models[section](instance=addon, request=request)
    else:
        form = False

    data = {
        'addon': addon,
        'webapp': webapp,
        'form': form,
        'editable': editable,
        'tags': tags,
        'restricted_tags': restricted_tags,
        'cat_form': cat_form,
        'preview_form': previews,
        'valid_slug': valid_slug,
        'device_type_form': device_type_form
    }

    return jingo.render(request, 'developers/apps/edit/%s.html' % section,
                        data)
示例#29
0
文件: views.py 项目: rskumar/zamboni
def addons_section(request, addon_id, addon, section, editable=False, webapp=False):
    basic = AppFormBasic if webapp else addon_forms.AddonFormBasic
    models = {
        "basic": basic,
        "media": AppFormMedia,
        "details": AppFormDetails,
        "support": AppFormSupport,
        "technical": AppFormTechnical,
        "admin": forms.AdminSettingsForm,
    }

    is_dev = acl.check_addon_ownership(request, addon, dev=True)

    if section not in models:
        raise http.Http404()

    version = addon.current_version or addon.latest_version

    tags, previews, restricted_tags = [], [], []
    cat_form = appfeatures = appfeatures_form = None

    # Permissions checks.
    # Only app owners can edit any of the details of their apps.
    # Users with 'Apps:Configure' can edit the admin settings.
    if (section != "admin" and not is_dev) or (
        section == "admin"
        and not acl.action_allowed(request, "Apps", "Configure")
        and not acl.action_allowed(request, "Apps", "ViewConfiguration")
    ):
        raise PermissionDenied

    if section == "basic":
        cat_form = CategoryForm(request.POST or None, product=addon, request=request)

    elif section == "media":
        previews = PreviewFormSet(request.POST or None, prefix="files", queryset=addon.get_previews())

    elif section == "technical":
        # Only show the list of features if app isn't packaged.
        if waffle.switch_is_active("buchets") and not addon.is_packaged and section == "technical":
            appfeatures = version.features
            formdata = request.POST if request.method == "POST" else None
            appfeatures_form = AppFeaturesForm(formdata, instance=appfeatures)

    elif section == "admin":
        tags = addon.tags.not_blacklisted().values_list("tag_text", flat=True)
        restricted_tags = addon.tags.filter(restricted=True)

    # Get the slug before the form alters it to the form data.
    valid_slug = addon.app_slug
    if editable:
        if request.method == "POST":

            if section == "admin" and not acl.action_allowed(request, "Apps", "Configure"):
                raise PermissionDenied

            form = models[section](request.POST, request.FILES, instance=addon, request=request)

            all_forms = [form, previews]
            if appfeatures_form:
                all_forms.append(appfeatures_form)
            if cat_form:
                all_forms.append(cat_form)
            if all(not f or f.is_valid() for f in all_forms):
                if cat_form:
                    cat_form.save()

                addon = form.save(addon)

                if appfeatures_form:
                    appfeatures_form.save()

                if "manifest_url" in form.changed_data:
                    addon.update(app_domain=addon.domain_from_url(addon.manifest_url))
                    update_manifests([addon.pk])

                if previews:
                    for preview in previews.forms:
                        preview.save(addon)

                editable = False
                if section == "media":
                    amo.log(amo.LOG.CHANGE_ICON, addon)
                else:
                    amo.log(amo.LOG.EDIT_PROPERTIES, addon)

                valid_slug = addon.app_slug
        else:
            form = models[section](instance=addon, request=request)
    else:
        form = False

    data = {
        "addon": addon,
        "webapp": webapp,
        "version": version,
        "form": form,
        "editable": editable,
        "tags": tags,
        "restricted_tags": restricted_tags,
        "cat_form": cat_form,
        "preview_form": previews,
        "valid_slug": valid_slug,
    }

    if appfeatures_form and appfeatures:
        data.update(
            {
                "appfeatures": appfeatures,
                "feature_list": [unicode(f) for f in appfeatures.to_list()],
                "appfeatures_form": appfeatures_form,
            }
        )

    return jingo.render(request, "developers/apps/edit/%s.html" % section, data)