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())),
|
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,22 +150,15 @@ 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)
|
self.create_notification(Notification::new(
|
||||||
if self
|
"Your post has received a like!".to_string(),
|
||||||
.get_userblock_by_initiator_receiver(post.owner, user.id)
|
format!(
|
||||||
.await
|
"[@{}](/api/v1/auth/user/find/{}) has liked your [post](/post/{})!",
|
||||||
.is_err()
|
user.username, user.id, data.asset
|
||||||
{
|
),
|
||||||
self.create_notification(Notification::new(
|
post.owner,
|
||||||
"Your post has received a like!".to_string(),
|
))
|
||||||
format!(
|
.await?
|
||||||
"[@{}](/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};
|
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,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue