Implement AsObject for Post

This commit is contained in:
Kitaiti Makoto 2022-04-03 19:22:30 +09:00
parent 9183d04e66
commit 01e8b0bce8

View File

@ -1210,6 +1210,16 @@ impl AsObject<User, Create, &DbConn> for Post {
}
}
impl AsObject07<User, Create07, &DbConn> for Post {
type Error = Error;
type Output = Self;
fn activity07(self, _conn: &DbConn, _actor: User, _id: &str) -> Result<Self::Output> {
// TODO: check that _actor is actually one of the author?
Ok(self)
}
}
impl AsObject<User, Delete, &DbConn> for Post {
type Error = Error;
type Output = ();
@ -1227,6 +1237,23 @@ impl AsObject<User, Delete, &DbConn> for Post {
}
}
impl AsObject07<User, Delete07, &DbConn> for Post {
type Error = Error;
type Output = ();
fn activity07(self, conn: &DbConn, actor: User, _id: &str) -> Result<Self::Output> {
let can_delete = self
.get_authors(conn)?
.into_iter()
.any(|a| actor.id == a.id);
if can_delete {
self.delete(conn).map(|_| ())
} else {
Err(Error::Unauthorized)
}
}
}
pub struct PostUpdate {
pub ap_url: String,
pub title: Option<String>,