Merge ~andersson123/autopkgtest-cloud:fix-package-page-nonexistent-package into autopkgtest-cloud:master

Proposed by Tim Andersson
Status: Needs review
Proposed branch: ~andersson123/autopkgtest-cloud:fix-package-page-nonexistent-package
Merge into: autopkgtest-cloud:master
Diff against target: 42 lines (+12/-1)
2 files modified
charms/focal/autopkgtest-web/webcontrol/browse.cgi (+3/-1)
charms/focal/autopkgtest-web/webcontrol/helpers/exceptions.py (+9/-0)
Reviewer Review Type Date Requested Status
Brian Murray Disapprove
Skia Approve
Review via email: mp+462703@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Skia (hyask) wrote :

Looking good!

review: Approve
Revision history for this message
Brian Murray (brian-murray) wrote :

Thinking about this some more I'm not sure what is the worst end user experience.

A) Mistype a package name and get a web page with no test results.

OR

B) Properly type a package name and get a 404.

I'm leaning towards B being the worst end user experience since at least with A I can click on the LP url and get a nicely formatted 404. Especially, since case A also will not show any releases which is a pretty good indicator you misspelled the package name.

review: Disapprove
Revision history for this message
Tim Andersson (andersson123) wrote :

Okay, understood, so, should I close this MP? And the related bug?

Revision history for this message
Brian Murray (brian-murray) wrote :

Well ideally the autopkgtest-web workers would know what is and is not a package and then could either return a 404 or a page saying the package has no tests. However, I think that makes the bug a lower priority given the difficulty of it.

Revision history for this message
Tim Andersson (andersson123) wrote :

How about 2 outcomes?

outcome 1:
- user types in a package which exists in launchpad but has no previous results - is greeted with a page stating as such
- user types in a package which doesn't exist in launchpad but does have previous results - is greeted with the normal package browsing page
- user types in a package which doesn't exist in launchpad and has no previous results - we then assume the package doesn't exist and we tell the user as such

The above solution is quite easy I believe. Let me know what you think. If you like that solution I can go ahead and implement it.

Revision history for this message
Tim Andersson (andersson123) wrote :

waiting on feedback for this MP.

Unmerged commits

ba44a14... by Tim Andersson

fix: web: Don't show package pages for packages that don't exist

Fixes bug LP: #2058059

Succeeded
[SUCCEEDED] pre_commit:0 (build)
[SUCCEEDED] unit_tests:0 (build)
[SUCCEEDED] build_charms:0 (build)
13 of 3 results

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/charms/focal/autopkgtest-web/webcontrol/browse.cgi b/charms/focal/autopkgtest-web/webcontrol/browse.cgi
2index 810163d..4352154 100755
3--- a/charms/focal/autopkgtest-web/webcontrol/browse.cgi
4+++ b/charms/focal/autopkgtest-web/webcontrol/browse.cgi
5@@ -12,7 +12,7 @@ from wsgiref.handlers import CGIHandler
6
7 import flask
8 from helpers.admin import select_abnormally_long_jobs
9-from helpers.exceptions import RunningJSONNotFound
10+from helpers.exceptions import NonExistentPackage, RunningJSONNotFound
11 from helpers.utils import get_all_releases, get_supported_releases
12 from werkzeug.middleware.proxy_fix import ProxyFix
13
14@@ -279,6 +279,8 @@ def package_overview(package, _=None):
15 ):
16 arches.add(row[3])
17 results.setdefault(row[2], {})[row[3]] = human_exitcode(row[1])
18+ if not results:
19+ raise NonExistentPackage(package)
20
21 running_info = dict(
22 (k, v) for (k, v) in get_running_jobs().items() if k == package
23diff --git a/charms/focal/autopkgtest-web/webcontrol/helpers/exceptions.py b/charms/focal/autopkgtest-web/webcontrol/helpers/exceptions.py
24index e94164e..c3a22d9 100644
25--- a/charms/focal/autopkgtest-web/webcontrol/helpers/exceptions.py
26+++ b/charms/focal/autopkgtest-web/webcontrol/helpers/exceptions.py
27@@ -15,6 +15,15 @@ class RunningJSONNotFound(FileNotFoundError):
28 return 500
29
30
31+class NonExistentPackage(Exception):
32+ def __init__(self, package):
33+ super().__init__("Package %s doesn't exist." % package)
34+ self._code = 404
35+
36+ def exit_code(self):
37+ return self._code
38+
39+
40 class WebControlException(Exception):
41 def __init__(self, message, exit_code):
42 super().__init__(message)

Subscribers

People subscribed via source and target branches