in src/olympia/search/filters.py [0:0]
def get_es_query(self):
value = self.query_data.get(self.query_param, '')
# Firefox 'return to AMO' feature sadly does not use a specific API but
# rather encodes the guid and adds a prefix to it, then passing that
# string as a guid to the search API. If the guid parameter matches
# this format, and the feature is enabled through a switch, then we
# decode it and later check it against badged promoted add-ons, which
# have to be pre-reviewed, so they should always be safe add-ons we can
# enable that feature for.
# We raise ValueError if anything goes wrong, they are eventually
# turned into 400 responses and this acts as a kill-switch for the
# feature in Firefox.
if value.startswith('rta:') and '@' not in value:
if not switch_is_active('return-to-amo'):
raise ValueError(gettext('Return To AMO is currently disabled'))
try:
# We need to keep force_str on the input because
# urlsafe_base64_decode requires str from Django 2.2 onwards.
value = force_str(urlsafe_base64_decode(force_str(value[4:])))
if not amo.ADDON_GUID_PATTERN.match(value):
raise ValueError()
except (TypeError, ValueError) as exc:
raise ValueError(
gettext('Invalid Return To AMO guid (not in base64url format?)')
) from exc
# Filter on the now decoded guid param as normal...
filters = super().get_es_query([value])
# If the switch to enable all listed add-ons for RTAMO is on, we
# don't need anthing else. If it's off, then we restrict to only
# promoted add-ons (which should all be reviewed).
if not switch_is_active('return-to-amo-for-all-listed'):
filters.extend(
AddonPromotedQueryParam(
self.request,
query_data={
AddonPromotedQueryParam.query_param: BADGED_API_NAME
},
).get_es_query()
)
return filters
else:
return super().get_es_query()