Skip to main content

systemprompt_models/auth/
roles.rs

1use std::collections::HashSet;
2
3#[derive(Debug, Clone)]
4pub struct BaseRole {
5    pub name: &'static str,
6    pub display_name: &'static str,
7    pub description: &'static str,
8    pub permissions: HashSet<&'static str>,
9}
10
11#[derive(Debug, Copy, Clone)]
12pub struct BaseRoles;
13
14impl BaseRoles {
15    pub const ANONYMOUS: &'static str = "anonymous";
16    pub const USER: &'static str = "user";
17    pub const ADMIN: &'static str = "admin";
18
19    pub const fn available_roles() -> &'static [&'static str] {
20        &[Self::USER, Self::ADMIN]
21    }
22
23    pub fn anonymous() -> BaseRole {
24        BaseRole {
25            name: Self::ANONYMOUS,
26            display_name: "Anonymous",
27            description: "Unauthenticated user with minimal permissions",
28            permissions: HashSet::from(["users.read"]),
29        }
30    }
31
32    pub fn admin() -> BaseRole {
33        BaseRole {
34            name: Self::ADMIN,
35            display_name: "Administrator",
36            description: "Full system administrator with all permissions",
37            permissions: HashSet::new(),
38        }
39    }
40
41    pub fn all() -> Vec<BaseRole> {
42        vec![Self::anonymous(), Self::admin()]
43    }
44
45    pub const fn is_admin_permission_wildcard() -> bool {
46        true
47    }
48}