- 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.
44 lines
1 KiB
Rust
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>;
|