add: don't allow blocked users to react to posts
This commit is contained in:
parent
d7a37809ba
commit
303703a9a6
2 changed files with 35 additions and 17 deletions
|
@ -67,6 +67,31 @@ impl DataManager {
|
|||
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!(
|
||||
&conn,
|
||||
"INSERT INTO reactions VALUES ($1, $2, $3, $4, $5, $6)",
|
||||
|
@ -125,22 +150,15 @@ impl DataManager {
|
|||
let post = self.get_post_by_id(data.asset).await.unwrap();
|
||||
|
||||
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(
|
||||
"Your post has received a like!".to_string(),
|
||||
format!(
|
||||
"[@{}](/api/v1/auth/user/find/{}) has liked your [post](/post/{})!",
|
||||
user.username, user.id, data.asset
|
||||
),
|
||||
post.owner,
|
||||
))
|
||||
.await?
|
||||
}
|
||||
self.create_notification(Notification::new(
|
||||
"Your post has received a like!".to_string(),
|
||||
format!(
|
||||
"[@{}](/api/v1/auth/user/find/{}) has liked your [post](/post/{})!",
|
||||
user.username, user.id, data.asset
|
||||
),
|
||||
post.owner,
|
||||
))
|
||||
.await?
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};
|
|||
use tetratto_shared::{snow::Snowflake, unix_epoch_timestamp};
|
||||
|
||||
/// All of the items which support reactions.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[derive(Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub enum AssetType {
|
||||
#[serde(alias = "community")]
|
||||
Community,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue