MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / validate_parent

Function validate_parent

nodedb/src/control/security/role.rs:382–393  ·  view source on GitHub ↗

Validate that `parent_name` refers to an existing role (built-in or custom) and that adopting it as `child_name`'s parent does not create a cycle or exceed `MAX_ROLE_INHERITANCE_DEPTH`. Shared by `prepare_role` and `create_role` so both catalog mutation paths enforce the same rules.

(
    child_name: &str,
    parent_name: &str,
    roles: &HashMap<String, CustomRole>,
)

Source from the content-addressed store, hash-verified

380/// cycle or exceed `MAX_ROLE_INHERITANCE_DEPTH`. Shared by `prepare_role`
381/// and `create_role` so both catalog mutation paths enforce the same rules.
382fn validate_parent(
383 child_name: &str,
384 parent_name: &str,
385 roles: &HashMap<String, CustomRole>,
386) -> crate::Result<()> {
387 if !is_builtin(parent_name) && !roles.contains_key(parent_name) {
388 return Err(crate::Error::BadRequest {
389 detail: format!("parent role '{parent_name}' does not exist"),
390 });
391 }
392 check_inheritance_chain(child_name, parent_name, roles)
393}
394
395fn is_builtin(name: &str) -> bool {
396 matches!(

Callers 2

prepare_roleMethod · 0.85
create_roleMethod · 0.85

Calls 2

is_builtinFunction · 0.85
check_inheritance_chainFunction · 0.85

Tested by

no test coverage detected