Example #1
0
    def from_upload(cls, upload, user=None):
        """Handle creating/editing the Extension instance and saving it to db,
        as well as file operations, from a FileUpload instance. Can throw
        a ParseError or SigningError, so should always be called within a
        try/except."""
        manifest_contents = cls.extract_and_validate_upload(upload)
        data = cls.extract_manifest_fields(manifest_contents)

        # Check for name collision in the same locale for the same user.
        default_language = data['default_language']
        name = data['name'][default_language]
        if user.extension_set.without_deleted().filter(
                name__locale=default_language,
                name__localized_string=name).exists():
            raise ParseError(
                _(u'An Add-on with the same name already exists in your '
                  u'submissions.'))

        # Build a new instance.
        instance = cls.objects.create(**data)

        # Now that the instance has been saved, we can add the author and start
        # saving version data. If everything checks out, a status will be set
        # on the ExtensionVersion we're creating which will automatically be
        # replicated on the Extension instance.
        instance.authors.add(user)
        version = ExtensionVersion.from_upload(
            upload, parent=instance, manifest_contents=manifest_contents)

        # Trigger icon fetch task asynchronously if necessary now that we have
        # an extension and a version.
        if 'icons' in manifest_contents:
            fetch_icon.delay(instance.pk, version.pk)
        return instance
Example #2
0
    def from_upload(cls, upload, user=None):
        """Handle creating/editing the Extension instance and saving it to db,
        as well as file operations, from a FileUpload instance. Can throw
        a ParseError or SigningError, so should always be called within a
        try/except."""
        manifest_contents = cls.extract_and_validate_upload(upload)
        data = cls.extract_manifest_fields(manifest_contents)

        # Check for name collision in the same locale for the same user.
        default_language = data['default_language']
        name = data['name'][default_language]
        if user.extension_set.without_deleted().filter(
                name__locale=default_language,
                name__localized_string=name).exists():
            raise ParseError(_(
                u'An Add-on with the same name already exists in your '
                u'submissions.'))

        # Build a new instance.
        instance = cls.objects.create(**data)

        # Now that the instance has been saved, we can add the author and start
        # saving version data. If everything checks out, a status will be set
        # on the ExtensionVersion we're creating which will automatically be
        # replicated on the Extension instance.
        instance.authors.add(user)
        version = ExtensionVersion.from_upload(
            upload, parent=instance, manifest_contents=manifest_contents)

        # Trigger icon fetch task asynchronously if necessary now that we have
        # an extension and a version.
        if 'icons' in manifest_contents:
            fetch_icon.delay(instance.pk, version.pk)
        return instance
Example #3
0
    def update_manifest_fields_from_latest_public_version(self):
        """Update all fields for which the manifest is the source of truth
        with the manifest from the latest public add-on."""
        try:
            version = self.latest_public_version
        except ExtensionVersion.DoesNotExist:
            return
        if not version.manifest:
            return
        # Trigger icon fetch task asynchronously if necessary now that we have
        # an extension and a version.
        if 'icons' in version.manifest:
            fetch_icon.delay(self.pk, version.pk)

        # We need to re-extract the fields from manifest contents because some
        # fields like default_language are transformed before being stored.
        data = self.extract_manifest_fields(version.manifest)
        return self.update(**data)
Example #4
0
    def update_manifest_fields_from_latest_public_version(self):
        """Update all fields for which the manifest is the source of truth
        with the manifest from the latest public add-on."""
        if self.is_blocked():
            raise BlockedExtensionError
        try:
            version = self.latest_public_version
        except ExtensionVersion.DoesNotExist:
            return
        if not version.manifest:
            return
        # Trigger icon fetch task asynchronously if necessary now that we have
        # an extension and a version.
        if 'icons' in version.manifest:
            fetch_icon.delay(self.pk, version.pk)

        # We need to re-extract the fields from manifest contents because some
        # fields like default_language are transformed before being stored.
        data = self.extract_manifest_fields(version.manifest)
        return self.update(**data)
Example #5
0
    def from_upload(cls, upload, user=None):
        """Handle creating/editing the Extension instance and saving it to db,
        as well as file operations, from a FileUpload instance. Can throw
        a ParseError or SigningError, so should always be called within a
        try/except."""
        manifest_contents = cls.extract_and_validate_upload(upload)
        data = cls.extract_manifest_fields(manifest_contents)

        # Build a new instance.
        instance = cls.objects.create(**data)

        # Now that the instance has been saved, we can add the author and start
        # saving version data. If everything checks out, a status will be set
        # on the ExtensionVersion we're creating which will automatically be
        # replicated on the Extension instance.
        instance.authors.add(user)
        version = ExtensionVersion.from_upload(
            upload, parent=instance, manifest_contents=manifest_contents)

        # Trigger icon fetch task asynchronously if necessary now that we have
        # an extension and a version.
        if 'icons' in manifest_contents:
            fetch_icon.delay(instance.pk, version.pk)
        return instance