From 852c58ce43596b8ddcb34a57cc282bd53c1d2edd Mon Sep 17 00:00:00 2001 From: Sharang Parnerkar <30073382+mighty840@users.noreply.github.com> Date: Fri, 30 Oct 2026 11:09:23 +0100 Subject: [PATCH] feat(store): public product documents may name their product MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The store upload accepted product_id only for internal documents, so a data sheet filed under "Produktdokumente (öffentlich)" never reached the product's CRA run in Werkmeister, which reads own, published documents linked to the product. product_public now takes the same optional product; legal website documents still refuse one. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_014aRnCGqELxoix5TfpX8Ejf --- internal/server/document_store.go | 13 +++++++------ internal/server/document_store_test.go | 21 ++++++++++++--------- openapi.yaml | 4 ++-- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/internal/server/document_store.go b/internal/server/document_store.go index 9f43775..4fdcf5b 100644 --- a/internal/server/document_store.go +++ b/internal/server/document_store.go @@ -129,8 +129,8 @@ func (s *Server) storeDocument(ctx context.Context, w http.ResponseWriter, r *ht } // uploadStoreDocument is POST /v1/tenants/{id}/store/documents: multipart -// fields "area", "legal_kind" (legal area), "product_id" (internal area, a -// product project of the tenant), "title", "process" ("on": an internal +// fields "area", "legal_kind" (legal area), "product_id" (product or internal +// area, a product project of the tenant), "title", "process" ("on": an internal // document goes to the Factory too), then the "file". The file is streamed to // the bucket; the document is visible at once with its original, and legal // and product documents wait for the Factory ("pending"). @@ -191,7 +191,7 @@ func (s *Server) uploadStoreDocument(w http.ResponseWriter, r *http.Request) { return } if d.ProjectIDs, code = s.storeProduct(ctx, t.ID, fields["product_id"], d.Area); code != "" { - writeError(w, http.StatusBadRequest, code, "product_id must be a product of this workspace, and only for internal documents") + writeError(w, http.StatusBadRequest, code, "product_id must be a product of this workspace, and only for product or internal documents") return } d.ID, d.TenantID, d.Filename, d.ContentType = uuid.NewString(), t.ID, filename, ctype @@ -274,13 +274,14 @@ func isOn(v string) bool { return v == "on" || v == "true" || v == "1" } -// storeProduct checks the optional product of an internal document: one -// product project of the tenant. +// storeProduct checks the optional product of a product or internal +// document: one product project of the tenant. Werkmeister reads a +// product's linked documents into its runs, whichever of the two areas. func (s *Server) storeProduct(ctx context.Context, tenantID, productID, area string) ([]string, string) { if productID == "" { return nil, "" } - if area != store.AreaInternal { + if area != store.AreaInternal && area != store.AreaProductPublic { return nil, "invalid_product" } p, err := s.Store.GetProject(ctx, productID) diff --git a/internal/server/document_store_test.go b/internal/server/document_store_test.go index d9c591c..d56a5d0 100644 --- a/internal/server/document_store_test.go +++ b/internal/server/document_store_test.go @@ -81,14 +81,14 @@ func TestStoreUploadRules(t *testing.T) { code int err string }{ - "unknown area": {map[string]string{"area": "secret"}, "a.pdf", 400, "invalid_area"}, - "legal without folder": {map[string]string{"area": "legal_web"}, "a.pdf", 400, "invalid_legal_kind"}, - "legal unknown folder": {map[string]string{"area": "legal_web", "legal_kind": "faq"}, "a.pdf", 400, "invalid_legal_kind"}, - "folder outside legal": {map[string]string{"area": "product_public", "legal_kind": "agb"}, "a.pdf", 400, "invalid_legal_kind"}, - "product on public doc": {map[string]string{"area": "product_public", "product_id": product.ID}, "a.pdf", 400, "invalid_product"}, - "topic as product": {map[string]string{"area": "internal", "product_id": topic.ID}, "a.pdf", 400, "invalid_product"}, - "unsupported type": {map[string]string{"area": "internal"}, "a.exe", 415, "unsupported_type"}, - "title too long": {map[string]string{"area": "internal", "title": strings.Repeat("t", 201)}, "a.pdf", 400, "invalid_title"}, + "unknown area": {map[string]string{"area": "secret"}, "a.pdf", 400, "invalid_area"}, + "legal without folder": {map[string]string{"area": "legal_web"}, "a.pdf", 400, "invalid_legal_kind"}, + "legal unknown folder": {map[string]string{"area": "legal_web", "legal_kind": "faq"}, "a.pdf", 400, "invalid_legal_kind"}, + "folder outside legal": {map[string]string{"area": "product_public", "legal_kind": "agb"}, "a.pdf", 400, "invalid_legal_kind"}, + "product on legal doc": {map[string]string{"area": "legal_web", "legal_kind": "agb", "product_id": product.ID}, "a.pdf", 400, "invalid_product"}, + "topic as product": {map[string]string{"area": "internal", "product_id": topic.ID}, "a.pdf", 400, "invalid_product"}, + "unsupported type": {map[string]string{"area": "internal"}, "a.exe", 415, "unsupported_type"}, + "title too long": {map[string]string{"area": "internal", "title": strings.Repeat("t", 201)}, "a.pdf", 400, "invalid_title"}, } { rr := f.upload(t, c.fields, c.file, pdf) if rr.Code != c.code || !strings.Contains(rr.Body.String(), c.err) { @@ -102,7 +102,7 @@ func TestStoreUploadRules(t *testing.T) { legal := f.upload(t, map[string]string{"area": "legal_web", "legal_kind": "impressum"}, "Impressum.pdf", pdf) internalPlain := f.upload(t, map[string]string{"area": "internal", "title": " Risikobeurteilung Lok 100 ", "product_id": product.ID}, "rb.docx", []byte("PK synthetic")) internalSent := f.upload(t, map[string]string{"area": "internal", "process": "on"}, "Richtlinie.pdf", pdf) - public := f.upload(t, map[string]string{"area": "product_public"}, "Datenblatt.pdf", pdf) + public := f.upload(t, map[string]string{"area": "product_public", "product_id": product.ID}, "Datenblatt.pdf", pdf) var d1, d2, d3, d4 store.Document for i, rr := range []*httptest.ResponseRecorder{legal, internalPlain, internalSent, public} { if rr.Code != 201 { @@ -119,6 +119,9 @@ func TestStoreUploadRules(t *testing.T) { if d2.ProcessingStatus != "none" || d2.Title != "Risikobeurteilung Lok 100" || len(d2.ProjectIDs) != 1 || d2.ProjectIDs[0] != product.ID { t.Errorf("internal without processing: %+v", d2) } + if len(d4.ProjectIDs) != 1 || d4.ProjectIDs[0] != product.ID || !d4.OwnDocument { + t.Errorf("public product document: %+v", d4) + } if d3.ProcessingStatus != "pending" || d4.ProcessingStatus != "pending" { t.Errorf("processing: internal sent %q, public %q", d3.ProcessingStatus, d4.ProcessingStatus) } diff --git a/openapi.yaml b/openapi.yaml index 8021ef4..2173b60 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -360,8 +360,8 @@ paths: summary: Upload a document into an area of the store. description: | multipart/form-data: `area` (legal_web, product_public, internal), - `legal_kind` (legal_web only), `product_id` (internal only, a product - project of the tenant), `title`, `process` ("on": an internal document + `legal_kind` (legal_web only), `product_id` (product_public or internal, a + product project of the tenant), `title`, `process` ("on": an internal document goes to the Factory too), then `file` (pdf, docx, txt, html). Legal and product documents wait for the Factory (`pending`). The portal checks the user's org role and names them in X-Portal-User-Email.