feat: update settings page to manage reminder times and retention policies
Revamped the settings page to allow coordinators to configure reminder email timings and the duration for retaining volunteer signup details. Removed the privacy text field from settings, reflecting the decision to not include unapproved privacy wording. Enhanced the user interface with clearer instructions and previews for reminder settings. Updated related tests to ensure proper functionality and validation of new settings.
This commit is contained in:
1 parent
e1bd85f879
commit
caaeded467
12 files changed
+461
-175
No files matched your search
@@ -10,7 +10,7 @@ This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
|
||||
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
**This is not ready for a public launch, and it is not ready for real volunteer records.** Phase 1A has public browsing, individual signup, cancellation, queued email, and coordinator sign-in for events, one-off shifts, rosters, and cancellation. A coordinator can add a walk-in and move a signup from a shift roster. A volunteer can switch shifts from their private link. An active weekly template fills shifts for the next three months. A coordinator can add, change, or end a weekly template, and can remove a cancelled person, a finished empty shift, an ended template, or an event that is off the public list and already empty. A confirmed signup can receive a reminder 48 hours before the shift and again 2 hours before, and can turn reminders off without cancelling. A coordinator can download a roster for one shift, one event, or a local date range. A coordinator can import a contact list, download it, open a person to see current and past shifts, use a saved contact when adding a walk-in, and add a saved contact to an open shift. A coordinator can set the two reminder times, the reply-to address, how many months to keep a signup, and the wording on the privacy page. A signed-in administrator can add another administrator. Removing someone takes away their sign-in access. The last administrator cannot be removed. After 1:00 AM Central Time, signups older than that many months lose their name and contact details in this app. After 2:30 AM Central Time, the app saves a database backup on this computer. A container can run that same app on this computer, on port 3020, without opening it to the network. This is not a public launch. Around 1:00 AM in each event's time zone, the app adds any missing weekly shifts for the next eight weeks, once that local day. Development prints mail in the server log. It does not send real email.
|
||||
**This is not ready for a public launch, and it is not ready for real volunteer records.** Phase 1A has public browsing, individual signup, cancellation, queued email, and coordinator sign-in for events, one-off shifts, rosters, and cancellation. A coordinator can add a walk-in and move a signup from a shift roster. A volunteer can switch shifts from their private link. An active weekly template fills shifts for the next three months. A coordinator can add, change, or end a weekly template, and can remove a cancelled person, a finished empty shift, an ended template, or an event that is off the public list and already empty. A confirmed signup can receive a reminder 48 hours before the shift and again 2 hours before, and can turn reminders off without cancelling. A coordinator can download a roster for one shift, one event, or a local date range. A coordinator can import a contact list, download it, open a person to see current and past shifts, use a saved contact when adding a walk-in, and add a saved contact to an open shift. A coordinator can set when reminder emails go out, where replies go, and how long signup details stay in the app. A signed-in administrator can add another administrator. Removing someone takes away their sign-in access. The last administrator cannot be removed. After 1:00 AM Central Time, signups older than that many months lose their name and contact details in this app. After 2:30 AM Central Time, the app saves a database backup on this computer. A container can run that same app on this computer, on port 3020, without opening it to the network. This is not a public launch. Around 1:00 AM in each event's time zone, the app adds any missing weekly shifts for the next eight weeks, once that local day. Development prints mail in the server log. It does not send real email.
|
||||
|
||||
## Current step
|
||||
|
||||
@@ -32,7 +32,7 @@ You should have received a copy of the GNU General Public License along with thi
|
||||
| Reminder emails, 48 hours and 2 hours, with a way to stop them | Done |
|
||||
| Download a roster for a shift, an event, or a date range | Done |
|
||||
| Import and download a contact list | Done |
|
||||
| Set reminder times, reply-to, privacy wording, and retention months | Done |
|
||||
| Set reminder times, where replies go, and how long signup details are kept | Done |
|
||||
| Refill weekly shifts around 1:00 AM in each event time zone | Done |
|
||||
| Remove personal details after the saved retention period | Done |
|
||||
| Save a database backup after 2:30 AM Central Time | Done |
|
||||
@@ -42,11 +42,11 @@ The core tables for later steps are already in `migrations/001_init.sql`. Behavi
|
||||
|
||||
## Decisions still open
|
||||
|
||||
Do not treat this repository as an approved privacy policy or an approved operating setup.
|
||||
Do not treat this repository as an approved operating setup.
|
||||
|
||||
- [ ] **D1.** SMTP2GO is the email provider. The pantry verifies the sender and the reply-to.
|
||||
- [ ] **D2.** Whether a group signup is essential. A shared email can already sign up more than one person on the same shift. Each person takes one spot and gets their own confirmation and private link. The same person, matched by name and email, cannot take a second spot on that shift. `group_size` stays 1. Group signup still needs its own decision: who the reservation is for, what happens when the count changes, and who receives mail.
|
||||
- [ ] **D3.** The pantry approves privacy wording and retention periods, including copies and exports.
|
||||
- [ ] **D3.** The pantry approves how long signup details are kept, including copies and exports.
|
||||
- [ ] **D4.** The pantry confirms the coordinator list, who owns the administrator account, and the recovery contact.
|
||||
- [ ] **D5.** Configure production Turnstile keys and the allowed hostname.
|
||||
- [ ] **D6.** The host owner confirms the offsite backup destination, who owns it, the recovery target, and a restore test.
|
||||
@@ -70,7 +70,7 @@ npm run seed
|
||||
|
||||
`npm run dev` serves the site on `127.0.0.1` at `BASE_URL` (from `.env`, `http://127.0.0.1:3000`). It is loopback only. Stop it with Ctrl+C.
|
||||
|
||||
Open `/` for the weekly pantry sign-up page. **View** starts on **List**: a card for each day with a shift in the next three months, split into that day's shifts. Each shift lists the names of the people who are signed up. A shift that has already ended stays on that day's card, grayed out, until midnight in the event's time zone. At midnight the day leaves the list. Emails, phone numbers, and notes stay off the page. **Calendar** is the other choice in that menu, at `/?view=calendar`, and it stops at that same three-month date. A shift later than that date is left off both views, and the signup form does not take a reservation for it. `/e/weekly-pantry` is the same seeded event. `/privacy` is the unapproved privacy notice. `/healthz` returns `{"ok":true,"database":"ok"}` and nothing else. A shift shows how many spots are filled, such as 3/5 spots filled. A shift with space left uses a soft green label. A full shift uses a soft red label.
|
||||
Open `/` for the weekly pantry sign-up page. **View** starts on **List**: a card for each day with a shift in the next three months, split into that day's shifts. Each shift lists the names of the people who are signed up. A shift that has already ended stays on that day's card, grayed out, until midnight in the event's time zone. At midnight the day leaves the list. Emails, phone numbers, and notes stay off the page. **Calendar** is the other choice in that menu, at `/?view=calendar`, and it stops at that same three-month date. A shift later than that date is left off both views, and the signup form does not take a reservation for it. `/e/weekly-pantry` is the same seeded event. `/healthz` returns `{"ok":true,"database":"ok"}` and nothing else. A shift shows how many spots are filled, such as 3/5 spots filled. A shift with space left uses a soft green label. A full shift uses a soft red label.
|
||||
|
||||
An open shift has a signup form. It asks for one person. Another person can use the same email and takes another spot. The same person cannot take a second spot. The form needs JavaScript because of the Turnstile check. Wait a few seconds after the page loads before submitting. The confirmation page shows a private link and says a confirmation email is on the way. That page works without JavaScript. Cancel this signup there to open the spot again. A cancellation email is queued, and a confirmation that has not been sent yet is dropped. That person can sign up again once the cancellation is saved. Someone else can use the email while the first signup is still confirmed. A cancelled signup stays on that private page until the link expires. A private link controls only that signup. Use the separate link for each signup.
|
||||
|
||||
@@ -104,7 +104,7 @@ A reminder is queued at each saved time before a confirmed signup, while the shi
|
||||
|
||||
**Contacts**, on the coordinator page, keeps a list of people. A confirmed signup is saved on this list. The name is split at the last space. A signup name with no space is saved with a hyphen as the last name. A different name is a separate contact, even when the email matches. The same name and email updates that contact. Cancelling the signup does not remove the contact. Saving someone here does not sign them up for a shift. The list is at the top of this page. **Add a contact**, **Import**, and **Download** stay closed until one is opened. **Import** reads a spreadsheet with First Name, Last Name, Email, and Phone, including the SignUpGenius people export. An Address column is ignored. The same name and email updates that person. A different name stays a separate person, even when the email matches. A different email stays a separate person, even when the name matches. A row without a phone is skipped. Names are capitalized. A word that already mixes upper and lower case stays as written. A phone number with ten digits is saved with dashes, like 712-555-0100. A leading 1 is left off. Email addresses are stored in lowercase. Importing does not take a spot and does not send email. **Download** saves that list. A cell that would be a spreadsheet formula is saved as text. A downloaded copy stays on the coordinator's computer. The signup retention job does not clear this list. The list is the contacts table in `app.db`. The list shows 20 people. **See more** shows the next 20 on this page, without returning to the top, and keeps a search. **Choose a name** to see the shifts they are signed up for and every past shift they signed up for. The signup has to use the same name and email. A signup name with no space matches the contact saved with a hyphen for the last name. A confirmed signup on a shift that has not ended is listed under Signed up for. A shift that has ended is listed under Past shifts, including a cancelled signup, which is marked cancelled. Choosing the shift opens it. Signup details cleared by retention drop off this page. **Edit contact** and **Add to a shift** stay closed until opened. **Add to a shift** uses their saved name, email, and phone. That takes one spot and queues a confirmation email. A full, cancelled, or ended shift is not in that list, and a shift they are already on is not in that list. A shift that is not on the public list can still be chosen. **Edit contact**, on that page, saves a corrected name, email, or phone on the same person. A phone typo can be replaced. A hyphen saved as the last name can be replaced with the real last name. Changing the name does not create a second person, even when the email stays the same. Phone is required. It does not change a signup, take a spot, or send email. **Remove** deletes that person from the list only. On an open shift, **Saved contact** fills a walk-in. The walk-in still takes one spot and queues a confirmation email. **Add a contact** saves one person who has not signed up. It does not take a spot and does not send email. The same name and email updates that person. A different name is saved separately, even with the same email. Typing a walk-in who is not on the list saves them here too.
|
||||
|
||||
**Settings**, on the coordinator page, saves the two reminder times, the reply-to address, the privacy-page wording, and how many months to keep a signup after the shift ends. The defaults are 48 hours, 2 hours, the reply-to address from the server configuration, a blank privacy notice, and 24 months. The two reminder times have to be different whole hours from 1 to 336. The month count is a whole number from 1 to 120. A blank privacy notice leaves the public page saying a notice is not approved yet. Saved wording is shown on `/privacy` as written. Saving it does not by itself make that wording an approved privacy policy. New mail uses the saved reply-to address. Mail already queued keeps the address it was given. The sending address stays in the server configuration.
|
||||
**Settings**, on the coordinator page, is three choices: when the two reminder emails go out, which inbox receives replies, and how long a signup keeps a person's name, email, and phone. The usual reminders are 2 days before the shift, then 2 hours before. The lists also offer 1 week, 3 days, and 1 day for the first email, and 1 day, 12 hours, 4 hours, and 1 hour for the second. The two times have to be different. A time already saved that is not on the list still appears, when it is a whole number of hours from 1 to 336. The usual keep time is 2 years. The list also offers 6 months, 1 year, 3 years, 5 years, and 10 years. A count already saved that is not on the list still appears, from 1 to 120 months. The reply address starts as the one in the server configuration. New mail uses the saved reply address. Mail already queued keeps the address it was given. The sending address stays in the server configuration. There is no privacy page.
|
||||
|
||||
**Administrators**, on the coordinator page, lists who can sign in. **Add an administrator** saves a name and email. It does not send email. That person requests a sign-in link at `/login`. Saving an address that was removed earlier gives that person access again and updates the name. **Remove** takes away access, signs that person out, and stops unused sign-in links. It does not send email. A roster notice that has not been sent yet is not sent to that address. The last administrator cannot be removed. Any administrator can add or remove the others, including themselves when someone else still has access.
|
||||
|
||||
@@ -279,4 +279,4 @@ The command prints the coordinator id, not the address. It does not deactivate a
|
||||
|
||||
## What is still unverified
|
||||
|
||||
Real inbox delivery, a production host, and a public launch. The container was checked on this computer with a temporary database, separate from the development database: it starts, the weekly page loads, `/healthz` answers, a path prefix is included in that health address, and a restart keeps the database. The development settings were refused. This computer does not have the Docker daemon running, so that check used Podman. It has not been deployed. Decision D6 is still open. The console driver only prints mail. SMTP2GO is the selected provider and is not connected on this computer yet. Gmail is not connected. The privacy page is waiting on decision D3 and is not a privacy policy. A real Turnstile hostname check still needs the production keys from decision D5. Development uses Cloudflare's always-pass test keys. Those keys succeed with hostname `example.com` and no action, so the hostname and action checks apply to real keys. Coordinator sign-in is covered here with the console driver, not with a real inbox.
|
||||
Real inbox delivery, a production host, and a public launch. The container was checked on this computer with a temporary database, separate from the development database: it starts, the weekly page loads, `/healthz` answers, a path prefix is included in that health address, and a restart keeps the database. The development settings were refused. This computer does not have the Docker daemon running, so that check used Podman. It has not been deployed. Decision D6 is still open. The console driver only prints mail. SMTP2GO is the selected provider and is not connected on this computer yet. Gmail is not connected. A real Turnstile hostname check still needs the production keys from decision D5. Development uses Cloudflare's always-pass test keys. Those keys succeed with hostname `example.com` and no action, so the hostname and action checks apply to real keys. Coordinator sign-in is covered here with the console driver, not with a real inbox.
|
||||
+214
-11
@@ -1661,6 +1661,101 @@ article.shift-card {
|
||||
color: var(--hope-ink-2);
|
||||
}
|
||||
|
||||
.settings-intro {
|
||||
max-width: 40rem;
|
||||
margin-bottom: 0.35rem;
|
||||
}
|
||||
|
||||
.settings-intro h1 {
|
||||
margin-bottom: 0.35rem;
|
||||
}
|
||||
|
||||
.settings-intro p {
|
||||
margin: 0;
|
||||
color: var(--hope-ink-2);
|
||||
}
|
||||
|
||||
.settings-form {
|
||||
display: grid;
|
||||
gap: 1rem;
|
||||
max-width: 46rem;
|
||||
margin-top: 1.15rem;
|
||||
}
|
||||
|
||||
.settings-card {
|
||||
display: grid;
|
||||
gap: 1rem;
|
||||
margin: 0;
|
||||
padding: 1.25rem 1.35rem 1.35rem;
|
||||
background: #fff;
|
||||
border: 1px solid #e6eef3;
|
||||
border-radius: 1.35rem;
|
||||
box-shadow: 0 8px 24px rgb(34 55 70 / 0.05);
|
||||
}
|
||||
|
||||
.settings-card h2 {
|
||||
margin: 0;
|
||||
font-size: 1.45rem;
|
||||
font-weight: 650;
|
||||
}
|
||||
|
||||
.settings-card-copy p,
|
||||
.settings-form .hint {
|
||||
margin: 0.35rem 0 0;
|
||||
font-weight: 400;
|
||||
color: var(--hope-ink-2);
|
||||
}
|
||||
|
||||
.settings-form label {
|
||||
display: grid;
|
||||
gap: 0.35rem;
|
||||
margin: 0;
|
||||
font-weight: 650;
|
||||
}
|
||||
|
||||
.settings-fields {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 0.95rem;
|
||||
align-items: start;
|
||||
}
|
||||
|
||||
.settings-form select,
|
||||
.settings-form input[type="email"] {
|
||||
width: 100%;
|
||||
min-height: 48px;
|
||||
padding: 0.7rem 1rem;
|
||||
background: var(--hope-blue-50);
|
||||
border: 0;
|
||||
border-radius: 999px;
|
||||
box-shadow: var(--hope-shadow);
|
||||
font: inherit;
|
||||
color: var(--hope-ink);
|
||||
}
|
||||
|
||||
.settings-preview {
|
||||
margin: 0;
|
||||
padding: 0.85rem 1.05rem;
|
||||
background: var(--hope-blue-wash);
|
||||
border-radius: 1rem;
|
||||
color: var(--hope-ink);
|
||||
font-weight: 650;
|
||||
}
|
||||
|
||||
.settings-save {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
@media (max-width: 42em) {
|
||||
.settings-fields {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.settings-form button {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.error,
|
||||
.field-error {
|
||||
font-weight: 650;
|
||||
@@ -2312,10 +2407,20 @@ button.btn-quiet::before {
|
||||
}
|
||||
|
||||
.event-page .shift-card {
|
||||
background: var(--hope-blue-50);
|
||||
background: #f3f7fb;
|
||||
box-shadow: var(--hope-shadow-soft);
|
||||
}
|
||||
|
||||
.event-page .desk-events {
|
||||
background: #fff;
|
||||
border: 1px solid #e6eef3;
|
||||
box-shadow: 0 8px 24px rgb(34 55 70 / 0.05);
|
||||
}
|
||||
|
||||
.event-page .desk-events .empty {
|
||||
background: #f3f7fb;
|
||||
}
|
||||
|
||||
.pick-bar {
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
@@ -2723,22 +2828,49 @@ button.btn-quiet::before {
|
||||
display: grid;
|
||||
grid-template-columns: auto minmax(0, 1fr);
|
||||
align-items: center;
|
||||
gap: 0.35rem;
|
||||
gap: 0.55rem;
|
||||
padding-left: 0.55rem;
|
||||
background: #f3f7fb;
|
||||
border-radius: 0.95rem;
|
||||
color: var(--hope-ink);
|
||||
}
|
||||
|
||||
.event-page .need-pick:hover,
|
||||
.event-page .need-pick:has(.desk-row:focus-visible) {
|
||||
background: #e8f1f7;
|
||||
}
|
||||
|
||||
.event-page .need-pick:has(.desk-row:focus-visible) {
|
||||
outline: 3px solid var(--hope-ink);
|
||||
outline-offset: 3px;
|
||||
}
|
||||
|
||||
.event-page .need-pick .pick {
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.event-page .need-pick .desk-row {
|
||||
min-width: 0;
|
||||
padding: 0.48rem 0.75rem 0.48rem 0;
|
||||
background: transparent;
|
||||
border-radius: 0;
|
||||
}
|
||||
|
||||
.event-page .desk-row.is-ended {
|
||||
.event-page .need-pick .desk-row:hover,
|
||||
.event-page .need-pick .desk-row:focus-visible {
|
||||
background: transparent;
|
||||
color: inherit;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.event-page .need-pick:has(.desk-row.is-ended) {
|
||||
background: #eef1f4;
|
||||
color: #6b7784;
|
||||
}
|
||||
|
||||
.event-page .desk-row.is-ended:hover,
|
||||
.event-page .desk-row.is-ended:focus-visible {
|
||||
.event-page .need-pick:has(.desk-row.is-ended):hover,
|
||||
.event-page .need-pick:has(.desk-row.is-ended:focus-visible) {
|
||||
background: #e4e9ee;
|
||||
color: #6b7784;
|
||||
}
|
||||
|
||||
.need-day .desk-rows {
|
||||
@@ -2773,7 +2905,7 @@ button.btn-quiet::before {
|
||||
gap: 0.75rem 1rem;
|
||||
min-height: 4.15rem;
|
||||
padding: 0.7rem 0.95rem;
|
||||
background: var(--hope-blue-75);
|
||||
background: #f3f7fb;
|
||||
border-radius: 0.95rem;
|
||||
color: var(--hope-ink);
|
||||
text-decoration: none;
|
||||
@@ -2781,7 +2913,7 @@ button.btn-quiet::before {
|
||||
|
||||
.desk-row:hover,
|
||||
.desk-row:focus-visible {
|
||||
background: var(--hope-blue-100);
|
||||
background: #e8f1f7;
|
||||
color: var(--hope-ink);
|
||||
text-decoration: none;
|
||||
}
|
||||
@@ -2913,7 +3045,7 @@ button.btn-quiet::before {
|
||||
.coordinator-board .desk-panel .empty {
|
||||
margin: 0;
|
||||
padding: 0.85rem 1rem;
|
||||
background: var(--hope-blue-75);
|
||||
background: #f3f7fb;
|
||||
border-radius: 0.95rem;
|
||||
box-shadow: none;
|
||||
}
|
||||
@@ -4330,7 +4462,9 @@ main > .crumb,
|
||||
display: contents;
|
||||
}
|
||||
|
||||
.event-edit:not([open]) > form {
|
||||
/* The closed details content is still a grid row. Hiding it drops the row gap that was sitting under the summary. */
|
||||
.event-edit:not([open]) > form,
|
||||
.event-edit:not([open])::details-content {
|
||||
display: none;
|
||||
}
|
||||
|
||||
@@ -4357,11 +4491,80 @@ main > .crumb,
|
||||
display: none;
|
||||
}
|
||||
|
||||
.event-edit[open] > form {
|
||||
.event-edit[open] > form,
|
||||
.event-edit[open]::details-content {
|
||||
grid-column: 1 / -1;
|
||||
grid-row: 2;
|
||||
}
|
||||
|
||||
.event-edit[open] > summary {
|
||||
background: #f4f8fb;
|
||||
}
|
||||
|
||||
.event-strip:has(.event-edit[open] .event-fields) {
|
||||
padding-bottom: 0;
|
||||
}
|
||||
|
||||
.event-fields {
|
||||
max-width: none;
|
||||
margin: 0.2rem -1rem 0;
|
||||
padding: 1rem 1rem 1.05rem;
|
||||
border-top: 1px solid #e6eef3;
|
||||
border-radius: 0 0 0.9rem 0.9rem;
|
||||
background: var(--hope-blue-75);
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 0.85rem 1rem;
|
||||
align-items: start;
|
||||
}
|
||||
|
||||
.event-fields > .error,
|
||||
.event-fields > label:not(.check) {
|
||||
grid-column: 1 / -1;
|
||||
}
|
||||
|
||||
.event-fields label {
|
||||
line-height: 1.35;
|
||||
}
|
||||
|
||||
.event-fields .hint {
|
||||
font-size: 0.86rem;
|
||||
line-height: 1.4;
|
||||
color: #5c6b78;
|
||||
}
|
||||
|
||||
.event-fields input[type="text"],
|
||||
.event-fields textarea {
|
||||
background: #fff;
|
||||
border: 1px solid #d5dee6;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.event-fields textarea {
|
||||
min-height: 5.75rem;
|
||||
}
|
||||
|
||||
.event-fields > .check {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
align-self: center;
|
||||
min-height: 2.75rem;
|
||||
}
|
||||
|
||||
.event-fields > button {
|
||||
justify-self: end;
|
||||
align-self: center;
|
||||
}
|
||||
|
||||
@media (max-width: 42em) {
|
||||
.event-fields {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.event-fields > button {
|
||||
justify-self: start;
|
||||
}
|
||||
}
|
||||
|
||||
.edit-chevron {
|
||||
width: 0.4rem;
|
||||
height: 0.4rem;
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
(function () {
|
||||
var form = document.querySelector('[data-settings]');
|
||||
if (!form) return;
|
||||
var far = form.querySelector('select[name="reminder_far"]');
|
||||
var near = form.querySelector('select[name="reminder_near"]');
|
||||
var months = form.querySelector('select[name="retention_months"]');
|
||||
var reminderPreview = form.querySelector('[data-reminder-preview]');
|
||||
var retentionPreview = form.querySelector('[data-retention-preview]');
|
||||
|
||||
var phrase = function (select) {
|
||||
if (!select || select.selectedIndex < 0) return '';
|
||||
return select.options[select.selectedIndex].text.replace(' (usual)', '');
|
||||
};
|
||||
|
||||
var clearError = function (select) {
|
||||
if (!select) return;
|
||||
var label = select.closest('label');
|
||||
var error = label && label.querySelector('.error');
|
||||
if (error) error.remove();
|
||||
};
|
||||
|
||||
var paintReminders = function () {
|
||||
clearError(far);
|
||||
clearError(near);
|
||||
if (!far || !near || !reminderPreview) return;
|
||||
var first = phrase(far);
|
||||
var second = phrase(near);
|
||||
if (!first || !second) return;
|
||||
if (far.value === near.value) {
|
||||
reminderPreview.textContent = 'Choose two different times. One email should go out earlier than the other.';
|
||||
return;
|
||||
}
|
||||
var earlier = Number(far.value) >= Number(near.value) ? first : second;
|
||||
var closer = Number(far.value) >= Number(near.value) ? second : first;
|
||||
reminderPreview.textContent = 'Volunteers get an email ' + earlier + ' the shift, and another ' + closer + ' the shift.';
|
||||
};
|
||||
|
||||
var paintRetention = function () {
|
||||
clearError(months);
|
||||
if (!months || !retentionPreview) return;
|
||||
var kept = phrase(months);
|
||||
if (!kept) return;
|
||||
retentionPreview.textContent = 'Names, email addresses, and phone numbers come off a signup ' + kept + ' after the shift ends.';
|
||||
};
|
||||
|
||||
if (far) far.addEventListener('change', paintReminders);
|
||||
if (near) near.addEventListener('change', paintReminders);
|
||||
if (months) months.addEventListener('change', paintRetention);
|
||||
})();
|
||||
@@ -726,7 +726,6 @@ function settingsFormFromBody(body: Record<string, unknown>): SettingsForm {
|
||||
reminderNear: textField(body, 'reminder_near'),
|
||||
replyTo: textField(body, 'reply_to'),
|
||||
retentionMonths: textField(body, 'retention_months'),
|
||||
privacyText: textField(body, 'privacy_text'),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+152
-57
@@ -2,7 +2,7 @@ import { Temporal } from '@js-temporal/polyfill';
|
||||
import { DESK_WINDOW_DAYS, type AdminEvent, type HomeEvent, type HomeShift, type AdminShift, type AdminShiftSummary, type AdminTemplate, type MoveTarget, type RosterPerson } from './admin/store.js';
|
||||
import { spotsSentence } from './schedule.js';
|
||||
import type { EventValues, ShiftValues, TemplateValues } from './admin/forms.js';
|
||||
import type { SettingsErrors, SettingsForm } from './settings.js';
|
||||
import { MAX_REMINDER_HOURS, MAX_RETENTION_MONTHS, type SettingsErrors, type SettingsForm } from './settings.js';
|
||||
import type { AppConfig } from './config.js';
|
||||
import {
|
||||
CONTACT_LIST_PAGE,
|
||||
@@ -337,6 +337,13 @@ export function AdminHome(props: {
|
||||
);
|
||||
}
|
||||
|
||||
const FIRST_REMINDER_HOURS = [168, 72, 48, 24] as const;
|
||||
const SECOND_REMINDER_HOURS = [24, 12, 4, 2, 1] as const;
|
||||
const RETENTION_MONTHS = [6, 12, 24, 36, 60, 120] as const;
|
||||
const USUAL_FIRST_HOURS = 48;
|
||||
const USUAL_SECOND_HOURS = 2;
|
||||
const USUAL_RETENTION_MONTHS = 24;
|
||||
|
||||
export function SettingsPage(props: {
|
||||
config: AppConfig;
|
||||
csrf: string;
|
||||
@@ -345,50 +352,149 @@ export function SettingsPage(props: {
|
||||
notice?: string;
|
||||
}) {
|
||||
const errors = props.errors ?? {};
|
||||
const reminderNote = reminderPreview(props.values.reminderFar, props.values.reminderNear);
|
||||
const keepNote = retentionPreview(props.values.retentionMonths);
|
||||
return (
|
||||
<>
|
||||
<Crumb items={[{ href: appPath(props.config, '/admin'), label: 'Coordinator' }, { label: 'Settings' }]} />
|
||||
<h1>Settings</h1>
|
||||
<header class="settings-intro">
|
||||
<h1>Settings</h1>
|
||||
<p>Choose when volunteers get a reminder, where their replies go, and how long signup details stay here. This applies to email that has not gone out yet.</p>
|
||||
</header>
|
||||
<Notice notice={props.notice} />
|
||||
<form method="post" action={appPath(props.config, '/admin/settings')} class="signup-form">
|
||||
<form method="post" action={appPath(props.config, '/admin/settings')} class="settings-form" data-settings>
|
||||
<input type="hidden" name="csrf" value={props.csrf} />
|
||||
<p>These apply to reminders and mail that have not been queued yet. Mail that was already accepted cannot be recalled.</p>
|
||||
<label>
|
||||
First reminder, hours before the shift
|
||||
<input name="reminder_far" type="number" min="1" max="336" required value={props.values.reminderFar} />
|
||||
<span class="hint">The default is 48. Use a whole number from 1 to 336.</span>
|
||||
{errors.reminderFar ? <span class="error">{errors.reminderFar}</span> : null}
|
||||
</label>
|
||||
<label>
|
||||
Second reminder, hours before the shift
|
||||
<input name="reminder_near" type="number" min="1" max="336" required value={props.values.reminderNear} />
|
||||
<span class="hint">The default is 2. The two times have to be different. A reminder is not sent after the shift starts.</span>
|
||||
{errors.reminderNear ? <span class="error">{errors.reminderNear}</span> : null}
|
||||
</label>
|
||||
<label>
|
||||
Reply-to address
|
||||
<input name="reply_to" type="email" required value={props.values.replyTo} />
|
||||
<span class="hint">Replies to volunteer and sign-in email go here. The sending address stays in the server configuration.</span>
|
||||
{errors.replyTo ? <span class="error">{errors.replyTo}</span> : null}
|
||||
</label>
|
||||
<label>
|
||||
Keep signups for, months
|
||||
<input name="retention_months" type="number" min="1" max="120" required value={props.values.retentionMonths} />
|
||||
<span class="hint">The default is 24, counted after the shift ends. After 1:00 AM Central Time, signups older than this lose their name, email, phone, and notes in this app. A spreadsheet already downloaded is left as it is.</span>
|
||||
{errors.retentionMonths ? <span class="error">{errors.retentionMonths}</span> : null}
|
||||
</label>
|
||||
<label>
|
||||
Privacy page wording
|
||||
<textarea name="privacy_text">{props.values.privacyText}</textarea>
|
||||
<span class="hint">Leave this blank until the pantry approves a notice. Saved wording is what the public privacy page shows. Saving it does not by itself make it an approved privacy policy. Start a new line for a new paragraph.</span>
|
||||
{errors.privacyText ? <span class="error">{errors.privacyText}</span> : null}
|
||||
</label>
|
||||
<button type="submit">Save settings</button>
|
||||
<section class="settings-card" aria-labelledby="reminders-heading">
|
||||
<div class="settings-card-copy">
|
||||
<h2 id="reminders-heading">Reminder emails</h2>
|
||||
<p>Each person who is signed up gets two emails before the shift, so they remember to come. A reminder is not sent after the shift starts.</p>
|
||||
</div>
|
||||
<div class="settings-fields">
|
||||
<label>
|
||||
First reminder
|
||||
<select name="reminder_far" required>
|
||||
<ReminderOptions selected={props.values.reminderFar} choices={FIRST_REMINDER_HOURS} usual={USUAL_FIRST_HOURS} />
|
||||
</select>
|
||||
{errors.reminderFar ? <span class="error">{errors.reminderFar}</span> : null}
|
||||
</label>
|
||||
<label>
|
||||
Second reminder
|
||||
<select name="reminder_near" required>
|
||||
<ReminderOptions selected={props.values.reminderNear} choices={SECOND_REMINDER_HOURS} usual={USUAL_SECOND_HOURS} />
|
||||
</select>
|
||||
{errors.reminderNear ? <span class="error">{errors.reminderNear}</span> : null}
|
||||
</label>
|
||||
</div>
|
||||
{reminderNote ? <p class="settings-preview" data-reminder-preview>{reminderNote}</p> : null}
|
||||
</section>
|
||||
<section class="settings-card" aria-labelledby="replies-heading">
|
||||
<div class="settings-card-copy">
|
||||
<h2 id="replies-heading">Where replies go</h2>
|
||||
<p>When a volunteer replies to a pantry email, it comes to this address. Use an inbox someone at the pantry checks.</p>
|
||||
</div>
|
||||
<label>
|
||||
Email address
|
||||
<input name="reply_to" type="email" autocomplete="email" required value={props.values.replyTo} />
|
||||
<span class="hint">This does not change the address the email is sent from.</span>
|
||||
{errors.replyTo ? <span class="error">{errors.replyTo}</span> : null}
|
||||
</label>
|
||||
</section>
|
||||
<section class="settings-card" aria-labelledby="keep-heading">
|
||||
<div class="settings-card-copy">
|
||||
<h2 id="keep-heading">How long we keep signup details</h2>
|
||||
<p>After a shift ends, that person's name, email, and phone stay on the signup for a while, then they are removed.</p>
|
||||
</div>
|
||||
<label>
|
||||
Keep them for
|
||||
<select name="retention_months" required>
|
||||
<RetentionOptions selected={props.values.retentionMonths} />
|
||||
</select>
|
||||
<span class="hint">A spreadsheet already downloaded is left as it is. People stay on the contact list.</span>
|
||||
{errors.retentionMonths ? <span class="error">{errors.retentionMonths}</span> : null}
|
||||
</label>
|
||||
{keepNote ? <p class="settings-preview" data-retention-preview>{keepNote}</p> : null}
|
||||
</section>
|
||||
<div class="settings-save">
|
||||
<button type="submit">Save these choices</button>
|
||||
</div>
|
||||
</form>
|
||||
<script src={assetHref(props.config, '/js/settings.js')} defer />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function ReminderOptions(props: { selected: string; choices: readonly number[]; usual: number }) {
|
||||
return listedHours(props.selected, props.choices).map((hours) => (
|
||||
<option value={String(hours)} key={hours} selected={String(hours) === props.selected.trim() ? true : undefined}>
|
||||
{`${aheadChoice(hours)}${hours === props.usual ? ' (usual)' : ''}`}
|
||||
</option>
|
||||
));
|
||||
}
|
||||
|
||||
function RetentionOptions(props: { selected: string }) {
|
||||
return listedMonths(props.selected).map((months) => (
|
||||
<option value={String(months)} key={months} selected={String(months) === props.selected.trim() ? true : undefined}>
|
||||
{`${keepPhrase(months)}${months === USUAL_RETENTION_MONTHS ? ' (usual)' : ''}`}
|
||||
</option>
|
||||
));
|
||||
}
|
||||
|
||||
function listedHours(selected: string, choices: readonly number[]): number[] {
|
||||
const current = wholeInRange(selected, 1, MAX_REMINDER_HOURS);
|
||||
if (current === null || choices.includes(current)) return [...choices];
|
||||
return [...choices, current].sort((a, b) => b - a);
|
||||
}
|
||||
|
||||
function listedMonths(selected: string): number[] {
|
||||
const current = wholeInRange(selected, 1, MAX_RETENTION_MONTHS);
|
||||
if (current === null || (RETENTION_MONTHS as readonly number[]).includes(current)) return [...RETENTION_MONTHS];
|
||||
return [...RETENTION_MONTHS, current].sort((a, b) => a - b);
|
||||
}
|
||||
|
||||
function reminderPreview(far: string, near: string): string | null {
|
||||
const first = wholeInRange(far, 1, MAX_REMINDER_HOURS);
|
||||
const second = wholeInRange(near, 1, MAX_REMINDER_HOURS);
|
||||
if (first === null || second === null) return null;
|
||||
if (first === second) return 'Choose two different times. One email should go out earlier than the other.';
|
||||
const earlier = Math.max(first, second);
|
||||
const closer = Math.min(first, second);
|
||||
return `Volunteers get an email ${aheadChoice(earlier)} the shift, and another ${aheadChoice(closer)} the shift.`;
|
||||
}
|
||||
|
||||
function retentionPreview(months: string): string | null {
|
||||
const count = wholeInRange(months, 1, MAX_RETENTION_MONTHS);
|
||||
if (count === null) return null;
|
||||
return `Names, email addresses, and phone numbers come off a signup ${keepPhrase(count)} after the shift ends.`;
|
||||
}
|
||||
|
||||
function aheadChoice(hours: number): string {
|
||||
if (hours === 1) return '1 hour before';
|
||||
if (hours % 168 === 0) {
|
||||
const weeks = hours / 168;
|
||||
return weeks === 1 ? '1 week before' : `${weeks} weeks before`;
|
||||
}
|
||||
if (hours % 24 === 0) {
|
||||
const days = hours / 24;
|
||||
return days === 1 ? '1 day before' : `${days} days before`;
|
||||
}
|
||||
return `${hours} hours before`;
|
||||
}
|
||||
|
||||
function keepPhrase(months: number): string {
|
||||
if (months % 12 === 0) {
|
||||
const years = months / 12;
|
||||
return years === 1 ? '1 year' : `${years} years`;
|
||||
}
|
||||
return months === 1 ? '1 month' : `${months} months`;
|
||||
}
|
||||
|
||||
function wholeInRange(value: string, min: number, max: number): number | null {
|
||||
const trimmed = value.trim();
|
||||
if (!/^[1-9][0-9]{0,2}$/.test(trimmed)) return null;
|
||||
const count = Number(trimmed);
|
||||
return count >= min && count <= max ? count : null;
|
||||
}
|
||||
|
||||
export function AdminsPage(props: {
|
||||
config: AppConfig;
|
||||
csrf: string;
|
||||
@@ -796,7 +902,7 @@ export function EventEditor(props: {
|
||||
Edit details
|
||||
<span class="edit-chevron" aria-hidden="true" />
|
||||
</summary>
|
||||
<EventForm action={props.action} csrf={props.csrf} values={props.values} error={props.error} submitLabel={props.submitLabel} wide />
|
||||
<EventForm action={props.action} csrf={props.csrf} values={props.values} error={props.error} submitLabel={props.submitLabel} wide panel />
|
||||
</details>
|
||||
</section>
|
||||
) : (
|
||||
@@ -1659,41 +1765,30 @@ function EventForm(props: {
|
||||
heading?: string;
|
||||
headingId?: string;
|
||||
wide?: boolean;
|
||||
panel?: boolean;
|
||||
}) {
|
||||
const formClass = ['signup-form', props.wide ? 'event-details-form' : '', props.panel ? 'event-fields' : ''].filter(Boolean).join(' ');
|
||||
return (
|
||||
<form method="post" action={props.action} class={props.wide ? 'signup-form event-details-form' : 'signup-form'}>
|
||||
<form method="post" action={props.action} class={formClass}>
|
||||
{props.heading ? <h2 id={props.headingId}>{props.heading}</h2> : null}
|
||||
<input type="hidden" name="csrf" value={props.csrf} />
|
||||
{props.creating ? <input type="hidden" name="tz" value={props.values.tz} /> : null}
|
||||
<input type="hidden" name="tz" value={props.values.tz} />
|
||||
{props.values.slug ? <input type="hidden" name="slug" value={props.values.slug} /> : null}
|
||||
{props.error ? <p class="error">{props.error}</p> : null}
|
||||
<label>
|
||||
Title
|
||||
<input name="title" type="text" required value={props.values.title} />
|
||||
</label>
|
||||
{props.creating ? null : (
|
||||
<label>
|
||||
Public address
|
||||
<input name="slug" type="text" value={props.values.slug} />
|
||||
<span class="hint">Letters, numbers, and hyphens. Leave this blank to build it from the title. This becomes /e/this-address.</span>
|
||||
</label>
|
||||
)}
|
||||
<label>
|
||||
Description
|
||||
<textarea name="description">{props.values.description}</textarea>
|
||||
</label>
|
||||
{props.creating ? null : (
|
||||
<>
|
||||
<label>
|
||||
Location
|
||||
<input name="location" type="text" value={props.values.location} />
|
||||
<span class="hint">Changing the location emails people on shifts that have not ended.</span>
|
||||
</label>
|
||||
<label>
|
||||
Time zone
|
||||
<input name="tz" type="text" required value={props.values.tz} />
|
||||
<span class="hint">Use an IANA time zone, such as America/Chicago.</span>
|
||||
</label>
|
||||
</>
|
||||
<label>
|
||||
Location
|
||||
<input name="location" type="text" value={props.values.location} />
|
||||
<span class="hint">Changing the location emails people on shifts that have not ended.</span>
|
||||
</label>
|
||||
)}
|
||||
<label class="check">
|
||||
<input type="checkbox" name="published" value="yes" checked={props.values.published ? true : undefined} />
|
||||
|
||||
+1
-1
@@ -51,7 +51,7 @@ export function parseEvent(values: EventValues): { ok: true; value: EventInput }
|
||||
if (title.length === 0) return { ok: false, error: 'Enter a title.' };
|
||||
if (title.length > 120) return { ok: false, error: 'Use a shorter title.' };
|
||||
const slug = values.slug.trim() ? normalizeSlug(values.slug) : normalizeSlug(title);
|
||||
if (!validSlug(slug)) return { ok: false, error: 'Use a public address with lowercase letters, numbers, and hyphens.' };
|
||||
if (!validSlug(slug)) return { ok: false, error: 'Use a title with a letter or number.' };
|
||||
const description = values.description.trim();
|
||||
if (description.length > 2000) return { ok: false, error: 'Use a shorter description.' };
|
||||
const location = values.location.trim();
|
||||
|
||||
+2
-2
@@ -349,7 +349,7 @@ export function createEvent(
|
||||
return { ok: true as const, id, mailed: 0 };
|
||||
}).immediate();
|
||||
} catch (err) {
|
||||
if (isUniqueConstraint(err)) return { ok: false, error: 'That public address is already used.' };
|
||||
if (isUniqueConstraint(err)) return { ok: false, error: 'Another event already uses that name.' };
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
@@ -386,7 +386,7 @@ export function updateEvent(
|
||||
return { ok: true as const, id, mailed };
|
||||
}).immediate();
|
||||
} catch (err) {
|
||||
if (isUniqueConstraint(err)) return { ok: false, error: 'That public address is already used.' };
|
||||
if (isUniqueConstraint(err)) return { ok: false, error: 'Another event already uses that name.' };
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-7
@@ -5,9 +5,8 @@ import type { Child } from 'hono/jsx';
|
||||
import { registerAdmin } from './admin-http.js';
|
||||
import { readSession } from './auth/session.js';
|
||||
import type { AppConfig } from './config.js';
|
||||
import { EmptySchedulePage, EventPage, Layout, NotFoundPage, PrivacyPage, ProblemPage } from './pages.js';
|
||||
import { EmptySchedulePage, EventPage, Layout, NotFoundPage, ProblemPage } from './pages.js';
|
||||
import { getPublishedEvent } from './schedule.js';
|
||||
import { privacyParagraphs, readPantrySettings } from './settings.js';
|
||||
import { registerReminderOff } from './reminder-http.js';
|
||||
import { registerPublicSignup } from './signup-http.js';
|
||||
import { securityHeaders } from './security.js';
|
||||
@@ -80,11 +79,6 @@ export function createApp(
|
||||
app.get(`${config.basePath}/`, (c) => c.redirect(config.basePath, 302));
|
||||
}
|
||||
|
||||
app.get(appPath(config, '/privacy'), (c) => {
|
||||
const paragraphs = privacyParagraphs(readPantrySettings(db, config.mail.replyTo).privacyText);
|
||||
return page(c, config, db, now(), 'Privacy · Hope Volunteer', <PrivacyPage paragraphs={paragraphs} />);
|
||||
});
|
||||
|
||||
app.get(appPath(config, '/e/:slug'), (c) => {
|
||||
const at = now();
|
||||
const slug = c.req.param('slug') ?? '';
|
||||
|
||||
@@ -484,24 +484,6 @@ export function ManagePage(props: {
|
||||
);
|
||||
}
|
||||
|
||||
// TODO(D3): The pantry still has to approve this wording, including retention and copies.
|
||||
// A blank setting keeps the unapproved message. Saved wording is shown as written, escaped, and is not a policy by itself.
|
||||
export function PrivacyPage(props: { paragraphs: string[] }) {
|
||||
return (
|
||||
<>
|
||||
<h1>Privacy</h1>
|
||||
{props.paragraphs.length === 0 ? (
|
||||
<>
|
||||
<p>Hope Volunteer does not have an approved privacy notice yet.</p>
|
||||
<p>When the pantry approves the wording, it will appear on this page. This page is not a privacy policy.</p>
|
||||
</>
|
||||
) : (
|
||||
props.paragraphs.map((paragraph, index) => <p key={index}>{paragraph}</p>)
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export function SwitchAlreadyPage() {
|
||||
return (
|
||||
<>
|
||||
|
||||
+10
-44
@@ -7,18 +7,15 @@ export const DEFAULT_REMINDER_HOURS = [48, 2] as const;
|
||||
export const DEFAULT_RETENTION_MONTHS = 24;
|
||||
export const MAX_REMINDER_HOURS = 336;
|
||||
export const MAX_RETENTION_MONTHS = 120;
|
||||
export const MAX_PRIVACY_TEXT = 8000;
|
||||
|
||||
const HOUR_KEY = 'reminder_hours';
|
||||
const REPLY_KEY = 'reply_to';
|
||||
const PRIVACY_KEY = 'privacy_text';
|
||||
const RETENTION_KEY = 'retention_months';
|
||||
|
||||
export type PantrySettings = {
|
||||
/** Larger hour count first, so the first reminder is the earlier one. */
|
||||
reminderHours: readonly [number, number];
|
||||
replyTo: string;
|
||||
privacyText: string;
|
||||
retentionMonths: number;
|
||||
};
|
||||
|
||||
@@ -27,7 +24,6 @@ export type SettingsForm = {
|
||||
reminderNear: string;
|
||||
replyTo: string;
|
||||
retentionMonths: string;
|
||||
privacyText: string;
|
||||
};
|
||||
|
||||
export type SettingsErrors = Partial<Record<keyof SettingsForm, string>>;
|
||||
@@ -40,7 +36,6 @@ export function readPantrySettings(db: Database.Database, fallbackReplyTo: strin
|
||||
return {
|
||||
reminderHours: storedHours(db),
|
||||
replyTo: storedReplyTo(db) ?? fallbackReplyTo,
|
||||
privacyText: storedPrivacy(db),
|
||||
retentionMonths: storedRetention(db),
|
||||
};
|
||||
}
|
||||
@@ -58,20 +53,12 @@ export function readReplyTo(db: Database.Database, fallback: string): string {
|
||||
return storedReplyTo(db) ?? fallback;
|
||||
}
|
||||
|
||||
export function privacyParagraphs(text: string): string[] {
|
||||
return text
|
||||
.split(/\n+/)
|
||||
.map((line) => line.trim())
|
||||
.filter((line) => line.length > 0);
|
||||
}
|
||||
|
||||
export function settingsFormFrom(settings: PantrySettings): SettingsForm {
|
||||
return {
|
||||
reminderFar: String(settings.reminderHours[0]),
|
||||
reminderNear: String(settings.reminderHours[1]),
|
||||
replyTo: settings.replyTo,
|
||||
retentionMonths: String(settings.retentionMonths),
|
||||
privacyText: settings.privacyText,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -79,18 +66,16 @@ export function parseSettingsForm(input: SettingsForm): { ok: true; value: Pantr
|
||||
const errors: SettingsErrors = {};
|
||||
const earlier = parseHour(input.reminderFar);
|
||||
const closer = parseHour(input.reminderNear);
|
||||
if (earlier === null) errors.reminderFar = `Enter a whole number of hours from 1 to ${MAX_REMINDER_HOURS}.`;
|
||||
if (closer === null) errors.reminderNear = `Enter a whole number of hours from 1 to ${MAX_REMINDER_HOURS}.`;
|
||||
if (earlier === null) errors.reminderFar = 'Choose when the first reminder goes out.';
|
||||
if (closer === null) errors.reminderNear = 'Choose when the second reminder goes out.';
|
||||
if (earlier !== null && closer !== null && earlier === closer) {
|
||||
errors.reminderNear = 'The two reminder times have to be different.';
|
||||
errors.reminderNear = 'Choose two different times.';
|
||||
}
|
||||
const reply = parseReply(input.replyTo);
|
||||
if (!reply.ok) errors.replyTo = reply.error;
|
||||
const months = parseMonths(input.retentionMonths);
|
||||
if (months === null) errors.retentionMonths = `Enter a whole number of months from 1 to ${MAX_RETENTION_MONTHS}.`;
|
||||
const privacy = parsePrivacy(input.privacyText);
|
||||
if (!privacy.ok) errors.privacyText = privacy.error;
|
||||
if (earlier === null || closer === null || earlier === closer || !reply.ok || months === null || !privacy.ok) {
|
||||
if (months === null) errors.retentionMonths = 'Choose how long to keep signup details.';
|
||||
if (earlier === null || closer === null || earlier === closer || !reply.ok || months === null) {
|
||||
return { ok: false, errors };
|
||||
}
|
||||
const reminderHours: [number, number] = earlier > closer ? [earlier, closer] : [closer, earlier];
|
||||
@@ -99,15 +84,14 @@ export function parseSettingsForm(input: SettingsForm): { ok: true; value: Pantr
|
||||
value: {
|
||||
reminderHours,
|
||||
replyTo: reply.value,
|
||||
privacyText: privacy.value,
|
||||
retentionMonths: months,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the four coordinator settings. Retention is stored only.
|
||||
* This does not anonymize signups, and it does not change mail that is already queued.
|
||||
* Saves reminder times, the reply address, and how long signup details are kept.
|
||||
* This does not remove signup details, and it does not change mail that is already queued.
|
||||
*/
|
||||
export function savePantrySettings(
|
||||
db: Database.Database,
|
||||
@@ -116,16 +100,15 @@ export function savePantrySettings(
|
||||
fallbackReplyTo: string,
|
||||
now: string,
|
||||
): { changed: boolean } {
|
||||
db.prepare(`DELETE FROM settings WHERE key = 'privacy_text'`).run();
|
||||
const current = readPantrySettings(db, fallbackReplyTo);
|
||||
const replyChanged = current.replyTo !== next.replyTo;
|
||||
const privacyChanged = current.privacyText !== next.privacyText;
|
||||
const hoursChanged = current.reminderHours[0] !== next.reminderHours[0] || current.reminderHours[1] !== next.reminderHours[1];
|
||||
const retentionChanged = current.retentionMonths !== next.retentionMonths;
|
||||
if (!replyChanged && !privacyChanged && !hoursChanged && !retentionChanged) return { changed: false };
|
||||
if (!replyChanged && !hoursChanged && !retentionChanged) return { changed: false };
|
||||
db.transaction(() => {
|
||||
writeValue(db, HOUR_KEY, [next.reminderHours[0], next.reminderHours[1]], now);
|
||||
writeValue(db, REPLY_KEY, next.replyTo, now);
|
||||
writeValue(db, PRIVACY_KEY, next.privacyText, now);
|
||||
writeValue(db, RETENTION_KEY, next.retentionMonths, now);
|
||||
writeAudit(
|
||||
db,
|
||||
@@ -136,7 +119,6 @@ export function savePantrySettings(
|
||||
reminderCloser: next.reminderHours[1],
|
||||
retentionMonths: next.retentionMonths,
|
||||
replyChanged: replyChanged ? 1 : 0,
|
||||
privacyChanged: privacyChanged ? 1 : 0,
|
||||
},
|
||||
now,
|
||||
);
|
||||
@@ -163,13 +145,6 @@ function storedReplyTo(db: Database.Database): string | null {
|
||||
}
|
||||
}
|
||||
|
||||
function storedPrivacy(db: Database.Database): string {
|
||||
const value = readValue(db, PRIVACY_KEY);
|
||||
if (typeof value !== 'string') return '';
|
||||
const parsed = parsePrivacy(value);
|
||||
return parsed.ok ? parsed.value : '';
|
||||
}
|
||||
|
||||
function storedRetention(db: Database.Database): number {
|
||||
const value = readValue(db, RETENTION_KEY);
|
||||
return isMonth(value) ? value : DEFAULT_RETENTION_MONTHS;
|
||||
@@ -208,7 +183,7 @@ function parseMonths(value: string): number | null {
|
||||
|
||||
function parseReply(value: string): { ok: true; value: string } | { ok: false; error: string } {
|
||||
if (value.includes('<') || value.includes('>')) {
|
||||
return { ok: false, error: 'Enter an email address without a display name.' };
|
||||
return { ok: false, error: 'Enter just the email address, without a name in front of it.' };
|
||||
}
|
||||
try {
|
||||
return { ok: true, value: normalizeEmail(value) };
|
||||
@@ -217,15 +192,6 @@ function parseReply(value: string): { ok: true; value: string } | { ok: false; e
|
||||
}
|
||||
}
|
||||
|
||||
function parsePrivacy(value: string): { ok: true; value: string } | { ok: false; error: string } {
|
||||
const cleaned = value.replace(/\r\n/g, '\n').replace(/\r/g, '\n').replace(/\t/g, ' ').trim();
|
||||
if (cleaned.length > MAX_PRIVACY_TEXT) return { ok: false, error: 'Keep the privacy wording under 8,000 characters.' };
|
||||
if (/[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F]/.test(cleaned)) {
|
||||
return { ok: false, error: 'Remove the unusual character in the privacy wording.' };
|
||||
}
|
||||
return { ok: true, value: cleaned };
|
||||
}
|
||||
|
||||
function isHour(value: unknown): value is number {
|
||||
return typeof value === 'number' && Number.isInteger(value) && value >= 1 && value <= MAX_REMINDER_HOURS;
|
||||
}
|
||||
|
||||
@@ -213,16 +213,16 @@ describe('public pages', () => {
|
||||
expect(stylesheet).not.toContain('h1.bare');
|
||||
});
|
||||
|
||||
it('serves an honest privacy page, a minimal health check, and static assets', async () => {
|
||||
it('leaves /privacy unavailable, and serves a minimal health check and static assets', async () => {
|
||||
const { app } = await buildApp();
|
||||
const privacy = await app.request('/privacy');
|
||||
const privacyHtml = await privacy.text();
|
||||
expect(privacy.status).toBe(200);
|
||||
expect(privacy.status).toBe(404);
|
||||
expect(privacyHtml).toContain('That page is not available');
|
||||
expect(privacyHtml).toContain('class="main-nav-link" href="/">Volunteering</a>');
|
||||
expect(privacyHtml).not.toContain('aria-current="page"');
|
||||
expect(privacyHtml).toContain('does not have an approved privacy notice yet');
|
||||
expect(privacyHtml).toContain('This page is not a privacy policy.');
|
||||
expect(privacyHtml).not.toContain('24 months');
|
||||
expect(privacyHtml).not.toContain('privacy notice');
|
||||
expect(privacyHtml).not.toContain('privacy policy');
|
||||
|
||||
const health = await app.request('/healthz');
|
||||
expect(health.status).toBe(200);
|
||||
|
||||
+20
-22
@@ -33,31 +33,32 @@ describe('coordinator settings', () => {
|
||||
expect(response.headers.get('location')).toBe('/login');
|
||||
});
|
||||
|
||||
it('shows the defaults, then saves reminder times, reply-to, retention, and privacy wording', async () => {
|
||||
it('shows the defaults, then saves reminder times, reply-to, and retention', async () => {
|
||||
const { app, db } = await buildApp();
|
||||
const cookie = await signIn(app, db);
|
||||
const first = await app.request('/admin/settings', { headers: { cookie } });
|
||||
const firstHtml = await first.text();
|
||||
expect(first.status).toBe(200);
|
||||
expect(firstHtml).toContain('value="48"');
|
||||
expect(firstHtml).toContain('2 days before (usual)');
|
||||
expect(firstHtml).toContain('value="2"');
|
||||
expect(firstHtml).toContain('2 hours before (usual)');
|
||||
expect(firstHtml).toContain('value="volunteer@example.invalid"');
|
||||
expect(firstHtml).toContain('value="24"');
|
||||
expect(firstHtml).toContain('2 years (usual)');
|
||||
expect(firstHtml).toContain('Volunteers get an email 2 days before the shift, and another 2 hours before the shift.');
|
||||
expect(firstHtml).toContain('A spreadsheet already downloaded is left as it is.');
|
||||
expect(firstHtml).toContain('does not by itself make it an approved privacy policy');
|
||||
expect(firstHtml).not.toContain('name="privacy_text"');
|
||||
expect(firstHtml).not.toContain('Privacy');
|
||||
|
||||
const rejected = await postSettings(app, cookie, validFields({ reminder_far: '12', reminder_near: '12' }));
|
||||
expect(rejected.status).toBe(400);
|
||||
expect(await rejected.text()).toContain('The two reminder times have to be different.');
|
||||
expect(await rejected.text()).toContain('Choose two different times.');
|
||||
expect(count(db, "SELECT COUNT(*) AS n FROM settings")).toBe(0);
|
||||
|
||||
const named = await postSettings(app, cookie, validFields({ reply_to: 'Hope <pantry@example.invalid>' }));
|
||||
expect(named.status).toBe(400);
|
||||
expect(await named.text()).toContain('Enter an email address without a display name.');
|
||||
|
||||
const huge = await postSettings(app, cookie, validFields({ privacy_text: 'a'.repeat(8001) }));
|
||||
expect(huge.status).toBe(400);
|
||||
expect(await huge.text()).toContain('Keep the privacy wording under 8,000 characters.');
|
||||
expect(await named.text()).toContain('Enter just the email address, without a name in front of it.');
|
||||
|
||||
const stale = await app.request('/admin/settings', {
|
||||
method: 'POST',
|
||||
@@ -66,6 +67,7 @@ describe('coordinator settings', () => {
|
||||
});
|
||||
expect(stale.status).toBe(403);
|
||||
|
||||
db.prepare(`INSERT INTO settings (key, value_json, updated_at) VALUES ('privacy_text', '"We keep names."', ?)`).run(NOW);
|
||||
const saved = await postSettings(
|
||||
app,
|
||||
cookie,
|
||||
@@ -74,7 +76,6 @@ describe('coordinator settings', () => {
|
||||
reminder_near: '24',
|
||||
reply_to: 'Pantry@Example.invalid',
|
||||
retention_months: '12',
|
||||
privacy_text: 'We keep names.\n\n<script>alert(1)</script>',
|
||||
}),
|
||||
);
|
||||
expect(saved.status).toBe(303);
|
||||
@@ -83,19 +84,19 @@ describe('coordinator settings', () => {
|
||||
const html = await page.text();
|
||||
expect(html).toContain('Settings saved.');
|
||||
expect(html).toContain('value="24"');
|
||||
expect(html).toContain('1 day before');
|
||||
expect(html).toContain('value="3"');
|
||||
expect(html).toContain('3 hours before');
|
||||
expect(html).toContain('value="pantry@example.invalid"');
|
||||
expect(html).toContain('value="12"');
|
||||
expect(html).toContain('We keep names.');
|
||||
expect(html).toContain('<script>');
|
||||
expect(html).not.toContain('<script>');
|
||||
expect(html).toContain('1 year');
|
||||
expect(html).not.toContain('We keep names.');
|
||||
expect(html).not.toContain('name="privacy_text"');
|
||||
expect(count(db, "SELECT COUNT(*) AS n FROM settings WHERE key = 'privacy_text'")).toBe(0);
|
||||
|
||||
const privacy = await app.request('/privacy');
|
||||
const privacyHtml = await privacy.text();
|
||||
expect(privacyHtml).toContain('We keep names.');
|
||||
expect(privacyHtml).toContain('<script>alert(1)</script>');
|
||||
expect(privacyHtml).not.toContain('<script>');
|
||||
expect(privacyHtml).not.toContain('does not have an approved privacy notice yet');
|
||||
const missing = await app.request('/privacy');
|
||||
expect(missing.status).toBe(404);
|
||||
expect(await missing.text()).toContain('That page is not available');
|
||||
|
||||
const audit = db.prepare("SELECT detail_json AS detail_json FROM audit WHERE action = 'settings.update'").all() as { detail_json: string }[];
|
||||
expect(audit).toHaveLength(1);
|
||||
@@ -103,9 +104,8 @@ describe('coordinator settings', () => {
|
||||
expect(audit[0]?.detail_json).toContain('"reminderCloser":3');
|
||||
expect(audit[0]?.detail_json).toContain('"retentionMonths":12');
|
||||
expect(audit[0]?.detail_json).toContain('"replyChanged":1');
|
||||
expect(audit[0]?.detail_json).toContain('"privacyChanged":1');
|
||||
expect(audit[0]?.detail_json).not.toContain('privacyChanged');
|
||||
expect(audit[0]?.detail_json).not.toContain('@');
|
||||
expect(audit[0]?.detail_json).not.toContain('We keep names');
|
||||
|
||||
const again = await postSettings(
|
||||
app,
|
||||
@@ -115,7 +115,6 @@ describe('coordinator settings', () => {
|
||||
reminder_near: '3',
|
||||
reply_to: 'pantry@example.invalid',
|
||||
retention_months: '12',
|
||||
privacy_text: 'We keep names.\n\n<script>alert(1)</script>',
|
||||
}),
|
||||
);
|
||||
expect(again.status).toBe(303);
|
||||
@@ -193,7 +192,6 @@ function validFields(overrides: Record<string, string> = {}): Record<string, str
|
||||
reminder_near: '2',
|
||||
reply_to: 'volunteer@example.invalid',
|
||||
retention_months: '24',
|
||||
privacy_text: '',
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user