add: don't allow blocked users to react to posts

This commit is contained in:
trisua 2025-05-08 17:12:15 -04:00
parent d7a37809ba
commit 303703a9a6
2 changed files with 35 additions and 17 deletions

View file

@ -67,6 +67,31 @@ impl DataManager {
Err(e) => return Err(Error::DatabaseConnection(e.to_string())), Err(e) => return Err(Error::DatabaseConnection(e.to_string())),
}; };
if data.asset_type == AssetType::Post {
let post = self.get_post_by_id(data.asset).await?;
if self
.get_userblock_by_initiator_receiver(post.owner, user.id)
.await
.is_ok()
&& !user.permissions.check(FinePermission::MANAGE_POSTS)
{
return Err(Error::NotAllowed);
}
} else if data.asset_type == AssetType::Question {
let question = self.get_question_by_id(data.asset).await?;
if self
.get_userblock_by_initiator_receiver(question.owner, user.id)
.await
.is_ok()
&& !user.permissions.check(FinePermission::MANAGE_POSTS)
{
return Err(Error::NotAllowed);
}
}
// ...
let res = execute!( let res = execute!(
&conn, &conn,
"INSERT INTO reactions VALUES ($1, $2, $3, $4, $5, $6)", "INSERT INTO reactions VALUES ($1, $2, $3, $4, $5, $6)",
@ -125,12 +150,6 @@ impl DataManager {
let post = self.get_post_by_id(data.asset).await.unwrap(); let post = self.get_post_by_id(data.asset).await.unwrap();
if post.owner != user.id { if post.owner != user.id {
// check block status (don't send notif if blocked)
if self
.get_userblock_by_initiator_receiver(post.owner, user.id)
.await
.is_err()
{
self.create_notification(Notification::new( self.create_notification(Notification::new(
"Your post has received a like!".to_string(), "Your post has received a like!".to_string(),
format!( format!(
@ -143,7 +162,6 @@ impl DataManager {
} }
} }
} }
}
AssetType::Question => { AssetType::Question => {
if let Err(e) = { if let Err(e) = {
if data.is_like { if data.is_like {

View file

@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};
use tetratto_shared::{snow::Snowflake, unix_epoch_timestamp}; use tetratto_shared::{snow::Snowflake, unix_epoch_timestamp};
/// All of the items which support reactions. /// All of the items which support reactions.
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize, PartialEq, Eq)]
pub enum AssetType { pub enum AssetType {
#[serde(alias = "community")] #[serde(alias = "community")]
Community, Community,