Beispiel #1
0
 def get_success_output(self):
     data = self.data['row']
     update = {
         'version':
         data['version'],
         'update_link':
         get_cdn_url(data['addon_id'],
                     filename=data['filename'],
                     filehash=data['hash']),
         'applications': {
             'gecko': {
                 'strict_min_version': data['min']
             }
         },
     }
     if data['strict_compat']:
         update['applications']['gecko']['strict_max_version'] = data['max']
     if data['hash']:
         update['update_hash'] = data['hash']
     if data['releasenotes']:
         update['update_info_url'] = '{}{}{}/%APP_LOCALE%/'.format(
             settings.SITE_URL,
             '/versions/updateInfo/',
             data['version_id'],
         )
     return {'addons': {self.data['guid']: {'updates': [update]}}}
Beispiel #2
0
 def get_json(self):
     if self.get_data():
         response = {
             "converted_theme": {
                 "url": get_cdn_url(self.data['stheme_id'], self.data),
                 "hash": self.data['hash']
             }
         }
         return json.dumps(response)
Beispiel #3
0
 def get_json(self):
     if self.get_data():
         response = {
             "converted_theme": {
                 "url": get_cdn_url(self.data['stheme_id'], self.data),
                 "hash": self.data['hash']
             }
         }
         return json.dumps(response)
Beispiel #4
0
 def get_success_output(self):
     data = self.data['row']
     update = {
         'version': data['version'],
         'update_link': get_cdn_url(
             data['addon_id'], filename=data['filename'], filehash=data['hash']
         ),
         'applications': {'gecko': {'strict_min_version': data['min']}},
     }
     if data['strict_compat']:
         update['applications']['gecko']['strict_max_version'] = data['max']
     if data['hash']:
         update['update_hash'] = data['hash']
     if data['releasenotes']:
         slug = data['slug']
         version = data['version']
         update['update_info_url'] = (
             f'{settings.SITE_URL}/%APP_LOCALE%/'
             f'{self.app.short}/addon/{slug}/versions/{version}/updateinfo/'
         )
     return {'addons': {self.data['guid']: {'updates': [update]}}}
Beispiel #5
0
    def get_update(self):
        data = self.data

        data['STATUS_APPROVED'] = base.STATUS_APPROVED
        data['RELEASE_CHANNEL_LISTED'] = base.RELEASE_CHANNEL_LISTED

        sql = [
            """
            SELECT
                `addons`.`guid` AS `guid`,
                `addons`.`addontype_id` AS `type`,
                `addons`.`inactive` AS `disabled_by_user`,
                `appmin`.`version` AS `min`,
                `appmax`.`version` AS `max`,
                `files`.`id` AS `file_id`,
                `files`.`status` AS `file_status`,
                `files`.`hash`,
                `files`.`filename`,
                `versions`.`id` AS `version_id`,
                `files`.`datestatuschanged` AS `datestatuschanged`,
                `files`.`strict_compatibility` AS strict_compat,
                `versions`.`releasenotes`,
                `versions`.`version` AS `version`
            FROM `versions`
            INNER JOIN `addons`
                ON `addons`.`id` = `versions`.`addon_id`
                AND `addons`.`id` = %(id)s
            INNER JOIN `applications_versions`
                ON `applications_versions`.`version_id` = `versions`.`id`
            INNER JOIN `appversions` `appmin`
                ON `appmin`.`id` = `applications_versions`.`min`
                AND `appmin`.`application_id` = %(app_id)s
            INNER JOIN `appversions` `appmax`
                ON `appmax`.`id` = `applications_versions`.`max`
                AND `appmax`.`application_id` = %(app_id)s
            INNER JOIN `files`
                ON `files`.`version_id` = `versions`.`id`
            -- Find a reference to the user's current version, if it exists.
            -- These should never be inner joins. We need results even if we
            -- can't find the current version.
            LEFT JOIN `versions` `curver`
                ON `curver`.`addon_id` = `addons`.`id`
                AND `curver`.`version` = %(version)s
            LEFT JOIN `files` `curfile`
                ON `curfile`.`version_id` = `curver`.`id`
            WHERE
                `versions`.`deleted` = 0
                AND `versions`.`channel` = %(RELEASE_CHANNEL_LISTED)s
                AND `files`.`status` = %(STATUS_APPROVED)s
                AND `appmin`.`version_int` <= %(version_int)s
        """
        ]

        if self.compat_mode == 'ignore':
            pass  # no further SQL modification required.

        elif self.compat_mode == 'normal':
            # When file has strict_compatibility enabled, default to compatible
            # is disabled.
            sql.append("""AND
                CASE WHEN `files`.`strict_compatibility` = 1
                THEN `appmax`.`version_int` >= %(version_int)s ELSE 1 END
            """)
            # Filter out versions that don't have the minimum maxVersion
            # requirement to qualify for default-to-compatible.
            d2c_min = applications.D2C_MIN_VERSIONS.get(data['app_id'])
            if d2c_min:
                data['d2c_min_version'] = version_int(d2c_min)
                sql.append(
                    'AND `appmax`.`version_int` >= %(d2c_min_version)s ')

        else:  # Not defined or 'strict'.
            sql.append('AND `appmax`.`version_int` >= %(version_int)s ')

        sql.append('ORDER BY `versions`.`id` DESC LIMIT 1;')
        self.cursor.execute(''.join(sql), data)
        result = self.cursor.fetchone()

        if result:
            row = dict(
                zip(
                    [
                        'guid',
                        'type',
                        'disabled_by_user',
                        'min',
                        'max',
                        'file_id',
                        'file_status',
                        'hash',
                        'filename',
                        'version_id',
                        'datestatuschanged',
                        'strict_compat',
                        'releasenotes',
                        'version',
                    ],
                    list(result),
                ))
            row['type'] = base.ADDON_SLUGS_UPDATE[row['type']]
            row['url'] = get_cdn_url(data['id'], row)
            row['appguid'] = applications.APPS_ALL[data['app_id']].guid
            data['row'] = row
            return True

        return False
