ValidateScopeBinding enforces the canonical scope/workspace invariant shared by task-domain records.
(scope Scope, workspaceBinding string, path string, workspaceField string)
| 1091 | |
| 1092 | // ValidateScopeBinding enforces the canonical scope/workspace invariant shared by task-domain records. |
| 1093 | func ValidateScopeBinding(scope Scope, workspaceBinding string, path string, workspaceField string) error { |
| 1094 | scopePath := nestedPath(path, "scope") |
| 1095 | if err := scope.Validate(scopePath); err != nil { |
| 1096 | return err |
| 1097 | } |
| 1098 | |
| 1099 | workspacePath := nestedPath(path, workspaceField) |
| 1100 | switch scope.Normalize() { |
| 1101 | case ScopeGlobal: |
| 1102 | if strings.TrimSpace(workspaceBinding) != "" { |
| 1103 | return fmt.Errorf( |
| 1104 | "%w: %s must be empty when %s is %q", |
| 1105 | ErrInvalidScopeBinding, |
| 1106 | workspacePath, |
| 1107 | scopePath, |
| 1108 | ScopeGlobal, |
| 1109 | ) |
| 1110 | } |
| 1111 | case ScopeWorkspace: |
| 1112 | if strings.TrimSpace(workspaceBinding) == "" { |
| 1113 | return fmt.Errorf( |
| 1114 | "%w: %s is required when %s is %q", |
| 1115 | ErrInvalidScopeBinding, |
| 1116 | workspacePath, |
| 1117 | scopePath, |
| 1118 | ScopeWorkspace, |
| 1119 | ) |
| 1120 | } |
| 1121 | } |
| 1122 | |
| 1123 | return nil |
| 1124 | } |
| 1125 | |
| 1126 | // ValidateImmutableTaskFields reports whether an update attempted to change immutable task fields. |
| 1127 | func ValidateImmutableTaskFields(current Task, next Task) error { |