Skip to main content

grp_core/common/users/
structs.rs

1
2/// # UserType
3/// represents the type of the user that was given.
4/// 
5/// 1. `LoggedUser`: **User** that is logged in
6/// 2. `LoggedOrg`: **Organization** that belongs to the logged user
7/// 3. `UnloggedUser`: **User** that is not logged in
8/// 4. `UnloggedOrg`: **Organization** that does not belong to the logged user
9#[derive(Clone, Debug)]
10pub enum UserType {
11    LoggedUser(User),
12    LoggedOrg(User),
13    UnloggedUser(User),
14    UnloggedOrg(User),
15}
16
17/// # User
18/// Represents a _user_ or _org_ for every platform.
19/// 
20/// 1. `id`: the id of the user.
21/// 2. `name`: the name of the user.
22/// 3. `path`: an optional path for the group or organization (gitea)
23#[derive(Clone, Debug)]
24pub struct User {
25    pub id: String,
26    pub name: String,
27    pub path: Option<String>, // Optional path for the group, for Gitea
28}
29
30impl UserType {
31    pub fn get_user(&self) -> User {
32        match self {
33            UserType::LoggedUser(name_or_id) => name_or_id,
34            UserType::LoggedOrg(name_or_id) => name_or_id,
35            UserType::UnloggedUser(name_or_id) => name_or_id,
36            UserType::UnloggedOrg(name_or_id) => name_or_id,
37        }.clone()
38    }
39}