From a5579bda500bbb083bdeb1fb31da34be1d1987e6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9lestin=20Matte?= <gitlab@cmatte.me>
Date: Wed, 27 Oct 2021 11:50:18 +0200
Subject: [PATCH] Add PGWEB_ADDRESS setting to remove hardcoded search form
 address

Search forms currently point to the hardcoded address of www.postgresql.org.
Add a parameter in the settings to make it possible to configure the domain
hosting the /search/ function.
---
 django/archives/mailarchives/templates/searchform.html | 4 ++--
 django/archives/mailarchives/views.py                  | 4 ++++
 django/archives/settings.py                            | 2 ++
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/django/archives/mailarchives/templates/searchform.html b/django/archives/mailarchives/templates/searchform.html
index 4855de2..8fef61b 100644
--- a/django/archives/mailarchives/templates/searchform.html
+++ b/django/archives/mailarchives/templates/searchform.html
@@ -1,6 +1,6 @@
 <h3>Search the Archives</h3>
 
-<form method="get" action="/search/">
+<form method="get" action="https://{{ PGWEB_ADDRESS }}/search/">
   <input type="hidden" name="m" value="1">
   {%if searchform_listname%} <input type="hidden" name="ln" value="{{searchform_listname}}"/>{%endif%}
   <div class="row">
@@ -17,7 +17,7 @@
         <small class="form-text text-muted">(enter a message-id to go directly to that message)</small>
       </div>
       <div class="input-group">
-        <a href="https://www.postgresql.org/search/?m=1{%if searchform_listname%}&amp;ln={{searchform_listname}}{%endif%}">Advanced Search</a>
+        <a href="https://{{ PGWEB_ADDRESS }}/search/?m=1{%if searchform_listname%}&amp;ln={{searchform_listname}}{%endif%}">Advanced Search</a>
       </div>
     </div><!-- /.col-lg-6 -->
   </div><!-- /.row -->
diff --git a/django/archives/mailarchives/views.py b/django/archives/mailarchives/views.py
index f711ce4..51fa21d 100644
--- a/django/archives/mailarchives/views.py
+++ b/django/archives/mailarchives/views.py
@@ -207,6 +207,7 @@ def index(request):
     (groups, listgroupid) = get_all_groups_and_lists(request)
     return render_nav(NavContext(request, all_groups=groups), 'index.html', {
         'groups': [{'groupname': g['groupname'], 'lists': g['lists']} for g in groups],
+        'PGWEB_ADDRESS': settings.PGWEB_ADDRESS,
     })
 
 
@@ -219,6 +220,7 @@ def groupindex(request, groupid):
 
     return render_nav(NavContext(request, all_groups=groups, expand_groupid=groupid), 'index.html', {
         'groups': mygroups,
+        'PGWEB_ADDRESS': settings.PGWEB_ADDRESS,
     })
 
 
@@ -234,6 +236,7 @@ def monthlist(request, listname):
     return render_nav(NavContext(request, l.listid, l.listname), 'monthlist.html', {
         'list': l,
         'months': months,
+        'PGWEB_ADDRESS': settings.PGWEB_ADDRESS,
     })
 
 
@@ -285,6 +288,7 @@ def _render_datelist(request, l, d, datefilter, title, queryproc):
         'title': title,
         'daysinmonth': daysinmonth,
         'yearmonth': yearmonth,
+        'PGWEB_ADDRESS': settings.PGWEB_ADDRESS,
     })
     if settings.PUBLIC_ARCHIVES:
         r['xkey'] = ' '.join(['pgam_{0}/{1}/{2}'.format(l.listid, year, month) for year, month in allyearmonths])
diff --git a/django/archives/settings.py b/django/archives/settings.py
index 906d91b..162122c 100644
--- a/django/archives/settings.py
+++ b/django/archives/settings.py
@@ -143,6 +143,8 @@ API_CLIENTS = ('127.0.0.1',)
 PUBLIC_ARCHIVES = False
 ALLOW_RESEND = False
 
+PGWEB_ADDRESS = 'www.postgresql.org'
+
 try:
     from .settings_local import *
 except ImportError:
-- 
2.33.1