Beispiel #6
0
    def get_update(self):
        data = self.data

        data['STATUS_APPROVED'] = base.STATUS_APPROVED
        data['RELEASE_CHANNEL_LISTED'] = base.RELEASE_CHANNEL_LISTED

        sql = [
            """
            SELECT
                addons.guid as guid, addons.addontype_id as type,
                addons.inactive as disabled_by_user, appmin.version as min,
                appmax.version as max, files.id as file_id,
                files.status as file_status, files.hash,
                files.filename, versions.id as version_id,
                files.datestatuschanged as datestatuschanged,
                files.strict_compatibility as strict_compat,
                versions.releasenotes, versions.version as version
            FROM versions
            INNER JOIN addons
                ON addons.id = versions.addon_id AND addons.id = %(id)s
            INNER JOIN applications_versions
                ON applications_versions.version_id = versions.id
            INNER JOIN appversions appmin
                ON appmin.id = applications_versions.min
                AND appmin.application_id = %(app_id)s
            INNER JOIN appversions appmax
                ON appmax.id = applications_versions.max
                AND appmax.application_id = %(app_id)s
            INNER JOIN files
                ON files.version_id = versions.id AND (files.platform_id = 1
            """
        ]
        if data.get('appOS'):
            sql.append(' OR files.platform_id = %(appOS)s')

        sql.append("""
            )
            -- Find a reference to the user's current version, if it exists.
            -- These should never be inner joins. We need results even if we
            -- can't find the current version.
            LEFT JOIN versions curver
                ON curver.addon_id = addons.id AND curver.version = %(version)s
            LEFT JOIN files curfile
                ON curfile.version_id = curver.id
            WHERE
                versions.deleted = 0 AND
                versions.channel = %(RELEASE_CHANNEL_LISTED)s AND
                files.status = %(STATUS_APPROVED)s
        """)

        sql.append('AND appmin.version_int <= %(version_int)s ')

        if self.compat_mode == 'ignore':
            pass  # no further SQL modification required.

        elif self.compat_mode == 'normal':
            # When file has strict_compatibility enabled, or file has binary
            # components, default to compatible is disabled.
            sql.append("""AND
                CASE WHEN files.strict_compatibility = 1 OR
                          files.binary_components = 1
                THEN appmax.version_int >= %(version_int)s ELSE 1 END
            """)
            # Filter out versions that don't have the minimum maxVersion
            # requirement to qualify for default-to-compatible.
            d2c_min = applications.D2C_MIN_VERSIONS.get(data['app_id'])
            if d2c_min:
                data['d2c_min_version'] = version_int(d2c_min)
                sql.append("AND appmax.version_int >= %(d2c_min_version)s ")

        else:  # Not defined or 'strict'.
            sql.append('AND appmax.version_int >= %(version_int)s ')

        sql.append('ORDER BY versions.id DESC LIMIT 1;')

        self.cursor.execute(''.join(sql), data)
        result = self.cursor.fetchone()

        if result:
            row = dict(
                zip([
                    'guid', 'type', 'disabled_by_user', 'min', 'max',
                    'file_id', 'file_status', 'hash', 'filename', 'version_id',
                    'datestatuschanged', 'strict_compat', 'releasenotes',
                    'version'
                ], list(result)))
            row['type'] = base.ADDON_SLUGS_UPDATE[row['type']]
            row['url'] = get_cdn_url(data['id'], row)
            row['appguid'] = applications.APPS_ALL[data['app_id']].guid
            data['row'] = row
            return True

        return False
