mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-26 19:31:05 +00:00
Rewrite some API handlers to remove Perform trait (#3735)
* Rewrite some API handlers to remove Perform trait * Convert CreateComment * ci
This commit is contained in:
parent
db76c5b7ff
commit
37998b3398
36 changed files with 858 additions and 963 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -2573,6 +2573,7 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||||
name = "lemmy_api"
|
name = "lemmy_api"
|
||||||
version = "0.18.1"
|
version = "0.18.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"activitypub_federation",
|
||||||
"actix-web",
|
"actix-web",
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
|
|
|
@ -20,6 +20,7 @@ lemmy_db_views = { workspace = true, features = ["full"] }
|
||||||
lemmy_db_views_moderator = { workspace = true, features = ["full"] }
|
lemmy_db_views_moderator = { workspace = true, features = ["full"] }
|
||||||
lemmy_db_views_actor = { workspace = true, features = ["full"] }
|
lemmy_db_views_actor = { workspace = true, features = ["full"] }
|
||||||
lemmy_api_common = { workspace = true, features = ["full"] }
|
lemmy_api_common = { workspace = true, features = ["full"] }
|
||||||
|
activitypub_federation = { workspace = true }
|
||||||
bcrypt = { workspace = true }
|
bcrypt = { workspace = true }
|
||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
actix-web = { workspace = true }
|
actix-web = { workspace = true }
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use crate::Perform;
|
use actix_web::web::{Data, Json};
|
||||||
use actix_web::web::Data;
|
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
comment::{CommentResponse, DistinguishComment},
|
comment::{CommentResponse, DistinguishComment},
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
|
@ -12,14 +11,12 @@ use lemmy_db_schema::{
|
||||||
use lemmy_db_views::structs::CommentView;
|
use lemmy_db_views::structs::CommentView;
|
||||||
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[tracing::instrument(skip(context))]
|
||||||
impl Perform for DistinguishComment {
|
pub async fn distinguish_comment(
|
||||||
type Response = CommentResponse;
|
data: Json<DistinguishComment>,
|
||||||
|
context: Data<LemmyContext>,
|
||||||
#[tracing::instrument(skip(context))]
|
) -> Result<Json<CommentResponse>, LemmyError> {
|
||||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<CommentResponse, LemmyError> {
|
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||||
let data: &DistinguishComment = self;
|
|
||||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
|
||||||
|
|
||||||
let comment_id = data.comment_id;
|
let comment_id = data.comment_id;
|
||||||
let orig_comment = CommentView::read(&mut context.pool(), comment_id, None).await?;
|
let orig_comment = CommentView::read(&mut context.pool(), comment_id, None).await?;
|
||||||
|
@ -52,10 +49,9 @@ impl Perform for DistinguishComment {
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
let comment_view = CommentView::read(&mut context.pool(), comment_id, Some(person_id)).await?;
|
let comment_view = CommentView::read(&mut context.pool(), comment_id, Some(person_id)).await?;
|
||||||
|
|
||||||
Ok(CommentResponse {
|
Ok(Json(CommentResponse {
|
||||||
comment_view,
|
comment_view,
|
||||||
recipient_ids: Vec::new(),
|
recipient_ids: Vec::new(),
|
||||||
form_id: None,
|
form_id: None,
|
||||||
})
|
}))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
mod distinguish;
|
pub mod distinguish;
|
||||||
mod like;
|
pub mod like;
|
||||||
mod save;
|
pub mod save;
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use crate::Perform;
|
use actix_web::web::{Data, Json};
|
||||||
use actix_web::web::Data;
|
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
comment::{CommentResponse, SaveComment},
|
comment::{CommentResponse, SaveComment},
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
|
@ -12,14 +11,12 @@ use lemmy_db_schema::{
|
||||||
use lemmy_db_views::structs::CommentView;
|
use lemmy_db_views::structs::CommentView;
|
||||||
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[tracing::instrument(skip(context))]
|
||||||
impl Perform for SaveComment {
|
pub async fn save_comment(
|
||||||
type Response = CommentResponse;
|
data: Json<SaveComment>,
|
||||||
|
context: Data<LemmyContext>,
|
||||||
#[tracing::instrument(skip(context))]
|
) -> Result<Json<CommentResponse>, LemmyError> {
|
||||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<CommentResponse, LemmyError> {
|
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||||
let data: &SaveComment = self;
|
|
||||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
|
||||||
|
|
||||||
let comment_saved_form = CommentSavedForm {
|
let comment_saved_form = CommentSavedForm {
|
||||||
comment_id: data.comment_id,
|
comment_id: data.comment_id,
|
||||||
|
@ -40,10 +37,9 @@ impl Perform for SaveComment {
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
let comment_view = CommentView::read(&mut context.pool(), comment_id, Some(person_id)).await?;
|
let comment_view = CommentView::read(&mut context.pool(), comment_id, Some(person_id)).await?;
|
||||||
|
|
||||||
Ok(CommentResponse {
|
Ok(Json(CommentResponse {
|
||||||
comment_view,
|
comment_view,
|
||||||
recipient_ids: Vec::new(),
|
recipient_ids: Vec::new(),
|
||||||
form_id: None,
|
form_id: None,
|
||||||
})
|
}))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use crate::Perform;
|
use actix_web::web::{Data, Json, Query};
|
||||||
use actix_web::web::Data;
|
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
comment::{ListCommentReports, ListCommentReportsResponse},
|
comment::{ListCommentReports, ListCommentReportsResponse},
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
|
@ -10,17 +9,12 @@ use lemmy_utils::error::LemmyError;
|
||||||
|
|
||||||
/// Lists comment reports for a community if an id is supplied
|
/// Lists comment reports for a community if an id is supplied
|
||||||
/// or returns all comment reports for communities a user moderates
|
/// or returns all comment reports for communities a user moderates
|
||||||
#[async_trait::async_trait(?Send)]
|
#[tracing::instrument(skip(context))]
|
||||||
impl Perform for ListCommentReports {
|
pub async fn list_comment_reports(
|
||||||
type Response = ListCommentReportsResponse;
|
data: Query<ListCommentReports>,
|
||||||
|
context: Data<LemmyContext>,
|
||||||
#[tracing::instrument(skip(context))]
|
) -> Result<Json<ListCommentReportsResponse>, LemmyError> {
|
||||||
async fn perform(
|
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||||
&self,
|
|
||||||
context: &Data<LemmyContext>,
|
|
||||||
) -> Result<ListCommentReportsResponse, LemmyError> {
|
|
||||||
let data: &ListCommentReports = self;
|
|
||||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
|
||||||
|
|
||||||
let community_id = data.community_id;
|
let community_id = data.community_id;
|
||||||
let unresolved_only = data.unresolved_only;
|
let unresolved_only = data.unresolved_only;
|
||||||
|
@ -36,6 +30,5 @@ impl Perform for ListCommentReports {
|
||||||
.list(&mut context.pool(), &local_user_view.person)
|
.list(&mut context.pool(), &local_user_view.person)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(ListCommentReportsResponse { comment_reports })
|
Ok(Json(ListCommentReportsResponse { comment_reports }))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
mod create;
|
pub mod create;
|
||||||
mod list;
|
pub mod list;
|
||||||
mod resolve;
|
pub mod resolve;
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use crate::Perform;
|
use actix_web::web::{Data, Json};
|
||||||
use actix_web::web::Data;
|
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
comment::{CommentReportResponse, ResolveCommentReport},
|
comment::{CommentReportResponse, ResolveCommentReport},
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
|
@ -10,17 +9,12 @@ use lemmy_db_views::structs::CommentReportView;
|
||||||
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
||||||
|
|
||||||
/// Resolves or unresolves a comment report and notifies the moderators of the community
|
/// Resolves or unresolves a comment report and notifies the moderators of the community
|
||||||
#[async_trait::async_trait(?Send)]
|
#[tracing::instrument(skip(context))]
|
||||||
impl Perform for ResolveCommentReport {
|
pub async fn resolve_comment_report(
|
||||||
type Response = CommentReportResponse;
|
data: Json<ResolveCommentReport>,
|
||||||
|
context: Data<LemmyContext>,
|
||||||
#[tracing::instrument(skip(context))]
|
) -> Result<Json<CommentReportResponse>, LemmyError> {
|
||||||
async fn perform(
|
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||||
&self,
|
|
||||||
context: &Data<LemmyContext>,
|
|
||||||
) -> Result<CommentReportResponse, LemmyError> {
|
|
||||||
let data: &ResolveCommentReport = self;
|
|
||||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
|
||||||
|
|
||||||
let report_id = data.report_id;
|
let report_id = data.report_id;
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
|
@ -43,8 +37,7 @@ impl Perform for ResolveCommentReport {
|
||||||
let comment_report_view =
|
let comment_report_view =
|
||||||
CommentReportView::read(&mut context.pool(), report_id, person_id).await?;
|
CommentReportView::read(&mut context.pool(), report_id, person_id).await?;
|
||||||
|
|
||||||
Ok(CommentReportResponse {
|
Ok(Json(CommentReportResponse {
|
||||||
comment_report_view,
|
comment_report_view,
|
||||||
})
|
}))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,15 +9,15 @@ use lemmy_utils::{
|
||||||
};
|
};
|
||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
|
|
||||||
mod comment;
|
pub mod comment;
|
||||||
mod comment_report;
|
pub mod comment_report;
|
||||||
mod community;
|
pub mod community;
|
||||||
mod local_user;
|
pub mod local_user;
|
||||||
mod post;
|
pub mod post;
|
||||||
mod post_report;
|
pub mod post_report;
|
||||||
mod private_message;
|
pub mod private_message;
|
||||||
mod private_message_report;
|
pub mod private_message_report;
|
||||||
mod site;
|
pub mod site;
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
pub trait Perform {
|
pub trait Perform {
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
mod add_admin;
|
pub mod add_admin;
|
||||||
mod ban_person;
|
pub mod ban_person;
|
||||||
mod block;
|
pub mod block;
|
||||||
mod change_password;
|
pub mod change_password;
|
||||||
mod change_password_after_reset;
|
pub mod change_password_after_reset;
|
||||||
mod get_captcha;
|
pub mod get_captcha;
|
||||||
mod list_banned;
|
pub mod list_banned;
|
||||||
mod login;
|
pub mod login;
|
||||||
mod notifications;
|
pub mod notifications;
|
||||||
mod report_count;
|
pub mod report_count;
|
||||||
mod reset_password;
|
pub mod reset_password;
|
||||||
mod save_settings;
|
pub mod save_settings;
|
||||||
mod verify_email;
|
pub mod verify_email;
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use crate::Perform;
|
use actix_web::web::{Data, Json};
|
||||||
use actix_web::web::Data;
|
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
person::{CommentReplyResponse, MarkCommentReplyAsRead},
|
person::{CommentReplyResponse, MarkCommentReplyAsRead},
|
||||||
|
@ -12,17 +11,12 @@ use lemmy_db_schema::{
|
||||||
use lemmy_db_views_actor::structs::CommentReplyView;
|
use lemmy_db_views_actor::structs::CommentReplyView;
|
||||||
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[tracing::instrument(skip(context))]
|
||||||
impl Perform for MarkCommentReplyAsRead {
|
pub async fn mark_reply_as_read(
|
||||||
type Response = CommentReplyResponse;
|
data: Json<MarkCommentReplyAsRead>,
|
||||||
|
context: Data<LemmyContext>,
|
||||||
#[tracing::instrument(skip(context))]
|
) -> Result<Json<CommentReplyResponse>, LemmyError> {
|
||||||
async fn perform(
|
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||||
&self,
|
|
||||||
context: &Data<LemmyContext>,
|
|
||||||
) -> Result<CommentReplyResponse, LemmyError> {
|
|
||||||
let data = self;
|
|
||||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
|
||||||
|
|
||||||
let comment_reply_id = data.comment_reply_id;
|
let comment_reply_id = data.comment_reply_id;
|
||||||
let read_comment_reply = CommentReply::read(&mut context.pool(), comment_reply_id).await?;
|
let read_comment_reply = CommentReply::read(&mut context.pool(), comment_reply_id).await?;
|
||||||
|
@ -47,6 +41,5 @@ impl Perform for MarkCommentReplyAsRead {
|
||||||
let comment_reply_view =
|
let comment_reply_view =
|
||||||
CommentReplyView::read(&mut context.pool(), comment_reply_id, Some(person_id)).await?;
|
CommentReplyView::read(&mut context.pool(), comment_reply_id, Some(person_id)).await?;
|
||||||
|
|
||||||
Ok(CommentReplyResponse { comment_reply_view })
|
Ok(Json(CommentReplyResponse { comment_reply_view }))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
mod list_mentions;
|
pub mod list_mentions;
|
||||||
mod list_replies;
|
pub mod list_replies;
|
||||||
mod mark_all_read;
|
pub mod mark_all_read;
|
||||||
mod mark_mention_read;
|
pub mod mark_mention_read;
|
||||||
mod mark_reply_read;
|
pub mod mark_reply_read;
|
||||||
mod unread_count;
|
pub mod unread_count;
|
||||||
|
|
|
@ -23,7 +23,7 @@ use lemmy_db_views_actor::structs::CommunityView;
|
||||||
use lemmy_utils::{error::LemmyError, utils::mention::MentionData};
|
use lemmy_utils::{error::LemmyError, utils::mention::MentionData};
|
||||||
|
|
||||||
pub async fn build_comment_response(
|
pub async fn build_comment_response(
|
||||||
context: &Data<LemmyContext>,
|
context: &LemmyContext,
|
||||||
comment_id: CommentId,
|
comment_id: CommentId,
|
||||||
local_user_view: Option<LocalUserView>,
|
local_user_view: Option<LocalUserView>,
|
||||||
form_id: Option<String>,
|
form_id: Option<String>,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::context::LemmyContext;
|
use crate::context::LemmyContext;
|
||||||
use activitypub_federation::config::Data;
|
use activitypub_federation::config::Data;
|
||||||
use futures::future::BoxFuture;
|
use futures::future::BoxFuture;
|
||||||
use lemmy_db_schema::source::post::Post;
|
use lemmy_db_schema::source::{comment::Comment, post::Post};
|
||||||
use lemmy_utils::{error::LemmyResult, SYNCHRONOUS_FEDERATION};
|
use lemmy_utils::{error::LemmyResult, SYNCHRONOUS_FEDERATION};
|
||||||
use once_cell::sync::{Lazy, OnceCell};
|
use once_cell::sync::{Lazy, OnceCell};
|
||||||
use tokio::{
|
use tokio::{
|
||||||
|
@ -22,6 +22,7 @@ pub static MATCH_OUTGOING_ACTIVITIES: OnceCell<MatchOutgoingActivitiesBoxed> = O
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum SendActivityData {
|
pub enum SendActivityData {
|
||||||
CreatePost(Post),
|
CreatePost(Post),
|
||||||
|
CreateComment(Comment),
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: instead of static, move this into LemmyContext. make sure that stopping the process with
|
// TODO: instead of static, move this into LemmyContext. make sure that stopping the process with
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
use crate::PerformCrud;
|
use activitypub_federation::config::Data;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Json;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
build_response::{build_comment_response, send_local_notifs},
|
build_response::{build_comment_response, send_local_notifs},
|
||||||
comment::{CommentResponse, CreateComment},
|
comment::{CommentResponse, CreateComment},
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
|
send_activity::{ActivityChannel, SendActivityData},
|
||||||
utils::{
|
utils::{
|
||||||
check_community_ban,
|
check_community_ban,
|
||||||
check_community_deleted_or_removed,
|
check_community_deleted_or_removed,
|
||||||
|
@ -35,17 +36,16 @@ use lemmy_utils::{
|
||||||
validation::is_valid_body_field,
|
validation::is_valid_body_field,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
use std::ops::Deref;
|
||||||
|
|
||||||
const MAX_COMMENT_DEPTH_LIMIT: usize = 100;
|
const MAX_COMMENT_DEPTH_LIMIT: usize = 100;
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[tracing::instrument(skip(context))]
|
||||||
impl PerformCrud for CreateComment {
|
pub async fn create_comment(
|
||||||
type Response = CommentResponse;
|
data: Json<CreateComment>,
|
||||||
|
context: Data<LemmyContext>,
|
||||||
#[tracing::instrument(skip(context))]
|
) -> Result<Json<CommentResponse>, LemmyError> {
|
||||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<CommentResponse, LemmyError> {
|
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||||
let data: &CreateComment = self;
|
|
||||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
|
||||||
let local_site = LocalSite::read(&mut context.pool()).await?;
|
let local_site = LocalSite::read(&mut context.pool()).await?;
|
||||||
|
|
||||||
let content = remove_slurs(
|
let content = remove_slurs(
|
||||||
|
@ -114,8 +114,7 @@ impl PerformCrud for CreateComment {
|
||||||
|
|
||||||
// Create the comment
|
// Create the comment
|
||||||
let parent_path = parent_opt.clone().map(|t| t.path);
|
let parent_path = parent_opt.clone().map(|t| t.path);
|
||||||
let inserted_comment =
|
let inserted_comment = Comment::create(&mut context.pool(), &comment_form, parent_path.as_ref())
|
||||||
Comment::create(&mut context.pool(), &comment_form, parent_path.as_ref())
|
|
||||||
.await
|
.await
|
||||||
.with_lemmy_type(LemmyErrorType::CouldntCreateComment)?;
|
.with_lemmy_type(LemmyErrorType::CouldntCreateComment)?;
|
||||||
|
|
||||||
|
@ -144,7 +143,7 @@ impl PerformCrud for CreateComment {
|
||||||
&local_user_view.person,
|
&local_user_view.person,
|
||||||
&post,
|
&post,
|
||||||
true,
|
true,
|
||||||
context,
|
&context,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
@ -160,6 +159,12 @@ impl PerformCrud for CreateComment {
|
||||||
.await
|
.await
|
||||||
.with_lemmy_type(LemmyErrorType::CouldntLikeComment)?;
|
.with_lemmy_type(LemmyErrorType::CouldntLikeComment)?;
|
||||||
|
|
||||||
|
ActivityChannel::submit_activity(
|
||||||
|
SendActivityData::CreateComment(updated_comment.clone()),
|
||||||
|
&context,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
// If its a reply, mark the parent as read
|
// If its a reply, mark the parent as read
|
||||||
if let Some(parent) = parent_opt {
|
if let Some(parent) = parent_opt {
|
||||||
let parent_id = parent.id;
|
let parent_id = parent.id;
|
||||||
|
@ -189,15 +194,16 @@ impl PerformCrud for CreateComment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ok(Json(
|
||||||
build_comment_response(
|
build_comment_response(
|
||||||
context,
|
context.deref(),
|
||||||
inserted_comment.id,
|
inserted_comment.id,
|
||||||
Some(local_user_view),
|
Some(local_user_view),
|
||||||
self.form_id.clone(),
|
data.form_id.clone(),
|
||||||
recipient_ids,
|
recipient_ids,
|
||||||
)
|
)
|
||||||
.await
|
.await?,
|
||||||
}
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_comment_depth(comment: &Comment) -> Result<(), LemmyError> {
|
pub fn check_comment_depth(comment: &Comment) -> Result<(), LemmyError> {
|
||||||
|
|
|
@ -15,6 +15,7 @@ use lemmy_db_schema::{
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::CommentView;
|
use lemmy_db_views::structs::CommentView;
|
||||||
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
||||||
|
use std::ops::Deref;
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl PerformCrud for DeleteComment {
|
impl PerformCrud for DeleteComment {
|
||||||
|
@ -68,7 +69,7 @@ impl PerformCrud for DeleteComment {
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
build_comment_response(
|
build_comment_response(
|
||||||
context,
|
context.deref(),
|
||||||
updated_comment.id,
|
updated_comment.id,
|
||||||
Some(local_user_view),
|
Some(local_user_view),
|
||||||
None,
|
None,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
mod create;
|
pub mod create;
|
||||||
mod delete;
|
pub mod delete;
|
||||||
mod read;
|
pub mod read;
|
||||||
mod remove;
|
pub mod remove;
|
||||||
mod update;
|
pub mod update;
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use crate::PerformCrud;
|
use actix_web::web::{Data, Json, Query};
|
||||||
use actix_web::web::Data;
|
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
build_response::build_comment_response,
|
build_response::build_comment_response,
|
||||||
comment::{CommentResponse, GetComment},
|
comment::{CommentResponse, GetComment},
|
||||||
|
@ -8,19 +7,19 @@ use lemmy_api_common::{
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::source::local_site::LocalSite;
|
use lemmy_db_schema::source::local_site::LocalSite;
|
||||||
use lemmy_utils::error::LemmyError;
|
use lemmy_utils::error::LemmyError;
|
||||||
|
use std::ops::Deref;
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[tracing::instrument(skip(context))]
|
||||||
impl PerformCrud for GetComment {
|
pub async fn get_comment(
|
||||||
type Response = CommentResponse;
|
data: Query<GetComment>,
|
||||||
|
context: Data<LemmyContext>,
|
||||||
#[tracing::instrument(skip(context))]
|
) -> Result<Json<CommentResponse>, LemmyError> {
|
||||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
|
let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), &context).await;
|
||||||
let data = self;
|
|
||||||
let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await;
|
|
||||||
let local_site = LocalSite::read(&mut context.pool()).await?;
|
let local_site = LocalSite::read(&mut context.pool()).await?;
|
||||||
|
|
||||||
check_private_instance(&local_user_view, &local_site)?;
|
check_private_instance(&local_user_view, &local_site)?;
|
||||||
|
|
||||||
build_comment_response(context, data.id, local_user_view, None, vec![]).await
|
Ok(Json(
|
||||||
}
|
build_comment_response(context.deref(), data.id, local_user_view, None, vec![]).await?,
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ use lemmy_db_schema::{
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::CommentView;
|
use lemmy_db_views::structs::CommentView;
|
||||||
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
||||||
|
use std::ops::Deref;
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl PerformCrud for RemoveComment {
|
impl PerformCrud for RemoveComment {
|
||||||
|
@ -76,7 +77,7 @@ impl PerformCrud for RemoveComment {
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
build_comment_response(
|
build_comment_response(
|
||||||
context,
|
context.deref(),
|
||||||
updated_comment.id,
|
updated_comment.id,
|
||||||
Some(local_user_view),
|
Some(local_user_view),
|
||||||
None,
|
None,
|
||||||
|
|
|
@ -29,6 +29,7 @@ use lemmy_utils::{
|
||||||
validation::is_valid_body_field,
|
validation::is_valid_body_field,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
use std::ops::Deref;
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl PerformCrud for EditComment {
|
impl PerformCrud for EditComment {
|
||||||
|
@ -95,7 +96,7 @@ impl PerformCrud for EditComment {
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
build_comment_response(
|
build_comment_response(
|
||||||
context,
|
context.deref(),
|
||||||
updated_comment.id,
|
updated_comment.id,
|
||||||
Some(local_user_view),
|
Some(local_user_view),
|
||||||
self.form_id.clone(),
|
self.form_id.clone(),
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use crate::PerformCrud;
|
use actix_web::web::{Data, Json, Query};
|
||||||
use actix_web::web::Data;
|
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
community::{ListCommunities, ListCommunitiesResponse},
|
community::{ListCommunities, ListCommunitiesResponse},
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
|
@ -9,17 +8,12 @@ use lemmy_db_schema::source::local_site::LocalSite;
|
||||||
use lemmy_db_views_actor::community_view::CommunityQuery;
|
use lemmy_db_views_actor::community_view::CommunityQuery;
|
||||||
use lemmy_utils::error::LemmyError;
|
use lemmy_utils::error::LemmyError;
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[tracing::instrument(skip(context))]
|
||||||
impl PerformCrud for ListCommunities {
|
pub async fn list_communities(
|
||||||
type Response = ListCommunitiesResponse;
|
data: Query<ListCommunities>,
|
||||||
|
context: Data<LemmyContext>,
|
||||||
#[tracing::instrument(skip(context))]
|
) -> Result<Json<ListCommunitiesResponse>, LemmyError> {
|
||||||
async fn perform(
|
let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), &context).await;
|
||||||
&self,
|
|
||||||
context: &Data<LemmyContext>,
|
|
||||||
) -> Result<ListCommunitiesResponse, LemmyError> {
|
|
||||||
let data: &ListCommunities = self;
|
|
||||||
let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await;
|
|
||||||
let local_site = LocalSite::read(&mut context.pool()).await?;
|
let local_site = LocalSite::read(&mut context.pool()).await?;
|
||||||
let is_admin = local_user_view.as_ref().map(|luv| is_admin(luv).is_ok());
|
let is_admin = local_user_view.as_ref().map(|luv| is_admin(luv).is_ok());
|
||||||
|
|
||||||
|
@ -45,6 +39,5 @@ impl PerformCrud for ListCommunities {
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
// Return the jwt
|
// Return the jwt
|
||||||
Ok(ListCommunitiesResponse { communities })
|
Ok(Json(ListCommunitiesResponse { communities }))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
mod create;
|
pub mod create;
|
||||||
mod delete;
|
pub mod delete;
|
||||||
mod list;
|
pub mod list;
|
||||||
mod remove;
|
pub mod remove;
|
||||||
mod update;
|
pub mod update;
|
||||||
|
|
|
@ -2,13 +2,13 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::context::LemmyContext;
|
use lemmy_api_common::context::LemmyContext;
|
||||||
use lemmy_utils::error::LemmyError;
|
use lemmy_utils::error::LemmyError;
|
||||||
|
|
||||||
mod comment;
|
pub mod comment;
|
||||||
mod community;
|
pub mod community;
|
||||||
mod custom_emoji;
|
pub mod custom_emoji;
|
||||||
pub mod post;
|
pub mod post;
|
||||||
mod private_message;
|
pub mod private_message;
|
||||||
mod site;
|
pub mod site;
|
||||||
mod user;
|
pub mod user;
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
pub trait PerformCrud {
|
pub trait PerformCrud {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
pub mod create;
|
pub mod create;
|
||||||
mod delete;
|
pub mod delete;
|
||||||
mod read;
|
pub mod read;
|
||||||
mod remove;
|
pub mod remove;
|
||||||
mod update;
|
pub mod update;
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use crate::PerformCrud;
|
use actix_web::web::{Data, Json, Query};
|
||||||
use actix_web::web::Data;
|
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
post::{GetPost, GetPostResponse},
|
post::{GetPost, GetPostResponse},
|
||||||
|
@ -19,14 +18,12 @@ use lemmy_db_views::{post_view::PostQuery, structs::PostView};
|
||||||
use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView};
|
use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView};
|
||||||
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[tracing::instrument(skip(context))]
|
||||||
impl PerformCrud for GetPost {
|
pub async fn get_post(
|
||||||
type Response = GetPostResponse;
|
data: Query<GetPost>,
|
||||||
|
context: Data<LemmyContext>,
|
||||||
#[tracing::instrument(skip(context))]
|
) -> Result<Json<GetPostResponse>, LemmyError> {
|
||||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<GetPostResponse, LemmyError> {
|
let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), &context).await;
|
||||||
let data: &GetPost = self;
|
|
||||||
let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await;
|
|
||||||
let local_site = LocalSite::read(&mut context.pool()).await?;
|
let local_site = LocalSite::read(&mut context.pool()).await?;
|
||||||
|
|
||||||
check_private_instance(&local_user_view, &local_site)?;
|
check_private_instance(&local_user_view, &local_site)?;
|
||||||
|
@ -95,8 +92,7 @@ impl PerformCrud for GetPost {
|
||||||
.with_lemmy_type(LemmyErrorType::CouldntFindPost)?;
|
.with_lemmy_type(LemmyErrorType::CouldntFindPost)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let moderators =
|
let moderators = CommunityModeratorView::for_community(&mut context.pool(), community_id).await?;
|
||||||
CommunityModeratorView::for_community(&mut context.pool(), community_id).await?;
|
|
||||||
|
|
||||||
// Fetch the cross_posts
|
// Fetch the cross_posts
|
||||||
let cross_posts = if let Some(url) = &post_view.post.url {
|
let cross_posts = if let Some(url) = &post_view.post.url {
|
||||||
|
@ -115,11 +111,10 @@ impl PerformCrud for GetPost {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Return the jwt
|
// Return the jwt
|
||||||
Ok(GetPostResponse {
|
Ok(Json(GetPostResponse {
|
||||||
post_view,
|
post_view,
|
||||||
community_view,
|
community_view,
|
||||||
moderators,
|
moderators,
|
||||||
cross_posts,
|
cross_posts,
|
||||||
})
|
}))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
mod create;
|
pub mod create;
|
||||||
mod delete;
|
pub mod delete;
|
||||||
mod read;
|
pub mod read;
|
||||||
mod update;
|
pub mod update;
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use crate::PerformCrud;
|
use actix_web::web::{Data, Json, Query};
|
||||||
use actix_web::web::Data;
|
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
private_message::{GetPrivateMessages, PrivateMessagesResponse},
|
private_message::{GetPrivateMessages, PrivateMessagesResponse},
|
||||||
|
@ -8,17 +7,12 @@ use lemmy_api_common::{
|
||||||
use lemmy_db_views::private_message_view::PrivateMessageQuery;
|
use lemmy_db_views::private_message_view::PrivateMessageQuery;
|
||||||
use lemmy_utils::error::LemmyError;
|
use lemmy_utils::error::LemmyError;
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[tracing::instrument(skip(context))]
|
||||||
impl PerformCrud for GetPrivateMessages {
|
pub async fn get_private_message(
|
||||||
type Response = PrivateMessagesResponse;
|
data: Query<GetPrivateMessages>,
|
||||||
|
context: Data<LemmyContext>,
|
||||||
#[tracing::instrument(skip(self, context))]
|
) -> Result<Json<PrivateMessagesResponse>, LemmyError> {
|
||||||
async fn perform(
|
let local_user_view = local_user_view_from_jwt(data.auth.as_ref(), &context).await?;
|
||||||
&self,
|
|
||||||
context: &Data<LemmyContext>,
|
|
||||||
) -> Result<PrivateMessagesResponse, LemmyError> {
|
|
||||||
let data: &GetPrivateMessages = self;
|
|
||||||
let local_user_view = local_user_view_from_jwt(data.auth.as_ref(), context).await?;
|
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
|
|
||||||
let page = data.page;
|
let page = data.page;
|
||||||
|
@ -40,8 +34,7 @@ impl PerformCrud for GetPrivateMessages {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(PrivateMessagesResponse {
|
Ok(Json(PrivateMessagesResponse {
|
||||||
private_messages: messages,
|
private_messages: messages,
|
||||||
})
|
}))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
use crate::{
|
use crate::site::{application_question_check, site_default_post_listing_type_check};
|
||||||
site::{application_question_check, site_default_post_listing_type_check},
|
|
||||||
PerformCrud,
|
|
||||||
};
|
|
||||||
use activitypub_federation::http_signatures::generate_actor_keypair;
|
use activitypub_federation::http_signatures::generate_actor_keypair;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::{Data, Json};
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
site::{CreateSite, SiteResponse},
|
site::{CreateSite, SiteResponse},
|
||||||
|
@ -43,20 +40,18 @@ use lemmy_utils::{
|
||||||
};
|
};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[tracing::instrument(skip(context))]
|
||||||
impl PerformCrud for CreateSite {
|
pub async fn create_site(
|
||||||
type Response = SiteResponse;
|
data: Json<CreateSite>,
|
||||||
|
context: Data<LemmyContext>,
|
||||||
#[tracing::instrument(skip(context))]
|
) -> Result<Json<SiteResponse>, LemmyError> {
|
||||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<SiteResponse, LemmyError> {
|
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||||
let data: &CreateSite = self;
|
|
||||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
|
||||||
let local_site = LocalSite::read(&mut context.pool()).await?;
|
let local_site = LocalSite::read(&mut context.pool()).await?;
|
||||||
|
|
||||||
// Make sure user is an admin; other types of users should not create site data...
|
// Make sure user is an admin; other types of users should not create site data...
|
||||||
is_admin(&local_user_view)?;
|
is_admin(&local_user_view)?;
|
||||||
|
|
||||||
validate_create_payload(&local_site, data)?;
|
validate_create_payload(&local_site, &data)?;
|
||||||
|
|
||||||
let actor_id: DbUrl = Url::parse(&context.settings().get_protocol_and_hostname())?.into();
|
let actor_id: DbUrl = Url::parse(&context.settings().get_protocol_and_hostname())?.into();
|
||||||
let inbox_url = Some(generate_site_inbox_url(&actor_id)?);
|
let inbox_url = Some(generate_site_inbox_url(&actor_id)?);
|
||||||
|
@ -140,11 +135,10 @@ impl PerformCrud for CreateSite {
|
||||||
.send(rate_limit_config)
|
.send(rate_limit_config)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(SiteResponse {
|
Ok(Json(SiteResponse {
|
||||||
site_view,
|
site_view,
|
||||||
taglines,
|
taglines,
|
||||||
})
|
}))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn validate_create_payload(local_site: &LocalSite, create_site: &CreateSite) -> LemmyResult<()> {
|
fn validate_create_payload(local_site: &LocalSite, create_site: &CreateSite) -> LemmyResult<()> {
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
use lemmy_db_schema::{ListingType, RegistrationMode};
|
use lemmy_db_schema::{ListingType, RegistrationMode};
|
||||||
use lemmy_utils::error::{LemmyErrorType, LemmyResult};
|
use lemmy_utils::error::{LemmyErrorType, LemmyResult};
|
||||||
|
|
||||||
mod create;
|
pub mod create;
|
||||||
mod read;
|
pub mod read;
|
||||||
mod update;
|
pub mod update;
|
||||||
|
|
||||||
/// Checks whether the default post listing type is valid for a site.
|
/// Checks whether the default post listing type is valid for a site.
|
||||||
pub fn site_default_post_listing_type_check(
|
pub fn site_default_post_listing_type_check(
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use crate::PerformCrud;
|
use actix_web::web::{Data, Json, Query};
|
||||||
use actix_web::web::Data;
|
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
sensitive::Sensitive,
|
sensitive::Sensitive,
|
||||||
|
@ -28,21 +27,18 @@ use lemmy_utils::{
|
||||||
version,
|
version,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[tracing::instrument(skip(context))]
|
||||||
impl PerformCrud for GetSite {
|
pub async fn get_site(
|
||||||
type Response = GetSiteResponse;
|
data: Query<GetSite>,
|
||||||
|
context: Data<LemmyContext>,
|
||||||
#[tracing::instrument(skip(context))]
|
) -> Result<Json<GetSiteResponse>, LemmyError> {
|
||||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<GetSiteResponse, LemmyError> {
|
|
||||||
let data: &GetSite = self;
|
|
||||||
|
|
||||||
let site_view = SiteView::read_local(&mut context.pool()).await?;
|
let site_view = SiteView::read_local(&mut context.pool()).await?;
|
||||||
|
|
||||||
let admins = PersonView::admins(&mut context.pool()).await?;
|
let admins = PersonView::admins(&mut context.pool()).await?;
|
||||||
|
|
||||||
// Build the local user
|
// Build the local user
|
||||||
let my_user = if let Some(local_user_view) =
|
let my_user = if let Some(local_user_view) =
|
||||||
local_user_settings_view_from_jwt_opt(data.auth.as_ref(), context).await
|
local_user_settings_view_from_jwt_opt(data.auth.as_ref(), &context).await
|
||||||
{
|
{
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
let local_user_id = local_user_view.local_user.id;
|
let local_user_id = local_user_view.local_user.id;
|
||||||
|
@ -87,7 +83,7 @@ impl PerformCrud for GetSite {
|
||||||
let custom_emojis =
|
let custom_emojis =
|
||||||
CustomEmojiView::get_all(&mut context.pool(), site_view.local_site.id).await?;
|
CustomEmojiView::get_all(&mut context.pool(), site_view.local_site.id).await?;
|
||||||
|
|
||||||
Ok(GetSiteResponse {
|
Ok(Json(GetSiteResponse {
|
||||||
site_view,
|
site_view,
|
||||||
admins,
|
admins,
|
||||||
version: version::VERSION.to_string(),
|
version: version::VERSION.to_string(),
|
||||||
|
@ -96,8 +92,7 @@ impl PerformCrud for GetSite {
|
||||||
discussion_languages,
|
discussion_languages,
|
||||||
taglines,
|
taglines,
|
||||||
custom_emojis,
|
custom_emojis,
|
||||||
})
|
}))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
use crate::{
|
use crate::site::{application_question_check, site_default_post_listing_type_check};
|
||||||
site::{application_question_check, site_default_post_listing_type_check},
|
use actix_web::web::{Data, Json};
|
||||||
PerformCrud,
|
|
||||||
};
|
|
||||||
use actix_web::web::Data;
|
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
site::{EditSite, SiteResponse},
|
site::{EditSite, SiteResponse},
|
||||||
|
@ -43,14 +40,12 @@ use lemmy_utils::{
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[tracing::instrument(skip(context))]
|
||||||
impl PerformCrud for EditSite {
|
pub async fn update_site(
|
||||||
type Response = SiteResponse;
|
data: Json<EditSite>,
|
||||||
|
context: Data<LemmyContext>,
|
||||||
#[tracing::instrument(skip(context))]
|
) -> Result<Json<SiteResponse>, LemmyError> {
|
||||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<SiteResponse, LemmyError> {
|
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||||
let data: &EditSite = self;
|
|
||||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
|
||||||
let site_view = SiteView::read_local(&mut context.pool()).await?;
|
let site_view = SiteView::read_local(&mut context.pool()).await?;
|
||||||
let local_site = site_view.local_site;
|
let local_site = site_view.local_site;
|
||||||
let site = site_view.site;
|
let site = site_view.site;
|
||||||
|
@ -58,7 +53,7 @@ impl PerformCrud for EditSite {
|
||||||
// Make sure user is an admin; other types of users should not update site data...
|
// Make sure user is an admin; other types of users should not update site data...
|
||||||
is_admin(&local_user_view)?;
|
is_admin(&local_user_view)?;
|
||||||
|
|
||||||
validate_update_payload(&local_site, data)?;
|
validate_update_payload(&local_site, &data)?;
|
||||||
|
|
||||||
if let Some(discussion_languages) = data.discussion_languages.clone() {
|
if let Some(discussion_languages) = data.discussion_languages.clone() {
|
||||||
SiteLanguage::update(&mut context.pool(), discussion_languages.clone(), &site).await?;
|
SiteLanguage::update(&mut context.pool(), discussion_languages.clone(), &site).await?;
|
||||||
|
@ -177,13 +172,10 @@ impl PerformCrud for EditSite {
|
||||||
.send(rate_limit_config)
|
.send(rate_limit_config)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let res = SiteResponse {
|
Ok(Json(SiteResponse {
|
||||||
site_view,
|
site_view,
|
||||||
taglines,
|
taglines,
|
||||||
};
|
}))
|
||||||
|
|
||||||
Ok(res)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn validate_update_payload(local_site: &LocalSite, edit_site: &EditSite) -> LemmyResult<()> {
|
fn validate_update_payload(local_site: &LocalSite, edit_site: &EditSite) -> LemmyResult<()> {
|
||||||
|
|
|
@ -25,7 +25,7 @@ use activitypub_federation::{
|
||||||
};
|
};
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
build_response::send_local_notifs,
|
build_response::send_local_notifs,
|
||||||
comment::{CommentResponse, CreateComment, EditComment},
|
comment::{CommentResponse, EditComment},
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
utils::{check_post_deleted_or_removed, is_mod_or_admin},
|
utils::{check_post_deleted_or_removed, is_mod_or_admin},
|
||||||
};
|
};
|
||||||
|
@ -43,25 +43,6 @@ use lemmy_db_schema::{
|
||||||
use lemmy_utils::{error::LemmyError, utils::mention::scrape_text_for_mentions};
|
use lemmy_utils::{error::LemmyError, utils::mention::scrape_text_for_mentions};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
impl SendActivity for CreateComment {
|
|
||||||
type Response = CommentResponse;
|
|
||||||
|
|
||||||
async fn send_activity(
|
|
||||||
_request: &Self,
|
|
||||||
response: &Self::Response,
|
|
||||||
context: &Data<LemmyContext>,
|
|
||||||
) -> Result<(), LemmyError> {
|
|
||||||
CreateOrUpdateNote::send(
|
|
||||||
&response.comment_view.comment,
|
|
||||||
response.comment_view.creator.id,
|
|
||||||
CreateOrUpdateType::Create,
|
|
||||||
context,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
impl SendActivity for EditComment {
|
impl SendActivity for EditComment {
|
||||||
type Response = CommentResponse;
|
type Response = CommentResponse;
|
||||||
|
@ -72,10 +53,10 @@ impl SendActivity for EditComment {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
CreateOrUpdateNote::send(
|
CreateOrUpdateNote::send(
|
||||||
&response.comment_view.comment,
|
response.comment_view.comment.clone(),
|
||||||
response.comment_view.creator.id,
|
response.comment_view.creator.id,
|
||||||
CreateOrUpdateType::Update,
|
CreateOrUpdateType::Update,
|
||||||
context,
|
context.reset_request_count(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
@ -83,11 +64,11 @@ impl SendActivity for EditComment {
|
||||||
|
|
||||||
impl CreateOrUpdateNote {
|
impl CreateOrUpdateNote {
|
||||||
#[tracing::instrument(skip(comment, person_id, kind, context))]
|
#[tracing::instrument(skip(comment, person_id, kind, context))]
|
||||||
async fn send(
|
pub(crate) async fn send(
|
||||||
comment: &Comment,
|
comment: Comment,
|
||||||
person_id: PersonId,
|
person_id: PersonId,
|
||||||
kind: CreateOrUpdateType,
|
kind: CreateOrUpdateType,
|
||||||
context: &Data<LemmyContext>,
|
context: Data<LemmyContext>,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
// TODO: might be helpful to add a comment method to retrieve community directly
|
// TODO: might be helpful to add a comment method to retrieve community directly
|
||||||
let post_id = comment.post_id;
|
let post_id = comment.post_id;
|
||||||
|
@ -102,7 +83,7 @@ impl CreateOrUpdateNote {
|
||||||
kind.clone(),
|
kind.clone(),
|
||||||
&context.settings().get_protocol_and_hostname(),
|
&context.settings().get_protocol_and_hostname(),
|
||||||
)?;
|
)?;
|
||||||
let note = ApubComment(comment.clone()).into_json(context).await?;
|
let note = ApubComment(comment).into_json(&context).await?;
|
||||||
|
|
||||||
let create_or_update = CreateOrUpdateNote {
|
let create_or_update = CreateOrUpdateNote {
|
||||||
actor: person.id().into(),
|
actor: person.id().into(),
|
||||||
|
@ -130,12 +111,12 @@ impl CreateOrUpdateNote {
|
||||||
.collect();
|
.collect();
|
||||||
let mut inboxes = vec![];
|
let mut inboxes = vec![];
|
||||||
for t in tagged_users {
|
for t in tagged_users {
|
||||||
let person = t.dereference(context).await?;
|
let person = t.dereference(&context).await?;
|
||||||
inboxes.push(person.shared_inbox_or_inbox());
|
inboxes.push(person.shared_inbox_or_inbox());
|
||||||
}
|
}
|
||||||
|
|
||||||
let activity = AnnouncableActivities::CreateOrUpdateComment(create_or_update);
|
let activity = AnnouncableActivities::CreateOrUpdateComment(create_or_update);
|
||||||
send_activity_in_community(activity, &person, &community, inboxes, false, context).await
|
send_activity_in_community(activity, &person, &community, inboxes, false, &context).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
objects::{community::ApubCommunity, person::ApubPerson},
|
objects::{community::ApubCommunity, person::ApubPerson},
|
||||||
protocol::activities::{create_or_update::page::CreateOrUpdatePage, CreateOrUpdateType},
|
protocol::activities::{
|
||||||
|
create_or_update::{note::CreateOrUpdateNote, page::CreateOrUpdatePage},
|
||||||
|
CreateOrUpdateType,
|
||||||
|
},
|
||||||
CONTEXT,
|
CONTEXT,
|
||||||
};
|
};
|
||||||
use activitypub_federation::{
|
use activitypub_federation::{
|
||||||
|
@ -217,15 +220,17 @@ pub async fn match_outgoing_activities(
|
||||||
data: SendActivityData,
|
data: SendActivityData,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
) -> LemmyResult<()> {
|
) -> LemmyResult<()> {
|
||||||
let fed_task = match data {
|
let context = context.reset_request_count();
|
||||||
|
let fed_task = async {
|
||||||
|
match data {
|
||||||
SendActivityData::CreatePost(post) => {
|
SendActivityData::CreatePost(post) => {
|
||||||
let creator_id = post.creator_id;
|
let creator_id = post.creator_id;
|
||||||
CreateOrUpdatePage::send(
|
CreateOrUpdatePage::send(post, creator_id, CreateOrUpdateType::Create, context).await
|
||||||
post,
|
}
|
||||||
creator_id,
|
SendActivityData::CreateComment(comment) => {
|
||||||
CreateOrUpdateType::Create,
|
let creator_id = comment.creator_id;
|
||||||
context.reset_request_count(),
|
CreateOrUpdateNote::send(comment, creator_id, CreateOrUpdateType::Create, context).await
|
||||||
)
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if *SYNCHRONOUS_FEDERATION {
|
if *SYNCHRONOUS_FEDERATION {
|
||||||
|
|
|
@ -16,7 +16,7 @@ use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView};
|
||||||
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorExt2, LemmyErrorType};
|
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorExt2, LemmyErrorType};
|
||||||
|
|
||||||
#[tracing::instrument(skip(context))]
|
#[tracing::instrument(skip(context))]
|
||||||
pub async fn read_community(
|
pub async fn get_community(
|
||||||
data: Query<GetCommunity>,
|
data: Query<GetCommunity>,
|
||||||
context: Data<LemmyContext>,
|
context: Data<LemmyContext>,
|
||||||
) -> Result<Json<GetCommunityResponse>, LemmyError> {
|
) -> Result<Json<GetCommunityResponse>, LemmyError> {
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 713ceed9c7ef84deaa222e68361e670e0763cd83
|
Subproject commit 1c42c579460871de7b4ea18e58dc25543b80d289
|
|
@ -1,19 +1,12 @@
|
||||||
use actix_web::{guard, web, Error, HttpResponse, Result};
|
use actix_web::{guard, web, Error, HttpResponse, Result};
|
||||||
use lemmy_api::Perform;
|
use lemmy_api::{
|
||||||
|
comment::{distinguish::distinguish_comment, save::save_comment},
|
||||||
|
comment_report::{list::list_comment_reports, resolve::resolve_comment_report},
|
||||||
|
local_user::notifications::mark_reply_read::mark_reply_as_read,
|
||||||
|
Perform,
|
||||||
|
};
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
comment::{
|
comment::{CreateCommentLike, CreateCommentReport, DeleteComment, EditComment, RemoveComment},
|
||||||
CreateComment,
|
|
||||||
CreateCommentLike,
|
|
||||||
CreateCommentReport,
|
|
||||||
DeleteComment,
|
|
||||||
DistinguishComment,
|
|
||||||
EditComment,
|
|
||||||
GetComment,
|
|
||||||
ListCommentReports,
|
|
||||||
RemoveComment,
|
|
||||||
ResolveCommentReport,
|
|
||||||
SaveComment,
|
|
||||||
},
|
|
||||||
community::{
|
community::{
|
||||||
AddModToCommunity,
|
AddModToCommunity,
|
||||||
BanFromCommunity,
|
BanFromCommunity,
|
||||||
|
@ -23,7 +16,6 @@ use lemmy_api_common::{
|
||||||
EditCommunity,
|
EditCommunity,
|
||||||
FollowCommunity,
|
FollowCommunity,
|
||||||
HideCommunity,
|
HideCommunity,
|
||||||
ListCommunities,
|
|
||||||
RemoveCommunity,
|
RemoveCommunity,
|
||||||
TransferCommunity,
|
TransferCommunity,
|
||||||
},
|
},
|
||||||
|
@ -43,7 +35,6 @@ use lemmy_api_common::{
|
||||||
GetUnreadCount,
|
GetUnreadCount,
|
||||||
Login,
|
Login,
|
||||||
MarkAllAsRead,
|
MarkAllAsRead,
|
||||||
MarkCommentReplyAsRead,
|
|
||||||
MarkPersonMentionAsRead,
|
MarkPersonMentionAsRead,
|
||||||
PasswordChangeAfterReset,
|
PasswordChangeAfterReset,
|
||||||
PasswordReset,
|
PasswordReset,
|
||||||
|
@ -57,7 +48,6 @@ use lemmy_api_common::{
|
||||||
DeletePost,
|
DeletePost,
|
||||||
EditPost,
|
EditPost,
|
||||||
FeaturePost,
|
FeaturePost,
|
||||||
GetPost,
|
|
||||||
GetSiteMetadata,
|
GetSiteMetadata,
|
||||||
ListPostReports,
|
ListPostReports,
|
||||||
LockPost,
|
LockPost,
|
||||||
|
@ -71,18 +61,14 @@ use lemmy_api_common::{
|
||||||
CreatePrivateMessageReport,
|
CreatePrivateMessageReport,
|
||||||
DeletePrivateMessage,
|
DeletePrivateMessage,
|
||||||
EditPrivateMessage,
|
EditPrivateMessage,
|
||||||
GetPrivateMessages,
|
|
||||||
ListPrivateMessageReports,
|
ListPrivateMessageReports,
|
||||||
MarkPrivateMessageAsRead,
|
MarkPrivateMessageAsRead,
|
||||||
ResolvePrivateMessageReport,
|
ResolvePrivateMessageReport,
|
||||||
},
|
},
|
||||||
site::{
|
site::{
|
||||||
ApproveRegistrationApplication,
|
ApproveRegistrationApplication,
|
||||||
CreateSite,
|
|
||||||
EditSite,
|
|
||||||
GetFederatedInstances,
|
GetFederatedInstances,
|
||||||
GetModlog,
|
GetModlog,
|
||||||
GetSite,
|
|
||||||
GetUnreadRegistrationApplicationCount,
|
GetUnreadRegistrationApplicationCount,
|
||||||
LeaveAdmin,
|
LeaveAdmin,
|
||||||
ListRegistrationApplications,
|
ListRegistrationApplications,
|
||||||
|
@ -92,12 +78,19 @@ use lemmy_api_common::{
|
||||||
PurgePost,
|
PurgePost,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use lemmy_api_crud::{post::create::create_post, PerformCrud};
|
use lemmy_api_crud::{
|
||||||
|
comment::{create::create_comment, read::get_comment},
|
||||||
|
community::list::list_communities,
|
||||||
|
post::{create::create_post, read::get_post},
|
||||||
|
private_message::read::get_private_message,
|
||||||
|
site::{create::create_site, read::get_site, update::update_site},
|
||||||
|
PerformCrud,
|
||||||
|
};
|
||||||
use lemmy_apub::{
|
use lemmy_apub::{
|
||||||
api::{
|
api::{
|
||||||
list_comments::list_comments,
|
list_comments::list_comments,
|
||||||
list_posts::list_posts,
|
list_posts::list_posts,
|
||||||
read_community::read_community,
|
read_community::get_community,
|
||||||
read_person::read_person,
|
read_person::read_person,
|
||||||
resolve_object::resolve_object,
|
resolve_object::resolve_object,
|
||||||
search::search,
|
search::search,
|
||||||
|
@ -114,10 +107,10 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) {
|
||||||
.service(
|
.service(
|
||||||
web::scope("/site")
|
web::scope("/site")
|
||||||
.wrap(rate_limit.message())
|
.wrap(rate_limit.message())
|
||||||
.route("", web::get().to(route_get_crud::<GetSite>))
|
.route("", web::get().to(get_site))
|
||||||
// Admin Actions
|
// Admin Actions
|
||||||
.route("", web::post().to(route_post_crud::<CreateSite>))
|
.route("", web::post().to(create_site))
|
||||||
.route("", web::put().to(route_post_crud::<EditSite>)),
|
.route("", web::put().to(update_site)),
|
||||||
)
|
)
|
||||||
.service(
|
.service(
|
||||||
web::resource("/modlog")
|
web::resource("/modlog")
|
||||||
|
@ -144,10 +137,10 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) {
|
||||||
.service(
|
.service(
|
||||||
web::scope("/community")
|
web::scope("/community")
|
||||||
.wrap(rate_limit.message())
|
.wrap(rate_limit.message())
|
||||||
.route("", web::get().to(read_community))
|
.route("", web::get().to(get_community))
|
||||||
.route("", web::put().to(route_post_crud::<EditCommunity>))
|
.route("", web::put().to(route_post_crud::<EditCommunity>))
|
||||||
.route("/hide", web::put().to(route_post::<HideCommunity>))
|
.route("/hide", web::put().to(route_post::<HideCommunity>))
|
||||||
.route("/list", web::get().to(route_get_crud::<ListCommunities>))
|
.route("/list", web::get().to(list_communities))
|
||||||
.route("/follow", web::post().to(route_post::<FollowCommunity>))
|
.route("/follow", web::post().to(route_post::<FollowCommunity>))
|
||||||
.route("/block", web::post().to(route_post::<BlockCommunity>))
|
.route("/block", web::post().to(route_post::<BlockCommunity>))
|
||||||
.route(
|
.route(
|
||||||
|
@ -179,7 +172,7 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) {
|
||||||
.service(
|
.service(
|
||||||
web::scope("/post")
|
web::scope("/post")
|
||||||
.wrap(rate_limit.message())
|
.wrap(rate_limit.message())
|
||||||
.route("", web::get().to(route_get_crud::<GetPost>))
|
.route("", web::get().to(get_post))
|
||||||
.route("", web::put().to(route_post_crud::<EditPost>))
|
.route("", web::put().to(route_post_crud::<EditPost>))
|
||||||
.route("/delete", web::post().to(route_post_crud::<DeletePost>))
|
.route("/delete", web::post().to(route_post_crud::<DeletePost>))
|
||||||
.route("/remove", web::post().to(route_post_crud::<RemovePost>))
|
.route("/remove", web::post().to(route_post_crud::<RemovePost>))
|
||||||
|
@ -209,41 +202,29 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) {
|
||||||
web::resource("/comment")
|
web::resource("/comment")
|
||||||
.guard(guard::Post())
|
.guard(guard::Post())
|
||||||
.wrap(rate_limit.comment())
|
.wrap(rate_limit.comment())
|
||||||
.route(web::post().to(route_post_crud::<CreateComment>)),
|
.route(web::post().to(create_comment)),
|
||||||
)
|
)
|
||||||
.service(
|
.service(
|
||||||
web::scope("/comment")
|
web::scope("/comment")
|
||||||
.wrap(rate_limit.message())
|
.wrap(rate_limit.message())
|
||||||
.route("", web::get().to(route_get_crud::<GetComment>))
|
.route("", web::get().to(get_comment))
|
||||||
.route("", web::put().to(route_post_crud::<EditComment>))
|
.route("", web::put().to(route_post_crud::<EditComment>))
|
||||||
.route("/delete", web::post().to(route_post_crud::<DeleteComment>))
|
.route("/delete", web::post().to(route_post_crud::<DeleteComment>))
|
||||||
.route("/remove", web::post().to(route_post_crud::<RemoveComment>))
|
.route("/remove", web::post().to(route_post_crud::<RemoveComment>))
|
||||||
.route(
|
.route("/mark_as_read", web::post().to(mark_reply_as_read))
|
||||||
"/mark_as_read",
|
.route("/distinguish", web::post().to(distinguish_comment))
|
||||||
web::post().to(route_post::<MarkCommentReplyAsRead>),
|
|
||||||
)
|
|
||||||
.route(
|
|
||||||
"/distinguish",
|
|
||||||
web::post().to(route_post::<DistinguishComment>),
|
|
||||||
)
|
|
||||||
.route("/like", web::post().to(route_post::<CreateCommentLike>))
|
.route("/like", web::post().to(route_post::<CreateCommentLike>))
|
||||||
.route("/save", web::put().to(route_post::<SaveComment>))
|
.route("/save", web::put().to(save_comment))
|
||||||
.route("/list", web::get().to(list_comments))
|
.route("/list", web::get().to(list_comments))
|
||||||
.route("/report", web::post().to(route_post::<CreateCommentReport>))
|
.route("/report", web::post().to(route_post::<CreateCommentReport>))
|
||||||
.route(
|
.route("/report/resolve", web::put().to(resolve_comment_report))
|
||||||
"/report/resolve",
|
.route("/report/list", web::get().to(list_comment_reports)),
|
||||||
web::put().to(route_post::<ResolveCommentReport>),
|
|
||||||
)
|
|
||||||
.route(
|
|
||||||
"/report/list",
|
|
||||||
web::get().to(route_get::<ListCommentReports>),
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
// Private Message
|
// Private Message
|
||||||
.service(
|
.service(
|
||||||
web::scope("/private_message")
|
web::scope("/private_message")
|
||||||
.wrap(rate_limit.message())
|
.wrap(rate_limit.message())
|
||||||
.route("/list", web::get().to(route_get_crud::<GetPrivateMessages>))
|
.route("/list", web::get().to(get_private_message))
|
||||||
.route("", web::post().to(route_post_crud::<CreatePrivateMessage>))
|
.route("", web::post().to(route_post_crud::<CreatePrivateMessage>))
|
||||||
.route("", web::put().to(route_post_crud::<EditPrivateMessage>))
|
.route("", web::put().to(route_post_crud::<EditPrivateMessage>))
|
||||||
.route(
|
.route(
|
||||||
|
@ -447,22 +428,6 @@ where
|
||||||
Ok(HttpResponse::Ok().json(&res))
|
Ok(HttpResponse::Ok().json(&res))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn route_get_crud<'a, Data>(
|
|
||||||
data: web::Query<Data>,
|
|
||||||
context: web::Data<LemmyContext>,
|
|
||||||
apub_data: activitypub_federation::config::Data<LemmyContext>,
|
|
||||||
) -> Result<HttpResponse, Error>
|
|
||||||
where
|
|
||||||
Data: PerformCrud
|
|
||||||
+ SendActivity<Response = <Data as PerformCrud>::Response>
|
|
||||||
+ Clone
|
|
||||||
+ Deserialize<'a>
|
|
||||||
+ Send
|
|
||||||
+ 'static,
|
|
||||||
{
|
|
||||||
perform_crud::<Data>(data.0, context, apub_data).await
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn route_post_crud<'a, Data>(
|
async fn route_post_crud<'a, Data>(
|
||||||
data: web::Json<Data>,
|
data: web::Json<Data>,
|
||||||
context: web::Data<LemmyContext>,
|
context: web::Data<LemmyContext>,
|
||||||
|
|
Loading…
Reference in a new issue