1
0
Fork 0
forked from alemi/upub

fix: delete with filters instead of activemodel

This commit is contained in:
əlemi 2024-04-23 04:24:27 +02:00
parent 43d5571b27
commit 63d78e7ff5
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -202,33 +202,30 @@ impl apb::server::Outbox for Context {
async fn undo(&self, uid: String, activity: serde_json::Value) -> crate::Result<String> { async fn undo(&self, uid: String, activity: serde_json::Value) -> crate::Result<String> {
let aid = self.aid(uuid::Uuid::new_v4().to_string()); let aid = self.aid(uuid::Uuid::new_v4().to_string());
let activity_targets = activity.addressed(); let activity_targets = activity.addressed();
{ let old_aid = activity.object().id().ok_or_else(UpubError::bad_request)?;
let Some(old_aid) = activity.object().id() else { let old_activity = model::activity::Entity::find_by_id(old_aid)
return Err(UpubError::bad_request()); .one(self.db())
}; .await?
let Some(old_activity) = model::activity::Entity::find_by_id(old_aid) .ok_or_else(UpubError::not_found)?;
.one(self.db()).await? if old_activity.actor != uid {
else { return Err(UpubError::forbidden());
return Err(UpubError::not_found()); }
}; match old_activity.activity_type {
if old_activity.actor != uid { apb::ActivityType::Like => {
return Err(UpubError::forbidden()); model::like::Entity::delete_many()
} .filter(model::like::Column::Actor.eq(old_activity.actor))
match old_activity.activity_type { .filter(model::like::Column::Likes.eq(old_activity.object.unwrap_or("".into())))
apb::ActivityType::Like => { .exec(self.db())
model::like::Entity::delete(model::like::ActiveModel { .await?;
actor: Set(old_activity.actor), likes: Set(old_activity.object.unwrap_or("".into())), },
..Default::default() apb::ActivityType::Follow => {
}).exec(self.db()).await?; model::relation::Entity::delete_many()
}, .filter(model::relation::Column::Follower.eq(old_activity.actor))
apb::ActivityType::Follow => { .filter(model::relation::Column::Following.eq(old_activity.object.unwrap_or("".into())))
model::relation::Entity::delete(model::relation::ActiveModel { .exec(self.db())
follower: Set(old_activity.actor), following: Set(old_activity.object.unwrap_or("".into())), .await?;
..Default::default() },
}).exec(self.db()).await?; t => tracing::warn!("extra side effects for activity {t:?} not implemented"),
},
t => tracing::warn!("extra side effects for activity {t:?} not implemented"),
}
} }
let activity_model = model::activity::Model::new( let activity_model = model::activity::Model::new(
&activity &activity