Beispiel #7
0
    def get_update(self):
        data = self.data

        data['STATUS_PUBLIC'] = base.STATUS_PUBLIC
        data['RELEASE_CHANNEL_LISTED'] = base.RELEASE_CHANNEL_LISTED

        sql = ["""
            SELECT
                addons.guid as guid, addons.addontype_id as type,
                addons.inactive as disabled_by_user, appmin.version as min,
                appmax.version as max, files.id as file_id,
                files.status as file_status, files.hash,
                files.filename, versions.id as version_id,
                files.datestatuschanged as datestatuschanged,
                files.strict_compatibility as strict_compat,
                versions.releasenotes, versions.version as version
            FROM versions
            INNER JOIN addons
                ON addons.id = versions.addon_id AND addons.id = %(id)s
            INNER JOIN applications_versions
                ON applications_versions.version_id = versions.id
            INNER JOIN appversions appmin
                ON appmin.id = applications_versions.min
                AND appmin.application_id = %(app_id)s
            INNER JOIN appversions appmax
                ON appmax.id = applications_versions.max
                AND appmax.application_id = %(app_id)s
            INNER JOIN files
                ON files.version_id = versions.id AND (files.platform_id = 1
            """]
        if data.get('appOS'):
            sql.append(' OR files.platform_id = %(appOS)s')

        sql.append("""
            )
            -- Find a reference to the user's current version, if it exists.
            -- These should never be inner joins. We need results even if we
            -- can't find the current version.
            LEFT JOIN versions curver
                ON curver.addon_id = addons.id AND curver.version = %(version)s
            LEFT JOIN files curfile
                ON curfile.version_id = curver.id
            WHERE
                versions.deleted = 0 AND
                versions.channel = %(RELEASE_CHANNEL_LISTED)s AND
                files.status = %(STATUS_PUBLIC)s
        """)

        sql.append('AND appmin.version_int <= %(version_int)s ')

        if self.compat_mode == 'ignore':
            pass  # no further SQL modification required.

        elif self.compat_mode == 'normal':
            # When file has strict_compatibility enabled, or file has binary
            # components, default to compatible is disabled.
            sql.append("""AND
                CASE WHEN files.strict_compatibility = 1 OR
                          files.binary_components = 1
                THEN appmax.version_int >= %(version_int)s ELSE 1 END
            """)
            # Filter out versions that don't have the minimum maxVersion
            # requirement to qualify for default-to-compatible.
            d2c_min = applications.D2C_MIN_VERSIONS.get(data['app_id'])
            if d2c_min:
                data['d2c_min_version'] = version_int(d2c_min)
                sql.append("AND appmax.version_int >= %(d2c_min_version)s ")

            # Filter out versions found in compat overrides
            sql.append("""AND
                NOT versions.id IN (
                SELECT version_id FROM incompatible_versions
                WHERE app_id=%(app_id)s AND
                  (min_app_version='0' AND
                       max_app_version_int >= %(version_int)s) OR
                  (min_app_version_int <= %(version_int)s AND
                       max_app_version='*') OR
                  (min_app_version_int <= %(version_int)s AND
                       max_app_version_int >= %(version_int)s)) """)

        else:  # Not defined or 'strict'.
            sql.append('AND appmax.version_int >= %(version_int)s ')

        sql.append('ORDER BY versions.id DESC LIMIT 1;')

        self.cursor.execute(''.join(sql), data)
        result = self.cursor.fetchone()

        if result:
            row = dict(zip([
                'guid', 'type', 'disabled_by_user', 'min', 'max',
                'file_id', 'file_status', 'hash', 'filename', 'version_id',
                'datestatuschanged', 'strict_compat', 'releasenotes',
                'version'],
                list(result)))
            row['type'] = base.ADDON_SLUGS_UPDATE[row['type']]
            row['url'] = get_cdn_url(data['id'], row)
            row['appguid'] = applications.APPS_ALL[data['app_id']].guid
            data['row'] = row
            return True

        return False