execution_engine_core/
auth.rs1use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
8pub struct UserContext {
9 pub user_id: Option<String>,
11 pub roles: Vec<String>,
13 pub permissions: Vec<String>,
15}
16
17impl UserContext {
18 pub fn new(user_id: Option<String>, roles: Vec<String>, permissions: Vec<String>) -> Self {
19 Self {
20 user_id,
21 roles,
22 permissions,
23 }
24 }
25
26 pub fn is_admin(&self) -> bool {
27 self.roles.iter().any(|r| r == "admin")
28 }
29
30 pub fn has_role(&self, role: &str) -> bool {
31 self.roles.iter().any(|r| r == role)
32 }
33
34 pub fn has_permission(&self, perm: &str) -> bool {
35 self.permissions.iter().any(|p| p == perm)
36 }
37}