Merge pull request 'feat(roles): company rule for separate determination and approval' (#129) from feat/company-rules into main
This commit was merged in pull request #129.
This commit is contained in:
commit
9cf4f7db05
5 files changed
+131
No files matched your search
@@ -24,6 +24,7 @@ import (
|
||||
// PUT /v1/tenants/{id}/role-dataset save (user token only)
|
||||
// GET /v1/tenants/{id}/role-dataset/revisions/{rev} the dataset a decision was made under
|
||||
// GET /v1/tenants/{id}/role-dataset/resolve who may decide a decision type now
|
||||
// GET /v1/tenants/{id}/role-dataset/rules the company rules now (docgen#4 Nr. 31)
|
||||
//
|
||||
// Reads: a user token of the tenant, or a service with tenants.read
|
||||
// (Werkmeister). Writes come only from a user token: the writer is the
|
||||
@@ -61,6 +62,15 @@ type roleDatasetHoldersResp struct {
|
||||
*roles.FunctionHolders
|
||||
}
|
||||
|
||||
type roleDatasetRulesResp struct {
|
||||
Revision int `json:"revision"`
|
||||
CatalogueVersion string `json:"catalogue_version"`
|
||||
// SeparateApproval: "Festlegung und Freigabe durch verschiedene
|
||||
// Personen" is on. Off when the company never set it.
|
||||
SeparateApproval bool `json:"separate_approval"`
|
||||
RecordedAt *time.Time `json:"recorded_at,omitempty"`
|
||||
}
|
||||
|
||||
type roleDatasetResolveResp struct {
|
||||
Revision int `json:"revision"`
|
||||
CatalogueVersion string `json:"catalogue_version"`
|
||||
@@ -285,6 +295,31 @@ func (s *Server) roleDatasetHolders(w http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(w, http.StatusOK, out)
|
||||
}
|
||||
|
||||
// roleDatasetRules is GET /v1/tenants/{id}/role-dataset/rules: the
|
||||
// company rules now, for a Werkmeister check that applies only while a rule
|
||||
// is on.
|
||||
func (s *Server) roleDatasetRules(w http.ResponseWriter, r *http.Request) {
|
||||
ctx, cancel := context.WithTimeout(r.Context(), 10*time.Second)
|
||||
defer cancel()
|
||||
t, ok := s.tenantInScope(ctx, w, r)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
stored, ds, err := s.currentRoleDataset(ctx, t.ID)
|
||||
if err != nil {
|
||||
writeError(w, http.StatusInternalServerError, "internal", err.Error())
|
||||
return
|
||||
}
|
||||
out := roleDatasetRulesResp{CatalogueVersion: roles.CatalogueVersion, SeparateApproval: ds.SeparateApproval()}
|
||||
if stored != nil {
|
||||
out.Revision, out.CatalogueVersion = stored.Revision, stored.CatalogueVersion
|
||||
}
|
||||
if ds.CompanyRules != nil {
|
||||
out.RecordedAt = ds.CompanyRules.RecordedAt
|
||||
}
|
||||
writeJSON(w, http.StatusOK, out)
|
||||
}
|
||||
|
||||
// resolveRoleDataset is GET /v1/tenants/{id}/role-dataset/resolve
|
||||
// ?decision_type=…[&document=…|&product=…|&area=…].
|
||||
func (s *Server) resolveRoleDataset(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@@ -256,6 +256,7 @@ func TestRoleDatasetPath(t *testing.T) {
|
||||
"/v1/tenants/x/role-dataset": true,
|
||||
"/v1/tenants/x/role-dataset/resolve": true,
|
||||
"/v1/tenants/x/role-dataset/holders": true,
|
||||
"/v1/tenants/x/role-dataset/rules": true,
|
||||
"/v1/tenants/x/role-dataset/revisions/2": true,
|
||||
"/v1/tenants/x/members": false,
|
||||
"/v1/tenants/role-dataset": false,
|
||||
@@ -267,3 +268,24 @@ func TestRoleDatasetPath(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Nr. 31: Werkmeister reads the company rules; off until management or a
|
||||
// maintainer switches the rule on.
|
||||
func TestRoleDataset_rules(t *testing.T) {
|
||||
f := newRoleFixture(t)
|
||||
code, out, raw := f.do(t, "werkmeister", "GET", f.path("/rules"), "")
|
||||
if code != http.StatusOK || out["separate_approval"] != false || out["revision"].(float64) != 0 {
|
||||
t.Fatalf("no dataset: %d %s", code, raw)
|
||||
}
|
||||
if code, _, raw := f.do(t, "signup", "PUT", f.path(""), saveBody(mgmtOnly, 0)); code != http.StatusOK {
|
||||
t.Fatalf("bootstrap: %d %s", code, raw)
|
||||
}
|
||||
on := strings.TrimSuffix(mgmtOnly, "}") + `,"company_rules":{"separate_approval":true}}`
|
||||
if code, _, raw := f.do(t, "ceo", "PUT", f.path(""), saveBody(on, 1)); code != http.StatusOK {
|
||||
t.Fatalf("switch on: %d %s", code, raw)
|
||||
}
|
||||
code, out, raw = f.do(t, "werkmeister", "GET", f.path("/rules"), "")
|
||||
if code != http.StatusOK || out["separate_approval"] != true || out["revision"].(float64) != 2 || out["recorded_at"] == nil {
|
||||
t.Fatalf("switched on: %d %s", code, raw)
|
||||
}
|
||||
}
|
||||
@@ -169,6 +169,7 @@ func NewRouter(s *Server) http.Handler {
|
||||
mux.HandleFunc("GET /v1/tenants/{id}/role-dataset/revisions/{rev}", s.getRoleDatasetRevision)
|
||||
mux.HandleFunc("GET /v1/tenants/{id}/role-dataset/resolve", s.resolveRoleDataset)
|
||||
mux.HandleFunc("GET /v1/tenants/{id}/role-dataset/holders", s.roleDatasetHolders)
|
||||
mux.HandleFunc("GET /v1/tenants/{id}/role-dataset/rules", s.roleDatasetRules)
|
||||
// Prüfwerk settings (0025, t72): the workspace's Prüftag cap.
|
||||
// R1 intake (0028, docgen#6 F01): intake.go.
|
||||
mux.HandleFunc("POST /v1/tenants/{id}/intake/reports", s.createIntakeReport)
|
||||
|
||||
Reference in new issue
Block a user