From c71bd130e0ba82f1cf409c49ac641a2834cd7036 Mon Sep 17 00:00:00 2001 From: Fredrik Jonsson Date: Mon, 31 Aug 2026 15:21:15 +0200 Subject: [PATCH 1/4] Use WAGTAILADMIN_BASE_URL to build all e-mail links etc. --- docker/prod/.env.example | 2 +- .../deployment/development/stand-alone.md | 2 +- .../deployment/production/stand-alone.md | 2 +- hypha/apply/activity/adapters/slack.py | 7 ++-- hypha/apply/activity/adapters/utils.py | 5 ++- .../messages/email/applicant_base.html | 4 +- .../messages/email/assign_paf_approvers.html | 2 +- .../messages/email/author_updated.html | 4 +- .../messages/email/batch_ready_to_review.html | 2 +- .../templates/messages/email/comment.html | 2 +- .../messages/email/comment_assigned.html | 2 +- .../messages/email/contract_uploaded.html | 6 +-- .../messages/email/determination.html | 2 +- .../messages/email/invite_co_applicant.html | 2 +- .../messages/email/invited_to_proposal.html | 4 +- .../messages/email/invoice_approved.html | 2 +- .../messages/email/invoice_created.html | 2 +- .../invoice_status_updated_applicant.html | 4 +- .../email/invoice_status_updated_staff.html | 4 +- .../messages/email/invoice_updated.html | 2 +- .../messages/email/paf_for_approval.html | 2 +- .../email/project_final_approval.html | 2 +- .../email/project_request_change.html | 4 +- .../messages/email/ready_for_contracting.html | 2 +- .../messages/email/ready_to_review.html | 2 +- .../messages/email/report_submitted.html | 2 +- .../messages/email/sent_to_compliance.html | 2 +- .../email/submission_confirmation.html | 4 +- .../email/submit_contract_documents.html | 2 +- .../templates/messages/email/transition.html | 2 +- .../management/commands/send_reminders.py | 12 +----- hypha/apply/funds/models/submissions.py | 1 - .../management/commands/notify_report_due.py | 9 +---- .../projects/reports/tests/test_commands.py | 32 ++++++++++----- hypha/apply/todo/options.py | 4 +- hypha/apply/todo/views.py | 2 +- hypha/apply/users/models.py | 7 +--- hypha/apply/users/services.py | 5 --- hypha/apply/users/signals.py | 2 - .../templates/users/activation/email.txt | 10 ++--- .../users/email_change/confirm_email.txt | 6 +-- .../users/email_change/update_info_email.html | 4 +- .../templates/users/emails/confirm_access.md | 4 +- .../users/emails/login_notification.md | 4 +- .../emails/passkey_added_notification.md | 4 +- .../emails/passkey_removed_notification.md | 4 +- .../users/emails/passwordless_login_email.md | 6 +-- .../emails/passwordless_new_account_login.md | 6 +-- .../templates/users/emails/set_password.txt | 6 +-- .../templates/users/password_reset/email.txt | 6 +-- hypha/apply/users/tests/test_views.py | 3 +- hypha/apply/users/utils.py | 9 +---- hypha/apply/users/views.py | 7 ---- hypha/apply/users/wagtail_hooks.py | 4 +- hypha/core/apps.py | 3 ++ hypha/core/checks.py | 39 +++++++++++++++++++ hypha/core/context_processors.py | 2 + hypha/core/templatetags/util_tags.py | 12 ++++++ hypha/core/tests/test_checks.py | 18 +++++++++ hypha/core/tests/test_utils.py | 21 +++++++++- hypha/core/utils.py | 22 +++++++++++ hypha/settings/base.py | 13 +++++-- 62 files changed, 233 insertions(+), 140 deletions(-) create mode 100644 hypha/core/checks.py create mode 100644 hypha/core/tests/test_checks.py diff --git a/docker/prod/.env.example b/docker/prod/.env.example index 657187a919..9dac1decda 100644 --- a/docker/prod/.env.example +++ b/docker/prod/.env.example @@ -1,7 +1,7 @@ DJANGO_SETTINGS_MODULE="hypha.settings.production" SECRET_KEY="changeme" -PRIMARY_HOST="https://test.hypha.app" +WAGTAILADMIN_BASE_URL="https://test.hypha.app" EMAIL_HOST="hypha.app" EMAIL_SUBJECT_PREFIX="[Hypha] " diff --git a/docs/setup/deployment/development/stand-alone.md b/docs/setup/deployment/development/stand-alone.md index 1f0b88ea9e..d90eca7038 100644 --- a/docs/setup/deployment/development/stand-alone.md +++ b/docs/setup/deployment/development/stand-alone.md @@ -162,7 +162,7 @@ Hypha supports configuration via either a `local.py` or a `.env` file: ```bash title="./.env" ALLOWED_HOSTS=hypha.test - BASE_URL=http://hypha.test + WAGTAILADMIN_BASE_URL=http://hypha.test SECRET_KEY= DATABASE_URL=postgres://localhost/hypha ``` diff --git a/docs/setup/deployment/production/stand-alone.md b/docs/setup/deployment/production/stand-alone.md index c1785a28fb..ebcef07d58 100644 --- a/docs/setup/deployment/production/stand-alone.md +++ b/docs/setup/deployment/production/stand-alone.md @@ -175,7 +175,7 @@ Here is a list of settings that can be set as environment variables or in a `hyp ```text SECRET_KEY: [KEY] DJANGO_SETTINGS_MODULE: hypha.settings.production -PRIMARY_HOST: www.example.org +WAGTAILADMIN_BASE_URL: https://apply.example.org EMAIL_HOST: example.org ORG_EMAIL: hello@example.org ORG_GUIDE_URL: https://guide.example.org/ diff --git a/hypha/apply/activity/adapters/slack.py b/hypha/apply/activity/adapters/slack.py index cc7f98348a..9aae54345f 100644 --- a/hypha/apply/activity/adapters/slack.py +++ b/hypha/apply/activity/adapters/slack.py @@ -168,11 +168,10 @@ def slack_links(self, links, sources): def extra_kwargs(self, message_type, **kwargs): source = kwargs["source"] sources = kwargs["sources"] - request = kwargs["request"] related = kwargs["related"] - link = link_to(source, request) - link_related = link_to(related, request) - links = {source.id: link_to(source, request) for source in sources} + link = link_to(source) + link_related = link_to(related) + links = {source.id: link_to(source) for source in sources} return { "link": link, "link_related": link_related, diff --git a/hypha/apply/activity/adapters/utils.py b/hypha/apply/activity/adapters/utils.py index 30578707c6..423514dcbb 100644 --- a/hypha/apply/activity/adapters/utils.py +++ b/hypha/apply/activity/adapters/utils.py @@ -20,11 +20,12 @@ FINANCE_GROUP_NAME, STAFF_GROUP_NAME, ) +from hypha.core.utils import get_base_url -def link_to(target, request): +def link_to(target): if target and hasattr(target, "get_absolute_url"): - return request.scheme + "://" + request.get_host() + target.get_absolute_url() + return get_base_url() + target.get_absolute_url() def group_reviewers(reviewers): diff --git a/hypha/apply/activity/templates/messages/email/applicant_base.html b/hypha/apply/activity/templates/messages/email/applicant_base.html index f0e7b57fa3..f091788323 100644 --- a/hypha/apply/activity/templates/messages/email/applicant_base.html +++ b/hypha/apply/activity/templates/messages/email/applicant_base.html @@ -11,9 +11,9 @@ {% block salutation %}{% blocktrans with name=source.user.get_full_name|default:"applicant" %}Dear {{ name }},{% endblocktrans %}{% endblock %} {# fmt:off #} -{% block more_info %}{% if source.submission %}{% trans "View your project here" %}{% else %}{% trans "View your submission here" %}{% endif %}: {{ request.scheme }}://{{ request.get_host }}{{ source.get_absolute_url }} +{% block more_info %}{% if source.submission %}{% trans "View your project here" %}{% else %}{% trans "View your submission here" %}{% endif %}: {{ BASE_URL }}{{ source.get_absolute_url }} -{% trans "If you have any questions, please submit them here" %}: {{ request.scheme }}://{{ request.get_host }}{% if source.submission %}{% url 'funds:submissions:comments' pk=source.submission.pk %}{% else %}{% url 'funds:submissions:comments' pk=source.pk %}{% endif %} +{% trans "If you have any questions, please submit them here" %}: {{ BASE_URL }}{% if source.submission %}{% url 'funds:submissions:comments' pk=source.submission.pk %}{% else %}{% url 'funds:submissions:comments' pk=source.pk %}{% endif %} {% trans "See our guide for more information" %}: {{ ORG_GUIDE_URL }} diff --git a/hypha/apply/activity/templates/messages/email/assign_paf_approvers.html b/hypha/apply/activity/templates/messages/email/assign_paf_approvers.html index 22df57998f..d79667aca7 100644 --- a/hypha/apply/activity/templates/messages/email/assign_paf_approvers.html +++ b/hypha/apply/activity/templates/messages/email/assign_paf_approvers.html @@ -7,7 +7,7 @@ {% trans "Project documents are ready to be assigned for approval." %} {% trans "Title" %}: {{ source.title_text_display }} -{% trans "Link" %}: {{ request.scheme }}://{{ request.get_host }}{% url 'apply:projects:approval' pk=source.pk %} +{% trans "Link" %}: {{ BASE_URL }}{% url 'apply:projects:approval' pk=source.pk %} {% blocktrans with lead=source.lead email=source.lead.email %}Please contact {{ lead }} - {{ email }} if you have any questions.{% endblocktrans %} {% endblock %}{# fmt:on #} diff --git a/hypha/apply/activity/templates/messages/email/author_updated.html b/hypha/apply/activity/templates/messages/email/author_updated.html index 8aea1da574..b5cab700e0 100644 --- a/hypha/apply/activity/templates/messages/email/author_updated.html +++ b/hypha/apply/activity/templates/messages/email/author_updated.html @@ -7,8 +7,8 @@ {% endblock %} {% block more_info %} -{% trans "Link to your submission" %}: {{ request.scheme }}://{{ request.get_host }}{{ source.get_absolute_url }} -{% trans "If you have any questions, please submit them here" %}: {{ request.scheme }}://{{ request.get_host }}{{ source.get_absolute_url }}#communications +{% trans "Link to your submission" %}: {{ BASE_URL }}{{ source.get_absolute_url }} +{% trans "If you have any questions, please submit them here" %}: {{ BASE_URL }}{{ source.get_absolute_url }}#communications {% trans "See our guide for more information" %}: {{ ORG_GUIDE_URL }} diff --git a/hypha/apply/activity/templates/messages/email/batch_ready_to_review.html b/hypha/apply/activity/templates/messages/email/batch_ready_to_review.html index af7542b521..25aa64c1c2 100644 --- a/hypha/apply/activity/templates/messages/email/batch_ready_to_review.html +++ b/hypha/apply/activity/templates/messages/email/batch_ready_to_review.html @@ -7,7 +7,7 @@ {% trans "New applications have been added to your review list." %} {% for submission in sources %} {% trans "Title" %}: {{ submission.title_text_display }} -{% trans "Link" %}: {{ request.scheme }}://{{ request.get_host }}{{ submission.get_absolute_url }} +{% trans "Link" %}: {{ BASE_URL }}{{ submission.get_absolute_url }} {% endfor %} {% endblock %}{# fmt:on #} diff --git a/hypha/apply/activity/templates/messages/email/comment.html b/hypha/apply/activity/templates/messages/email/comment.html index 959ccad860..77020f29dd 100644 --- a/hypha/apply/activity/templates/messages/email/comment.html +++ b/hypha/apply/activity/templates/messages/email/comment.html @@ -9,7 +9,7 @@ {% display_name_for_email user as display_user %} {% blocktrans with title=source.title user=comment.user %}There has been a new comment on "{{ title }}" by {{ display_user }}.{% endblocktrans %} -{% trans "Read the full comment here" %}: {{ request.scheme }}://{{ request.get_host }}{{ comment.get_absolute_url }} +{% trans "Read the full comment here" %}: {{ BASE_URL }}{{ comment.get_absolute_url }} {% endblock %} {% block more_info %} diff --git a/hypha/apply/activity/templates/messages/email/comment_assigned.html b/hypha/apply/activity/templates/messages/email/comment_assigned.html index 9b86afe85b..7e2b9a7b55 100644 --- a/hypha/apply/activity/templates/messages/email/comment_assigned.html +++ b/hypha/apply/activity/templates/messages/email/comment_assigned.html @@ -9,5 +9,5 @@ {% endblock %} {% block more_info %} -{% trans "View it here" %}: {{ request.scheme }}://{{ request.get_host }}{{ comment.get_absolute_url }} +{% trans "View it here" %}: {{ BASE_URL }}{{ comment.get_absolute_url }} {% endblock %} \ No newline at end of file diff --git a/hypha/apply/activity/templates/messages/email/contract_uploaded.html b/hypha/apply/activity/templates/messages/email/contract_uploaded.html index 646113a2d3..ddef21546c 100644 --- a/hypha/apply/activity/templates/messages/email/contract_uploaded.html +++ b/hypha/apply/activity/templates/messages/email/contract_uploaded.html @@ -13,7 +13,7 @@ {% trans "A new contract has been added to your Project" %}: {% trans "Title" %}: {{ source.title_text_display }} -{% trans "Link" %}: {{ request.scheme }}://{{ request.get_host }}{{ source.get_absolute_url }} +{% trans "Link" %}: {{ BASE_URL }}{{ source.get_absolute_url }} {% if contract.is_signed %} {% trans "This contract has already been signed and there is no action for you to take." %} @@ -25,8 +25,8 @@ {% block more_info %} {% if request.user != source.user %} -{% trans "View your project here" %}: {{ request.scheme }}://{{ request.get_host }}{{ source.get_absolute_url }} -{% trans "If you have any questions, please submit them here" %}: {{ request.scheme }}://{{ request.get_host }}{% url 'funds:submissions:comments' pk=source.submission.pk %} +{% trans "View your project here" %}: {{ BASE_URL }}{{ source.get_absolute_url }} +{% trans "If you have any questions, please submit them here" %}: {{ BASE_URL }}{% url 'funds:submissions:comments' pk=source.submission.pk %} {% trans "See our guide for more information" %}: {{ ORG_GUIDE_URL }} diff --git a/hypha/apply/activity/templates/messages/email/determination.html b/hypha/apply/activity/templates/messages/email/determination.html index 42ca483433..1ca3eb27d0 100644 --- a/hypha/apply/activity/templates/messages/email/determination.html +++ b/hypha/apply/activity/templates/messages/email/determination.html @@ -6,5 +6,5 @@ {{ determination.message|nh3|striptags }} -{% trans "Read the full determination here" %}: {{ request.scheme }}://{{ request.get_host }}{{ determination.get_absolute_url }} +{% trans "Read the full determination here" %}: {{ BASE_URL }}{{ determination.get_absolute_url }} {% endblock %}{# fmt:on #} diff --git a/hypha/apply/activity/templates/messages/email/invite_co_applicant.html b/hypha/apply/activity/templates/messages/email/invite_co_applicant.html index caa97b38c0..451a4d24e9 100644 --- a/hypha/apply/activity/templates/messages/email/invite_co_applicant.html +++ b/hypha/apply/activity/templates/messages/email/invite_co_applicant.html @@ -10,6 +10,6 @@ {% else %} {% blocktrans %}Click on link if you want to accept it.{% endblocktrans %} -{% trans "Link" %}: {{ request.scheme }}://{{ request.get_host }}{{ accept_link }} +{% trans "Link" %}: {{ BASE_URL }}{{ accept_link }} {% endif %} {% endblock %}{# fmt:on #} diff --git a/hypha/apply/activity/templates/messages/email/invited_to_proposal.html b/hypha/apply/activity/templates/messages/email/invited_to_proposal.html index 0728dabc83..0f22450bcd 100644 --- a/hypha/apply/activity/templates/messages/email/invited_to_proposal.html +++ b/hypha/apply/activity/templates/messages/email/invited_to_proposal.html @@ -7,8 +7,8 @@ {% blocktrans %}Please review our Proposal Guide at {{ ORG_GUIDE_URL }} to learn more about the information we’d like to see. In the proposal please also address the feedback we provided in the concept note determination.{% endblocktrans %}{% endblock %} {% block more_info %} -{% trans "Here is the link to start creating your proposal" %}: {{ request.scheme }}://{{ request.get_host }}{{ source.get_absolute_url }} -{% trans "If you have any questions, please submit them here" %}: {{ request.scheme }}://{{ request.get_host }}{% url 'funds:submissions:comments' pk=source.pk %} +{% trans "Here is the link to start creating your proposal" %}: {{ BASE_URL }}{{ source.get_absolute_url }} +{% trans "If you have any questions, please submit them here" %}: {{ BASE_URL }}{% url 'funds:submissions:comments' pk=source.pk %} {% blocktrans %}The system will allow you to save a draft of your proposal as you work on it. When you feel it is ready for our review, please click the “Submit” button and we’ll know to take a look at it. We’ll reply to you with feedback on your Proposal as quickly as possible.{% endblocktrans %} diff --git a/hypha/apply/activity/templates/messages/email/invoice_approved.html b/hypha/apply/activity/templates/messages/email/invoice_approved.html index 17523792ad..2eec23c88d 100644 --- a/hypha/apply/activity/templates/messages/email/invoice_approved.html +++ b/hypha/apply/activity/templates/messages/email/invoice_approved.html @@ -5,7 +5,7 @@ {% block content %}{# fmt:off #} {% blocktrans with title=source.title_text_display %}An invoice on project "{{title}}" is waiting for your approval.{% endblocktrans %} -{% trans "View the invoice here" %}: {{ request.scheme }}://{{ request.get_host }}{{ invoice.get_absolute_url }} +{% trans "View the invoice here" %}: {{ BASE_URL }}{{ invoice.get_absolute_url }} {% blocktrans with lead=source.lead email=source.lead.email %}Please contact {{ lead }} - {{ email }} if you have any questions.{% endblocktrans %} {% endblock %}{# fmt:on #} diff --git a/hypha/apply/activity/templates/messages/email/invoice_created.html b/hypha/apply/activity/templates/messages/email/invoice_created.html index 5a10da38ee..ce83ab1624 100644 --- a/hypha/apply/activity/templates/messages/email/invoice_created.html +++ b/hypha/apply/activity/templates/messages/email/invoice_created.html @@ -5,6 +5,6 @@ {% block content %}{# fmt:off #} {% blocktrans with title=source.title_text_display %}A new invoice has been submitted for project "{{title}}".{% endblocktrans %} -{% trans "View the invoice here" %}: {{ request.scheme }}://{{ request.get_host }}{{ related.get_absolute_url }} +{% trans "View the invoice here" %}: {{ BASE_URL }}{{ related.get_absolute_url }} {% endblock %}{# fmt:on #} diff --git a/hypha/apply/activity/templates/messages/email/invoice_status_updated_applicant.html b/hypha/apply/activity/templates/messages/email/invoice_status_updated_applicant.html index 12f4d699a7..cd4ae2b9f4 100644 --- a/hypha/apply/activity/templates/messages/email/invoice_status_updated_applicant.html +++ b/hypha/apply/activity/templates/messages/email/invoice_status_updated_applicant.html @@ -9,9 +9,9 @@ {% blocktrans with status=invoice_status %}It's status is now "{{ status }}".{% endblocktrans %} {% if invoice.comment %} -{% trans "A staff member left a comment that can be read here" %}: {{ request.scheme }}://{{ request.get_host }}{{ comment_url }} +{% trans "A staff member left a comment that can be read here" %}: {{ BASE_URL }}{{ comment_url }} {% endif %} -{% trans "View your invoice here" %}: {{ request.scheme }}://{{ request.get_host }}{{ invoice.get_absolute_url }} +{% trans "View your invoice here" %}: {{ BASE_URL }}{{ invoice.get_absolute_url }} {% endblock %}{# fmt:on #} diff --git a/hypha/apply/activity/templates/messages/email/invoice_status_updated_staff.html b/hypha/apply/activity/templates/messages/email/invoice_status_updated_staff.html index 1bd5480a84..9a44e4ad92 100644 --- a/hypha/apply/activity/templates/messages/email/invoice_status_updated_staff.html +++ b/hypha/apply/activity/templates/messages/email/invoice_status_updated_staff.html @@ -9,9 +9,9 @@ {% blocktrans with status=invoice_status %}It's status is now "{{ status }}".{% endblocktrans %} {% if invoice.comment %} -{% trans "A comment was left that can be read here" %}: {{ request.scheme }}://{{ request.get_host }}{{ comment_url }} +{% trans "A comment was left that can be read here" %}: {{ BASE_URL }}{{ comment_url }} {% endif %} -{% trans "View the invoice here" %}: {{ request.scheme }}://{{ request.get_host }}{{ invoice.get_absolute_url }} +{% trans "View the invoice here" %}: {{ BASE_URL }}{{ invoice.get_absolute_url }} {% endblock %}{# fmt:on #} diff --git a/hypha/apply/activity/templates/messages/email/invoice_updated.html b/hypha/apply/activity/templates/messages/email/invoice_updated.html index 03c157d06e..570f7bfb9d 100644 --- a/hypha/apply/activity/templates/messages/email/invoice_updated.html +++ b/hypha/apply/activity/templates/messages/email/invoice_updated.html @@ -5,5 +5,5 @@ {% blocktrans with title=source.title_text_display %}An {{ ORG_SHORT_NAME }} staff member has updated an invoice on your project "{{ title }}".{% endblocktrans %} -{% trans "View the invoice here:" %}: {{ request.scheme }}://{{ request.get_host }}{{ source.get_absolute_url }} +{% trans "View the invoice here:" %}: {{ BASE_URL }}{{ source.get_absolute_url }} {% endblock %}{# fmt:on #} diff --git a/hypha/apply/activity/templates/messages/email/paf_for_approval.html b/hypha/apply/activity/templates/messages/email/paf_for_approval.html index c15f334ad0..967db74e59 100644 --- a/hypha/apply/activity/templates/messages/email/paf_for_approval.html +++ b/hypha/apply/activity/templates/messages/email/paf_for_approval.html @@ -6,7 +6,7 @@ {% block content %}{# fmt:off #} {% blocktrans with title=source.title_text_display %}The {{ title }} project is awaiting your review.{% endblocktrans %} -{% trans "View the project here" %}: {{ request.scheme }}://{{ request.get_host }}{% url 'apply:projects:approval' pk=source.pk %} +{% trans "View the project here" %}: {{ BASE_URL }}{% url 'apply:projects:approval' pk=source.pk %} {% blocktrans with lead=source.lead email=source.lead.email %}Please contact {{ lead }} - {{ email }} if you have any questions.{% endblocktrans %} {% endblock %}{# fmt:on #} diff --git a/hypha/apply/activity/templates/messages/email/project_final_approval.html b/hypha/apply/activity/templates/messages/email/project_final_approval.html index 253048f0a0..1c65b3764c 100644 --- a/hypha/apply/activity/templates/messages/email/project_final_approval.html +++ b/hypha/apply/activity/templates/messages/email/project_final_approval.html @@ -6,7 +6,7 @@ {% block content %}{# fmt:off #} {% blocktrans with title=source.title_text_display %}The project "{{title}}" is awaiting final approval.{% endblocktrans %} -{% trans "Approve the project here" %}: {{ request.scheme }}://{{ request.get_host }}{% url 'apply:projects:approval' pk=source.pk %} +{% trans "Approve the project here" %}: {{ BASE_URL }}{% url 'apply:projects:approval' pk=source.pk %} {% blocktrans with lead=source.lead email=source.lead.email %}Please contact {{ lead }} - {{ email }} if you have any questions.{% endblocktrans %} {% endblock %}{# fmt:on #} diff --git a/hypha/apply/activity/templates/messages/email/project_request_change.html b/hypha/apply/activity/templates/messages/email/project_request_change.html index 43e83d0f44..6f03523fad 100644 --- a/hypha/apply/activity/templates/messages/email/project_request_change.html +++ b/hypha/apply/activity/templates/messages/email/project_request_change.html @@ -7,8 +7,8 @@ {% blocktrans with title=source.title_text_display %}The project forms for "{{ title }}" was rejected by project form reviewers, please update it accordingly and resubmit it to the reviewers. {% endblocktrans %} {% if comment_url %} -{% trans "A comment was left that can be viewed here" %}: {{ request.scheme }}://{{ request.get_host }}{{ comment_url }} +{% trans "A comment was left that can be viewed here" %}: {{ BASE_URL }}{{ comment_url }} {% endif %} -{% trans "View the project here" %}: {{ request.scheme }}://{{ request.get_host }}{{ source.get_absolute_url }} +{% trans "View the project here" %}: {{ BASE_URL }}{{ source.get_absolute_url }} {% endblock %}{# fmt:on #} diff --git a/hypha/apply/activity/templates/messages/email/ready_for_contracting.html b/hypha/apply/activity/templates/messages/email/ready_for_contracting.html index 92f3280060..b7dfbc7efb 100644 --- a/hypha/apply/activity/templates/messages/email/ready_for_contracting.html +++ b/hypha/apply/activity/templates/messages/email/ready_for_contracting.html @@ -6,7 +6,7 @@ {% block content %}{# fmt:off #} {% blocktrans with title=source.title_text_display%}The project "{{ title }}" is waiting for contract.{% endblocktrans %} -{% trans "View the project here" %}: {{ request.scheme }}://{{ request.get_host }}{{ source.get_absolute_url }} +{% trans "View the project here" %}: {{ BASE_URL }}{{ source.get_absolute_url }} {% blocktrans with lead=source.lead email=source.lead.email %}Please contact {{ lead }} - {{ email }} if you have any questions.{% endblocktrans %} {% endblock %}{# fmt:on #} diff --git a/hypha/apply/activity/templates/messages/email/ready_to_review.html b/hypha/apply/activity/templates/messages/email/ready_to_review.html index 5495ce9109..80b54af41e 100644 --- a/hypha/apply/activity/templates/messages/email/ready_to_review.html +++ b/hypha/apply/activity/templates/messages/email/ready_to_review.html @@ -8,5 +8,5 @@ {% trans "Title" %}: {{ source.title_text_display }} {% if related.title %}{% trans "Reminder Title" %}: {{ related.title }}{% endif %} {% if related.description %}{% trans "Reminder Description" %}: {{ related.description }}{% endif %} -{% trans "Link" %}: {{ request.scheme }}://{{ request.get_host }}{{ source.get_absolute_url }} +{% trans "Link" %}: {{ BASE_URL }}{{ source.get_absolute_url }} {% endblock %}{# fmt:on #} diff --git a/hypha/apply/activity/templates/messages/email/report_submitted.html b/hypha/apply/activity/templates/messages/email/report_submitted.html index 6ea48b821e..a6cb0942a3 100644 --- a/hypha/apply/activity/templates/messages/email/report_submitted.html +++ b/hypha/apply/activity/templates/messages/email/report_submitted.html @@ -5,5 +5,5 @@ {% block content %}{# fmt:off #} {% blocktrans with title=source.title_text_display start_date=report.start_date end_date=report.end_date %}An {{ ORG_SHORT_NAME }} staff member has submitted a report for your project "{{ title }}" for period {{ start_date }} to {{ end_date }}.{% endblocktrans %} -{% trans "You can review the report here" %}: {{ request.scheme }}://{{ request.get_host }}{{ report.get_absolute_url }} +{% trans "You can review the report here" %}: {{ BASE_URL }}{{ report.get_absolute_url }} {% endblock %}{# fmt:on #} diff --git a/hypha/apply/activity/templates/messages/email/sent_to_compliance.html b/hypha/apply/activity/templates/messages/email/sent_to_compliance.html index 51e3a425f1..c101ff1442 100644 --- a/hypha/apply/activity/templates/messages/email/sent_to_compliance.html +++ b/hypha/apply/activity/templates/messages/email/sent_to_compliance.html @@ -6,7 +6,7 @@ {% block content %}{# fmt:off #} {% blocktrans with title=source.title_text_display %}The project "{{ title }}" is awaiting your review.{% endblocktrans %} -{% trans "View the project here" %}: {{ request.scheme }}://{{ request.get_host }}{% url 'apply:projects:approval' pk=source.pk %} +{% trans "View the project here" %}: {{ BASE_URL }}{% url 'apply:projects:approval' pk=source.pk %} {% blocktrans with lead=source.lead email=source.lead.email %}Please contact {{ lead }} - {{ email }} if you have any questions.{% endblocktrans %} {% endblock %}{# fmt:on #} diff --git a/hypha/apply/activity/templates/messages/email/submission_confirmation.html b/hypha/apply/activity/templates/messages/email/submission_confirmation.html index c457653107..990b2a740e 100644 --- a/hypha/apply/activity/templates/messages/email/submission_confirmation.html +++ b/hypha/apply/activity/templates/messages/email/submission_confirmation.html @@ -5,9 +5,9 @@ {% block content %}{# fmt:off #} {% blocktrans with title=source.title %}We appreciate your "{{ title }}" application submission to the {{ ORG_LONG_NAME }}.{% endblocktrans %} -{% if source.is_draft %}{% trans "Please note that it is not submitted for review because it's still in draft." %} {% trans "You can access the draft at" %}: {{ request.scheme }}://{{ request.get_host }}{{ source.get_absolute_url }}{% else %}{% trans "We will review and reply to your submission as quickly as possible." %}{% endif %} +{% if source.is_draft %}{% trans "Please note that it is not submitted for review because it's still in draft." %} {% trans "You can access the draft at" %}: {{ BASE_URL }}{{ source.get_absolute_url }}{% else %}{% trans "We will review and reply to your submission as quickly as possible." %}{% endif %} -{% trans "If you have any questions, please submit them here" %}: {{ request.scheme }}://{{ request.get_host }}{% url 'funds:submissions:comments' pk=source.pk %} +{% trans "If you have any questions, please submit them here" %}: {{ BASE_URL }}{% url 'funds:submissions:comments' pk=source.pk %} {% blocktrans %}If you have issues accessing the submission system or general inquiries, please email us at {{ ORG_EMAIL }}.{% endblocktrans %} diff --git a/hypha/apply/activity/templates/messages/email/submit_contract_documents.html b/hypha/apply/activity/templates/messages/email/submit_contract_documents.html index afa7b227d8..1683bdcbaf 100644 --- a/hypha/apply/activity/templates/messages/email/submit_contract_documents.html +++ b/hypha/apply/activity/templates/messages/email/submit_contract_documents.html @@ -7,7 +7,7 @@ {% block content %}{# fmt:off #} {% blocktrans with title=source.title_text_display %}The contract for project "{{ title }}" is awaiting your review.{% endblocktrans %} -{% trans "View the project here" %}: {{ request.scheme }}://{{ request.get_host }}{{ source.get_absolute_url }} +{% trans "View the project here" %}: {{ BASE_URL }}{{ source.get_absolute_url }} {% blocktrans with lead=source.lead email=source.lead.email %}Please contact {{ lead }} - {{ email }} if you have any questions.{% endblocktrans %} {% endblock %}{# fmt:on #} diff --git a/hypha/apply/activity/templates/messages/email/transition.html b/hypha/apply/activity/templates/messages/email/transition.html index edd277ea68..4654251b2f 100644 --- a/hypha/apply/activity/templates/messages/email/transition.html +++ b/hypha/apply/activity/templates/messages/email/transition.html @@ -5,5 +5,5 @@ {% block content %}{# fmt:off #} {% blocktrans %}Your application is now in "{{ new_phase }}" status (progressed from "{{ old_phase }}").{% endblocktrans %} -{% trans "Please submit any questions related to your application here" %}: {{ request.scheme }}://{{ request.get_host }}{% url 'funds:submissions:comments' pk=source.pk %} +{% trans "Please submit any questions related to your application here" %}: {{ BASE_URL }}{% url 'funds:submissions:comments' pk=source.pk %} {% endblock %}{# fmt:on #} diff --git a/hypha/apply/funds/management/commands/send_reminders.py b/hypha/apply/funds/management/commands/send_reminders.py index 54d849dc3c..6cf74e0234 100644 --- a/hypha/apply/funds/management/commands/send_reminders.py +++ b/hypha/apply/funds/management/commands/send_reminders.py @@ -1,4 +1,3 @@ -from django.conf import settings from django.contrib.messages.storage.fallback import FallbackStorage from django.core.management.base import BaseCommand from django.http import HttpRequest @@ -6,22 +5,15 @@ from hypha.apply.activity.messaging import messenger from hypha.apply.funds.models import Reminder -from hypha.home.models import ApplyHomePage class Command(BaseCommand): help = "Send reminders" def handle(self, *args, **options): - site = ApplyHomePage.objects.first().get_site() - - # Mock a HTTPRequest in order to pass the site settings into the - # templates + # Mock a HTTPRequest as the messenger expects one. Links in the + # notifications are built from `get_base_url()`, not from the request. request = HttpRequest() - request.META["SERVER_NAME"] = site.hostname - request.META["SERVER_PORT"] = site.port - proxy_ssl_header, proxy_ssl_value = settings.SECURE_PROXY_SSL_HEADER - request.META[proxy_ssl_header] = proxy_ssl_value request.session = {} request._messages = FallbackStorage(request) diff --git a/hypha/apply/funds/models/submissions.py b/hypha/apply/funds/models/submissions.py index 8cf67a6a65..c52a7e5548 100644 --- a/hypha/apply/funds/models/submissions.py +++ b/hypha/apply/funds/models/submissions.py @@ -621,7 +621,6 @@ def ensure_user_has_account(self): else: self.user, _ = User.objects.get_or_create_and_notify( email=email, - site=self.page.get_site(), defaults={"full_name": full_name}, ) diff --git a/hypha/apply/projects/reports/management/commands/notify_report_due.py b/hypha/apply/projects/reports/management/commands/notify_report_due.py index 4ca5a51cc4..f6b629d226 100644 --- a/hypha/apply/projects/reports/management/commands/notify_report_due.py +++ b/hypha/apply/projects/reports/management/commands/notify_report_due.py @@ -1,5 +1,4 @@ from dateutil.relativedelta import relativedelta -from django.conf import settings from django.contrib.messages.storage.fallback import FallbackStorage from django.core.management.base import BaseCommand from django.http import HttpRequest @@ -20,13 +19,9 @@ class Command(BaseCommand): def handle(self, *args, **options): site = ApplyHomePage.objects.first().get_site() - # Mock a HTTPRequest in order to pass the site settings into the - # templates + # Mock a HTTPRequest as the messenger expects one. Links in the + # notifications are built from `get_base_url()`, not from the request. request = HttpRequest() - request.META["SERVER_NAME"] = site.hostname - request.META["SERVER_PORT"] = site.port - proxy_ssl_header, proxy_ssl_value = settings.SECURE_PROXY_SSL_HEADER - request.META[proxy_ssl_header] = proxy_ssl_value request.session = {} request._messages = FallbackStorage(request) diff --git a/hypha/apply/projects/reports/tests/test_commands.py b/hypha/apply/projects/reports/tests/test_commands.py index e07b1e08e5..effa58f2ef 100644 --- a/hypha/apply/projects/reports/tests/test_commands.py +++ b/hypha/apply/projects/reports/tests/test_commands.py @@ -1,8 +1,9 @@ from io import StringIO from dateutil.relativedelta import relativedelta +from django.core import mail from django.core.management import call_command -from django.test import TestCase +from django.test import TestCase, override_settings from django.utils import timezone from hypha.apply.projects.models.project import ( @@ -11,7 +12,6 @@ ) from hypha.apply.projects.tests.factories import ProjectFactory from hypha.home.factories import ApplySiteFactory -from hypha.home.models import ApplyHomePage from .factories import ReportConfigFactory, ReportFactory @@ -40,10 +40,7 @@ def test_notify_report_due_in_7_days(self): ) out = StringIO() - with self.settings( - ALLOWED_HOSTS=[ApplyHomePage.objects.first().get_site().hostname] - ): - call_command("notify_report_due", stdout=out) + call_command("notify_report_due", stdout=out) assert "Notified project" in out.getvalue() def test_dont_notify_report_due_in_7_days_already_submitted(self): @@ -57,10 +54,7 @@ def test_dont_notify_report_due_in_7_days_already_submitted(self): end_date=config.schedule_start, ) out = StringIO() - with self.settings( - ALLOWED_HOSTS=[ApplyHomePage.objects.first().get_site().hostname] - ): - call_command("notify_report_due", stdout=out) + call_command("notify_report_due", stdout=out) assert "Notified project" not in out.getvalue() def test_dont_notify_already_notified(self): @@ -88,3 +82,21 @@ def test_dont_notify_project_complete(self): out = StringIO() call_command("notify_report_due", stdout=out) assert "Notified project" not in out.getvalue() + + @override_settings( + WAGTAILADMIN_BASE_URL="https://apply.example.org", SEND_MESSAGES=True + ) + def test_notification_links_use_the_configured_base_url(self): + """The default Wagtail site record uses port 80, which used to leak into + the links as `https://host:80/...`.""" + in_a_week = timezone.now() + relativedelta(days=7) + ReportConfigFactory( + disable_reporting=False, schedule_start=in_a_week, project__in_progress=True + ) + + call_command("notify_report_due", stdout=StringIO()) + + assert len(mail.outbox) > 0 + body = mail.outbox[0].body + assert "https://apply.example.org/" in body + assert ":80/" not in body diff --git a/hypha/apply/todo/options.py b/hypha/apply/todo/options.py index 4ce7877924..1f0803ca47 100644 --- a/hypha/apply/todo/options.py +++ b/hypha/apply/todo/options.py @@ -251,7 +251,7 @@ } -def get_task_template(request, task, **kwargs): +def get_task_template(task, **kwargs): related_obj = task.related_object code = task.code # if related_object is none/deleted and task remain there(edge case, avoiding 500) @@ -266,7 +266,7 @@ def get_task_template(request, task, **kwargs): return None template_kwargs = { "related": related_obj, - "link": link_to(related_obj, request), + "link": link_to(related_obj), } if task.code == COMMENT_TASK: # Replace all newlines with spaces and truncate to 60 characters diff --git a/hypha/apply/todo/views.py b/hypha/apply/todo/views.py index cf644f441a..bde58455ef 100644 --- a/hypha/apply/todo/views.py +++ b/hypha/apply/todo/views.py @@ -213,6 +213,6 @@ def render_task_templates_for_user(request, user): ] """ tasks = get_tasks_for_user(user) - templates = [get_task_template(request, task=task) for task in tasks] + templates = [get_task_template(task=task) for task in tasks] return list(filter(None, templates)) diff --git a/hypha/apply/users/models.py b/hypha/apply/users/models.py index 7be79c4099..7056cefae0 100644 --- a/hypha/apply/users/models.py +++ b/hypha/apply/users/models.py @@ -157,14 +157,11 @@ def _extract_model_params(self, defaults, **kwargs): ) return params - def get_or_create_and_notify( - self, defaults: dict | None = None, site=None, **kwargs - ): + def get_or_create_and_notify(self, defaults: dict | None = None, **kwargs): """Create or get an account for applicant and send activation email to applicant. Args: defaults: Dict containing user attributes for user creation. Defaults to dict(). - site: current site for sending activation email. Defaults to None. Raises: IntegrityError: if multiple account exist with same email @@ -212,7 +209,7 @@ def get_or_create_and_notify( except IntegrityError: raise - send_activation_email(user, site, redirect_url=redirect_url) + send_activation_email(user, redirect_url=redirect_url) _created = True return user, _created diff --git a/hypha/apply/users/services.py b/hypha/apply/users/services.py index e225e28149..bcaa4029ca 100644 --- a/hypha/apply/users/services.py +++ b/hypha/apply/users/services.py @@ -8,7 +8,6 @@ from django.utils.encoding import force_bytes from django.utils.http import urlsafe_base64_encode from django.utils.translation import gettext as _ -from wagtail.models import Site from hypha.core.mail import MarkdownMail @@ -55,7 +54,6 @@ def send_passkey_notification(request, user, passkey_name, *, added): "user": user, "passkey_name": passkey_name, "event_time": local_event_time(request), - "site": Site.find_for_request(request) if request else None, "ORG_EMAIL": settings.ORG_EMAIL, }, ) @@ -86,7 +84,6 @@ def __init__( self.next_url = get_redirect_url(request, self.redirect_field_name) # type: ignore[arg-type] self.extended_session = extended_session self.request = request - self.site = Site.find_for_request(request) def _get_login_path(self, user): token = self.login_token_generator_class().make_token(user) @@ -146,7 +143,6 @@ def send_login_email(self, user): "username": user.get_username(), "login_path": login_path, "timeout_minutes": timeout_minutes, - "site": self.site, } subject = _("Log in to {user} at {ORG_LONG_NAME}").format( @@ -170,7 +166,6 @@ def send_new_account_login_email(self, signup_obj): context = { "signup_path": signup_path, "timeout_minutes": timeout_minutes, - "site": self.site, } subject = _("Welcome to {ORG_LONG_NAME}").format( diff --git a/hypha/apply/users/signals.py b/hypha/apply/users/signals.py index 97b31abad5..fcc796b16e 100644 --- a/hypha/apply/users/signals.py +++ b/hypha/apply/users/signals.py @@ -2,7 +2,6 @@ from django.contrib.auth.signals import user_logged_in from django.dispatch import receiver from django.utils.translation import gettext_lazy as _ -from wagtail.models import Site from hypha.core.mail import MarkdownMail @@ -40,7 +39,6 @@ def send_login_notification(sender, request, user, **kwargs): context={ "user": user, "login_time": local_event_time(request), - "site": Site.find_for_request(request) if request else None, "ORG_EMAIL": settings.ORG_EMAIL, }, ) diff --git a/hypha/apply/users/templates/users/activation/email.txt b/hypha/apply/users/templates/users/activation/email.txt index 003cbd6e3a..6c6a0cfd54 100644 --- a/hypha/apply/users/templates/users/activation/email.txt +++ b/hypha/apply/users/templates/users/activation/email.txt @@ -1,22 +1,22 @@ -{% load i18n wagtailadmin_tags %}{% base_url_setting as base_url %}{% firstof name username as user %} +{% load i18n util_tags %}{% firstof name username as user %} {% blocktrans %}Dear {{ user }},{% endblocktrans %} {% blocktrans %}Activate your account on the {{ ORG_LONG_NAME }} web site by clicking this link or copying and pasting it to your browser:{% endblocktrans %} -{% if site %}{{ site.root_url }}{% else %}{{ base_url }}{% endif %}{{ activation_path }} +{% base_url %}{{ activation_path }} {% blocktrans %}This link can be used only once and will lead you to a page where you can set your password. It will remain active for {{ timeout_minutes }} minutes, so please set your password as soon as possible.{% endblocktrans %} -{% trans "After setting your password, you will be able to log in at" %}: {% if site %}{{ site.root_url }}{% else %}{{ base_url }}{% endif %} {% trans "in the future using" %}: +{% trans "After setting your password, you will be able to log in at" %}: {% base_url %} {% trans "in the future using" %}: {% trans "Username" %}: {{ username }} {% trans "Password" %}: {% trans "Your chosen password" %} -{% blocktrans %}If you do not complete the activation process within {{ timeout_minutes }} minutes you can use the password reset form at{% endblocktrans %}: {% if site %}{{ site.root_url }}{% else %}{{ base_url }}{% endif %}{% url 'users:password_reset' %} +{% blocktrans %}If you do not complete the activation process within {{ timeout_minutes }} minutes you can use the password reset form at{% endblocktrans %}: {% base_url %}{% url 'users:password_reset' %} {% blocktrans %}Kind Regards, The {{ ORG_SHORT_NAME }} Team{% endblocktrans %} -- {{ ORG_LONG_NAME }} -{% if site %}{{ site.root_url }}{% else %}{{ base_url }}{% endif %} +{% base_url %} diff --git a/hypha/apply/users/templates/users/email_change/confirm_email.txt b/hypha/apply/users/templates/users/email_change/confirm_email.txt index e6ddd72a8a..cc793ac479 100644 --- a/hypha/apply/users/templates/users/email_change/confirm_email.txt +++ b/hypha/apply/users/templates/users/email_change/confirm_email.txt @@ -1,9 +1,9 @@ -{% load i18n wagtailadmin_tags %}{% base_url_setting as base_url %}{% firstof name username as user %} +{% load i18n util_tags %}{% firstof name username as user %} {% blocktrans %}Dear {{ user }},{% endblocktrans %} {% blocktrans %}Request to change email of your account on the {{ ORG_LONG_NAME }} web site has been accepted. Confirm your email by clicking this link or copying and pasting it to your browser:{% endblocktrans %} -{% if site %}{{ site.root_url }}{% else %}{{ base_url }}{% endif %}{{ activation_path }} +{% base_url %}{{ activation_path }} {% blocktrans %}This link will only remain active for {{ timeout_minutes }} minutes and will lead you to profile page after verification.{% endblocktrans %} @@ -12,4 +12,4 @@ The {{ ORG_SHORT_NAME }} Team{% endblocktrans %} -- {{ ORG_LONG_NAME }} -{% if site %}{{ site.root_url }}{% else %}{{ base_url }}{% endif %} +{% base_url %} diff --git a/hypha/apply/users/templates/users/email_change/update_info_email.html b/hypha/apply/users/templates/users/email_change/update_info_email.html index 5849022fbf..952147befd 100644 --- a/hypha/apply/users/templates/users/email_change/update_info_email.html +++ b/hypha/apply/users/templates/users/email_change/update_info_email.html @@ -1,4 +1,4 @@ -{% load i18n wagtailadmin_tags %}{% base_url_setting as base_url %}{% firstof name username as user %} +{% load i18n util_tags %}{% firstof name username as user %} {% blocktrans %}Dear {{ user }},{% endblocktrans %} {% blocktrans %}There has been an attempt to change email of your account on the {{ ORG_LONG_NAME }} web site. If this action wasn't made by you, please contact support at {{ ORG_EMAIL }} {% endblocktrans %} @@ -9,4 +9,4 @@ -- {{ ORG_LONG_NAME }} -{% if site %}{{ site.root_url }}{% else %}{{ base_url }}{% endif %}{# fmt:on #} +{% base_url %}{# fmt:on #} diff --git a/hypha/apply/users/templates/users/emails/confirm_access.md b/hypha/apply/users/templates/users/emails/confirm_access.md index 236883ea4a..f391957c7e 100644 --- a/hypha/apply/users/templates/users/emails/confirm_access.md +++ b/hypha/apply/users/templates/users/emails/confirm_access.md @@ -1,4 +1,4 @@ -{% load i18n wagtailadmin_tags %}{% base_url_setting as base_url %} +{% load i18n util_tags %} {% blocktrans %}Dear {{ user }},{% endblocktrans %} {% blocktrans %}To confirm access at {{ ORG_LONG_NAME }} use the code below (valid for {{ timeout_minutes }} minutes):{% endblocktrans %} @@ -16,4 +16,4 @@ The {{ ORG_SHORT_NAME }} Team{% endblocktrans %} -- {{ ORG_LONG_NAME }} -{% if site %}{{ site.root_url }}{% else %}{{ base_url }}{% endif %} +{% base_url %} diff --git a/hypha/apply/users/templates/users/emails/login_notification.md b/hypha/apply/users/templates/users/emails/login_notification.md index 8cd8a29169..83e6ed3b3e 100644 --- a/hypha/apply/users/templates/users/emails/login_notification.md +++ b/hypha/apply/users/templates/users/emails/login_notification.md @@ -1,4 +1,4 @@ -{% load i18n wagtailadmin_tags %}{% base_url_setting as base_url %} +{% load i18n util_tags %} {% blocktrans %}Dear {{ user }},{% endblocktrans %} {% blocktrans %}This is to notify you that your account was successfully logged in to {{ ORG_LONG_NAME }}.{% endblocktrans %} @@ -16,4 +16,4 @@ The {{ ORG_SHORT_NAME }} Team{% endblocktrans %} -- {{ ORG_LONG_NAME }} -{% if site %}{{ site.root_url }}{% else %}{{ base_url }}{% endif %} +{% base_url %} diff --git a/hypha/apply/users/templates/users/emails/passkey_added_notification.md b/hypha/apply/users/templates/users/emails/passkey_added_notification.md index 86d8027ec7..654c0f2c7f 100644 --- a/hypha/apply/users/templates/users/emails/passkey_added_notification.md +++ b/hypha/apply/users/templates/users/emails/passkey_added_notification.md @@ -1,4 +1,4 @@ -{% load i18n wagtailadmin_tags %}{% base_url_setting as base_url %} +{% load i18n util_tags %} {% blocktrans %}Dear {{ user }},{% endblocktrans %} {% blocktrans %}This is to notify you that a new passkey was added to your account at {{ ORG_LONG_NAME }}.{% endblocktrans %} @@ -17,4 +17,4 @@ The {{ ORG_SHORT_NAME }} Team{% endblocktrans %} -- {{ ORG_LONG_NAME }} -{% if site %}{{ site.root_url }}{% else %}{{ base_url }}{% endif %} +{% base_url %} diff --git a/hypha/apply/users/templates/users/emails/passkey_removed_notification.md b/hypha/apply/users/templates/users/emails/passkey_removed_notification.md index c031b9de84..5a1d804bed 100644 --- a/hypha/apply/users/templates/users/emails/passkey_removed_notification.md +++ b/hypha/apply/users/templates/users/emails/passkey_removed_notification.md @@ -1,4 +1,4 @@ -{% load i18n wagtailadmin_tags %}{% base_url_setting as base_url %} +{% load i18n util_tags %} {% blocktrans %}Dear {{ user }},{% endblocktrans %} {% blocktrans %}This is to notify you that a passkey was removed from your account at {{ ORG_LONG_NAME }}.{% endblocktrans %} @@ -17,4 +17,4 @@ The {{ ORG_SHORT_NAME }} Team{% endblocktrans %} -- {{ ORG_LONG_NAME }} -{% if site %}{{ site.root_url }}{% else %}{{ base_url }}{% endif %} +{% base_url %} diff --git a/hypha/apply/users/templates/users/emails/passwordless_login_email.md b/hypha/apply/users/templates/users/emails/passwordless_login_email.md index 37eae599a4..f480f38073 100644 --- a/hypha/apply/users/templates/users/emails/passwordless_login_email.md +++ b/hypha/apply/users/templates/users/emails/passwordless_login_email.md @@ -1,10 +1,10 @@ -{% load i18n wagtailadmin_tags %}{% base_url_setting as base_url %}{% firstof name username as user %} +{% load i18n util_tags %}{% firstof name username as user %} {% blocktrans %}Dear {{ user }},{% endblocktrans %} {% if is_active %} {% blocktrans %}Login to your account on the {{ ORG_LONG_NAME }} web site by clicking this link or copying and pasting it to your browser:{% endblocktrans %} -{% if site %}{{ site.root_url }}{% else %}{{ base_url }}{% endif %}{{ login_path }} +{% base_url %}{{ login_path }} {% blocktrans %}This link will be valid for {{ timeout_minutes }} minutes and can be used only once.{% endblocktrans %} @@ -23,4 +23,4 @@ The {{ ORG_SHORT_NAME }} Team{% endblocktrans %} -- {{ ORG_LONG_NAME }} -{% if site %}{{ site.root_url }}{% else %}{{ base_url }}{% endif %} +{% base_url %} diff --git a/hypha/apply/users/templates/users/emails/passwordless_new_account_login.md b/hypha/apply/users/templates/users/emails/passwordless_new_account_login.md index 9058cac734..d798f2a714 100644 --- a/hypha/apply/users/templates/users/emails/passwordless_new_account_login.md +++ b/hypha/apply/users/templates/users/emails/passwordless_new_account_login.md @@ -1,9 +1,9 @@ -{% load i18n wagtailadmin_tags %}{% base_url_setting as base_url %} +{% load i18n util_tags %} {% blocktrans %}Dear,{% endblocktrans %} {% blocktrans %}Welcome to {{ ORG_LONG_NAME }} web site. Create your account by clicking this link or copying and pasting it to your browser:{% endblocktrans %} -{% if site %}{{ site.root_url }}{% else %}{{ base_url }}{% endif %}{{ signup_path }} +{% base_url %}{{ signup_path }} {% blocktrans %}This link will be valid for {{ timeout_minutes }} minutes and can be used only once.{% endblocktrans %} @@ -18,4 +18,4 @@ The {{ ORG_SHORT_NAME }} Team{% endblocktrans %} -- {{ ORG_LONG_NAME }} -{% if site %}{{ site.root_url }}{% else %}{{ base_url }}{% endif %} +{% base_url %} diff --git a/hypha/apply/users/templates/users/emails/set_password.txt b/hypha/apply/users/templates/users/emails/set_password.txt index db827b9d62..1a9a772001 100644 --- a/hypha/apply/users/templates/users/emails/set_password.txt +++ b/hypha/apply/users/templates/users/emails/set_password.txt @@ -1,9 +1,9 @@ -{% load i18n wagtailadmin_tags %}{% base_url_setting as base_url %}{% firstof name username as user %} +{% load i18n util_tags %}{% firstof name username as user %} {% blocktrans %}Dear {{ user }},{% endblocktrans %} {% blocktrans %}Set your account password on the {{ ORG_LONG_NAME }} web site by clicking this link or copying and pasting it to your browser:{% endblocktrans %} -{% if site %}{{ site.root_url }}{% else %}{{ base_url }}{% endif %}{{ activation_path }} +{% base_url %}{{ activation_path }} {% blocktrans %}This link can be used only once and will lead you to a page where you can set your password. It will remain active for {{ timeout_minutes }} minutes, so please set your password as soon as possible.{% endblocktrans %} @@ -12,4 +12,4 @@ The {{ ORG_SHORT_NAME }} Team{% endblocktrans %} -- {{ ORG_LONG_NAME }} -{% if site %}{{ site.root_url }}{% else %}{{ base_url }}{% endif %} +{% base_url %} diff --git a/hypha/apply/users/templates/users/password_reset/email.txt b/hypha/apply/users/templates/users/password_reset/email.txt index c26906d6e1..6fa810488d 100644 --- a/hypha/apply/users/templates/users/password_reset/email.txt +++ b/hypha/apply/users/templates/users/password_reset/email.txt @@ -1,11 +1,11 @@ -{% load i18n wagtailadmin_tags %}{% base_url_setting as base_url %} +{% load i18n util_tags %} {% blocktranslate %}Dear {{ user }},{% endblocktranslate %} {% blocktranslate %}You're receiving this email because you requested a password reset for your user account at {{ ORG_LONG_NAME }}.{% endblocktranslate %} {% trans "Please follow the link below to reset your password:" %} -{{ protocol }}://{{ domain }}{% url 'users:password_reset_confirm' uidb64=uid token=token %}{% if redirect_url %}?next={{ redirect_url }}{% endif%} +{% base_url %}{% url 'users:password_reset_confirm' uidb64=uid token=token %}{% if redirect_url %}?next={{ redirect_url }}{% endif%} {% blocktrans %}This link will lead you to a page where you can set your password. It will remain active for {{ timeout_minutes }} minutes, so please set your password as soon as possible.{% endblocktrans %} @@ -14,4 +14,4 @@ The {{ ORG_SHORT_NAME }} Team{% endblocktrans %} -- {{ ORG_LONG_NAME }} -{% if site %}{{ site.root_url }}{% else %}{{ base_url }}{% endif %} +{% base_url %} diff --git a/hypha/apply/users/tests/test_views.py b/hypha/apply/users/tests/test_views.py index 2004e8e10e..acd48e5704 100644 --- a/hypha/apply/users/tests/test_views.py +++ b/hypha/apply/users/tests/test_views.py @@ -81,7 +81,8 @@ def test_receives_email(self): self.assertRedirects(response, self.url(None, view_name="password_reset_done")) self.assertEqual(len(mail.outbox), 1) self.assertIn( - "https://testserver/account/password/reset/confirm", mail.outbox[0].body + "https://primary-test-host.org/account/password/reset/confirm", + mail.outbox[0].body, ) diff --git a/hypha/apply/users/utils.py b/hypha/apply/users/utils.py index 509e2c8767..bf3e3cd295 100644 --- a/hypha/apply/users/utils.py +++ b/hypha/apply/users/utils.py @@ -66,7 +66,6 @@ def can_use_oauth_check(user): def send_activation_email( user, - site=None, email_template="users/activation/email.txt", email_subject_template="users/activation/email_subject.txt", redirect_url="", @@ -96,9 +95,6 @@ def send_activation_email( "ORG_SHORT_NAME": settings.ORG_SHORT_NAME, } - if site: - context.update(site=site) - subject = render_to_string(email_subject_template, context) # Force subject to a single line to avoid header-injection issues. subject = "".join(subject.splitlines()) @@ -106,7 +102,7 @@ def send_activation_email( user.email_user(subject, message, settings.DEFAULT_FROM_EMAIL) -def send_confirmation_email(user, token, updated_email=None, site=None): +def send_confirmation_email(user, token, updated_email=None): """ Send the confirmation email. The confirmation token is the update email, signed using TimestampSigner. @@ -131,9 +127,6 @@ def send_confirmation_email(user, token, updated_email=None, site=None): "ORG_SHORT_NAME": settings.ORG_SHORT_NAME, } - if site: - context.update(site=site) - subject = _("Confirmation email for {unverified_email} at {ORG_LONG_NAME}").format( **context ) diff --git a/hypha/apply/users/views.py b/hypha/apply/users/views.py index 81e471b32a..41ac53bb1b 100644 --- a/hypha/apply/users/views.py +++ b/hypha/apply/users/views.py @@ -49,7 +49,6 @@ from two_factor.views import LoginView as TwoFactorLoginView from two_factor.views import SetupView as TwoFactorSetupView from wagtail.admin.views.account import password_management_enabled -from wagtail.models import Site from wagtail.users.views.users import change_user_perm from hypha.core.mail import MarkdownMail @@ -208,7 +207,6 @@ def account_email_change(request): dumps({"updated_email": value["updated_email"], "id": request.user.id}) ), updated_email=value["updated_email"], - site=Site.find_for_request(request), ) # alert email @@ -426,7 +424,6 @@ def get_extra_email_context(self): return { "timeout_minutes": settings.PASSWORD_RESET_TIMEOUT // 60, "redirect_url": get_redirect_url(self.request, self.redirect_field_name), - "site": Site.find_for_request(self.request), "ORG_SHORT_NAME": settings.ORG_SHORT_NAME, "ORG_LONG_NAME": settings.ORG_LONG_NAME, } @@ -817,7 +814,6 @@ def send_confirm_access_email_view(request): email_context = { "token": token_obj.token, "username": request.user.email, - "site": Site.find_for_request(request), "user": request.user, "timeout_minutes": settings.PASSWORDLESS_LOGIN_TIMEOUT // 60, } @@ -873,12 +869,9 @@ def set_password_view(request): This will the case when the user signed up using passwordless signup or using oauth. """ - site = Site.find_for_request(request) - if not request.user.has_usable_password(): send_activation_email( user=request.user, - site=site, email_template="users/emails/set_password.txt", email_subject_template="users/emails/set_password_subject.txt", ) diff --git a/hypha/apply/users/wagtail_hooks.py b/hypha/apply/users/wagtail_hooks.py index afea594851..ba8ae8d881 100644 --- a/hypha/apply/users/wagtail_hooks.py +++ b/hypha/apply/users/wagtail_hooks.py @@ -1,7 +1,6 @@ from django.apps import apps from django.conf import settings from wagtail import hooks -from wagtail.models import Site from hypha.apply.activity.messaging import MESSAGES, messenger from hypha.apply.users.models import User @@ -19,8 +18,7 @@ def notify_after_create_user(request, user): source=user, ) - site = Site.find_for_request(request) - send_activation_email(user, site) + send_activation_email(user) @hooks.register("after_edit_user") diff --git a/hypha/core/apps.py b/hypha/core/apps.py index 43a8cb96b3..65ab8b9a1e 100644 --- a/hypha/core/apps.py +++ b/hypha/core/apps.py @@ -3,3 +3,6 @@ class CoreAppConfig(AppConfig): name = "hypha.core" + + def ready(self): + from hypha.core import checks # noqa: F401 diff --git a/hypha/core/checks.py b/hypha/core/checks.py new file mode 100644 index 0000000000..ee6f0c91ef --- /dev/null +++ b/hypha/core/checks.py @@ -0,0 +1,39 @@ +from django.conf import settings +from django.core.checks import Warning, register + +W001 = "hypha.core.W001" +W002 = "hypha.core.W002" + + +@register() +def primary_host_deprecated(app_configs, **kwargs): + """PRIMARY_HOST is deprecated in favour of WAGTAILADMIN_BASE_URL.""" + primary_host = getattr(settings, "PRIMARY_HOST", None) + if not primary_host: + return [] + + warnings = [ + Warning( + "The PRIMARY_HOST setting is deprecated.", + hint=( + "Set WAGTAILADMIN_BASE_URL to the full base URL of the site, " + "including the scheme, and remove PRIMARY_HOST." + ), + id=W001, + ) + ] + + if "://" in primary_host: + warnings.append( + Warning( + f"PRIMARY_HOST should be a bare hostname, not '{primary_host}'.", + hint=( + "'https://' is prepended to PRIMARY_HOST, so a value that " + "already includes a scheme produces a broken base URL. Set " + "WAGTAILADMIN_BASE_URL instead." + ), + id=W002, + ) + ) + + return warnings diff --git a/hypha/core/context_processors.py b/hypha/core/context_processors.py index 46b70f49ad..737e1a34de 100644 --- a/hypha/core/context_processors.py +++ b/hypha/core/context_processors.py @@ -1,12 +1,14 @@ from django.conf import settings from hypha.apply.users.utils import passkeys_enabled +from hypha.core.utils import get_base_url from hypha.home.models import ApplyHomePage def global_vars(request): return { "APPLY_SITE": ApplyHomePage.objects.first().get_site(), + "BASE_URL": get_base_url(), "ORG_LONG_NAME": settings.ORG_LONG_NAME, "ORG_SHORT_NAME": settings.ORG_SHORT_NAME, "ORG_EMAIL": settings.ORG_EMAIL, diff --git a/hypha/core/templatetags/util_tags.py b/hypha/core/templatetags/util_tags.py index 66368c4a4d..8fd72d220c 100644 --- a/hypha/core/templatetags/util_tags.py +++ b/hypha/core/templatetags/util_tags.py @@ -3,6 +3,8 @@ from django import template from wagtail.coreutils import camelcase_to_underscore +from hypha.core.utils import get_base_url + register = template.Library() @@ -27,3 +29,13 @@ def verbose_name(instance) -> str: @register.simple_tag def generate_uuid() -> str: return str(uuid.uuid4()) + + +@register.simple_tag(name="base_url") +def base_url_tag() -> str: + """Absolute base URL for links in outbound notifications. + + Usable in templates rendered without a request, where the + `global_vars` context processor does not run. + """ + return get_base_url() diff --git a/hypha/core/tests/test_checks.py b/hypha/core/tests/test_checks.py new file mode 100644 index 0000000000..dc0433cf66 --- /dev/null +++ b/hypha/core/tests/test_checks.py @@ -0,0 +1,18 @@ +from django.test import override_settings + +from hypha.core.checks import W001, W002, primary_host_deprecated + + +@override_settings(PRIMARY_HOST=None) +def test_no_warning_without_primary_host(): + assert primary_host_deprecated(None) == [] + + +@override_settings(PRIMARY_HOST="apply.example.org") +def test_warns_that_primary_host_is_deprecated(): + assert [warning.id for warning in primary_host_deprecated(None)] == [W001] + + +@override_settings(PRIMARY_HOST="https://apply.example.org") +def test_warns_when_primary_host_includes_a_scheme(): + assert [warning.id for warning in primary_host_deprecated(None)] == [W001, W002] diff --git a/hypha/core/tests/test_utils.py b/hypha/core/tests/test_utils.py index 7256d4f687..c1f6b551ab 100644 --- a/hypha/core/tests/test_utils.py +++ b/hypha/core/tests/test_utils.py @@ -1,6 +1,8 @@ import pytest +from django.test import override_settings +from wagtail.models import Site -from hypha.core.utils import markdown_to_html +from hypha.core.utils import get_base_url, markdown_to_html markdown_test_dataset = [ ("**bold**", "

bold

"), @@ -19,3 +21,20 @@ def test_markdown_to_html(test_input, expected): output = markdown_to_html(test_input).replace("\n", "").replace(" ", "") assert output == expected + + +@override_settings(WAGTAILADMIN_BASE_URL="https://apply.example.org") +def test_get_base_url_uses_the_setting(): + assert get_base_url() == "https://apply.example.org" + + +@override_settings(WAGTAILADMIN_BASE_URL="https://apply.example.org/") +def test_get_base_url_strips_trailing_slash(): + assert get_base_url() == "https://apply.example.org" + + +@pytest.mark.django_db +@override_settings(WAGTAILADMIN_BASE_URL=None) +def test_get_base_url_falls_back_to_the_default_site(): + site = Site.objects.get(is_default_site=True) + assert get_base_url() == site.root_url diff --git a/hypha/core/utils.py b/hypha/core/utils.py index 89554d2aed..9fb91affcb 100644 --- a/hypha/core/utils.py +++ b/hypha/core/utils.py @@ -1,4 +1,5 @@ import mistune +from django.conf import settings def markdown_to_html(text: str) -> str: @@ -23,3 +24,24 @@ def markdown_to_html(text: str) -> str: ) return md(text) + + +def get_base_url() -> str: + """Absolute base URL used to build links in outbound notifications. + + Returns the scheme, host and (if non-standard) port, without a trailing + slash, e.g. "https://apply.example.org". + + Prefers the explicit `WAGTAILADMIN_BASE_URL` setting. Falls back to the + default Wagtail site so installs that never configured it keep working. + """ + # Imported here as this module is loaded before the app registry is ready. + from wagtail.models import Site + + if base_url := getattr(settings, "WAGTAILADMIN_BASE_URL", None): + return base_url.rstrip("/") + + if site := Site.objects.filter(is_default_site=True).first(): + return site.root_url + + return "" diff --git a/hypha/settings/base.py b/hypha/settings/base.py index b0c9114aeb..1f4ad5e5c0 100644 --- a/hypha/settings/base.py +++ b/hypha/settings/base.py @@ -637,11 +637,16 @@ "SESSION_COOKIE_AGE_LONG", 60 * 60 * 24 * 7 * 2 ) # 2 weeks -# This is used by Wagtail's email notifications for constructing absolute URLs. +# Base URL used to build absolute links in outbound emails and Slack messages, +# and by Wagtail's own email notifications. Include the scheme, e.g. +# "https://apply.example.org". +WAGTAILADMIN_BASE_URL = env.str("WAGTAILADMIN_BASE_URL", None) + +# Deprecated, set WAGTAILADMIN_BASE_URL instead. Kept as a fallback for +# deployments that have not migrated yet; see hypha/core/checks.py. PRIMARY_HOST = env.str("PRIMARY_HOST", None) -WAGTAILADMIN_BASE_URL = env.str("WAGTAILADMIN_BASE_URL", None) or ( - f"https://{PRIMARY_HOST}" if PRIMARY_HOST else None -) +if PRIMARY_HOST and not WAGTAILADMIN_BASE_URL: + WAGTAILADMIN_BASE_URL = f"https://{PRIMARY_HOST}" # Security settings From aec220a464e0e6b9839de6ad1cf43a129eacaee7 Mon Sep 17 00:00:00 2001 From: Fredrik Jonsson Date: Wed, 9 Sep 2026 08:22:58 +0200 Subject: [PATCH 2/4] Use {% base_url %} for all e-mail templates and PDFs. --- .../activity/templates/messages/email/applicant_base.html | 6 +++--- .../templates/messages/email/assign_paf_approvers.html | 4 ++-- .../activity/templates/messages/email/author_updated.html | 6 +++--- .../templates/messages/email/batch_ready_to_review.html | 4 ++-- .../apply/activity/templates/messages/email/comment.html | 4 ++-- .../templates/messages/email/comment_assigned.html | 6 +++--- .../templates/messages/email/contract_uploaded.html | 8 ++++---- .../activity/templates/messages/email/determination.html | 4 ++-- .../templates/messages/email/invite_co_applicant.html | 4 ++-- .../templates/messages/email/invited_to_proposal.html | 6 +++--- .../templates/messages/email/invoice_approved.html | 4 ++-- .../templates/messages/email/invoice_created.html | 4 ++-- .../messages/email/invoice_status_updated_applicant.html | 6 +++--- .../messages/email/invoice_status_updated_staff.html | 6 +++--- .../templates/messages/email/invoice_updated.html | 4 ++-- .../templates/messages/email/paf_for_approval.html | 4 ++-- .../templates/messages/email/project_final_approval.html | 4 ++-- .../templates/messages/email/project_request_change.html | 6 +++--- .../templates/messages/email/ready_for_contracting.html | 4 ++-- .../templates/messages/email/ready_to_review.html | 4 ++-- .../templates/messages/email/report_submitted.html | 4 ++-- .../templates/messages/email/sent_to_compliance.html | 4 ++-- .../templates/messages/email/submission_confirmation.html | 6 +++--- .../messages/email/submit_contract_documents.html | 4 ++-- .../activity/templates/messages/email/transition.html | 4 ++-- .../application_projects/pdf_invoice_approved_page.html | 2 +- 26 files changed, 61 insertions(+), 61 deletions(-) diff --git a/hypha/apply/activity/templates/messages/email/applicant_base.html b/hypha/apply/activity/templates/messages/email/applicant_base.html index f091788323..e25ad029bd 100644 --- a/hypha/apply/activity/templates/messages/email/applicant_base.html +++ b/hypha/apply/activity/templates/messages/email/applicant_base.html @@ -1,6 +1,6 @@ {% extends "messages/email/base.html" %} -{% load i18n %} +{% load i18n util_tags %} {# fmt:off #} {% block pre_salutation %}{% for co_applicant in source.co_applicants.all %}{% if recipient == co_applicant.user.email %} @@ -11,9 +11,9 @@ {% block salutation %}{% blocktrans with name=source.user.get_full_name|default:"applicant" %}Dear {{ name }},{% endblocktrans %}{% endblock %} {# fmt:off #} -{% block more_info %}{% if source.submission %}{% trans "View your project here" %}{% else %}{% trans "View your submission here" %}{% endif %}: {{ BASE_URL }}{{ source.get_absolute_url }} +{% block more_info %}{% if source.submission %}{% trans "View your project here" %}{% else %}{% trans "View your submission here" %}{% endif %}: {% base_url %}{{ source.get_absolute_url }} -{% trans "If you have any questions, please submit them here" %}: {{ BASE_URL }}{% if source.submission %}{% url 'funds:submissions:comments' pk=source.submission.pk %}{% else %}{% url 'funds:submissions:comments' pk=source.pk %}{% endif %} +{% trans "If you have any questions, please submit them here" %}: {% base_url %}{% if source.submission %}{% url 'funds:submissions:comments' pk=source.submission.pk %}{% else %}{% url 'funds:submissions:comments' pk=source.pk %}{% endif %} {% trans "See our guide for more information" %}: {{ ORG_GUIDE_URL }} diff --git a/hypha/apply/activity/templates/messages/email/assign_paf_approvers.html b/hypha/apply/activity/templates/messages/email/assign_paf_approvers.html index d79667aca7..c2ffccfe80 100644 --- a/hypha/apply/activity/templates/messages/email/assign_paf_approvers.html +++ b/hypha/apply/activity/templates/messages/email/assign_paf_approvers.html @@ -1,13 +1,13 @@ {% extends "messages/email/base.html" %} -{% load i18n %} +{% load i18n util_tags %} {% block salutation %}{% endblock %} {% block content %}{# fmt:off #} {% trans "Project documents are ready to be assigned for approval." %} {% trans "Title" %}: {{ source.title_text_display }} -{% trans "Link" %}: {{ BASE_URL }}{% url 'apply:projects:approval' pk=source.pk %} +{% trans "Link" %}: {% base_url %}{% url 'apply:projects:approval' pk=source.pk %} {% blocktrans with lead=source.lead email=source.lead.email %}Please contact {{ lead }} - {{ email }} if you have any questions.{% endblocktrans %} {% endblock %}{# fmt:on #} diff --git a/hypha/apply/activity/templates/messages/email/author_updated.html b/hypha/apply/activity/templates/messages/email/author_updated.html index b5cab700e0..cde300c6cd 100644 --- a/hypha/apply/activity/templates/messages/email/author_updated.html +++ b/hypha/apply/activity/templates/messages/email/author_updated.html @@ -1,14 +1,14 @@ {% extends "messages/email/applicant_base.html" %} -{% load i18n %} +{% load i18n util_tags %} {% block content %}{# fmt:off #} {% blocktrans with title=source.title %}You have been assigned as an Applicant to submission "{{ title }}".{% endblocktrans %} {% endblock %} {% block more_info %} -{% trans "Link to your submission" %}: {{ BASE_URL }}{{ source.get_absolute_url }} -{% trans "If you have any questions, please submit them here" %}: {{ BASE_URL }}{{ source.get_absolute_url }}#communications +{% trans "Link to your submission" %}: {% base_url %}{{ source.get_absolute_url }} +{% trans "If you have any questions, please submit them here" %}: {% base_url %}{{ source.get_absolute_url }}#communications {% trans "See our guide for more information" %}: {{ ORG_GUIDE_URL }} diff --git a/hypha/apply/activity/templates/messages/email/batch_ready_to_review.html b/hypha/apply/activity/templates/messages/email/batch_ready_to_review.html index 25aa64c1c2..9c10492c1c 100644 --- a/hypha/apply/activity/templates/messages/email/batch_ready_to_review.html +++ b/hypha/apply/activity/templates/messages/email/batch_ready_to_review.html @@ -1,13 +1,13 @@ {% extends "messages/email/base.html" %} -{% load i18n %} +{% load i18n util_tags %} {% block salutation %}{% trans "Dear Reviewer," %}{% endblock %} {% block content %}{# fmt:off #} {% trans "New applications have been added to your review list." %} {% for submission in sources %} {% trans "Title" %}: {{ submission.title_text_display }} -{% trans "Link" %}: {{ BASE_URL }}{{ submission.get_absolute_url }} +{% trans "Link" %}: {% base_url %}{{ submission.get_absolute_url }} {% endfor %} {% endblock %}{# fmt:on #} diff --git a/hypha/apply/activity/templates/messages/email/comment.html b/hypha/apply/activity/templates/messages/email/comment.html index 77020f29dd..7b0cfef38a 100644 --- a/hypha/apply/activity/templates/messages/email/comment.html +++ b/hypha/apply/activity/templates/messages/email/comment.html @@ -1,6 +1,6 @@ {% extends "messages/email/applicant_base.html" %} -{% load i18n activity_tags %} +{% load i18n activity_tags util_tags %} {% block salutation %}{% trans "Dear" %} {{ recipient }},{% endblock %} {% block content %}{# fmt:off #} @@ -9,7 +9,7 @@ {% display_name_for_email user as display_user %} {% blocktrans with title=source.title user=comment.user %}There has been a new comment on "{{ title }}" by {{ display_user }}.{% endblocktrans %} -{% trans "Read the full comment here" %}: {{ BASE_URL }}{{ comment.get_absolute_url }} +{% trans "Read the full comment here" %}: {% base_url %}{{ comment.get_absolute_url }} {% endblock %} {% block more_info %} diff --git a/hypha/apply/activity/templates/messages/email/comment_assigned.html b/hypha/apply/activity/templates/messages/email/comment_assigned.html index 7e2b9a7b55..244c4858df 100644 --- a/hypha/apply/activity/templates/messages/email/comment_assigned.html +++ b/hypha/apply/activity/templates/messages/email/comment_assigned.html @@ -1,6 +1,6 @@ {% extends "messages/email/base.html" %} -{% load i18n %} +{% load i18n util_tags %} {% block salutation %}{% trans "Hey there," %}{% endblock %} @@ -9,5 +9,5 @@ {% endblock %} {% block more_info %} -{% trans "View it here" %}: {{ BASE_URL }}{{ comment.get_absolute_url }} -{% endblock %} \ No newline at end of file +{% trans "View it here" %}: {% base_url %}{{ comment.get_absolute_url }} +{% endblock %} diff --git a/hypha/apply/activity/templates/messages/email/contract_uploaded.html b/hypha/apply/activity/templates/messages/email/contract_uploaded.html index ddef21546c..00fc7b7a1e 100644 --- a/hypha/apply/activity/templates/messages/email/contract_uploaded.html +++ b/hypha/apply/activity/templates/messages/email/contract_uploaded.html @@ -1,6 +1,6 @@ {% extends "messages/email/base.html" %} -{% load i18n %} +{% load i18n util_tags %} {% block salutation %} {% if request.user != source.user %} @@ -13,7 +13,7 @@ {% trans "A new contract has been added to your Project" %}: {% trans "Title" %}: {{ source.title_text_display }} -{% trans "Link" %}: {{ BASE_URL }}{{ source.get_absolute_url }} +{% trans "Link" %}: {% base_url %}{{ source.get_absolute_url }} {% if contract.is_signed %} {% trans "This contract has already been signed and there is no action for you to take." %} @@ -25,8 +25,8 @@ {% block more_info %} {% if request.user != source.user %} -{% trans "View your project here" %}: {{ BASE_URL }}{{ source.get_absolute_url }} -{% trans "If you have any questions, please submit them here" %}: {{ BASE_URL }}{% url 'funds:submissions:comments' pk=source.submission.pk %} +{% trans "View your project here" %}: {% base_url %}{{ source.get_absolute_url }} +{% trans "If you have any questions, please submit them here" %}: {% base_url %}{% url 'funds:submissions:comments' pk=source.submission.pk %} {% trans "See our guide for more information" %}: {{ ORG_GUIDE_URL }} diff --git a/hypha/apply/activity/templates/messages/email/determination.html b/hypha/apply/activity/templates/messages/email/determination.html index 1ca3eb27d0..bebdd6eb10 100644 --- a/hypha/apply/activity/templates/messages/email/determination.html +++ b/hypha/apply/activity/templates/messages/email/determination.html @@ -1,10 +1,10 @@ {% extends "messages/email/applicant_base.html" %} -{% load nh3_tags i18n %} +{% load nh3_tags i18n util_tags %} {% block content %}{# fmt:off #} {% trans "Your application has been reviewed and the outcome is" %}: {{ determination.clean_outcome }} {{ determination.message|nh3|striptags }} -{% trans "Read the full determination here" %}: {{ BASE_URL }}{{ determination.get_absolute_url }} +{% trans "Read the full determination here" %}: {% base_url %}{{ determination.get_absolute_url }} {% endblock %}{# fmt:on #} diff --git a/hypha/apply/activity/templates/messages/email/invite_co_applicant.html b/hypha/apply/activity/templates/messages/email/invite_co_applicant.html index 451a4d24e9..80855dab14 100644 --- a/hypha/apply/activity/templates/messages/email/invite_co_applicant.html +++ b/hypha/apply/activity/templates/messages/email/invite_co_applicant.html @@ -1,5 +1,5 @@ {% extends "messages/email/base.html" %} -{% load i18n activity_tags %} +{% load i18n activity_tags util_tags %} {% block salutation %}{% if invited_user %}{% blocktrans with name=invited_user.get_display_name %}Dear {{ name }},{% endblocktrans %}{% else %}{% blocktrans with name=related.invited_user_email|email_name %}Dear {{ name }},{% endblocktrans %}{% endif %}{% endblock %} @@ -10,6 +10,6 @@ {% else %} {% blocktrans %}Click on link if you want to accept it.{% endblocktrans %} -{% trans "Link" %}: {{ BASE_URL }}{{ accept_link }} +{% trans "Link" %}: {% base_url %}{{ accept_link }} {% endif %} {% endblock %}{# fmt:on #} diff --git a/hypha/apply/activity/templates/messages/email/invited_to_proposal.html b/hypha/apply/activity/templates/messages/email/invited_to_proposal.html index 0f22450bcd..f48f1256cf 100644 --- a/hypha/apply/activity/templates/messages/email/invited_to_proposal.html +++ b/hypha/apply/activity/templates/messages/email/invited_to_proposal.html @@ -1,14 +1,14 @@ {% extends "messages/email/applicant_base.html" %} -{% load i18n %} +{% load i18n util_tags %} {% block content %}{# fmt:off #} {% blocktrans %}We’ve reviewed your Concept note and think it could be a good fit for {{ ORG_SHORT_NAME }} funding. We would like to invite you to submit a Proposal with more details about your project. You will receive a second email linking to a determination message with detailed feedback.{% endblocktrans %} {% blocktrans %}Please review our Proposal Guide at {{ ORG_GUIDE_URL }} to learn more about the information we’d like to see. In the proposal please also address the feedback we provided in the concept note determination.{% endblocktrans %}{% endblock %} {% block more_info %} -{% trans "Here is the link to start creating your proposal" %}: {{ BASE_URL }}{{ source.get_absolute_url }} -{% trans "If you have any questions, please submit them here" %}: {{ BASE_URL }}{% url 'funds:submissions:comments' pk=source.pk %} +{% trans "Here is the link to start creating your proposal" %}: {% base_url %}{{ source.get_absolute_url }} +{% trans "If you have any questions, please submit them here" %}: {% base_url %}{% url 'funds:submissions:comments' pk=source.pk %} {% blocktrans %}The system will allow you to save a draft of your proposal as you work on it. When you feel it is ready for our review, please click the “Submit” button and we’ll know to take a look at it. We’ll reply to you with feedback on your Proposal as quickly as possible.{% endblocktrans %} diff --git a/hypha/apply/activity/templates/messages/email/invoice_approved.html b/hypha/apply/activity/templates/messages/email/invoice_approved.html index 2eec23c88d..c9f0c88be2 100644 --- a/hypha/apply/activity/templates/messages/email/invoice_approved.html +++ b/hypha/apply/activity/templates/messages/email/invoice_approved.html @@ -1,11 +1,11 @@ {% extends "messages/email/base.html" %} -{% load i18n %} +{% load i18n util_tags %} {% block salutation %}{% endblock %} {% block content %}{# fmt:off #} {% blocktrans with title=source.title_text_display %}An invoice on project "{{title}}" is waiting for your approval.{% endblocktrans %} -{% trans "View the invoice here" %}: {{ BASE_URL }}{{ invoice.get_absolute_url }} +{% trans "View the invoice here" %}: {% base_url %}{{ invoice.get_absolute_url }} {% blocktrans with lead=source.lead email=source.lead.email %}Please contact {{ lead }} - {{ email }} if you have any questions.{% endblocktrans %} {% endblock %}{# fmt:on #} diff --git a/hypha/apply/activity/templates/messages/email/invoice_created.html b/hypha/apply/activity/templates/messages/email/invoice_created.html index ce83ab1624..5198b7da05 100644 --- a/hypha/apply/activity/templates/messages/email/invoice_created.html +++ b/hypha/apply/activity/templates/messages/email/invoice_created.html @@ -1,10 +1,10 @@ {% extends "messages/email/base.html" %} -{% load i18n %} +{% load i18n util_tags %} {% block salutation %}{% endblock %} {% block content %}{# fmt:off #} {% blocktrans with title=source.title_text_display %}A new invoice has been submitted for project "{{title}}".{% endblocktrans %} -{% trans "View the invoice here" %}: {{ BASE_URL }}{{ related.get_absolute_url }} +{% trans "View the invoice here" %}: {% base_url %}{{ related.get_absolute_url }} {% endblock %}{# fmt:on #} diff --git a/hypha/apply/activity/templates/messages/email/invoice_status_updated_applicant.html b/hypha/apply/activity/templates/messages/email/invoice_status_updated_applicant.html index cd4ae2b9f4..d96f414824 100644 --- a/hypha/apply/activity/templates/messages/email/invoice_status_updated_applicant.html +++ b/hypha/apply/activity/templates/messages/email/invoice_status_updated_applicant.html @@ -1,6 +1,6 @@ {% extends "messages/email/applicant_base.html" %} -{% load i18n invoice_tools %} +{% load i18n invoice_tools util_tags %} {% block content %}{# fmt:off #} {% display_invoice_status_for_user source.user invoice as invoice_status %} @@ -9,9 +9,9 @@ {% blocktrans with status=invoice_status %}It's status is now "{{ status }}".{% endblocktrans %} {% if invoice.comment %} -{% trans "A staff member left a comment that can be read here" %}: {{ BASE_URL }}{{ comment_url }} +{% trans "A staff member left a comment that can be read here" %}: {% base_url %}{{ comment_url }} {% endif %} -{% trans "View your invoice here" %}: {{ BASE_URL }}{{ invoice.get_absolute_url }} +{% trans "View your invoice here" %}: {% base_url %}{{ invoice.get_absolute_url }} {% endblock %}{# fmt:on #} diff --git a/hypha/apply/activity/templates/messages/email/invoice_status_updated_staff.html b/hypha/apply/activity/templates/messages/email/invoice_status_updated_staff.html index 9a44e4ad92..7d60dcfd42 100644 --- a/hypha/apply/activity/templates/messages/email/invoice_status_updated_staff.html +++ b/hypha/apply/activity/templates/messages/email/invoice_status_updated_staff.html @@ -1,6 +1,6 @@ {% extends "messages/email/base.html" %} -{% load i18n invoice_tools %} +{% load i18n invoice_tools util_tags %} {% block content %}{# fmt:off #} {% display_invoice_status_for_user user invoice as invoice_status %} @@ -9,9 +9,9 @@ {% blocktrans with status=invoice_status %}It's status is now "{{ status }}".{% endblocktrans %} {% if invoice.comment %} -{% trans "A comment was left that can be read here" %}: {{ BASE_URL }}{{ comment_url }} +{% trans "A comment was left that can be read here" %}: {% base_url %}{{ comment_url }} {% endif %} -{% trans "View the invoice here" %}: {{ BASE_URL }}{{ invoice.get_absolute_url }} +{% trans "View the invoice here" %}: {% base_url %}{{ invoice.get_absolute_url }} {% endblock %}{# fmt:on #} diff --git a/hypha/apply/activity/templates/messages/email/invoice_updated.html b/hypha/apply/activity/templates/messages/email/invoice_updated.html index 570f7bfb9d..f5aa03ea6e 100644 --- a/hypha/apply/activity/templates/messages/email/invoice_updated.html +++ b/hypha/apply/activity/templates/messages/email/invoice_updated.html @@ -1,9 +1,9 @@ {% extends "messages/email/applicant_base.html" %} -{% load i18n invoice_tools %} +{% load i18n invoice_tools util_tags %} {% block content %}{# fmt:off #} {% blocktrans with title=source.title_text_display %}An {{ ORG_SHORT_NAME }} staff member has updated an invoice on your project "{{ title }}".{% endblocktrans %} -{% trans "View the invoice here:" %}: {{ BASE_URL }}{{ source.get_absolute_url }} +{% trans "View the invoice here:" %}: {% base_url %}{{ source.get_absolute_url }} {% endblock %}{# fmt:on #} diff --git a/hypha/apply/activity/templates/messages/email/paf_for_approval.html b/hypha/apply/activity/templates/messages/email/paf_for_approval.html index 967db74e59..10dab3ba00 100644 --- a/hypha/apply/activity/templates/messages/email/paf_for_approval.html +++ b/hypha/apply/activity/templates/messages/email/paf_for_approval.html @@ -1,12 +1,12 @@ {% extends "messages/email/base.html" %} -{% load i18n %} +{% load i18n util_tags %} {% block salutation %}{% endblock %} {% block content %}{# fmt:off #} {% blocktrans with title=source.title_text_display %}The {{ title }} project is awaiting your review.{% endblocktrans %} -{% trans "View the project here" %}: {{ BASE_URL }}{% url 'apply:projects:approval' pk=source.pk %} +{% trans "View the project here" %}: {% base_url %}{% url 'apply:projects:approval' pk=source.pk %} {% blocktrans with lead=source.lead email=source.lead.email %}Please contact {{ lead }} - {{ email }} if you have any questions.{% endblocktrans %} {% endblock %}{# fmt:on #} diff --git a/hypha/apply/activity/templates/messages/email/project_final_approval.html b/hypha/apply/activity/templates/messages/email/project_final_approval.html index 1c65b3764c..e064cbe65e 100644 --- a/hypha/apply/activity/templates/messages/email/project_final_approval.html +++ b/hypha/apply/activity/templates/messages/email/project_final_approval.html @@ -1,12 +1,12 @@ {% extends "messages/email/base.html" %} -{% load i18n %} +{% load i18n util_tags %} {% block salutation %}{% endblock %} {% block content %}{# fmt:off #} {% blocktrans with title=source.title_text_display %}The project "{{title}}" is awaiting final approval.{% endblocktrans %} -{% trans "Approve the project here" %}: {{ BASE_URL }}{% url 'apply:projects:approval' pk=source.pk %} +{% trans "Approve the project here" %}: {% base_url %}{% url 'apply:projects:approval' pk=source.pk %} {% blocktrans with lead=source.lead email=source.lead.email %}Please contact {{ lead }} - {{ email }} if you have any questions.{% endblocktrans %} {% endblock %}{# fmt:on #} diff --git a/hypha/apply/activity/templates/messages/email/project_request_change.html b/hypha/apply/activity/templates/messages/email/project_request_change.html index 6f03523fad..297aaea742 100644 --- a/hypha/apply/activity/templates/messages/email/project_request_change.html +++ b/hypha/apply/activity/templates/messages/email/project_request_change.html @@ -1,14 +1,14 @@ {% extends "messages/email/base.html" %} -{% load i18n %} +{% load i18n util_tags %} {% block salutation %}{% endblock %} {% block content %}{# fmt:off #} {% blocktrans with title=source.title_text_display %}The project forms for "{{ title }}" was rejected by project form reviewers, please update it accordingly and resubmit it to the reviewers. {% endblocktrans %} {% if comment_url %} -{% trans "A comment was left that can be viewed here" %}: {{ BASE_URL }}{{ comment_url }} +{% trans "A comment was left that can be viewed here" %}: {% base_url %}{{ comment_url }} {% endif %} -{% trans "View the project here" %}: {{ BASE_URL }}{{ source.get_absolute_url }} +{% trans "View the project here" %}: {% base_url %}{{ source.get_absolute_url }} {% endblock %}{# fmt:on #} diff --git a/hypha/apply/activity/templates/messages/email/ready_for_contracting.html b/hypha/apply/activity/templates/messages/email/ready_for_contracting.html index b7dfbc7efb..a8d07746f6 100644 --- a/hypha/apply/activity/templates/messages/email/ready_for_contracting.html +++ b/hypha/apply/activity/templates/messages/email/ready_for_contracting.html @@ -1,12 +1,12 @@ {% extends "messages/email/base.html" %} -{% load i18n %} +{% load i18n util_tags %} {% block salutation %}{% endblock %} {% block content %}{# fmt:off #} {% blocktrans with title=source.title_text_display%}The project "{{ title }}" is waiting for contract.{% endblocktrans %} -{% trans "View the project here" %}: {{ BASE_URL }}{{ source.get_absolute_url }} +{% trans "View the project here" %}: {% base_url %}{{ source.get_absolute_url }} {% blocktrans with lead=source.lead email=source.lead.email %}Please contact {{ lead }} - {{ email }} if you have any questions.{% endblocktrans %} {% endblock %}{# fmt:on #} diff --git a/hypha/apply/activity/templates/messages/email/ready_to_review.html b/hypha/apply/activity/templates/messages/email/ready_to_review.html index 80b54af41e..838a432ee3 100644 --- a/hypha/apply/activity/templates/messages/email/ready_to_review.html +++ b/hypha/apply/activity/templates/messages/email/ready_to_review.html @@ -1,6 +1,6 @@ {% extends "messages/email/base.html" %} -{% load i18n %} +{% load i18n util_tags %} {% block salutation %}{% trans "Dear Reviewer," %}{% endblock %} {% block content %}{# fmt:off #} {% trans "This application is awaiting your review." %} @@ -8,5 +8,5 @@ {% trans "Title" %}: {{ source.title_text_display }} {% if related.title %}{% trans "Reminder Title" %}: {{ related.title }}{% endif %} {% if related.description %}{% trans "Reminder Description" %}: {{ related.description }}{% endif %} -{% trans "Link" %}: {{ BASE_URL }}{{ source.get_absolute_url }} +{% trans "Link" %}: {% base_url %}{{ source.get_absolute_url }} {% endblock %}{# fmt:on #} diff --git a/hypha/apply/activity/templates/messages/email/report_submitted.html b/hypha/apply/activity/templates/messages/email/report_submitted.html index a6cb0942a3..7a0f56ba51 100644 --- a/hypha/apply/activity/templates/messages/email/report_submitted.html +++ b/hypha/apply/activity/templates/messages/email/report_submitted.html @@ -1,9 +1,9 @@ {% extends "messages/email/applicant_base.html" %} -{% load i18n %} +{% load i18n util_tags %} {% block content %}{# fmt:off #} {% blocktrans with title=source.title_text_display start_date=report.start_date end_date=report.end_date %}An {{ ORG_SHORT_NAME }} staff member has submitted a report for your project "{{ title }}" for period {{ start_date }} to {{ end_date }}.{% endblocktrans %} -{% trans "You can review the report here" %}: {{ BASE_URL }}{{ report.get_absolute_url }} +{% trans "You can review the report here" %}: {% base_url %}{{ report.get_absolute_url }} {% endblock %}{# fmt:on #} diff --git a/hypha/apply/activity/templates/messages/email/sent_to_compliance.html b/hypha/apply/activity/templates/messages/email/sent_to_compliance.html index c101ff1442..afc11a111e 100644 --- a/hypha/apply/activity/templates/messages/email/sent_to_compliance.html +++ b/hypha/apply/activity/templates/messages/email/sent_to_compliance.html @@ -1,12 +1,12 @@ {% extends "messages/email/base.html" %} -{% load i18n %} +{% load i18n util_tags %} {% block salutation %}{% endblock %} {% block content %}{# fmt:off #} {% blocktrans with title=source.title_text_display %}The project "{{ title }}" is awaiting your review.{% endblocktrans %} -{% trans "View the project here" %}: {{ BASE_URL }}{% url 'apply:projects:approval' pk=source.pk %} +{% trans "View the project here" %}: {% base_url %}{% url 'apply:projects:approval' pk=source.pk %} {% blocktrans with lead=source.lead email=source.lead.email %}Please contact {{ lead }} - {{ email }} if you have any questions.{% endblocktrans %} {% endblock %}{# fmt:on #} diff --git a/hypha/apply/activity/templates/messages/email/submission_confirmation.html b/hypha/apply/activity/templates/messages/email/submission_confirmation.html index 990b2a740e..8bc3ba40db 100644 --- a/hypha/apply/activity/templates/messages/email/submission_confirmation.html +++ b/hypha/apply/activity/templates/messages/email/submission_confirmation.html @@ -1,13 +1,13 @@ {% extends "messages/email/base.html" %} -{% load i18n %} +{% load i18n util_tags %} {% block content %}{# fmt:off #} {% blocktrans with title=source.title %}We appreciate your "{{ title }}" application submission to the {{ ORG_LONG_NAME }}.{% endblocktrans %} -{% if source.is_draft %}{% trans "Please note that it is not submitted for review because it's still in draft." %} {% trans "You can access the draft at" %}: {{ BASE_URL }}{{ source.get_absolute_url }}{% else %}{% trans "We will review and reply to your submission as quickly as possible." %}{% endif %} +{% if source.is_draft %}{% trans "Please note that it is not submitted for review because it's still in draft." %} {% trans "You can access the draft at" %}: {% base_url %}{{ source.get_absolute_url }}{% else %}{% trans "We will review and reply to your submission as quickly as possible." %}{% endif %} -{% trans "If you have any questions, please submit them here" %}: {{ BASE_URL }}{% url 'funds:submissions:comments' pk=source.pk %} +{% trans "If you have any questions, please submit them here" %}: {% base_url %}{% url 'funds:submissions:comments' pk=source.pk %} {% blocktrans %}If you have issues accessing the submission system or general inquiries, please email us at {{ ORG_EMAIL }}.{% endblocktrans %} diff --git a/hypha/apply/activity/templates/messages/email/submit_contract_documents.html b/hypha/apply/activity/templates/messages/email/submit_contract_documents.html index 1683bdcbaf..55f6b0c5e2 100644 --- a/hypha/apply/activity/templates/messages/email/submit_contract_documents.html +++ b/hypha/apply/activity/templates/messages/email/submit_contract_documents.html @@ -1,13 +1,13 @@ {% extends "messages/email/base.html" %} -{% load i18n %} +{% load i18n util_tags %} {% block salutation %}{% endblock %} {% block content %}{# fmt:off #} {% blocktrans with title=source.title_text_display %}The contract for project "{{ title }}" is awaiting your review.{% endblocktrans %} -{% trans "View the project here" %}: {{ BASE_URL }}{{ source.get_absolute_url }} +{% trans "View the project here" %}: {% base_url %}{{ source.get_absolute_url }} {% blocktrans with lead=source.lead email=source.lead.email %}Please contact {{ lead }} - {{ email }} if you have any questions.{% endblocktrans %} {% endblock %}{# fmt:on #} diff --git a/hypha/apply/activity/templates/messages/email/transition.html b/hypha/apply/activity/templates/messages/email/transition.html index 4654251b2f..61452935ff 100644 --- a/hypha/apply/activity/templates/messages/email/transition.html +++ b/hypha/apply/activity/templates/messages/email/transition.html @@ -1,9 +1,9 @@ {% extends "messages/email/applicant_base.html" %} -{% load i18n %} +{% load i18n util_tags %} {% block content %}{# fmt:off #} {% blocktrans %}Your application is now in "{{ new_phase }}" status (progressed from "{{ old_phase }}").{% endblocktrans %} -{% trans "Please submit any questions related to your application here" %}: {{ BASE_URL }}{% url 'funds:submissions:comments' pk=source.pk %} +{% trans "Please submit any questions related to your application here" %}: {% base_url %}{% url 'funds:submissions:comments' pk=source.pk %} {% endblock %}{# fmt:on #} diff --git a/hypha/apply/projects/templates/application_projects/pdf_invoice_approved_page.html b/hypha/apply/projects/templates/application_projects/pdf_invoice_approved_page.html index 2683eb297f..3c3cdcb880 100644 --- a/hypha/apply/projects/templates/application_projects/pdf_invoice_approved_page.html +++ b/hypha/apply/projects/templates/application_projects/pdf_invoice_approved_page.html @@ -19,7 +19,7 @@

{% trans "Invoice Status" %}

- {% trans "Generated" %}: {{ generated_at|date:"c" }} · {{ request.scheme }}://{{ request.get_host }}{{ invoice.get_absolute_url}} + {% trans "Generated" %}: {{ generated_at|date:"c" }} · {% base_url %}{{ invoice.get_absolute_url}}

From bb0126553ddd1f36c70ac61238b52ce8ba28b6ac Mon Sep 17 00:00:00 2001 From: Fredrik Jonsson Date: Wed, 9 Sep 2026 08:56:51 +0200 Subject: [PATCH 3/4] Use wagails get_dummy_request to add dummy requests when sending e-mails on cronjobs etc. --- hypha/apply/activity/adapters/base.py | 6 +++++- .../funds/management/commands/send_reminders.py | 14 +++++++------- .../management/commands/notify_report_due.py | 11 ++++------- .../pdf_invoice_approved_page.html | 2 +- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/hypha/apply/activity/adapters/base.py b/hypha/apply/activity/adapters/base.py index 3957b43209..2ace11f736 100644 --- a/hypha/apply/activity/adapters/base.py +++ b/hypha/apply/activity/adapters/base.py @@ -207,7 +207,11 @@ def process_send( debug_message = _("{adapter}: {message}").format( adapter=self.adapter_type, message=message ) - messages.add_message(request, messages.DEBUG, debug_message) + # Fails silently as notifications sent outside the + # request cycle have no message storage to write to. + messages.add_message( + request, messages.DEBUG, debug_message, fail_silently=True + ) def create_logs(self, message, recipient, *events): from ..models import Message diff --git a/hypha/apply/funds/management/commands/send_reminders.py b/hypha/apply/funds/management/commands/send_reminders.py index 6cf74e0234..678d15097e 100644 --- a/hypha/apply/funds/management/commands/send_reminders.py +++ b/hypha/apply/funds/management/commands/send_reminders.py @@ -1,7 +1,7 @@ -from django.contrib.messages.storage.fallback import FallbackStorage from django.core.management.base import BaseCommand -from django.http import HttpRequest from django.utils import timezone +from wagtail.coreutils import get_dummy_request +from wagtail.models import Site from hypha.apply.activity.messaging import messenger from hypha.apply.funds.models import Reminder @@ -11,11 +11,11 @@ class Command(BaseCommand): help = "Send reminders" def handle(self, *args, **options): - # Mock a HTTPRequest as the messenger expects one. Links in the - # notifications are built from `get_base_url()`, not from the request. - request = HttpRequest() - request.session = {} - request._messages = FallbackStorage(request) + # The messenger expects a request. Links in the notifications are built + # from `get_base_url()`, not from the request. + request = get_dummy_request( + site=Site.objects.filter(is_default_site=True).first() + ) for reminder in Reminder.objects.filter( sent=False, time__lte=timezone.now() diff --git a/hypha/apply/projects/reports/management/commands/notify_report_due.py b/hypha/apply/projects/reports/management/commands/notify_report_due.py index f6b629d226..fc9a7b58a1 100644 --- a/hypha/apply/projects/reports/management/commands/notify_report_due.py +++ b/hypha/apply/projects/reports/management/commands/notify_report_due.py @@ -1,8 +1,7 @@ from dateutil.relativedelta import relativedelta -from django.contrib.messages.storage.fallback import FallbackStorage from django.core.management.base import BaseCommand -from django.http import HttpRequest from django.utils import timezone +from wagtail.coreutils import get_dummy_request from hypha.apply.activity.messaging import MESSAGES, messenger from hypha.apply.projects.models import ( @@ -19,11 +18,9 @@ class Command(BaseCommand): def handle(self, *args, **options): site = ApplyHomePage.objects.first().get_site() - # Mock a HTTPRequest as the messenger expects one. Links in the - # notifications are built from `get_base_url()`, not from the request. - request = HttpRequest() - request.session = {} - request._messages = FallbackStorage(request) + # The messenger expects a request. Links in the notifications are built + # from `get_base_url()`, not from the request. + request = get_dummy_request(site=site) today = timezone.now().date() diff --git a/hypha/apply/projects/templates/application_projects/pdf_invoice_approved_page.html b/hypha/apply/projects/templates/application_projects/pdf_invoice_approved_page.html index 3c3cdcb880..40e42c39a1 100644 --- a/hypha/apply/projects/templates/application_projects/pdf_invoice_approved_page.html +++ b/hypha/apply/projects/templates/application_projects/pdf_invoice_approved_page.html @@ -1,4 +1,4 @@ -{% load invoice_tools i18n tz %} +{% load invoice_tools i18n tz util_tags %} From e61391093be8186535d8145680868a3e6f29faa6 Mon Sep 17 00:00:00 2001 From: Fredrik Jonsson Date: Wed, 9 Sep 2026 09:26:31 +0200 Subject: [PATCH 4/4] Add check to warn if WAGTAILADMIN_BASE_URL is not set. --- hypha/core/checks.py | 21 +++++++++++++++++++++ hypha/core/tests/test_checks.py | 18 +++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/hypha/core/checks.py b/hypha/core/checks.py index ee6f0c91ef..d92e4b43df 100644 --- a/hypha/core/checks.py +++ b/hypha/core/checks.py @@ -3,6 +3,7 @@ W001 = "hypha.core.W001" W002 = "hypha.core.W002" +W003 = "hypha.core.W003" @register() @@ -37,3 +38,23 @@ def primary_host_deprecated(app_configs, **kwargs): ) return warnings + + +@register() +def base_url_not_set(app_configs, **kwargs): + """WAGTAILADMIN_BASE_URL is needed to build links in notifications.""" + if getattr(settings, "WAGTAILADMIN_BASE_URL", None): + return [] + + return [ + Warning( + "The WAGTAILADMIN_BASE_URL setting is not set.", + hint=( + "Links in emails and Slack messages fall back to the default " + "Wagtail site, which does not know if the site is served over " + "HTTPS. Set WAGTAILADMIN_BASE_URL to the full base URL of the " + "site, including the scheme, e.g. 'https://apply.example.org'." + ), + id=W003, + ) + ] diff --git a/hypha/core/tests/test_checks.py b/hypha/core/tests/test_checks.py index dc0433cf66..bf345d315c 100644 --- a/hypha/core/tests/test_checks.py +++ b/hypha/core/tests/test_checks.py @@ -1,6 +1,12 @@ from django.test import override_settings -from hypha.core.checks import W001, W002, primary_host_deprecated +from hypha.core.checks import ( + W001, + W002, + W003, + base_url_not_set, + primary_host_deprecated, +) @override_settings(PRIMARY_HOST=None) @@ -16,3 +22,13 @@ def test_warns_that_primary_host_is_deprecated(): @override_settings(PRIMARY_HOST="https://apply.example.org") def test_warns_when_primary_host_includes_a_scheme(): assert [warning.id for warning in primary_host_deprecated(None)] == [W001, W002] + + +@override_settings(WAGTAILADMIN_BASE_URL="https://apply.example.org") +def test_no_warning_when_base_url_is_set(): + assert base_url_not_set(None) == [] + + +@override_settings(WAGTAILADMIN_BASE_URL=None) +def test_warns_when_base_url_is_not_set(): + assert [warning.id for warning in base_url_not_set(None)] == [W003]