From d49c69da1070cd02e22f9a7762058a739c4cad8e Mon Sep 17 00:00:00 2001 From: NubWizard Date: Mon, 12 Jun 2023 18:27:04 -0500 Subject: [PATCH] Cleans up the files from debugging --- tildes/tildes/routes.py | 7 ++++++- tildes/tildes/views/exceptions.py | 15 ++++----------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/tildes/tildes/routes.py b/tildes/tildes/routes.py index 1641a17..dd4f20f 100644 --- a/tildes/tildes/routes.py +++ b/tildes/tildes/routes.py @@ -191,7 +191,12 @@ def add_intercooler_routes(config: Configurator) -> None: class LoggedInFactory: - """Simple class to use as `factory` to restrict routes to logged-in users.""" + """Simple class to use as `factory` to restrict routes to logged-in users. + + This class can be used when a route should only be accessible to logged-in users but + doesn't already have another factory that would handle that by checking access to a + specific resource (such as a topic or message). + """ __acl__ = [ (Allow, Authenticated, "view"), diff --git a/tildes/tildes/views/exceptions.py b/tildes/tildes/views/exceptions.py index bdbf201..852b546 100644 --- a/tildes/tildes/views/exceptions.py +++ b/tildes/tildes/views/exceptions.py @@ -83,11 +83,10 @@ def generic_error_page(request: Request) -> dict: request.response.status_int = request.exception.status_int error = f"Error {request.exception.status_code} ({request.exception.title})" - description = "" if isinstance(request.exception, HTTPForbidden): - description = request.exception - elif isinstance(request.exception, HTTPUnprocessableEntity) and isinstance( + description = "You don't have access to this page" + if isinstance(request.exception, HTTPUnprocessableEntity) and isinstance( request.exception.__context__, ValidationError ): errors = errors_from_validationerror(request.exception.__context__) @@ -95,14 +94,7 @@ def generic_error_page(request: Request) -> dict: else: description = request.exception.explanation - # For debugging, add the exception details - debug_info = { - "message": str(request.exception), - "type": str(type(request.exception)), - "args": request.exception.args, - } - - return {"error": error, "description": description, "debug_info": debug_info} + return {"error": error, "description": description} @forbidden_view_config(xhr=False) @@ -112,3 +104,4 @@ def logged_out_forbidden(request: Request) -> HTTPFound: login_url = request.route_url("login", _query={"from_url": forbidden_path}) return HTTPFound(location=login_url) +