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,60 @@ # 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.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 +68,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,12 +96,24 @@ 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/` """ + + # snapshot_context = get_snapshot_or_raise( + # { + # "origin_url": request.GET.get("origin_url"), + # "snapshot_id": request.GET.get("snapshot"), + # "timestamp": timestamp, + # } + # ) + return browse_snapshot_content( request, origin_url=request.GET.get("origin_url"), @@ -89,7 +131,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