Clarify policy hierarchy traversal
This commit is contained in:
@@ -66,21 +66,27 @@ def validate_hierarchical_policy_patch(
|
||||
relock_message: Callable[[str], str] | None = None,
|
||||
) -> tuple[PolicyValidationIssue, ...]:
|
||||
issues: list[PolicyValidationIssue] = []
|
||||
lock_message = locked_field_message or (lambda field: f"{field} is locked by the parent policy.")
|
||||
reenable_message = relock_message or (lambda field: f"{field} limiting cannot be re-enabled below a parent policy lock.")
|
||||
lock_message = locked_field_message or (lambda field_name: f"{field_name} is locked by the parent policy.")
|
||||
reenable_message = relock_message or (
|
||||
lambda field_name: f"{field_name} limiting cannot be re-enabled below a parent policy lock."
|
||||
)
|
||||
|
||||
for field in field_keys:
|
||||
if field in patch and patch.get(field) is not None and not parent_allow_lower_level_limits.get(field, True):
|
||||
for field_name in field_keys:
|
||||
if (
|
||||
field_name in patch
|
||||
and patch.get(field_name) is not None
|
||||
and not parent_allow_lower_level_limits.get(field_name, True)
|
||||
):
|
||||
issues.append(PolicyValidationIssue(
|
||||
code="field_locked_by_parent",
|
||||
field=field,
|
||||
message=lock_message(field),
|
||||
field=field_name,
|
||||
message=lock_message(field_name),
|
||||
))
|
||||
|
||||
patch_allow = patch.get("allow_lower_level_limits")
|
||||
if isinstance(patch_allow, Mapping):
|
||||
for field, allowed in patch_allow.items():
|
||||
clean_field = str(field)
|
||||
for field_name, allowed in patch_allow.items():
|
||||
clean_field = str(field_name)
|
||||
if bool(allowed) and not parent_allow_lower_level_limits.get(clean_field, True):
|
||||
issues.append(PolicyValidationIssue(
|
||||
code="lower_level_limit_locked_by_parent",
|
||||
@@ -125,9 +131,9 @@ def simulate_hierarchical_policy_change(
|
||||
relock_message=relock_message,
|
||||
)
|
||||
changed_fields = tuple(
|
||||
field
|
||||
for field in (*field_keys, "allow_lower_level_limits")
|
||||
if field in patch and current_policy.get(field) != patch.get(field)
|
||||
field_name
|
||||
for field_name in (*field_keys, "allow_lower_level_limits")
|
||||
if field_name in patch and current_policy.get(field_name) != patch.get(field_name)
|
||||
)
|
||||
allowed = not any(issue.severity == "blocker" for issue in issues)
|
||||
decision = PolicyDecision(
|
||||
|
||||
Reference in New Issue
Block a user