mirror of
https://github.com/LemmyNet/lemmy.git
synced 2025-04-27 13:14:44 +00:00
* add private visibility * filter private communities in post_view.rs * also filter in comment_view * community follower state * remove unused method * sql fmt * add CommunityFollower.approved_by * implement api endpoints * api changes * only admins can create private community for now * add local api tests * fix api tests * follow remote private community * use authorized fetch for content in private community * federate community visibility * dont mark content in private community as public * expose ApprovalRequired in api * also check content fetchable for outbox/featured * address private community content to followers * implement reject activity * fix tests * add files * remove local api tests * dont use delay * is_new_instance * single query for is_new_instance * return subscribed type for pending follow * working * need to catch errors in waitUntil * clippy * fix query * lint for unused async * diesel.toml comment * add comment * avoid db reads * rename approved_by to approver_id * add helper * form init * list pending follows should return items for all communities * clippy * ci * fix down migration * fix api tests * references * rename * run git diff * ci * fix schema check * fix joins * ci * ci * skip_serializing_none * fix test --------- Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
65 lines
1.7 KiB
Rust
65 lines
1.7 KiB
Rust
use activitypub_federation::config::Data;
|
|
use actix_web::web::Json;
|
|
use lemmy_api_common::{
|
|
build_response::build_post_response,
|
|
context::LemmyContext,
|
|
post::{DeletePost, PostResponse},
|
|
send_activity::{ActivityChannel, SendActivityData},
|
|
utils::check_community_user_action,
|
|
};
|
|
use lemmy_db_schema::{
|
|
source::{
|
|
community::Community,
|
|
post::{Post, PostUpdateForm},
|
|
},
|
|
traits::Crud,
|
|
};
|
|
use lemmy_db_views::structs::LocalUserView;
|
|
use lemmy_utils::error::{LemmyErrorType, LemmyResult};
|
|
|
|
#[tracing::instrument(skip(context))]
|
|
pub async fn delete_post(
|
|
data: Json<DeletePost>,
|
|
context: Data<LemmyContext>,
|
|
local_user_view: LocalUserView,
|
|
) -> LemmyResult<Json<PostResponse>> {
|
|
let post_id = data.post_id;
|
|
let orig_post = Post::read(&mut context.pool(), post_id).await?;
|
|
|
|
// Dont delete it if its already been deleted.
|
|
if orig_post.deleted == data.deleted {
|
|
Err(LemmyErrorType::CouldntUpdatePost)?
|
|
}
|
|
|
|
let community = Community::read(&mut context.pool(), orig_post.community_id).await?;
|
|
check_community_user_action(&local_user_view.person, &community, &mut context.pool()).await?;
|
|
|
|
// Verify that only the creator can delete
|
|
if !Post::is_post_creator(local_user_view.person.id, orig_post.creator_id) {
|
|
Err(LemmyErrorType::NoPostEditAllowed)?
|
|
}
|
|
|
|
// Update the post
|
|
let post = Post::update(
|
|
&mut context.pool(),
|
|
data.post_id,
|
|
&PostUpdateForm {
|
|
deleted: Some(data.deleted),
|
|
..Default::default()
|
|
},
|
|
)
|
|
.await?;
|
|
|
|
ActivityChannel::submit_activity(
|
|
SendActivityData::DeletePost(post, local_user_view.person.clone(), data.0),
|
|
&context,
|
|
)?;
|
|
|
|
build_post_response(
|
|
&context,
|
|
orig_post.community_id,
|
|
local_user_view,
|
|
data.post_id,
|
|
)
|
|
.await
|
|
}
|