: asapien/signet

commit 1fc24fb1295c4d40f1eea1a304ce831e225ded5b
parent a7313ffb9d2fd885f716298e1cae203cef36cd19
Author: Bharatvaj Hemanth <bharatvaj@yahoo.com>
Date: Sat, 19 Sep 2026 04:45:43 +0530

Task 7: Reject retired templates and series at submission

- Reject document creation with retired templates
- Reject submissions for documents using retired series
- Validate series.retired_at IS NOT NULL before serial allocation

Completes Task 7 business logic per spec ยง07.
Remaining: client UI for retire/delete/unlink buttons (minor feature).
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
1 file changed, 13 insertions(+), 1 deletion(-)
M
src/signet-api.c
|
14
+++++++++++++-
diff --git a/src/signet-api.c b/src/signet-api.c
@@ -387,7 +387,7 @@ h_doc_create(struct kreq *r, PGconn *pg, const struct ident *id)
 		res = db_q(pg, "INSERT INTO documents (drafter_user, template_id, "
 		    "series_code, layout_json, route_json) SELECT $1::varchar, t.id, "
 		    "t.series_code, t.layout_json, t.route_json FROM templates t "
-		    "WHERE t.id = $2 RETURNING id", 2, p);
+		    "WHERE t.id = $2 AND t.retired_at IS NULL RETURNING id", 2, p);
 	} else if (file != NULL && file->valsz > 5 && file->valsz <= 32u * 1024 * 1024 &&
 	    memcmp(file->val, "%PDF-", 5) == 0) {
 		res = db_q(pg, "INSERT INTO documents (drafter_user) VALUES ($1) "

@@ -539,6 +539,18 @@ h_doc_submit(struct kreq *r, PGconn *pg, const struct ident *id, const char *doc
 	    org_code, has_series, err, sizeof(err)) == -1)
 		goto fail;
 
+	if (has_series) {
+		const char *sp[] = { PQgetvalue(res, 0, 2) };
+		PGresult *sres = db_q(pg, "SELECT retired_at FROM series WHERE code = $1", 1, sp);
+		if (sres != NULL) {
+			if (!PQgetisnull(sres, 0, 0)) {
+				snprintf(err, sizeof(err), "this series has been retired");
+				PQclear(sres);
+				goto fail;
+			}
+			PQclear(sres);
+		}
+	}
 	if (has_series && !has_serial) {
 		const char *sp[] = { PQgetvalue(res, 0, 2) };