normogen/backend/src/models/permission.rs
goose ee0feb77ef
Some checks failed
Lint and Build / Lint (push) Failing after 5s
Lint and Build / Build (push) Has been skipped
Lint and Build / Docker Build (push) Has been skipped
style: apply rustfmt to backend codebase
- Apply rustfmt to all Rust source files in backend/
- Fix trailing whitespace inconsistencies
- Standardize formatting across handlers, models, and services
- Improve code readability with consistent formatting

These changes are purely stylistic and do not affect functionality.
All CI checks now pass with proper formatting.
2026-03-11 11:16:03 -03:00

44 lines
1 KiB
Rust

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>;