add: allow community questions to be deleted by community owner

This commit is contained in:
trisua 2025-04-13 00:48:32 -04:00
parent 09ef0fc301
commit c49e4458e2
4 changed files with 67 additions and 1 deletions

View file

@ -2,6 +2,7 @@ use std::collections::HashMap;
use super::*;
use crate::cache::Cache;
use crate::model::communities_permissions::CommunityPermission;
use crate::model::{
Error, Result,
communities::Question,
@ -206,7 +207,18 @@ impl DataManager {
&& user.id != y.receiver
&& !user.permissions.check(FinePermission::MANAGE_QUESTIONS)
{
return Err(Error::NotAllowed);
if y.community != 0 {
// check for MANAGE_QUESTIONS permission
let membership = self
.get_membership_by_owner_community_no_void(user.id, y.community)
.await?;
if !membership.role.check(CommunityPermission::MANAGE_QUESTIONS) {
return Err(Error::NotAllowed);
}
} else {
return Err(Error::NotAllowed);
}
}
let conn = match self.connect().await {

View file

@ -17,6 +17,7 @@ bitflags! {
const REQUESTED = 1 << 6;
const MANAGE_PINS = 1 << 7;
const MANAGE_COMMUNITY = 1 << 8;
const MANAGE_QUESTIONS = 1 << 9;
const _ = !0;
}