@@ -96,6 +96,11 @@ class ViewType(Enum):
9696 fragment = "fragment"
9797
9898
99+ VIEW_REPORT = {
100+ ViewType .markdown : 'report.md' ,
101+ ViewType .fragment : 'report.md' ,
102+ ViewType .page : 'overview.html' ,
103+ }
99104VIEW_DETAIL = {
100105 ViewType .markdown : 'details.md' ,
101106 ViewType .fragment : 'details.md' ,
@@ -111,7 +116,7 @@ class ViewType(Enum):
111116 ViewType .fragment : 'scope.md' ,
112117 ViewType .page : 'overview.html' ,
113118}
114- REQUIRED_TEMPLATES = tuple (set (fn for view in (VIEW_DETAIL , VIEW_TABLE , VIEW_SCOPE ) for fn in view .values ()))
119+ REQUIRED_TEMPLATES = tuple (set (fn for view in (VIEW_REPORT , VIEW_DETAIL , VIEW_TABLE , VIEW_SCOPE ) for fn in view .values ()))
115120
116121
117122# do I hate these globals, but I don't see another way with these frameworks
@@ -544,14 +549,23 @@ async def get_status(
544549 return convert_result_rows_to_dict2 (rows2 , get_scopes (), include_report = True )
545550
546551
552+ def _build_report_url (base_url , report , * args , ** kwargs ):
553+ if kwargs .get ('download' ):
554+ return f"{ base_url } reports/{ report } "
555+ url = f"{ base_url } page/report/{ report } "
556+ if len (args ) == 2 : # version, testcase_id --> add corresponding fragment specifier
557+ url += f"#{ args [0 ]} _{ args [1 ]} "
558+ return url
559+
560+
547561def render_view (view , view_type , detail_page = 'detail' , base_url = '/' , title = None , ** kwargs ):
548562 media_type = {ViewType .markdown : 'text/markdown' }.get (view_type , 'text/html' )
549563 stage1 = stage2 = view [view_type ]
550564 if view_type is ViewType .page :
551565 stage1 = view [ViewType .fragment ]
552566 def scope_url (uuid ): return f"{ base_url } page/scope/{ uuid } " # noqa: E306,E704
553567 def detail_url (subject , scope ): return f"{ base_url } page/{ detail_page } /{ subject } /{ scope } " # noqa: E306,E704
554- def report_url (report ): return f" { base_url } reports/ { report } " # noqa: E306,E704
568+ def report_url (report , * args , ** kwargs ): return _build_report_url ( base_url , report , * args , ** kwargs ) # noqa: E306,E704
555569 fragment = templates_map [stage1 ].render (detail_url = detail_url , report_url = report_url , scope_url = scope_url , ** kwargs )
556570 if view_type != ViewType .markdown and stage1 .endswith ('.md' ):
557571 fragment = markdown (fragment , extensions = ['extra' ])
@@ -560,6 +574,23 @@ def report_url(report): return f"{base_url}reports/{report}" # noqa: E306,E704
560574 return Response (content = fragment , media_type = media_type )
561575
562576
577+ @app .get ("/{view_type}/report/{report_uuid}" )
578+ async def get_report_view (
579+ request : Request ,
580+ account : Annotated [Optional [tuple [str , str ]], Depends (auth )],
581+ conn : Annotated [connection , Depends (get_conn )],
582+ view_type : ViewType ,
583+ report_uuid : str ,
584+ ):
585+ with conn .cursor () as cur :
586+ specs = db_get_report (cur , report_uuid )
587+ if not specs :
588+ raise HTTPException (status_code = 404 )
589+ spec = specs [0 ]
590+ check_role (account , spec ['subject' ], ROLES ['read_any' ])
591+ return render_view (VIEW_REPORT , view_type , report = spec , base_url = settings .base_url , title = f'Report { report_uuid } ' )
592+
593+
563594@app .get ("/{view_type}/detail/{subject}/{scopeuuid}" )
564595async def get_detail (
565596 request : Request ,
0 commit comments