feat(roles): functions of owner decision Nr. 2 in the catalogue #131

Merged
sharang merged 2 commits from feat/function-catalogue-r2-r5 into main 2026-11-16 11:57:11 +00:00
4 changed files with 105 additions and 15 deletions

No files matched your search

+23 -2
View File
@@ -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
+14 -4
View File
@@ -3,6 +3,7 @@ package roles
import (
"encoding/json"
"net/http"
"slices"
"strings"
"testing"
"time"
@@ -65,8 +66,11 @@ 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).
rank := strings.HasPrefix(f.Code, "r1.") ||
slices.Contains(f.Sources, "B2") && (strings.HasPrefix(f.Code, "r2.") || strings.HasPrefix(f.Code, "r5."))
if !rank {
t.Errorf("%s: keys are namespaced by their rank", f.Code)
}
}
a1 := []string{"Geschäftsleitung", "Produkt-Cybersecurity-Verantwortlicher", "Technischer Ansprechpartner", "Vorfallkontakt",
@@ -81,8 +85,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] {
+15 -9
View File
@@ -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
}
@@ -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)
}
}
}