actor User {
relations = { direct_manager: User };
roles = ["manager"];
"manager" if "direct_manager";
# This forms the recursive hierarchy; we could remove this line and simplify
# the policy a bit if we only wanted a single-level of hierarchical
# visibility.
"manager" if "manager" on "direct_manager";
}
resource Repository {
roles = ["viewer"];
permissions = ["read"];
relations = { creator: User };
"viewer" if "creator";
"viewer" if "manager" on "creator";
"read" if "viewer";
}
test "manager can have viewer role on employees repos" {
setup {
has_relation(Repository{"acme"}, "creator", User{"alice"});
has_relation(User{"alice"}, "direct_manager", User{"bhav"});
has_relation(User{"bhav"}, "direct_manager", User{"crystal"});
# fergie not in alice's direct hierarchy
has_relation(User{"fergie"}, "direct_manager", User{"crystal"});
}
assert allow(User{"alice"}, "read", Repository{"acme"});
assert allow(User{"bhav"}, "read", Repository{"acme"});
assert allow(User{"crystal"}, "read", Repository{"acme"});
# fergie not in alice's direct hierarchy, so cannot read
assert_not allow(User{"fergie"}, "read", Repository{"acme"});
}