feat: add user roles and storage quota management
This commit is contained in:
25
libertas_core/src/authz.rs
Normal file
25
libertas_core/src/authz.rs
Normal file
@@ -0,0 +1,25 @@
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::models::{Album, Media, Role, User};
|
||||
|
||||
pub trait Ownable {
|
||||
fn owner_id(&self) -> Uuid;
|
||||
}
|
||||
impl Ownable for Media {
|
||||
fn owner_id(&self) -> Uuid {
|
||||
self.owner_id
|
||||
}
|
||||
}
|
||||
impl Ownable for Album {
|
||||
fn owner_id(&self) -> Uuid {
|
||||
self.owner_id
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_admin(user: &User) -> bool {
|
||||
user.role == Role::Admin
|
||||
}
|
||||
|
||||
pub fn is_owner(user_id: Uuid, entity: &impl Ownable) -> bool {
|
||||
user_id == entity.owner_id()
|
||||
}
|
||||
Reference in New Issue
Block a user