Resolve effective scopes for a user. Collects: user's direct scopes + org scopes for each org membership. Filters out expired grants.
(&self, user_id: &str, org_ids: &[String])
| 264 | /// Collects: user's direct scopes + org scopes for each org membership. |
| 265 | /// Filters out expired grants. |
| 266 | pub fn effective_scopes(&self, user_id: &str, org_ids: &[String]) -> HashSet<String> { |
| 267 | let grants = self.grants.read().unwrap_or_else(|p| p.into_inner()); |
| 268 | let mut effective = HashSet::new(); |
| 269 | |
| 270 | for g in grants.values() { |
| 271 | if !g.is_effective() { |
| 272 | continue; // Skip expired grants. |
| 273 | } |
| 274 | // Direct user grant. |
| 275 | if g.grantee_type == "user" && g.grantee_id == user_id { |
| 276 | effective.insert(g.scope_name.clone()); |
| 277 | } |
| 278 | // Org grant (user inherits via membership). |
| 279 | if g.grantee_type == "org" && org_ids.contains(&g.grantee_id) { |
| 280 | effective.insert(g.scope_name.clone()); |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | effective |
| 285 | } |
| 286 | |
| 287 | /// Check if a user (directly or via orgs) has a specific scope. |
| 288 | pub fn has_scope(&self, user_id: &str, org_ids: &[String], scope_name: &str) -> bool { |