← 返回 snowflake 的题目列表Role-Based Access Control with Inheritance and Deny Rules
类型:online_judge
Implement a role-based access control system supporting role inheritance and deny rules. The system should support the following operations:
check_assigned_role(relationship: List[List[int]], assigned: List[int], role: int) -> bool
Given role inheritance relationships relationship, roles assigned to the user assigned, and a role to check role, return whether the user is assigned that role.
is_denied(relationship: List[List[int]], deny_pairs: List[List[int]], user_role: int, target_role: int) -> bool
Based on relationship and deny_pairs, along with user's role user_role and target role target_role, return whether the user's role is denied by the target role.
Example
relationship = [[0, 1], [1, 2]]
assigned = [0]
role = 2
check_assigned_role(relationship, assigned, role) // returns True
relationship = [[0, 1], [1, 2]]
deny_pairs = [[0, 2]]
user_role = 2
target_role = 0
is_denied(relationship, deny_pairs, user_role, target_role) // returns True
Constraints
The number of relationships and deny pairs is from [1, 500].
Role IDs range from [0, 500].
Example
Input
check_assigned_role [[0, 1], [1, 2]] [0] 2