add: finish forge stuff

This commit is contained in:
trisua 2025-06-10 22:02:06 -04:00
parent 53fb4d5778
commit 68071b96c8
21 changed files with 329 additions and 18 deletions

View file

@ -124,6 +124,7 @@ impl DataManager {
// SKIP tsvector (12)
poll_id: get!(x->13(i64)) as usize,
title: get!(x->14(String)),
is_open: get!(x->15(i32)) as i8 == 1,
}
}
@ -1564,7 +1565,7 @@ impl DataManager {
let res = execute!(
&conn,
"INSERT INTO posts VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, DEFAULT, $13, $14)",
"INSERT INTO posts VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, DEFAULT, $13, $14, $15)",
params![
&(data.id as i64),
&(data.created as i64),
@ -1583,7 +1584,8 @@ impl DataManager {
&serde_json::to_string(&data.uploads).unwrap(),
&{ if data.is_deleted { 1 } else { 0 } },
&(data.poll_id as i64),
&data.title
&data.title,
&{ if data.is_open { 1 } else { 0 } },
]
);
@ -1803,6 +1805,59 @@ impl DataManager {
Ok(())
}
pub async fn update_post_is_open(&self, id: usize, user: User, is_open: bool) -> Result<()> {
let y = self.get_post_by_id(id).await?;
// make sure this is a forge community
let community = self.get_community_by_id(y.community).await?;
if !community.is_forge {
return Err(Error::MiscError(
"This community does not support this".to_string(),
));
}
// check permissions
let user_membership = self
.get_membership_by_owner_community(user.id, y.community)
.await?;
if (user.id != y.owner)
&& !user_membership
.role
.check(CommunityPermission::MANAGE_POSTS)
{
if !user.permissions.check(FinePermission::MANAGE_POSTS) {
return Err(Error::NotAllowed);
} else {
self.create_audit_log_entry(AuditLogEntry::new(
user.id,
format!("invoked `update_post_is_open` with x value `{id}`"),
))
.await?
}
}
// ...
let conn = match self.0.connect().await {
Ok(c) => c,
Err(e) => return Err(Error::DatabaseConnection(e.to_string())),
};
let res = execute!(
&conn,
"UPDATE posts SET is_open = $1 WHERE id = $2",
params![if is_open { 1 } else { 0 }, &(id as i64)]
);
if let Err(e) = res {
return Err(Error::DatabaseError(e.to_string()));
}
self.0.1.remove(format!("atto.post:{}", id)).await;
Ok(())
}
pub async fn update_post_context(
&self,
id: usize,