From bef4e31c05b71e31f19cafff12db4b207b3992e2 Mon Sep 17 00:00:00 2001 From: Sharang Parnerkar <30073382+mighty840@users.noreply.github.com> Date: Mon, 16 Nov 2026 12:48:02 +0100 Subject: [PATCH] feat(roles): functions of owner decision Nr. 2 in the catalogue MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Catalogue r1-2026-11-16.1 adds the functions owner decision Nr. 2 (docgen#6 17878, 18011) names and that no R1 function already covers: CVD-Verantwortung and Veröffentlichungsverantwortung (R5), Meldefreigabe, Fristführung, Vorabprüfung, Weitergabe von Informationen and Datenschutzfunktion (R2), and the R1 functions Erstzuordnung, Eskalation and Einsichtsprotokollkontrolle. External holders as proposed in 18110 K-4. The safety check and product measures wait for the owner (K-1, K-2). GET /role-dataset now names the current catalogue as catalogue_version and the stored one as stored_catalogue_version. It named the stored one, which the portal sends back on save: after any catalogue change every save of an existing dataset was refused as catalogue_outdated, and reloading answered the same version again. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_014aRnCGqELxoix5TfpX8Ejf --- internal/roles/catalogue.go | 25 ++++++++- internal/roles/dataset_test.go | 16 ++++-- internal/server/role_dataset.go | 24 +++++---- .../server/role_dataset_catalogue_test.go | 53 +++++++++++++++++++ 4 files changed, 103 insertions(+), 15 deletions(-) create mode 100644 internal/server/role_dataset_catalogue_test.go diff --git a/internal/roles/catalogue.go b/internal/roles/catalogue.go index 4c943f7..58ff768 100644 --- a/internal/roles/catalogue.go +++ b/internal/roles/catalogue.go @@ -8,7 +8,7 @@ package roles // CatalogueVersion names this catalogue. A save names the version it was // made against; another version is refused, so the portal reloads. -const CatalogueVersion = "r1-2026-10-26.1" +const CatalogueVersion = "r1-2026-11-16.1" // Per is the scope an assignment of a function needs. type Per string @@ -34,7 +34,8 @@ type Function struct { Code string `json:"key"` Label string `json:"label"` // Sources: A1 (R1 frontend spec v4 §2.3) and/or A4 (document contract - // R1-D01/R1-D02 §4, the seven functions of R1-D02 §18). + // R1-D01/R1-D02 §4, the seven functions of R1-D02 §18); B2 for the + // functions of owner decision Nr. 2 (docgen#6 17878, 18011). Sources []string `json:"sources"` Per Per `json:"per"` Multiple bool `json:"multiple"` @@ -80,6 +81,26 @@ var Functions = []Function{ {Code: "r1.prueffunktion", Label: "Prüffunktion", Sources: []string{"A1"}, Per: PerCompany, Multiple: true, External: ExternalAllowed}, {Code: "r1.abschlussverantwortung", Label: "Abschlussverantwortlicher", Sources: []string{"A1"}, Per: PerCompany, Multiple: true, External: ExternalNo}, {Code: "r1.fachlich_verantwortliche_stelle", Label: "Fachlich verantwortliche Stelle", Sources: []string{"A1"}, Per: PerCompany, Multiple: true, External: ExternalNo}, + + // Owner decision Nr. 2 (B-2): the R1 functions of the ratified R1 + // specification not yet in the catalogue. + {Code: "r1.erstzuordnung", Label: "Erstzuordnung", Sources: []string{"B2"}, Per: PerCompany, Multiple: true, External: ExternalNo}, + {Code: "r1.eskalation", Label: "Eskalation", Sources: []string{"B2"}, Per: PerCompany, Multiple: true, External: ExternalNo}, + {Code: "r1.einsichtsprotokollkontrolle", Label: "Einsichtsprotokollkontrolle", Sources: []string{"B2"}, Per: PerCompany, Multiple: true, External: ExternalNo}, + + // Owner decision Nr. 2 (B-2), checked against the R1 catalogue (18011: + // none equivalent). External as proposed in 18110 K-4, until the owner + // answers. Safety check (K-1) and product measures (K-2) wait. + {Code: "r5.cvd_verantwortung", Label: "CVD-Verantwortung", Sources: []string{"B2"}, Per: PerCompany, Multiple: true, External: ExternalNo}, + {Code: "r5.veroeffentlichung", Label: "Veröffentlichungsverantwortung", Sources: []string{"B2"}, Per: PerCompany, Multiple: true, External: ExternalNo}, + // Meldefreigabe releases a report; submitting it stays with + // r1.meldeberechtigt (Nr. 2, 18110 K-3). + {Code: "r2.meldefreigabe", Label: "Meldefreigabe", Sources: []string{"B2"}, Per: PerCompany, Multiple: true, External: ExternalNo}, + {Code: "r2.fristfuehrung", Label: "Fristführung", Sources: []string{"B2"}, Per: PerCompany, Multiple: true, External: ExternalNo}, + {Code: "r2.vorabpruefung", Label: "Vorabprüfung", Sources: []string{"B2"}, Per: PerCompany, Multiple: true, External: ExternalAllowed}, + {Code: "r2.weitergabe", Label: "Weitergabe von Informationen", Sources: []string{"B2"}, Per: PerCompany, Multiple: true, External: ExternalNo}, + // Not the statutory data protection officer (18011). + {Code: "r2.datenschutzfunktion", Label: "Datenschutzfunktion", Sources: []string{"B2"}, Per: PerCompany, Multiple: true, External: ExternalAllowed}, } // DecisionType is a customer decision (BM-4: Breakpilot's own steps are diff --git a/internal/roles/dataset_test.go b/internal/roles/dataset_test.go index abc9aa1..b0ba4ff 100644 --- a/internal/roles/dataset_test.go +++ b/internal/roles/dataset_test.go @@ -3,6 +3,7 @@ package roles import ( "encoding/json" "net/http" + "slices" "strings" "testing" "time" @@ -65,8 +66,9 @@ func TestCatalogue_unionOfA1AndA4(t *testing.T) { if f.D02Row > 0 { rows[f.D02Row] = true } - if !strings.HasPrefix(f.Code, "r1.") { - t.Errorf("%s: R1 keys are namespaced r1.*", f.Code) + // Keys are namespaced by the rank that defines them (Nr. 2: R2, R5). + if !strings.HasPrefix(f.Code, "r1.") && !(slices.Contains(f.Sources, "B2") && (strings.HasPrefix(f.Code, "r2.") || strings.HasPrefix(f.Code, "r5."))) { + t.Errorf("%s: keys are namespaced by their rank", f.Code) } } a1 := []string{"Geschäftsleitung", "Produkt-Cybersecurity-Verantwortlicher", "Technischer Ansprechpartner", "Vorfallkontakt", @@ -81,8 +83,14 @@ func TestCatalogue_unionOfA1AndA4(t *testing.T) { t.Errorf("missing %q", l) } } - if len(a1) != 18 || len(a4) != 7 || len(Functions) != 21 { - t.Errorf("union of 18 and 7 with 4 shared is 21, got %d", len(Functions)) + b2 := 0 + for _, f := range Functions { + if slices.Contains(f.Sources, "B2") { + b2++ + } + } + if len(a1) != 18 || len(a4) != 7 || len(Functions)-b2 != 21 || b2 != 10 { + t.Errorf("union of 18 and 7 with 4 shared is 21, plus 10 of Nr. 2; got %d and %d", len(Functions)-b2, b2) } for i := 1; i <= 7; i++ { if !rows[i] { diff --git a/internal/server/role_dataset.go b/internal/server/role_dataset.go index 6449ab5..9b057ab 100644 --- a/internal/server/role_dataset.go +++ b/internal/server/role_dataset.go @@ -42,14 +42,20 @@ type roleDatasetSaveReq struct { } type roleDatasetResp struct { - TenantID string `json:"tenant_id"` - Revision int `json:"revision"` - CatalogueVersion string `json:"catalogue_version"` - UpdatedBy string `json:"updated_by,omitempty"` - UpdatedAt *time.Time `json:"updated_at,omitempty"` - Data json.RawMessage `json:"data"` - Derived roleDatasetDerived `json:"derived"` - Catalogue roles.Catalogue `json:"catalogue"` + TenantID string `json:"tenant_id"` + Revision int `json:"revision"` + // CatalogueVersion is the catalogue the answer is edited against: the + // current one, which a save must name. The stored dataset may have been + // saved against an older one (StoredCatalogueVersion); answering that + // instead would refuse every save after a catalogue change for good, + // since reloading answered it again. + CatalogueVersion string `json:"catalogue_version"` + StoredCatalogueVersion string `json:"stored_catalogue_version,omitempty"` + UpdatedBy string `json:"updated_by,omitempty"` + UpdatedAt *time.Time `json:"updated_at,omitempty"` + Data json.RawMessage `json:"data"` + Derived roleDatasetDerived `json:"derived"` + Catalogue roles.Catalogue `json:"catalogue"` } type roleDatasetDerived struct { @@ -113,7 +119,7 @@ func (s *Server) roleDatasetAnswer(tenantID string, stored *store.RoleDataset, d Catalogue: roles.CurrentCatalogue(), } if stored != nil { - out.Revision, out.CatalogueVersion, out.UpdatedBy = stored.Revision, stored.CatalogueVersion, stored.UpdatedBy + out.Revision, out.StoredCatalogueVersion, out.UpdatedBy = stored.Revision, stored.CatalogueVersion, stored.UpdatedBy at := stored.UpdatedAt out.UpdatedAt = &at } diff --git a/internal/server/role_dataset_catalogue_test.go b/internal/server/role_dataset_catalogue_test.go new file mode 100644 index 0000000..bb1fdf5 --- /dev/null +++ b/internal/server/role_dataset_catalogue_test.go @@ -0,0 +1,53 @@ +package server + +import ( + "context" + "encoding/json" + "net/http" + "strings" + "testing" + "time" + + "git.breakpilot.com/platform/tenant-registry/internal/roles" + "git.breakpilot.com/platform/tenant-registry/internal/store" +) + +// A dataset saved against an older catalogue: the answer names the current +// catalogue to edit against, and a save with what the answer named goes +// through. Before, the answer named the stored version, the save was +// refused as catalogue_outdated, and reloading answered the same again. +func TestRoleDataset_afterACatalogueChange(t *testing.T) { + f := newRoleFixture(t) + if _, _, err := f.s.Store.SaveRoleDataset(context.Background(), store.RoleDatasetWrite{ + TenantID: f.tenant.ID, Data: json.RawMessage(mgmtOnly), CatalogueVersion: "r1-older", ExpectedRevision: 0, By: "u-ceo", At: time.Now(), + }); err != nil { + t.Fatal(err) + } + code, out, raw := f.do(t, "ceo", "GET", f.path(""), "") + if code != http.StatusOK || out["catalogue_version"] != roles.CatalogueVersion || out["stored_catalogue_version"] != "r1-older" { + t.Fatalf("answer: %d %s", code, raw) + } + body := strings.Replace(saveBody(mgmtOnly, 1), roles.CatalogueVersion, out["catalogue_version"].(string), 1) + if code, _, raw := f.do(t, "ceo", "PUT", f.path(""), body); code != http.StatusOK { + t.Fatalf("save with the answered version: %d %s", code, raw) + } + if code, out, raw := f.do(t, "ceo", "GET", f.path(""), ""); code != http.StatusOK || out["stored_catalogue_version"] != roles.CatalogueVersion { + t.Fatalf("stored against the current catalogue now: %d %s", code, raw) + } +} + +// The functions of owner decision Nr. 2 are in the catalogue; the safety +// check and the product measures are not yet (18110 K-1, K-2). +func TestCatalogue_ownerDecisionNr2(t *testing.T) { + for _, k := range []string{"r5.cvd_verantwortung", "r5.veroeffentlichung", "r2.meldefreigabe", "r2.fristfuehrung", + "r2.vorabpruefung", "r2.weitergabe", "r2.datenschutzfunktion", "r1.erstzuordnung", "r1.eskalation", "r1.einsichtsprotokollkontrolle"} { + if _, ok := roles.FunctionByKey(k); !ok { + t.Errorf("missing %s", k) + } + } + for _, f := range roles.Functions { + if strings.Contains(f.Code, "safety") || strings.Contains(f.Code, "produktmassnahmen") { + t.Errorf("%s waits for the owner", f.Code) + } + } +}