normogen/backend/src/models/permission.rs
goose e1ef96b9b0
Some checks failed
Lint and Build / Lint (push) Failing after 1m35s
Lint and Build / Build (push) Has been skipped
Lint and Build / Docker Build (push) Has been skipped
fix(clippy): resolve all clippy warnings
- Add #![allow(dead_code)] to modules with future features
- Fix trailing whitespace in main.rs
- Remove unused imports (Claims, ObjectId, Deserialize, Serialize)
- Fix unnecessary map_err in health_stats.rs
- Add allow attributes for experimental and redundant code
- Fix redundant pattern matching in health.rs
2026-03-12 09:03:38 -03:00

45 lines
1 KiB
Rust

#![allow(dead_code)]
use serde::{Deserialize, Serialize};
use std::fmt;
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum Permission {
Read,
Write,
Delete,
Share,
Admin,
}
impl fmt::Display for Permission {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Read => write!(f, "read"),
Self::Write => write!(f, "write"),
Self::Delete => write!(f, "delete"),
Self::Share => write!(f, "share"),
Self::Admin => write!(f, "admin"),
}
}
}
impl Permission {
pub fn can_read(&self) -> bool {
matches!(self, Self::Read | Self::Admin)
}
pub fn can_write(&self) -> bool {
matches!(self, Self::Write | Self::Admin)
}
pub fn can_delete(&self) -> bool {
matches!(self, Self::Delete | Self::Admin)
}
pub fn can_share(&self) -> bool {
matches!(self, Self::Share | Self::Admin)
}
}
pub type Permissions = Vec<Permission>;