feat(store): public product documents may name their product #109

Merged
sharang merged 1 commits from feat/public-product-docs into main 2026-10-30 10:36:21 +00:00
3 changed files with 21 additions and 17 deletions

No files matched your search

+7 -6
View File
@@ -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)
+12 -9
View File
@@ -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)
}
+2 -2
View File
@@ -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.