Phase 1 fix auth redirect API handling and route issues

This commit is contained in:
A R R R Associates
2026-06-25 20:33:15 +05:30
parent f07544cfd7
commit b97af0ea1e
22 changed files with 185 additions and 37 deletions
+20 -7
View File
@@ -106,7 +106,8 @@ def _render(request: Request, template: str, db, user, **ctx):
def _redirect_denied():
return RedirectResponse(url="/system-settings", status_code=303)
from app.core.http_responses import ui_access_denied
return ui_access_denied()
def _require_user(request: Request, db, permission_code: str):
@@ -382,10 +383,13 @@ def download_latest_document(request: Request, document_id: int):
return response
scope = build_document_scope(request, db, user)
document = get_document(db, document_id)
if not document:
from app.core.http_responses import not_found_response
return not_found_response(request, "Document not found")
active_fy = _active_financial_year(request)
if active_fy and document and getattr(document, "financial_year", None) != active_fy:
return RedirectResponse(url=f"/documents?financial_year={active_fy}&error=wrong_year", status_code=303)
if not document or not document.engagement or not user_can_view_engagement(db, user, document.engagement, scope):
if not document.engagement or not user_can_view_engagement(db, user, document.engagement, scope):
return _redirect_denied()
version = get_latest_version(document)
if not version:
@@ -404,11 +408,14 @@ def download_document_version(request: Request, version_id: int):
return response
scope = build_document_scope(request, db, user)
version = get_version(db, version_id)
document = version.document if version else None
if not version:
from app.core.http_responses import not_found_response
return not_found_response(request, "Document version not found")
document = version.document
active_fy = _active_financial_year(request)
if active_fy and document and getattr(document, "financial_year", None) != active_fy:
return RedirectResponse(url=f"/documents?financial_year={active_fy}&error=wrong_year", status_code=303)
if not version or not document or not document.engagement or not user_can_view_engagement(db, user, document.engagement, scope):
if not document or not document.engagement or not user_can_view_engagement(db, user, document.engagement, scope):
return _redirect_denied()
return _download_or_queue_from_local_node(request, db, user, document, version, action="download_version")
finally:
@@ -578,7 +585,10 @@ def download_latest_permanent_document(request: Request, document_id: int):
return response
scope = build_document_scope(request, db, user)
document = get_permanent_document(db, document_id)
if not document or not document.client or not user_can_view_client_documents(db, user, document.client, scope):
if not document:
from app.core.http_responses import not_found_response
return not_found_response(request, "Permanent document not found")
if not document.client or not user_can_view_client_documents(db, user, document.client, scope):
return _redirect_denied()
version = get_latest_permanent_version(document)
if not version:
@@ -597,8 +607,11 @@ def download_permanent_version(request: Request, version_id: int):
return response
scope = build_document_scope(request, db, user)
version = get_permanent_version(db, version_id)
document = version.document if version else None
if not version or not document or not document.client or not user_can_view_client_documents(db, user, document.client, scope):
if not version:
from app.core.http_responses import not_found_response
return not_found_response(request, "Permanent document version not found")
document = version.document
if not document or not document.client or not user_can_view_client_documents(db, user, document.client, scope):
return _redirect_denied()
return _download_or_queue_permanent_from_local_node(request, db, user, document, version)
finally: