Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Hide footer legal links when no URL is configured (#5642)

jaysbeekay160085c72f45
diff --git a/.env.example b/.env.example
index 13ea40d865..eb4dc7ab9b 100644
--- a/.env.example
+++ b/.env.example
@@ -251,6 +251,13 @@ OIDC_REDIRECT_URI=
PRODUCT_NAME=
BRAND_NAME=
+# Legal pages
+# Full URLs of this instance's privacy policy and terms of service. When set,
+# /privacy and /terms redirect to them and the login, signup and onboarding
+# footers link to them; when unset, the footer shows no link for that page.
+# LEGAL_PRIVACY_URL=
+# LEGAL_TERMS_URL=
+
# PostHog configuration
POSTHOG_KEY=
POSTHOG_HOST=
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 2ab793c84c..a193199175 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -15,6 +15,12 @@ module ApplicationHelper
Rails.configuration.x.brand_name
end
+ # The instance's own privacy policy or terms URL, or nil when unset. The
+ # /privacy and /terms routes redirect to the same variables.
+ def legal_page_url(page)
+ ENV[{ privacy: "LEGAL_PRIVACY_URL", terms: "LEGAL_TERMS_URL" }.fetch(page)].presence
+ end
+
def styled_form_with(**options, &block)
options[:builder] = StyledFormBuilder
form_with(**options, &block)
diff --git a/app/views/layouts/shared/_footer.html.erb b/app/views/layouts/shared/_footer.html.erb
index b16cc9d9fc..e632d55a12 100644
--- a/app/views/layouts/shared/_footer.html.erb
+++ b/app/views/layouts/shared/_footer.html.erb
@@ -1,10 +1,16 @@
+<% privacy_link = legal_page_url(:privacy) %>
+<% terms_link = legal_page_url(:terms) %>
<footer class="p-6">
<div class="space-y-2 text-center text-xs text-secondary">
<p>&copy; <%= Date.current.year %>, <%= brand_name %> <%= product_name %> (community fork of Maybe Finance)</p>
- <div class="flex justify-center items-center gap-2">
- <%= link_to "Privacy Policy", privacy_path, class: "text-secondary", target: "_blank" %>
- <span>&bull;</span>
- <%= link_to "Terms of Service", terms_path, class: "text-secondary", target: "_blank" %>
- </div>
+ <% if privacy_link || terms_link %>
+ <div class="flex justify-center items-center gap-2">
+ <%= link_to t(".privacy_policy"), privacy_path, class: "text-secondary", target: "_blank" if privacy_link %>
+ <% if privacy_link && terms_link %>
+ <span>&bull;</span>
+ <% end %>
+ <%= link_to t(".terms_of_service"), terms_path, class: "text-secondary", target: "_blank" if terms_link %>
+ </div>
+ <% end %>
</div>
</footer>
diff --git a/compose.example.ai.yml b/compose.example.ai.yml
index 87f365569c..43a84948af 100644
--- a/compose.example.ai.yml
+++ b/compose.example.ai.yml
@@ -94,6 +94,9 @@ x-rails-env: &rails_env
REDIS_URL: redis://redis:6379/1
# Seconds a missed scheduled job may run late (default 600); see docs/hosting/docker.md
SIDEKIQ_CRON_GRACE_PERIOD_SECONDS: ${SIDEKIQ_CRON_GRACE_PERIOD_SECONDS:-}
+ # Optional privacy policy and terms URLs for the footer links; see docs/hosting/docker.md
+ LEGAL_PRIVACY_URL: ${LEGAL_PRIVACY_URL:-}
+ LEGAL_TERMS_URL: ${LEGAL_TERMS_URL:-}
# MCP server endpoint — enables /mcp for external AI assistants (e.g. Claude, GPT).
# Set both values to activate. MCP_USER_EMAIL must match an existing user's email.
# External AI clients should connect via Pipelock (port 8889) for scanning.
diff --git a/compose.example.yml b/compose.example.yml
index bf8a2fe6d5..563e791e21 100644
--- a/compose.example.yml
+++ b/compose.example.yml
@@ -73,6 +73,9 @@ x-rails-env: &rails_env
REDIS_URL: redis://redis:6379/1
# Seconds a missed scheduled job may run late (default 600); see docs/hosting/docker.md
SIDEKIQ_CRON_GRACE_PERIOD_SECONDS: ${SIDEKIQ_CRON_GRACE_PERIOD_SECONDS:-}
+ # Optional privacy policy and terms URLs for the footer links; see docs/hosting/docker.md
+ LEGAL_PRIVACY_URL: ${LEGAL_PRIVACY_URL:-}
+ LEGAL_TERMS_URL: ${LEGAL_TERMS_URL:-}
# NOTE: enabling OpenAI will incur costs when you use AI-related features in the app (chat, rules). Make sure you have set appropriate spend limits on your account before adding this.
OPENAI_ACCESS_TOKEN: ${OPENAI_ACCESS_TOKEN}
OPENAI_MODEL: ${OPENAI_MODEL:-}
diff --git a/docs/hosting/docker.md b/docs/hosting/docker.md
index e8057de1c0..663c78ca5f 100644
--- a/docs/hosting/docker.md
+++ b/docs/hosting/docker.md
@@ -230,6 +230,26 @@ WEBAUTHN_ALLOWED_ORIGINS="https://sure.example.com"
`WEBAUTHN_RP_ID` should usually be your registrable domain, not a full URL. See [WebAuthn MFA Configuration](webauthn.md) before changing hostnames or reverse proxy settings for an instance with registered passkeys.
+#### Privacy policy and terms links (optional)
+
+To link your own privacy policy and terms of service from the login, signup and onboarding pages, set their full URLs in your `.env` file:
+
+```txt
+LEGAL_PRIVACY_URL="https://example.com/privacy"
+LEGAL_TERMS_URL="https://example.com/terms"
+```
+
+`compose.example.yml` passes both to the app through its `x-rails-env` anchor. If your `compose.yml` was copied before they were added, add them there yourself:
+
+```yaml
+x-rails-env: &rails_env
+ # ...existing keys...
+ LEGAL_PRIVACY_URL: ${LEGAL_PRIVACY_URL:-}
+ LEGAL_TERMS_URL: ${LEGAL_TERMS_URL:-}
+```
+
+`/privacy` and `/terms` then redirect to these URLs. Each footer link appears only when its URL is set, so an instance without them shows neither link. Restart the app after changing them; the redirects are read at boot.
+
#### Binding to IPv6 (optional)
By default Sure listens on `0.0.0.0:3000` (IPv4 wildcard) inside the container and Docker publishes the port on the host's IPv4 interface only. If you want the app reachable over IPv6 as well, two things need to change:
diff --git a/test/views/layouts/shared/footer_test.rb b/test/views/layouts/shared/footer_test.rb
new file mode 100644
index 0000000000..62f8719f18
--- /dev/null
+++ b/test/views/layouts/shared/footer_test.rb
@@ -0,0 +1,82 @@
+require "test_helper"
+
+class FooterTest < ActionDispatch::IntegrationTest
+ # The routes read LEGAL_* when they load, which is lazy outside CI. Load them
+ # before any override so /privacy and /terms keep their unset-variable routes.
+ setup { Rails.application.reload_routes_unless_loaded }
+
+ test "leaves out both legal links when neither URL is configured" do
+ with_env_overrides("LEGAL_PRIVACY_URL" => nil, "LEGAL_TERMS_URL" => nil) do
+ get new_session_path
+ end
+
+ assert_response :ok
+ assert_select "footer a", text: "Privacy Policy", count: 0
+ assert_select "footer a", text: "Terms of Service", count: 0
+ end
+
+ test "treats empty legal URLs as unset" do
+ with_env_overrides("LEGAL_PRIVACY_URL" => "", "LEGAL_TERMS_URL" => "") do
+ get new_session_path
+ end
+
+ assert_response :ok
+ assert_select "footer a", text: "Privacy Policy", count: 0
+ assert_select "footer a", text: "Terms of Service", count: 0
+ end
+
+ test "links both legal pages when both URLs are configured" do
+ with_env_overrides("LEGAL_PRIVACY_URL" => "https://example.com/privacy", "LEGAL_TERMS_URL" => "https://example.com/terms") do
+ get new_session_path
+ end
+
+ assert_select "footer a[href='#{privacy_path}']", text: "Privacy Policy"
+ assert_select "footer a[href='#{terms_path}']", text: "Terms of Service"
+ assert_select "footer span", text: "•"
+ end
+
+ test "labels the legal links in the request's locale" do
+ with_env_overrides("LEGAL_PRIVACY_URL" => "https://example.com/privacy", "LEGAL_TERMS_URL" => "https://example.com/terms") do
+ get new_session_path(locale: "nb")
+ end
+
+ assert_select "footer a[href='#{privacy_path}']", text: I18n.t("layouts.shared.footer.privacy_policy", locale: :nb)
+ assert_select "footer a[href='#{terms_path}']", text: I18n.t("layouts.shared.footer.terms_of_service", locale: :nb)
+ end
+
+ test "links only the configured privacy page, without a separator" do
+ with_env_overrides("LEGAL_PRIVACY_URL" => "https://example.com/privacy", "LEGAL_TERMS_URL" => nil) do
+ get new_session_path
+ end
+
+ assert_select "footer a[href='#{privacy_path}']", text: "Privacy Policy"
+ assert_select "footer a", text: "Terms of Service", count: 0
+ assert_select "footer span", text: "•", count: 0
+ end
+
+ test "links only the configured terms page, without a separator" do
+ with_env_overrides("LEGAL_PRIVACY_URL" => nil, "LEGAL_TERMS_URL" => "https://example.com/terms") do
+ get new_session_path
+ end
+
+ assert_select "footer a[href='#{terms_path}']", text: "Terms of Service"
+ assert_select "footer a", text: "Privacy Policy", count: 0
+ assert_select "footer span", text: "•", count: 0
+ end
+
+ test "legal pages still render their placeholder when no URL is configured" do
+ with_env_overrides("LEGAL_PRIVACY_URL" => nil, "LEGAL_TERMS_URL" => nil) do
+ Rails.application.reload_routes!
+
+ get privacy_path
+ assert_response :ok
+ assert_includes response.body, I18n.t("pages.privacy.placeholder")
+
+ get terms_path
+ assert_response :ok
+ assert_includes response.body, I18n.t("pages.terms.placeholder")
+ end
+ ensure
+ Rails.application.reload_routes!
+ end
+end