1
use std::collections::HashMap;
2

            
3
/// Role definitions in sylvia-iot platform.
4
pub struct Role;
5

            
6
impl Role {
7
    /// The system administrator who has all privileges.
8
    pub const ADMIN: &'static str = "admin";
9
    /// The developer who can create clients.
10
    pub const DEV: &'static str = "dev";
11
    /// The system manager who has much of priviledges than normal user.
12
    pub const MANAGER: &'static str = "manager";
13
    /// The service (process, program, client).
14
    pub const SERVICE: &'static str = "service";
15

            
16
    /// To check if a user who has `role_map` with the specific `role_name`.
17
3
    pub fn is_role(role_map: &HashMap<String, bool>, role_name: &'static str) -> bool {
18
3
        match role_map.get(role_name) {
19
1
            None => false,
20
2
            Some(map) => *map,
21
        }
22
3
    }
23
}