1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2025-07-03 22:45:01 +00:00

Start to implement admin roles logic

This commit is contained in:
2021-05-14 18:25:53 +02:00
parent 57a5752fe7
commit 73837553c7
8 changed files with 182 additions and 23 deletions

View File

@ -4,6 +4,8 @@
use webauthn_rs::proto::Credential;
use crate::constants::admin::{ADMIN_ROLES_LIST, AdminRole};
#[derive(Copy, Clone, Eq, PartialEq, Debug, Hash)]
pub struct AdminID(u64);
@ -37,6 +39,7 @@ pub struct Admin {
pub name: String,
pub email: String,
pub reset_token: Option<AdminResetToken>,
pub roles: Vec<AdminRole>,
}
pub struct AdminKey {
@ -62,4 +65,21 @@ pub struct NewAdminGeneralSettings {
pub id: AdminID,
pub name: String,
pub email: String,
}
impl AdminRole {
pub fn from_id(id: &str) -> Option<Self> {
ADMIN_ROLES_LIST.iter()
.filter(|r| r.id.eq(id))
.map(|r| r.role)
.next()
}
pub fn to_id(&self) -> &'static str {
ADMIN_ROLES_LIST.iter()
.filter(|r| r.role.eq(self))
.map(|r| r.id)
.next()
.expect("Should have found a role!!!")
}
}