This question evaluates understanding of hierarchical data structures, role-based access control semantics, and set/map operations for computing effective permissions across account ancestors in the Coding & Algorithms domain.
You are given:
accounts = [
{"accountId": "org_1", "parent": null},
{"accountId": "wksp_1", "parent": "org_1"}
]
user_role_assignments = [
{"userId": "usr_1", "accountId": "org_1", "role": "admin"}
]
Roles are strings.
Implement:
getRoles(userId, accountId) -> set(roles)
based only on direct assignments on that exact account.
Implement:
getRolesWithAncestors(userId, accountId) -> set(roles)
that returns roles assigned to the user on accountId and on all ancestor accounts up to the root.
Implement:
getUsersForAccount(accountId) -> map(userId -> set(roles))
Return all users who have at least one role effective on accountId when considering ancestor inheritance as in Part 2.
Implement:
getUsersForAccountWithFilter(accountId, rolesFilter) -> list(userId)
Return only users whose effective role set (including ancestors) contains all roles in rolesFilter.
getUsersForAccountWithFilter("wksp_1", []) should return all users effective on wksp_1.