-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Addons: make it work on invalid URLs #12372
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -134,7 +134,10 @@ def _resolve_resources(self): | |
else: | ||
# When not sending "url", we require "project-slug" and "version-slug". | ||
project = get_object_or_404(Project, slug=project_slug) | ||
version = get_object_or_404(project.versions.all(), slug=version_slug) | ||
# We do allow hitting this URL without a valid version. | ||
# This is the same case than sending `?url=` with a partial match | ||
# (eg. invalid URL path). | ||
version = project.versions.filter(slug=version_slug).first() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should probably check if the version slug is empty instead. Given a wrong version and not version at all isn't the same. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We aren't doing anything different if the version slug is invalid/empty when the I'm happy to discuss behaving differently in those cases if we want that, but I want to move forward with this PR here and work on that different behavior in a different one. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Opened #12420 |
||
|
||
# A project is always required. | ||
if not project: | ||
|
@@ -378,6 +381,10 @@ def _v1(self, project, version, build, filename, url, request): | |
project.addons.flyout_sorting_latest_stable_at_beginning, | ||
) | ||
|
||
search_default_filter = f"project:{project.slug}" | ||
if version: | ||
search_default_filter = f"project:{project.slug}/{version.slug}" | ||
|
||
data = { | ||
"api_version": "1", | ||
"projects": self._get_projects_response( | ||
|
@@ -478,7 +485,7 @@ def _v1(self, project, version, build, filename, url, request): | |
# f"subprojects:{project.slug}/{version.slug}", | ||
# ], | ||
], | ||
"default_filter": f"project:{project.slug}/{version.slug}" if version else None, | ||
"default_filter": search_default_filter, | ||
}, | ||
"linkpreviews": { | ||
"enabled": project.addons.linkpreviews_enabled, | ||
|
Uh oh!
There was an error while loading. Please reload this page.