fix(roles): first releases are management's; external-only decides nothing (#101)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014aRnCGqELxoix5TfpX8Ejf
This commit was merged in pull request #101.
This commit is contained in:
1 parent
cb173104b6
commit
5fff4dd581
3 files changed
+55
-4
No files matched your search
@@ -116,6 +116,11 @@ var DecisionTypes = []DecisionType{
|
||||
{Code: "r1.acceptance", Label: "Abnahme"},
|
||||
}
|
||||
|
||||
// FirstReleases are management's alone (A2 §1: Erstfreigabe durch die
|
||||
// Geschäftsleitung): a company names no other body for them. The update of
|
||||
// R1-D02 is different; it follows B8.
|
||||
var FirstReleases = []string{"r1.release_d01", "r1.release_d02"}
|
||||
|
||||
// Documents are the R1 document keys a document-scoped function refers to.
|
||||
var Documents = []string{"r1_d01", "r1_d02"}
|
||||
|
||||
|
||||
@@ -138,6 +138,20 @@ type Error struct {
|
||||
|
||||
func (e *Error) Error() string { return e.Code + ": " + e.Message }
|
||||
|
||||
// checkDeciding: a known function the company can hold. Under BM-4 only the
|
||||
// company decides, so a function held only outside it decides nothing.
|
||||
func checkDeciding(path, function string) *Error {
|
||||
f, ok := FunctionByKey(function)
|
||||
if !ok {
|
||||
return invalid(path+".function", "unknown function %q", function)
|
||||
}
|
||||
if f.External == ExternalOnly {
|
||||
return &Error{Status: http.StatusBadRequest, Code: "external_decides", Path: path + ".function",
|
||||
Message: "a function held only outside the company decides nothing (BM-4)"}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func invalid(path, format string, a ...any) *Error {
|
||||
return &Error{Status: http.StatusBadRequest, Code: "invalid_role_dataset", Message: fmt.Sprintf(format, a...), Path: path}
|
||||
}
|
||||
@@ -272,8 +286,12 @@ func Validate(ds *Dataset) *Error {
|
||||
return invalid(path+".decision_type", "%s is set twice", a.DecisionType)
|
||||
}
|
||||
authority[a.DecisionType] = true
|
||||
if _, ok := FunctionByKey(a.Function); !ok {
|
||||
return invalid(path+".function", "unknown function %q", a.Function)
|
||||
if err := checkDeciding(path, a.Function); err != nil {
|
||||
return err
|
||||
}
|
||||
if slices.Contains(FirstReleases, a.DecisionType) && a.Function != Management {
|
||||
return &Error{Status: http.StatusBadRequest, Code: "first_release_management", Path: path + ".function",
|
||||
Message: "the first releases of R1-D01 and R1-D02 are management's (A2 §1)"}
|
||||
}
|
||||
if len(a.D02Reference) > maxText {
|
||||
return invalid(path+".d02_reference", "at most %d characters", maxText)
|
||||
@@ -292,8 +310,8 @@ func Validate(ds *Dataset) *Error {
|
||||
if _, ok := DecisionTypeByKey(a.DecisionType); !ok {
|
||||
return invalid(path+".decision_type", "unknown decision type %q", a.DecisionType)
|
||||
}
|
||||
if _, ok := FunctionByKey(a.Function); !ok {
|
||||
return invalid(path+".function", "unknown function %q", a.Function)
|
||||
if err := checkDeciding(path, a.Function); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := checkBasis(path+".basis", a.Basis, true); err != nil {
|
||||
return err
|
||||
|
||||
@@ -254,6 +254,34 @@ func TestValidate_B8(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidate_whoDecides(t *testing.T) {
|
||||
ds := base(t)
|
||||
cases := map[string]struct {
|
||||
next Dataset
|
||||
code string
|
||||
}{
|
||||
"first release of R1-D01 to another body": {Dataset{Authority: []Authority{{DecisionType: "r1.release_d01", Function: "r1.freigabestelle"}}}, "first_release_management"},
|
||||
"first release of R1-D02 to another body": {Dataset{Authority: []Authority{{DecisionType: "r1.release_d02", Function: "r1.produkt_cybersecurity"}}}, "first_release_management"},
|
||||
"external-only function decides": {Dataset{Authority: []Authority{{DecisionType: "r1.escalation", Function: "r1.externer_cybersecurity_dienstleister"}}}, "external_decides"},
|
||||
"external-only function decides at once": {Dataset{ImmediateAuthority: []ImmediateAuthority{{DecisionType: "r1.escalation", Function: "r1.externer_cybersecurity_dienstleister", Basis: Basis{Text: "Notfallregelung"}}}}, "external_decides"},
|
||||
"unknown immediate function": {Dataset{ImmediateAuthority: []ImmediateAuthority{{DecisionType: "r1.escalation", Function: "r1.nope", Basis: Basis{Text: "x"}}}}, "invalid_role_dataset"},
|
||||
}
|
||||
for name, c := range cases {
|
||||
next := *ds
|
||||
next.Authority, next.ImmediateAuthority = c.next.Authority, c.next.ImmediateAuthority
|
||||
if _, err := Prepare(ds, &next, nil, Writer{Sub: ceo}, now); code(err) != c.code {
|
||||
t.Errorf("%s: %v", name, err)
|
||||
}
|
||||
}
|
||||
// Management itself, and a function the company may also hold outside, still decide.
|
||||
next := *ds
|
||||
next.Authority = []Authority{{DecisionType: "r1.release_d01", Function: Management}, {DecisionType: "r1.escalation", Function: "r1.vorfallkontakt"}}
|
||||
next.ImmediateAuthority = []ImmediateAuthority{{DecisionType: "r1.escalation", Function: "r1.vorfallkontakt", Basis: Basis{Text: "Notfallregelung"}}}
|
||||
if _, err := Prepare(ds, &next, nil, Writer{Sub: ceo}, now); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidate_catalogueRules(t *testing.T) {
|
||||
cases := map[string]Assignment{
|
||||
"unknown function": {ID: "a", Function: "r1.nope", Holder: member(staff)},
|
||||
|
||||
Reference in new issue
Block a user