diff --git a/swh/web/browse/views/origin.py b/swh/web/browse/views/origin.py --- a/swh/web/browse/views/origin.py +++ b/swh/web/browse/views/origin.py @@ -3,38 +3,54 @@ # License: GNU Affero General Public License version 3, or any later version # See top-level LICENSE file for more information +from django.http import Http404 from django.shortcuts import redirect, render from swh.web.browse.browseurls import browse_route -from swh.web.browse.snapshot_context import ( - browse_snapshot_branches, - browse_snapshot_content, - browse_snapshot_directory, - browse_snapshot_log, - browse_snapshot_releases, - get_snapshot_context, -) +from swh.web.browse.snapshot_context import get_snapshot_context from swh.web.common import archive -from swh.web.common.exc import BadInputExc +from swh.web.common.exc import BadInputExc, NotFoundExc from swh.web.common.origin_visits import get_origin_visits from swh.web.common.utils import format_utc_iso_date, parse_iso8601_date_to_utc, reverse +def get_snapshot_or_raise(snapshot_params): + try: + snapshot_context = get_snapshot_context(**snapshot_params) + except NotFoundExc as e: + raise Http404("Requested snapshot does not exist", str(e)) + return snapshot_context + + +def deprecate_route(alternate_route, args, params): + return redirect(reverse(alternate_route, url_args=args, query_params=params)) + + @browse_route( r"origin/directory/", view_name="browse-origin-directory", ) def origin_directory_browse(request): - """Django view for browsing the content of a directory associated + """ + This route is deprecated; use /browse/directory// instead + + Django view for browsing the content of a directory associated to an origin for a given visit. The URL that points to it is :http:get:`/browse/origin/directory/` """ - return browse_snapshot_directory( - request, - origin_url=request.GET.get("origin_url"), - snapshot_id=request.GET.get("snapshot"), - timestamp=request.GET.get("timestamp"), - path=request.GET.get("path"), + + snapshot_context = get_snapshot_or_raise( + { + "origin_url": request.GET.get("origin_url"), + "snapshot_id": request.GET.get("snapshot"), + "timestamp": request.GET.get("timestamp"), + "path": request.GET.get("path"), + } + ) + return deprecate_route( + "browse-directory", + {"sha1_git": snapshot_context["root_directory"]}, + params=request.GET, ) @@ -46,19 +62,27 @@ view_name="browse-origin-directory-legacy", ) def origin_directory_browse_legacy(request, origin_url, timestamp=None, path=None): - """Django view for browsing the content of a directory associated + """ + This route is deprecated, use /browse/directory// instead + + Django view for browsing the content of a directory associated to an origin for a given visit. The URLs that point to it are :http:get:`/browse/origin/(origin_url)/directory/[(path)/]` and :http:get:`/browse/origin/(origin_url)/visit/(timestamp)/directory/[(path)/]` """ - return browse_snapshot_directory( - request, - origin_url=origin_url, - snapshot_id=request.GET.get("snapshot"), - timestamp=timestamp, - path=path, + snapshot_context = get_snapshot_or_raise( + { + "origin_url": origin_url, + "snapshot_id": request.GET.get("snapshot"), + "timestamp": timestamp, + } + ) + return deprecate_route( + "browse-directory", + {"sha1_git": snapshot_context["root_directory"]}, + params=request.GET, ) @@ -66,19 +90,29 @@ r"origin/content/", view_name="browse-origin-content", ) def origin_content_browse(request): - """Django view that produces an HTML display of a content + """ + This route is deprecated, use /browse/content// instead + + Django view that produces an HTML display of a content associated to an origin for a given visit. The URL that points to it is :http:get:`/browse/origin/content/` """ - return browse_snapshot_content( - request, - origin_url=request.GET.get("origin_url"), - snapshot_id=request.GET.get("snapshot"), - timestamp=request.GET.get("timestamp"), - path=request.GET.get("path"), - selected_language=request.GET.get("language"), + + snapshot_context = get_snapshot_or_raise( + { + "origin_url": request.GET.get("origin_url"), + "snapshot_id": request.GET.get("snapshot"), + "timestamp": request.GET.get("timestamp"), + } + ) + + # get the content sha1 + return deprecate_route( + "browse-content", + {"sha1_git": snapshot_context["root_directory"]}, + params=request.GET, ) @@ -89,7 +123,10 @@ view_name="browse-origin-content-legacy", ) def origin_content_browse_legacy(request, origin_url, path=None, timestamp=None): - """Django view that produces an HTML display of a content + """ + This route is deprecated, use /browse/content// instead + + Django view that produces an HTML display of a content associated to an origin for a given visit. The URLs that point to it are @@ -97,13 +134,19 @@ :http:get:`/browse/origin/(origin_url)/visit/(timestamp)/content/(path)/` """ - return browse_snapshot_content( - request, - origin_url=origin_url, - snapshot_id=request.GET.get("snapshot"), - timestamp=timestamp, - path=path, - selected_language=request.GET.get("language"), + snapshot_context = get_snapshot_or_raise( + { + "origin_url": request.GET.get("origin_url"), + "snapshot_id": request.GET.get("snapshot"), + "timestamp": timestamp, + } + ) + + # get the content sha1 + return deprecate_route( + "browse-content", + {"sha1_git": snapshot_context["root_directory"]}, + params=request.GET, ) @@ -111,16 +154,28 @@ r"origin/log/", view_name="browse-origin-log", ) def origin_log_browse(request): - """Django view that produces an HTML display of revisions history (aka + """ + This route is deprecated, + use /browse/snapshot/(?P[0-9a-f]+)/log/ instead + + Django view that produces an HTML display of revisions history (aka the commit log) associated to a software origin. The URL that points to it is :http:get:`/browse/origin/log/` """ - return browse_snapshot_log( - request, - origin_url=request.GET.get("origin_url"), - snapshot_id=request.GET.get("snapshot"), - timestamp=request.GET.get("timestamp"), + snapshot_context = get_snapshot_or_raise( + { + "origin_url": request.GET.get("origin_url"), + "snapshot_id": request.GET.get("snapshot"), + "timestamp": request.GET.get("timestamp"), + } + ) + # get the snapshot sha1 and redirect + + return deprecate_route( + "browse-snapshot-log", + {"sha1_git": snapshot_context["root_directory"]}, + params=request.GET, ) @@ -130,7 +185,11 @@ view_name="browse-origin-log-legacy", ) def origin_log_browse_legacy(request, origin_url, timestamp=None): - """Django view that produces an HTML display of revisions history (aka + """ + This route is deprecated, + use /browse/snapshot/(?P[0-9a-f]+)/log/ instead + + Django view that produces an HTML display of revisions history (aka the commit log) associated to a software origin. The URLs that point to it are @@ -138,11 +197,19 @@ :http:get:`/browse/origin/(origin_url)/visit/(timestamp)/log/` """ - return browse_snapshot_log( - request, - origin_url=origin_url, - snapshot_id=request.GET.get("snapshot"), - timestamp=timestamp, + snapshot_context = get_snapshot_or_raise( + { + "origin_url": request.GET.get("origin_url"), + "snapshot_id": request.GET.get("snapshot"), + "timestamp": request.GET.get("timestamp"), + } + ) + # get the snapshot sha1 and redirect + + return deprecate_route( + "browse-snapshot-log", + {"sha1_git": snapshot_context["root_directory"]}, + params=request.GET, ) @@ -150,18 +217,29 @@ r"origin/branches/", view_name="browse-origin-branches", ) def origin_branches_browse(request): - """Django view that produces an HTML display of the list of branches + """ + This route is deprecated, + use /browse/snapshot/(?P[0-9a-f]+)/branches/ instead + + Django view that produces an HTML display of the list of branches associated to an origin for a given visit. The URL that points to it is :http:get:`/browse/origin/branches/` """ - return browse_snapshot_branches( - request, - origin_url=request.GET.get("origin_url"), - snapshot_id=request.GET.get("snapshot"), - timestamp=request.GET.get("timestamp"), - branch_name_include=request.GET.get("name_include"), + snapshot_context = get_snapshot_or_raise( + { + "origin_url": request.GET.get("origin_url"), + "snapshot_id": request.GET.get("snapshot"), + "timestamp": request.GET.get("timestamp"), + } + ) + # get the snapshot sha1 and redirect + + return deprecate_route( + "browse-snapshot-branches", + {"sha1_git": snapshot_context["root_directory"]}, + params=request.GET, ) @@ -171,7 +249,11 @@ view_name="browse-origin-branches-legacy", ) def origin_branches_browse_legacy(request, origin_url, timestamp=None): - """Django view that produces an HTML display of the list of branches + """ + This route is deprecated, + use /browse/snapshot/(?P[0-9a-f]+)/branches/ instead + + Django view that produces an HTML display of the list of branches associated to an origin for a given visit. The URLs that point to it are @@ -179,11 +261,19 @@ :http:get:`/browse/origin/(origin_url)/visit/(timestamp)/branches/` """ - return browse_snapshot_branches( - request, - origin_url=origin_url, - snapshot_id=request.GET.get("snapshot"), - timestamp=timestamp, + snapshot_context = get_snapshot_or_raise( + { + "origin_url": request.GET.get("origin_url"), + "snapshot_id": request.GET.get("snapshot"), + "timestamp": request.GET.get("timestamp"), + } + ) + # get the snapshot sha1 and redirect + + return deprecate_route( + "browse-snapshot-branches", + {"sha1_git": snapshot_context["root_directory"]}, + params=request.GET, ) @@ -191,18 +281,29 @@ r"origin/releases/", view_name="browse-origin-releases", ) def origin_releases_browse(request): - """Django view that produces an HTML display of the list of releases + """ + This route is deprecated, + use /browse/snapshot/(?P[0-9a-f]+)/releases/ instead + + Django view that produces an HTML display of the list of releases associated to an origin for a given visit. The URL that points to it is :http:get:`/browse/origin/releases/` """ - return browse_snapshot_releases( - request, - origin_url=request.GET.get("origin_url"), - snapshot_id=request.GET.get("snapshot"), - timestamp=request.GET.get("timestamp"), - release_name_include=request.GET.get("name_include"), + snapshot_context = get_snapshot_or_raise( + { + "origin_url": request.GET.get("origin_url"), + "snapshot_id": request.GET.get("snapshot"), + "timestamp": request.GET.get("timestamp"), + } + ) + # get the snapshot sha1 and redirect + + return deprecate_route( + "browse-snapshot-releases", + {"sha1_git": snapshot_context["root_directory"]}, + params=request.GET, ) @@ -212,7 +313,11 @@ view_name="browse-origin-releases-legacy", ) def origin_releases_browse_legacy(request, origin_url, timestamp=None): - """Django view that produces an HTML display of the list of releases + """ + This route is deprecated, + use /browse/snapshot/(?P[0-9a-f]+)/releases/ instead + + Django view that produces an HTML display of the list of releases associated to an origin for a given visit. The URLs that point to it are @@ -220,11 +325,19 @@ :http:get:`/browse/origin/(origin_url)/visit/(timestamp)/releases/` """ - return browse_snapshot_releases( - request, - origin_url=origin_url, - snapshot_id=request.GET.get("snapshot"), - timestamp=timestamp, + snapshot_context = get_snapshot_or_raise( + { + "origin_url": request.GET.get("origin_url"), + "snapshot_id": request.GET.get("snapshot"), + "timestamp": request.GET.get("timestamp"), + } + ) + # get the snapshot sha1 and redirect + + return deprecate_route( + "browse-snapshot-releases", + {"sha1_git": snapshot_context["root_directory"]}, + params=request.GET, )