Phase 7: the client link
Staff make a link for a person (or "+ New client": a record with only the name they know, and its link); the client fills in their own record from their phone without a login, and presses Send. - Links (src/links.rs, migrations/0006): the table keeps the SHA-256 of the token only, as sessions do; the link is shown once, to copy, to email (mailto with the person's address) or as a QR code (qrcode crate, inline SVG). It is open 14 days, until Send, or until staff close it; a new link closes the earlier one. States open, opened, sent, closed, expired. - The client's pages at /c/<token> (src/web/client.rs, client_*.html in a frame of their own, phone first): About you, Passport (the photo reader; a zone fills in the personal details still empty), Address in Thailand, Contact, Documents, Send. Each part is saved on its own, straight into the record. Forms carry the link's own token plus the same-site check. A passport with the same number is changed; an address unlike the current one is added beside it, so the current one and its TM.30 receipt stay; a second save changes what the link added. Uploads (passport page, photo, visa, arrival stamp, TDAC, work permit, other) go through the same checks and encrypted store as staff uploads, tied to the person's newest record of their kind. - Audit: the client's views and changes carry the actor `link <id>`; actions send and close and entity link are new. The person's page shows the newest links, when they were opened and sent, and each record the client changed, with the fields, to check. - Demo data: Erika sent her link an hour ago (phone and email changed), Jane opened hers. - documents::read_upload returns why it refused, so the client's pages answer in their own words. Checks: fmt, clippy; 101 unit and 54 integration tests (tests/client.rs: the link shown once and kept as a hash, a new client, the whole client flow with the login on, forged, closed, expired and made-up links); layout check light/dark desk/phone on the client pages, the person page and the new client form: no problems; the camera reader on the client's passport page with a fake camera filled the form and Send closed the link.
This commit is contained in:
1 parent
a6ebdfc89c
commit
43ed75d81b
32 files changed
+2706
-40
No files matched your search
+22
-13
@@ -446,8 +446,8 @@ fn broken_upload(st: &AppState, e: &MultipartError) -> Response {
|
||||
|
||||
/// An upload as it arrived, before any check.
|
||||
#[derive(Default)]
|
||||
struct Upload {
|
||||
values: Values,
|
||||
pub(crate) struct Upload {
|
||||
pub(crate) values: Values,
|
||||
files: Vec<(String, Vec<u8>)>,
|
||||
/// files over the limit, by name
|
||||
too_big: Vec<String>,
|
||||
@@ -474,13 +474,21 @@ async fn read_field(
|
||||
Ok((!over).then_some(out))
|
||||
}
|
||||
|
||||
/// Why an upload was refused before its files were checked.
|
||||
pub(crate) enum Refused {
|
||||
/// No form token, or not the session's (or the client link's).
|
||||
Token,
|
||||
/// More than `MAX_FILES` files.
|
||||
TooMany,
|
||||
}
|
||||
|
||||
/// The form token must come first (the page puts it there), so a forged
|
||||
/// form is refused before any file is read.
|
||||
async fn read_upload(
|
||||
st: &AppState,
|
||||
/// form is refused before any file is read. `user` is the session's, or
|
||||
/// the one a client link acts as (`web::client`).
|
||||
pub(crate) async fn read_upload(
|
||||
user: &User,
|
||||
mut mp: Multipart,
|
||||
) -> Result<Result<Upload, Response>, MultipartError> {
|
||||
) -> Result<Result<Upload, Refused>, MultipartError> {
|
||||
let token = match mp.next_field().await? {
|
||||
Some(mut f) if f.name() == Some("csrf") => read_field(&mut f, FIELD_LIMIT)
|
||||
.await?
|
||||
@@ -492,7 +500,7 @@ async fn read_upload(
|
||||
"refused an upload without a valid token from {}",
|
||||
user.login
|
||||
);
|
||||
return Ok(Err(super::expired(st)));
|
||||
return Ok(Err(Refused::Token));
|
||||
}
|
||||
let mut up = Upload::default();
|
||||
let mut count = 0;
|
||||
@@ -530,7 +538,7 @@ async fn read_upload(
|
||||
}
|
||||
}
|
||||
if count > MAX_FILES {
|
||||
return Ok(Err(too_large(st)));
|
||||
return Ok(Err(Refused::TooMany));
|
||||
}
|
||||
Ok(Ok(up))
|
||||
}
|
||||
@@ -587,7 +595,7 @@ async fn check_meta(st: &AppState, owner: Owner, v: &Values) -> anyhow::Result<(
|
||||
))
|
||||
}
|
||||
|
||||
struct Checked {
|
||||
pub(crate) struct Checked {
|
||||
name: String,
|
||||
bytes: Vec<u8>,
|
||||
content_type: &'static str,
|
||||
@@ -596,7 +604,7 @@ struct Checked {
|
||||
|
||||
/// The files, checked: a type the app takes (by the file's first bytes),
|
||||
/// not empty, not too large, not uploaded before for this person or company.
|
||||
async fn check_files(
|
||||
pub(crate) async fn check_files(
|
||||
st: &AppState,
|
||||
owner: Owner,
|
||||
up: Upload,
|
||||
@@ -651,7 +659,7 @@ async fn check_files(
|
||||
/// Saves the checked files as documents: the rows, the encrypted files and
|
||||
/// the audit entries in one transaction. Files written before a failure are
|
||||
/// removed again. Returns the first new id.
|
||||
async fn save(
|
||||
pub(crate) async fn save(
|
||||
st: &AppState,
|
||||
user: &User,
|
||||
store: &Store,
|
||||
@@ -728,9 +736,10 @@ pub async fn upload(st: Arc<AppState>, user: User, owner: Owner, mp: Multipart)
|
||||
None
|
||||
}
|
||||
};
|
||||
let up = match read_upload(&st, &user, mp).await {
|
||||
let up = match read_upload(&user, mp).await {
|
||||
Ok(Ok(up)) => up,
|
||||
Ok(Err(resp)) => return Ok(resp),
|
||||
Ok(Err(Refused::Token)) => return Ok(super::expired(&st)),
|
||||
Ok(Err(Refused::TooMany)) => return Ok(too_large(&st)),
|
||||
Err(e) => return Ok(broken_upload(&st, &e)),
|
||||
};
|
||||
let Some(store) = st.files.clone() else {
|
||||
|
||||
Reference in new issue
Block a user