From 08366ca895393c4e84cb7d351a2466fc7c4b30f9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?=
Date: Wed, 26 Aug 2026 16:26:35 +0300
Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(settings):=20send=20a=20test?=
=?UTF-8?q?=20mail=20to=20yourself=20and=20keep=20the=20result?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The sender panel could be filled in and saved, but nothing told an admin
whether what they saved actually works. The artboard answers that with a
row under the fields — `delivered in 1.2 s — Aug 25 10:41` — so the result
has to survive a reload, not live in a signal that a refresh throws away.
- `send_test_mail` is admin-only in the handler, refuses when no sender is
saved rather than burning a send, and mails only the caller's own address:
a test pointable at a typed address would be a way to make Dizey mail a
stranger on demand.
- The outcome is stored on the workspace (migration 0009) and cleared by
`set_sender`, so a green line never sits under settings nobody has tried.
- Forms cannot nest, so the test form sits beside the settings form in a
split foot and Save reaches back with `form="sender-settings"` — which
works with and without script.
- `.panel-foot` now sets `flex-direction: row`: a foot inside a `.panel-body`
was inheriting that column and stacking the sign-out row centred.
Verified in a headless browser: pressing the button with no sender saved
says so; with a sender pointed at a closed port the row reads
`not delivered, Aug 26 13:25 — Connection error: Connection refused (os
error 111)` and is still there after a reload. The `delivered in 1.2 s`
formatting is gated by a unit test, not by a live send.
---
.../migrations/0009_sender_test.sql | 14 ++
crates/dizey-core/src/mail.rs | 23 +++
crates/dizey-core/src/store/mod.rs | 20 ++
crates/dizey-core/src/store/turso_store.rs | 38 +++-
crates/dizey-core/tests/store.rs | 4 +-
crates/dizey-web/src/server.rs | 8 +
crates/dizey-web/src/settings.rs | 176 +++++++++++++++++-
crates/dizey-web/tests/http.rs | 79 +++++++-
style/main.scss | 11 ++
9 files changed, 363 insertions(+), 10 deletions(-)
create mode 100644 crates/dizey-core/migrations/0009_sender_test.sql
diff --git a/crates/dizey-core/migrations/0009_sender_test.sql b/crates/dizey-core/migrations/0009_sender_test.sql
new file mode 100644
index 0000000..e5d2c92
--- /dev/null
+++ b/crates/dizey-core/migrations/0009_sender_test.sql
@@ -0,0 +1,14 @@
+-- The result of the last "send test mail to myself", kept on the workspace.
+--
+-- It is kept rather than shown once because of what the panel is for: an admin
+-- fills the sender in, presses the button, and comes back tomorrow wondering
+-- whether it ever worked. A result that vanished on reload would answer that
+-- question with silence, and silence is what the whole mail ledger exists to
+-- avoid.
+--
+-- `smtp_test_error` is the mail server's own words, kept so the admin can act
+-- on them. Nothing writes the password into it: the mailer builds its errors
+-- from what the server said, never from the credentials it sent.
+ALTER TABLE workspace ADD COLUMN smtp_test_at INTEGER;
+ALTER TABLE workspace ADD COLUMN smtp_test_ms INTEGER;
+ALTER TABLE workspace ADD COLUMN smtp_test_error TEXT;
diff --git a/crates/dizey-core/src/mail.rs b/crates/dizey-core/src/mail.rs
index 0a3e714..46f3fa9 100644
--- a/crates/dizey-core/src/mail.rs
+++ b/crates/dizey-core/src/mail.rs
@@ -137,6 +137,29 @@ impl Engine {
}
}
+ /// Sends one mail to the address given, right now, and says how long the
+ /// mail server took to accept it.
+ ///
+ /// This is the only send that does not go through the ledger, and that is
+ /// deliberate: a test mail is owed to nobody. If it fails there is nothing
+ /// to retry and nothing to abandon — the person who pressed the button is
+ /// watching, and the answer is for them.
+ pub async fn send_test(&self, to: &str) -> std::result::Result {
+ let mail = Outgoing {
+ to: to.to_string(),
+ subject: "Dizey test mail".to_string(),
+ body: "Somebody pressed the test button in Dizey's settings, and this \
+ is what came out. Nothing else was sent, and nobody else was \
+ written to.\n"
+ .to_string(),
+ };
+ let started = std::time::Instant::now();
+ self.mailer.send(&mail).await?;
+ Ok(Duration::milliseconds(
+ started.elapsed().as_millis().min(i64::MAX as u128) as i64,
+ ))
+ }
+
/// Everything one crossing owes. Called after the move has committed, never
/// inside it.
pub async fn on_transition(&self, transition: &Transition) -> crate::store::Result {
diff --git a/crates/dizey-core/src/store/mod.rs b/crates/dizey-core/src/store/mod.rs
index d7dc785..c4bc8f4 100644
--- a/crates/dizey-core/src/store/mod.rs
+++ b/crates/dizey-core/src/store/mod.rs
@@ -56,6 +56,9 @@ pub struct Workspace {
/// Whether a password is stored, never the password. Derived in the query
/// so that the value itself does not travel even this far.
pub smtp_password_set: bool,
+ /// How the last "send test mail to myself" went, if one has been pressed
+ /// since the sender was last edited.
+ pub sender_test: Option,
pub attachment_limit_bytes: u64,
pub photo_limit_bytes: u64,
pub allowed_file_types: Vec,
@@ -67,6 +70,19 @@ pub struct Workspace {
/// the screen sends when a password is already stored: the field is write-only,
/// so an edit to the port must not blank the password just because the form had
/// nothing to put in it.
+/// What came of pressing the test button: when, how long the mail server took,
+/// and what it said if it refused.
+///
+/// `error` is `None` for a mail that was accepted. It holds the mail server's
+/// own words otherwise, because "it did not work" is not something an admin can
+/// act on and "535 authentication failed" is.
+#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
+pub struct SenderTest {
+ pub at: OffsetDateTime,
+ pub took_ms: u64,
+ pub error: Option,
+}
+
#[derive(Debug, Clone, PartialEq)]
pub struct NewSender {
pub host: String,
@@ -322,6 +338,10 @@ pub trait Store: BoardReads + DetailReads + 'static {
/// screen was never allowed to show them.
async fn set_sender(&self, workspace_id: &str, sender: NewSender) -> Result<()>;
+ /// Writes down how the last test send went. Editing the sender clears it,
+ /// so what is stored is always about the settings that are stored.
+ async fn record_sender_test(&self, workspace_id: &str, test: SenderTest) -> Result<()>;
+
/// Reads the sender's password. Only the mailer calls this, and nothing it
/// returns reaches a response body.
async fn smtp_password(&self, workspace_id: &str) -> Result
}
})}
-
+
-
+
+ // The test lives outside the settings form because it is its
+ // own call, and a form cannot hold another. Save reaches back
+ // into that form by name, which is what the `form` attribute is
+ // for, and works in a browser with no script as well as one
+ // with.
+
+
+
+
+
+ {test_line}
+
+
{move || refusal()}"Saved."
-
+
-
+
}
@@ -1032,3 +1185,18 @@ fn MembersPanel(
}
}
+
+#[cfg(all(test, feature = "ssr"))]
+mod tests {
+ use super::took_label;
+
+ #[test]
+ fn a_send_is_timed_the_way_the_artboard_writes_it() {
+ // The artboard's own line reads `delivered in 1.2 s`.
+ assert_eq!(took_label(1234), "1.2 s");
+ assert_eq!(took_label(1000), "1.0 s");
+ // Under a second the seconds reading would be all zeroes, so say milliseconds.
+ assert_eq!(took_label(999), "999 ms");
+ assert_eq!(took_label(0), "0 ms");
+ }
+}
diff --git a/crates/dizey-web/tests/http.rs b/crates/dizey-web/tests/http.rs
index 7c1bd3e..d0d85a7 100644
--- a/crates/dizey-web/tests/http.rs
+++ b/crates/dizey-web/tests/http.rs
@@ -901,7 +901,8 @@ async fn an_admin_sees_the_sender_and_never_a_password() {
answer.body.contains(
"\"sender\":{\"host\":\"smtp.fastmail.com\",\"port\":465,\
\"username\":\"dizey\",\"from_name\":\"Dizey\",\
- \"from_address\":\"dizey@dizey.sh\",\"password_set\":true}"
+ \"from_address\":\"dizey@dizey.sh\",\"password_set\":true,\
+ \"test\":null}"
),
"{}",
answer.body
@@ -1566,3 +1567,79 @@ async fn signing_out_leaves_every_other_session_alone() {
.await;
assert!(still.body.contains("administers"), "{}", still.body);
}
+
+#[tokio::test]
+async fn a_member_may_not_press_the_test_button() {
+ let app = App::open().await;
+ let admin_cookie = admin(&app).await;
+ let member = invited(&app, &admin_cookie, "emre@dizey.sh", "Emre", Role::Member).await;
+
+ let answer = app
+ .post(
+ path::(),
+ Some(&member),
+ &[],
+ )
+ .await;
+
+ assert_eq!(answer.status, StatusCode::OK, "{}", answer.body);
+ assert!(answer.body.contains("Forbidden"), "{}", answer.body);
+}
+
+#[tokio::test]
+async fn a_viewer_may_not_press_the_test_button() {
+ let app = App::open().await;
+ let admin_cookie = admin(&app).await;
+ let viewer = invited(&app, &admin_cookie, "pinar@dizey.sh", "Pinar", Role::Viewer).await;
+
+ let answer = app
+ .post(
+ path::(),
+ Some(&viewer),
+ &[],
+ )
+ .await;
+
+ assert_eq!(answer.status, StatusCode::OK, "{}", answer.body);
+ assert!(answer.body.contains("Forbidden"), "{}", answer.body);
+}
+
+#[tokio::test]
+async fn a_signed_out_browser_may_not_press_the_test_button() {
+ let app = App::open().await;
+
+ let answer = app
+ .post(path::(), None, &[])
+ .await;
+
+ assert_eq!(answer.status, StatusCode::OK, "{}", answer.body);
+ assert!(answer.body.contains("SignInFirst"), "{}", answer.body);
+}
+
+#[tokio::test]
+async fn testing_a_sender_that_was_never_filled_in_says_so_rather_than_sending() {
+ let app = App::open().await;
+ let admin_cookie = admin(&app).await;
+
+ let answer = app
+ .post(
+ path::(),
+ Some(&admin_cookie),
+ &[],
+ )
+ .await;
+
+ assert_eq!(answer.status, StatusCode::OK, "{}", answer.body);
+ assert!(answer.body.contains("BadSender"), "{}", answer.body);
+ assert!(answer.body.contains("save it first"), "{}", answer.body);
+
+ // Nothing was recorded either: the panel still has no test line to show.
+ let seen = app
+ .post(
+ path::(),
+ Some(&admin_cookie),
+ &[],
+ )
+ .await;
+ assert!(!seen.body.contains("\"test\":{"), "{}", seen.body);
+}
diff --git a/style/main.scss b/style/main.scss
index 8b30011..d54b88b 100644
--- a/style/main.scss
+++ b/style/main.scss
@@ -1572,12 +1572,23 @@ a {
.panel-foot {
display: flex;
+ // A foot inside a `.panel-body` would inherit that column, and a foot is a row.
+ flex-direction: row;
align-items: center;
gap: 12px;
justify-content: flex-end;
// A foot with something to say on the left and the button on the right.
&-split { justify-content: space-between; }
+
+}
+
+// One end of a split foot: its own controls, kept together.
+.foot-side {
+ display: flex;
+ align-items: center;
+ gap: 12px;
+ min-width: 0;
}
// The quiet counterpart of `.primary`, for an action that is real but is not