From 7dca46b94b8f2dbc04db16979a54ba33a08fc43e Mon Sep 17 00:00:00 2001 From: Christian Krakau-Louis Date: Thu, 3 Apr 2025 22:12:12 +0200 Subject: [PATCH] feat: add license page and version display in templates, update LICENSE file, and enhance footer with license information --- Dockerfile | 1 + LICENSE | 15 ++---------- app/views/base.py | 14 +++++++++++ app/views/general.py | 41 +++++++++++++++++++++++++++++++++ frontend/templates/base.html | 3 ++- frontend/templates/license.html | 23 ++++++++++++++++++ frontend/templates/version.html | 1 + 7 files changed, 84 insertions(+), 14 deletions(-) create mode 100644 frontend/templates/license.html create mode 100644 frontend/templates/version.html diff --git a/Dockerfile b/Dockerfile index ad490bfc..a31c46e5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,6 +19,7 @@ COPY --from=builder /usr/local/bin /usr/local/bin COPY ./app /app/app COPY ./frontend /app/frontend COPY ./VERSION /app/VERSION +COPY ./LICENSE /app/LICENSE # Set Python path explicitly ENV PYTHONPATH=/app diff --git a/LICENSE b/LICENSE index 29f81d81..7db58f12 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ - Apache License +Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ @@ -175,18 +175,7 @@ END OF TERMS AND CONDITIONS - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] + Copyright 2025 Christian Krakau-Louis Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/app/views/base.py b/app/views/base.py index 247515f3..11849d13 100644 --- a/app/views/base.py +++ b/app/views/base.py @@ -15,6 +15,20 @@ from app.config import settings templates_dir = Path(__file__).parent.parent.parent / "frontend" / "templates" templates = Jinja2Templates(directory=str(templates_dir)) +# Customize Jinja2Templates to include app_version in all templates +original_template_response = templates.TemplateResponse + +def template_response_with_version(*args, **kwargs): + """Wrapper for TemplateResponse to include version in all templates""" + # If context dict is provided, add version to it + if len(args) >= 2 and isinstance(args[1], dict): + args[1].setdefault("version", settings.version) + elif "context" in kwargs and isinstance(kwargs["context"], dict): + kwargs["context"].setdefault("version", settings.version) + return original_template_response(*args, **kwargs) + +templates.TemplateResponse = template_response_with_version + # Set up logging logger = logging.getLogger(__name__) diff --git a/app/views/general.py b/app/views/general.py index 5bfc4ad5..ba82c59b 100644 --- a/app/views/general.py +++ b/app/views/general.py @@ -33,3 +33,44 @@ def favicon(): # If favicon doesn't exist, return a 404 raise HTTPException(status_code=404, detail="Favicon not found") return FileResponse(favicon_path) + +@router.get("/license", include_in_schema=False) +async def serve_license(request: Request): + """Serve the license page.""" + # Try multiple possible locations for the license file + possible_locations = [ + Path(__file__).parent.parent.parent / "LICENSE", # Repository root + Path("/app/LICENSE"), # Docker container path + Path.home() / "LICENSE", # Home directory (fallback) + ] + + license_text = None + + # Try to read from any of the possible locations + for path in possible_locations: + try: + with open(path, "r") as f: + license_text = f.read() + break # File found and read, exit loop + except (FileNotFoundError, PermissionError): + continue # Try next location + + # If license text is still None, use embedded text + if license_text is None: + license_text = """ +Apache License +Version 2.0, January 2004 +http://www.apache.org/licenses/ + +This software is licensed under the Apache License 2.0. +The full license text could not be located on this system. +Please visit http://www.apache.org/licenses/LICENSE-2.0 for the complete license text. +""" + + return templates.TemplateResponse( + "license.html", + { + "request": request, + "license_text": license_text + } + ) diff --git a/frontend/templates/base.html b/frontend/templates/base.html index 9a958df7..2466ed69 100644 --- a/frontend/templates/base.html +++ b/frontend/templates/base.html @@ -104,7 +104,8 @@
- © 2025 DocuNova. All rights reserved. + DocuNova 2025 - Licensed under Apache License 2.0 - + Version {{ app_version|default(version, true) }}
diff --git a/frontend/templates/license.html b/frontend/templates/license.html new file mode 100644 index 00000000..b51416a4 --- /dev/null +++ b/frontend/templates/license.html @@ -0,0 +1,23 @@ +{% extends "base.html" %} + +{% block title %}DocuNova - License{% endblock %} + +{% block content %} +
+

License Information

+ +
+

Apache License 2.0

+ +
+
{{ license_text }}
+
+ +

+ DocuNova is distributed under the Apache License 2.0, which is a permissive + open-source software license that allows you to use, modify, distribute, and + contribute to the project. +

+
+
+{% endblock %} diff --git a/frontend/templates/version.html b/frontend/templates/version.html new file mode 100644 index 00000000..697e7527 --- /dev/null +++ b/frontend/templates/version.html @@ -0,0 +1 @@ +{{ version }}