Make Role an enum

This commit is contained in:
2021-08-12 15:48:02 +02:00
committed by dietrich
parent 67439c1c49
commit 61afbecda9
5 changed files with 109 additions and 57 deletions
+29
View File
@@ -62,3 +62,32 @@ pub enum UserOverviewColumns {
Email,
Username,
}
/// The possible roles a user could have.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Copy)]
pub enum Role {
NotAuthenticated,
Disabled,
Regular,
Admin,
}
impl Role {
pub fn convert(i: i64) -> Self {
match i {
0 => Self::Disabled,
1 => Self::Regular,
2 => Self::Admin,
_ => Self::NotAuthenticated,
}
}
pub fn to_i64(&self) -> i64 {
match self {
Role::NotAuthenticated => 3,
Role::Disabled => 0,
Role::Regular => 1,
Role::Admin => 2,
}
}
}
+3 -1
View File
@@ -2,6 +2,8 @@ use std::ops::Deref;
use serde::{Deserialize, Serialize, Serializer};
use strum_macros::{AsRefStr, EnumIter, EnumString, ToString};
use crate::apirequests::users::Role;
/// A generic list returntype containing the User and a Vec containing e.g. Links or Users
#[derive(Clone, Deserialize, Serialize)]
pub struct ListWithOwner<T> {
@@ -23,7 +25,7 @@ pub struct User {
pub username: String,
pub email: String,
pub password: Secret,
pub role: i64,
pub role: Role,
pub language: Lang,
}