Make Role an enum
This commit is contained in:
@@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user