From 095b1dc8f50d02bd630149d51bd4ca62549880b2 Mon Sep 17 00:00:00 2001 From: alemi Date: Thu, 30 May 2024 18:36:47 +0200 Subject: [PATCH] fix: refuse creating objects from activities/actor --- src/model/object.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/model/object.rs b/src/model/object.rs index 880ed12..4f29637 100644 --- a/src/model/object.rs +++ b/src/model/object.rs @@ -145,10 +145,19 @@ impl Entity { impl ActiveModel { pub fn new(object: &impl apb::Object) -> Result { + let t = object.object_type().ok_or(super::FieldError("type"))?; + if matches!(t, + apb::ObjectType::Activity(_) + | apb::ObjectType::Actor(_) + | apb::ObjectType::Collection(_) + | apb::ObjectType::Document(_) + ) { + return Err(super::FieldError("type")); + } Ok(ActiveModel { internal: sea_orm::ActiveValue::NotSet, id: sea_orm::ActiveValue::Set(object.id().ok_or(super::FieldError("id"))?.to_string()), - object_type: sea_orm::ActiveValue::Set(object.object_type().ok_or(super::FieldError("type"))?), + object_type: sea_orm::ActiveValue::Set(t), attributed_to: sea_orm::ActiveValue::Set(object.attributed_to().id()), name: sea_orm::ActiveValue::Set(object.name().map(|x| x.to_string())), summary: sea_orm::ActiveValue::Set(object.summary().map(|x| x.to_string())),