Client link: read and sign the agreements first, then the details
CI / secret scan (push) Successful in 5s
CI / fmt, clippy, tests (push) Successful in 1m1s
CI / release (push) Skipped

While an active agreement is unsigned in its current version, the
link's other parts are locked: the overview shows them dashed with
"After signing" and no Send button, and every other page of the link
(About you, Contact, Passport, Address, Documents, Send) redirects to the
agreement and takes nothing posted to it. A new version locks them again
until it is signed.

Checks: fmt, clippy, 105 unit and 56 integration tests (tests/agreements.rs
asserts the redirects, that nothing posted before signing is saved, and
that the parts open after signing and close at a new version); the
locked overview checked on a phone in light and dark.
This commit is contained in:
grabowski committed 2026-11-20 20:40:26 +07:00
1 parent d0e13dffd2
commit 506221ecd0
6 files changed
+120 -17

No files matched your search

+44 -10
View File
@@ -202,6 +202,28 @@ macro_rules! open_or_return {
};
}
/// The first active agreement the client has not signed in its current
/// version: the client reads and signs it before anything else.
async fn unsigned(st: &AppState, c: &Client) -> anyhow::Result<Option<i64>> {
Ok(agreements::for_person(&st.db, c.id())
.await?
.into_iter()
.find(|d| d.signed.is_none())
.map(|d| d.agreement.id))
}
/// Opens the link like `open_or_return!`, and sends a client who still has
/// an agreement to sign there first; what they posted is not taken.
macro_rules! signed_or_return {
($st:expr, $token:expr) => {{
let c = open_or_return!($st, $token);
if let Some(id) = unsigned(&$st, &c).await? {
return Ok(Redirect::to(&format!("{}/agree/{id}", c.base)).into_response());
}
c
}};
}
// ------------------------------------------------------------- overview
#[derive(Debug, Serialize)]
@@ -211,6 +233,8 @@ struct Part {
what: String,
done: bool,
status: String,
/// Opens only once the agreements are signed.
locked: bool,
}
fn part(slug: &str, title: &str, what: &str, done: bool, status: String) -> Part {
@@ -220,6 +244,7 @@ fn part(slug: &str, title: &str, what: &str, done: bool, status: String) -> Part
what: what.to_string(),
done,
status,
locked: false,
}
}
@@ -262,6 +287,8 @@ async fn parts(st: &AppState, c: &Client) -> anyhow::Result<Vec<Part>> {
)
})
.collect();
let locked = out.iter().any(|p| !p.done);
let first = out.len();
out.extend([
part(
"about",
@@ -304,6 +331,12 @@ async fn parts(st: &AppState, c: &Client) -> anyhow::Result<Vec<Part>> {
},
),
]);
if locked {
for p in &mut out[first..] {
p.locked = true;
p.status = "After signing".into();
}
}
Ok(out)
}
@@ -329,6 +362,7 @@ pub async fn overview(
.filter(|p| !p.done)
.map(|p| p.title.as_str())
.collect();
let locked = parts.iter().any(|p| p.locked);
let actor = c.link.actor();
audit::record(
&st.db,
@@ -341,7 +375,7 @@ pub async fn overview(
"client.html",
"Your details",
StatusCode::OK,
context! { parts, saved, missing },
context! { parts, saved, missing, locked },
))
}
@@ -436,14 +470,14 @@ fn person_part(st: &AppState, c: &Client, part: &str, f: &PersonForm, errors: &E
}
async fn person_get(st: Arc<AppState>, token: String, part: &str) -> Res {
let c = open_or_return!(st, token);
let c = signed_or_return!(st, token);
viewed(&st, &c, Entity::Person, c.id()).await?;
let f = PersonForm::from_person(&c.person);
Ok(person_part(&st, &c, part, &f, &Errors::new()))
}
async fn person_post(st: Arc<AppState>, token: String, part: &str, f: Fields) -> Res {
let c = open_or_return!(st, token);
let c = signed_or_return!(st, token);
if !token_ok(&c, &f) {
return Ok(stale(&st));
}
@@ -510,7 +544,7 @@ async fn shown_passport(st: &AppState, c: &Client) -> anyhow::Result<Option<peop
}
pub async fn passport(State(st): State<Arc<AppState>>, Path(token): Path<String>) -> Res {
let c = open_or_return!(st, token);
let c = signed_or_return!(st, token);
let pf = match shown_passport(&st, &c).await? {
Some(p) => {
viewed(&st, &c, Entity::Passport, p.id).await?;
@@ -538,7 +572,7 @@ pub async fn passport_save(
Path(token): Path<String>,
Form(f): Form<Fields>,
) -> Res {
let c = open_or_return!(st, token);
let c = signed_or_return!(st, token);
if !token_ok(&c, &f) {
return Ok(stale(&st));
}
@@ -662,7 +696,7 @@ async fn current_address(st: &AppState, c: &Client) -> anyhow::Result<Option<peo
}
pub async fn address(State(st): State<Arc<AppState>>, Path(token): Path<String>) -> Res {
let c = open_or_return!(st, token);
let c = signed_or_return!(st, token);
let shown = match made_address(&st, &c).await? {
Some(a) => Some(a),
None => current_address(&st, &c).await?,
@@ -689,7 +723,7 @@ pub async fn address_save(
Path(token): Path<String>,
Form(f): Form<Fields>,
) -> Res {
let c = open_or_return!(st, token);
let c = signed_or_return!(st, token);
if !token_ok(&c, &f) {
return Ok(stale(&st));
}
@@ -811,7 +845,7 @@ async fn documents_page(
}
pub async fn documents_get(State(st): State<Arc<AppState>>, Path(token): Path<String>) -> Res {
let c = open_or_return!(st, token);
let c = signed_or_return!(st, token);
let actor = c.link.actor();
audit::record(
&st.db,
@@ -882,7 +916,7 @@ pub async fn documents_upload(
Path(token): Path<String>,
mp: Multipart,
) -> Res {
let c = open_or_return!(st, token);
let c = signed_or_return!(st, token);
let user = c.user();
let up = match webdocs::read_upload(&user, mp).await {
Ok(Ok(up)) => up,
@@ -931,7 +965,7 @@ pub async fn send(
Path(token): Path<String>,
Form(f): Form<Fields>,
) -> Res {
let c = open_or_return!(st, token);
let c = signed_or_return!(st, token);
if !token_ok(&c, &f) {
return Ok(stale(&st));
}