security(favorite,recent): ensure read permission

This commit is contained in:
Edouard Vanbelle
2026-07-04 19:36:17 +02:00
parent cf5423b723
commit 2cda8e7e22
4 changed files with 138 additions and 64 deletions
+28
View File
@@ -118,6 +118,34 @@ impl Resource {
_ => None,
}
}
/// Parse `(item_type, item_id)` from an API-facing pair of strings
/// (favorites, recent, batch endpoints all take this shape).
/// Combines UUID parse + type mapping so callers stay one-line and
/// error shapes are identical across surfaces. Returns
/// `DomainError::new(InvalidInput, …)` on malformed input; callers
/// that need the anti-enum 404 shape do that separately by feeding
/// the parsed `Resource` into `authz.require(...)`.
pub fn parse(
item_type: &str,
item_id: &str,
) -> Result<Self, crate::common::errors::DomainError> {
use crate::common::errors::{DomainError, ErrorKind};
let uuid = Uuid::parse_str(item_id).map_err(|_| {
DomainError::new(
ErrorKind::InvalidInput,
"Resource",
format!("Invalid item UUID '{item_id}'"),
)
})?;
Self::from_parts(item_type, uuid).ok_or_else(|| {
DomainError::new(
ErrorKind::InvalidInput,
"Resource",
format!("Unsupported item type '{item_type}'"),
)
})
}
}
impl fmt::Display for Resource {