* Get rid of remaining Perform/SendActivity traits (fixes #3670) * fix api tests * ci
This commit is contained in:
parent
a1a9c3e4c0
commit
366d9d1e2e
49 changed files with 1373 additions and 1981 deletions
|
@ -1,5 +1,4 @@
|
|||
use crate::Perform;
|
||||
use actix_web::web::Data;
|
||||
use actix_web::web::{Data, Json};
|
||||
use anyhow::Context;
|
||||
use lemmy_api_common::{
|
||||
community::{GetCommunityResponse, TransferCommunity},
|
||||
|
@ -21,17 +20,12 @@ use lemmy_utils::{
|
|||
|
||||
// TODO: we dont do anything for federation here, it should be updated the next time the community
|
||||
// gets fetched. i hope we can get rid of the community creator role soon.
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl Perform for TransferCommunity {
|
||||
type Response = GetCommunityResponse;
|
||||
|
||||
#[tracing::instrument(skip(context))]
|
||||
async fn perform(
|
||||
&self,
|
||||
context: &Data<LemmyContext>,
|
||||
) -> Result<GetCommunityResponse, LemmyError> {
|
||||
let data: &TransferCommunity = self;
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
pub async fn transfer_community(
|
||||
data: Json<TransferCommunity>,
|
||||
context: Data<LemmyContext>,
|
||||
) -> Result<Json<GetCommunityResponse>, LemmyError> {
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||
|
||||
// Fetch the community mods
|
||||
let community_id = data.community_id;
|
||||
|
@ -39,8 +33,7 @@ impl Perform for TransferCommunity {
|
|||
CommunityModeratorView::for_community(&mut context.pool(), community_id).await?;
|
||||
|
||||
// Make sure transferrer is either the top community mod, or an admin
|
||||
if !(is_top_mod(&local_user_view, &community_mods).is_ok()
|
||||
|| is_admin(&local_user_view).is_ok())
|
||||
if !(is_top_mod(&local_user_view, &community_mods).is_ok() || is_admin(&local_user_view).is_ok())
|
||||
{
|
||||
Err(LemmyErrorType::NotAnAdmin)?
|
||||
}
|
||||
|
@ -94,11 +87,10 @@ impl Perform for TransferCommunity {
|
|||
.with_lemmy_type(LemmyErrorType::CouldntFindCommunity)?;
|
||||
|
||||
// Return the jwt
|
||||
Ok(GetCommunityResponse {
|
||||
Ok(Json(GetCommunityResponse {
|
||||
community_view,
|
||||
site: None,
|
||||
moderators,
|
||||
discussion_languages: vec![],
|
||||
})
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
use actix_web::web::Data;
|
||||
use base64::{engine::general_purpose::STANDARD_NO_PAD as base64, Engine};
|
||||
use captcha::Captcha;
|
||||
use lemmy_api_common::{context::LemmyContext, utils::local_site_to_slur_regex};
|
||||
use lemmy_api_common::utils::local_site_to_slur_regex;
|
||||
use lemmy_db_schema::source::local_site::LocalSite;
|
||||
use lemmy_utils::{
|
||||
error::{LemmyError, LemmyErrorExt, LemmyErrorType},
|
||||
|
@ -20,13 +19,6 @@ pub mod private_message_report;
|
|||
pub mod site;
|
||||
pub mod sitemap;
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
pub trait Perform {
|
||||
type Response: serde::ser::Serialize + Send + Clone + Sync;
|
||||
|
||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError>;
|
||||
}
|
||||
|
||||
/// Converts the captcha to a base64 encoded wav audio file
|
||||
pub(crate) fn captcha_as_wav_base64(captcha: &Captcha) -> Result<String, LemmyError> {
|
||||
let letters = captcha.as_wav();
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use crate::Perform;
|
||||
use actix_web::web::Data;
|
||||
use actix_web::web::{Data, Json};
|
||||
use lemmy_api_common::{
|
||||
context::LemmyContext,
|
||||
person::{AddAdmin, AddAdminResponse},
|
||||
|
@ -15,14 +14,12 @@ use lemmy_db_schema::{
|
|||
use lemmy_db_views_actor::structs::PersonView;
|
||||
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl Perform for AddAdmin {
|
||||
type Response = AddAdminResponse;
|
||||
|
||||
#[tracing::instrument(skip(context))]
|
||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<AddAdminResponse, LemmyError> {
|
||||
let data: &AddAdmin = self;
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
pub async fn add_admin(
|
||||
data: Json<AddAdmin>,
|
||||
context: Data<LemmyContext>,
|
||||
) -> Result<Json<AddAdminResponse>, LemmyError> {
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||
|
||||
// Make sure user is an admin
|
||||
is_admin(&local_user_view)?;
|
||||
|
@ -49,6 +46,5 @@ impl Perform for AddAdmin {
|
|||
|
||||
let admins = PersonView::admins(&mut context.pool()).await?;
|
||||
|
||||
Ok(AddAdminResponse { admins })
|
||||
}
|
||||
Ok(Json(AddAdminResponse { admins }))
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use crate::Perform;
|
||||
use actix_web::web::Data;
|
||||
use actix_web::web::{Data, Json};
|
||||
use lemmy_api_common::{
|
||||
context::LemmyContext,
|
||||
person::{BlockPerson, BlockPersonResponse},
|
||||
|
@ -13,14 +12,12 @@ use lemmy_db_views::structs::LocalUserView;
|
|||
use lemmy_db_views_actor::structs::PersonView;
|
||||
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl Perform for BlockPerson {
|
||||
type Response = BlockPersonResponse;
|
||||
|
||||
#[tracing::instrument(skip(context))]
|
||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<BlockPersonResponse, LemmyError> {
|
||||
let data: &BlockPerson = self;
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
pub async fn block_person(
|
||||
data: Json<BlockPerson>,
|
||||
context: Data<LemmyContext>,
|
||||
) -> Result<Json<BlockPersonResponse>, LemmyError> {
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||
|
||||
let target_id = data.person_id;
|
||||
let person_id = local_user_view.person.id;
|
||||
|
@ -51,9 +48,8 @@ impl Perform for BlockPerson {
|
|||
}
|
||||
|
||||
let person_view = PersonView::read(&mut context.pool(), target_id).await?;
|
||||
Ok(BlockPersonResponse {
|
||||
Ok(Json(BlockPersonResponse {
|
||||
person_view,
|
||||
blocked: data.block,
|
||||
})
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use crate::Perform;
|
||||
use actix_web::web::Data;
|
||||
use actix_web::web::{Data, Json};
|
||||
use bcrypt::verify;
|
||||
use lemmy_api_common::{
|
||||
context::LemmyContext,
|
||||
|
@ -12,14 +11,12 @@ use lemmy_utils::{
|
|||
error::{LemmyError, LemmyErrorType},
|
||||
};
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl Perform for ChangePassword {
|
||||
type Response = LoginResponse;
|
||||
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<LoginResponse, LemmyError> {
|
||||
let data: &ChangePassword = self;
|
||||
let local_user_view = local_user_view_from_jwt(data.auth.as_ref(), context).await?;
|
||||
#[tracing::instrument(skip(context))]
|
||||
pub async fn change_password(
|
||||
data: Json<ChangePassword>,
|
||||
context: Data<LemmyContext>,
|
||||
) -> Result<Json<LoginResponse>, LemmyError> {
|
||||
let local_user_view = local_user_view_from_jwt(data.auth.as_ref(), &context).await?;
|
||||
|
||||
password_length_check(&data.new_password)?;
|
||||
|
||||
|
@ -44,7 +41,7 @@ impl Perform for ChangePassword {
|
|||
LocalUser::update_password(&mut context.pool(), local_user_id, &new_password).await?;
|
||||
|
||||
// Return the jwt
|
||||
Ok(LoginResponse {
|
||||
Ok(Json(LoginResponse {
|
||||
jwt: Some(
|
||||
Claims::jwt(
|
||||
updated_local_user.id.0,
|
||||
|
@ -55,6 +52,5 @@ impl Perform for ChangePassword {
|
|||
),
|
||||
verify_email_sent: false,
|
||||
registration_created: false,
|
||||
})
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use crate::Perform;
|
||||
use actix_web::web::Data;
|
||||
use actix_web::web::{Data, Json};
|
||||
use lemmy_api_common::{
|
||||
context::LemmyContext,
|
||||
person::{LoginResponse, PasswordChangeAfterReset},
|
||||
|
@ -11,14 +10,11 @@ use lemmy_db_schema::source::{
|
|||
};
|
||||
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl Perform for PasswordChangeAfterReset {
|
||||
type Response = LoginResponse;
|
||||
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<LoginResponse, LemmyError> {
|
||||
let data: &PasswordChangeAfterReset = self;
|
||||
|
||||
#[tracing::instrument(skip(context))]
|
||||
pub async fn change_password_after_reset(
|
||||
data: Json<PasswordChangeAfterReset>,
|
||||
context: Data<LemmyContext>,
|
||||
) -> Result<Json<LoginResponse>, LemmyError> {
|
||||
// Fetch the user_id from the token
|
||||
let token = data.token.clone();
|
||||
let local_user_id = PasswordResetRequest::read_from_token(&mut context.pool(), &token)
|
||||
|
@ -38,10 +34,9 @@ impl Perform for PasswordChangeAfterReset {
|
|||
.await
|
||||
.with_lemmy_type(LemmyErrorType::CouldntUpdateUser)?;
|
||||
|
||||
Ok(LoginResponse {
|
||||
Ok(Json(LoginResponse {
|
||||
jwt: None,
|
||||
verify_email_sent: false,
|
||||
registration_created: false,
|
||||
})
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use crate::{captcha_as_wav_base64, Perform};
|
||||
use actix_web::web::Data;
|
||||
use crate::captcha_as_wav_base64;
|
||||
use actix_web::web::{Data, Json};
|
||||
use captcha::{gen, Difficulty};
|
||||
use lemmy_api_common::{
|
||||
context::LemmyContext,
|
||||
person::{CaptchaResponse, GetCaptcha, GetCaptchaResponse},
|
||||
person::{CaptchaResponse, GetCaptchaResponse},
|
||||
};
|
||||
use lemmy_db_schema::source::{
|
||||
captcha_answer::{CaptchaAnswer, CaptchaAnswerForm},
|
||||
|
@ -11,16 +11,14 @@ use lemmy_db_schema::source::{
|
|||
};
|
||||
use lemmy_utils::error::LemmyError;
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl Perform for GetCaptcha {
|
||||
type Response = GetCaptchaResponse;
|
||||
|
||||
#[tracing::instrument(skip(context))]
|
||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
|
||||
pub async fn get_captcha(
|
||||
context: Data<LemmyContext>,
|
||||
) -> Result<Json<GetCaptchaResponse>, LemmyError> {
|
||||
let local_site = LocalSite::read(&mut context.pool()).await?;
|
||||
|
||||
if !local_site.captcha_enabled {
|
||||
return Ok(GetCaptchaResponse { ok: None });
|
||||
return Ok(Json(GetCaptchaResponse { ok: None }));
|
||||
}
|
||||
|
||||
let captcha = gen(match local_site.captcha_difficulty.as_str() {
|
||||
|
@ -39,12 +37,11 @@ impl Perform for GetCaptcha {
|
|||
// Stores the captcha item in the db
|
||||
let captcha = CaptchaAnswer::insert(&mut context.pool(), &captcha_form).await?;
|
||||
|
||||
Ok(GetCaptchaResponse {
|
||||
Ok(Json(GetCaptchaResponse {
|
||||
ok: Some(CaptchaResponse {
|
||||
png,
|
||||
wav,
|
||||
uuid: captcha.uuid.to_string(),
|
||||
}),
|
||||
})
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use crate::Perform;
|
||||
use actix_web::web::Data;
|
||||
use actix_web::web::{Data, Json, Query};
|
||||
use lemmy_api_common::{
|
||||
context::LemmyContext,
|
||||
person::{BannedPersonsResponse, GetBannedPersons},
|
||||
|
@ -8,19 +7,16 @@ use lemmy_api_common::{
|
|||
use lemmy_db_views_actor::structs::PersonView;
|
||||
use lemmy_utils::error::LemmyError;
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl Perform for GetBannedPersons {
|
||||
type Response = BannedPersonsResponse;
|
||||
|
||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
|
||||
let data: &GetBannedPersons = self;
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
pub async fn list_banned_users(
|
||||
data: Query<GetBannedPersons>,
|
||||
context: Data<LemmyContext>,
|
||||
) -> Result<Json<BannedPersonsResponse>, LemmyError> {
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||
|
||||
// Make sure user is an admin
|
||||
is_admin(&local_user_view)?;
|
||||
|
||||
let banned = PersonView::banned(&mut context.pool()).await?;
|
||||
|
||||
Ok(Self::Response { banned })
|
||||
}
|
||||
Ok(Json(BannedPersonsResponse { banned }))
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use crate::Perform;
|
||||
use actix_web::web::Data;
|
||||
use actix_web::web::{Data, Json};
|
||||
use bcrypt::verify;
|
||||
use lemmy_api_common::{
|
||||
context::LemmyContext,
|
||||
|
@ -13,14 +12,11 @@ use lemmy_utils::{
|
|||
utils::validation::check_totp_2fa_valid,
|
||||
};
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl Perform for Login {
|
||||
type Response = LoginResponse;
|
||||
|
||||
#[tracing::instrument(skip(context))]
|
||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<LoginResponse, LemmyError> {
|
||||
let data: &Login = self;
|
||||
|
||||
pub async fn login(
|
||||
data: Json<Login>,
|
||||
context: Data<LemmyContext>,
|
||||
) -> Result<Json<LoginResponse>, LemmyError> {
|
||||
let site_view = SiteView::read_local(&mut context.pool()).await?;
|
||||
|
||||
// Fetch that username / email
|
||||
|
@ -66,7 +62,7 @@ impl Perform for Login {
|
|||
)?;
|
||||
|
||||
// Return the jwt
|
||||
Ok(LoginResponse {
|
||||
Ok(Json(LoginResponse {
|
||||
jwt: Some(
|
||||
Claims::jwt(
|
||||
local_user_view.local_user.id.0,
|
||||
|
@ -77,6 +73,5 @@ impl Perform for Login {
|
|||
),
|
||||
verify_email_sent: false,
|
||||
registration_created: false,
|
||||
})
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use crate::Perform;
|
||||
use actix_web::web::Data;
|
||||
use actix_web::web::{Data, Json, Query};
|
||||
use lemmy_api_common::{
|
||||
context::LemmyContext,
|
||||
person::{GetPersonMentions, GetPersonMentionsResponse},
|
||||
|
@ -8,17 +7,12 @@ use lemmy_api_common::{
|
|||
use lemmy_db_views_actor::person_mention_view::PersonMentionQuery;
|
||||
use lemmy_utils::error::LemmyError;
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl Perform for GetPersonMentions {
|
||||
type Response = GetPersonMentionsResponse;
|
||||
|
||||
#[tracing::instrument(skip(context))]
|
||||
async fn perform(
|
||||
&self,
|
||||
context: &Data<LemmyContext>,
|
||||
) -> Result<GetPersonMentionsResponse, LemmyError> {
|
||||
let data: &GetPersonMentions = self;
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
pub async fn list_mentions(
|
||||
data: Query<GetPersonMentions>,
|
||||
context: Data<LemmyContext>,
|
||||
) -> Result<Json<GetPersonMentionsResponse>, LemmyError> {
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||
|
||||
let sort = data.sort;
|
||||
let page = data.page;
|
||||
|
@ -39,6 +33,5 @@ impl Perform for GetPersonMentions {
|
|||
.list(&mut context.pool())
|
||||
.await?;
|
||||
|
||||
Ok(GetPersonMentionsResponse { mentions })
|
||||
}
|
||||
Ok(Json(GetPersonMentionsResponse { mentions }))
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use crate::Perform;
|
||||
use actix_web::web::Data;
|
||||
use actix_web::web::{Data, Json, Query};
|
||||
use lemmy_api_common::{
|
||||
context::LemmyContext,
|
||||
person::{GetReplies, GetRepliesResponse},
|
||||
|
@ -8,14 +7,12 @@ use lemmy_api_common::{
|
|||
use lemmy_db_views_actor::comment_reply_view::CommentReplyQuery;
|
||||
use lemmy_utils::error::LemmyError;
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl Perform for GetReplies {
|
||||
type Response = GetRepliesResponse;
|
||||
|
||||
#[tracing::instrument(skip(context))]
|
||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<GetRepliesResponse, LemmyError> {
|
||||
let data: &GetReplies = self;
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
pub async fn list_replies(
|
||||
data: Query<GetReplies>,
|
||||
context: Data<LemmyContext>,
|
||||
) -> Result<Json<GetRepliesResponse>, LemmyError> {
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||
|
||||
let sort = data.sort;
|
||||
let page = data.page;
|
||||
|
@ -36,6 +33,5 @@ impl Perform for GetReplies {
|
|||
.list(&mut context.pool())
|
||||
.await?;
|
||||
|
||||
Ok(GetRepliesResponse { replies })
|
||||
}
|
||||
Ok(Json(GetRepliesResponse { replies }))
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use crate::Perform;
|
||||
use actix_web::web::Data;
|
||||
use actix_web::web::{Data, Json};
|
||||
use lemmy_api_common::{
|
||||
context::LemmyContext,
|
||||
person::{GetRepliesResponse, MarkAllAsRead},
|
||||
|
@ -12,14 +11,12 @@ use lemmy_db_schema::source::{
|
|||
};
|
||||
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl Perform for MarkAllAsRead {
|
||||
type Response = GetRepliesResponse;
|
||||
|
||||
#[tracing::instrument(skip(context))]
|
||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<GetRepliesResponse, LemmyError> {
|
||||
let data: &MarkAllAsRead = self;
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
pub async fn mark_all_notifications_read(
|
||||
data: Json<MarkAllAsRead>,
|
||||
context: Data<LemmyContext>,
|
||||
) -> Result<Json<GetRepliesResponse>, LemmyError> {
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||
let person_id = local_user_view.person.id;
|
||||
|
||||
// Mark all comment_replies as read
|
||||
|
@ -37,6 +34,5 @@ impl Perform for MarkAllAsRead {
|
|||
.await
|
||||
.with_lemmy_type(LemmyErrorType::CouldntUpdatePrivateMessage)?;
|
||||
|
||||
Ok(GetRepliesResponse { replies: vec![] })
|
||||
}
|
||||
Ok(Json(GetRepliesResponse { replies: vec![] }))
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use crate::Perform;
|
||||
use actix_web::web::Data;
|
||||
use actix_web::web::{Data, Json};
|
||||
use lemmy_api_common::{
|
||||
context::LemmyContext,
|
||||
person::{MarkPersonMentionAsRead, PersonMentionResponse},
|
||||
|
@ -12,17 +11,12 @@ use lemmy_db_schema::{
|
|||
use lemmy_db_views_actor::structs::PersonMentionView;
|
||||
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl Perform for MarkPersonMentionAsRead {
|
||||
type Response = PersonMentionResponse;
|
||||
|
||||
#[tracing::instrument(skip(context))]
|
||||
async fn perform(
|
||||
&self,
|
||||
context: &Data<LemmyContext>,
|
||||
) -> Result<PersonMentionResponse, LemmyError> {
|
||||
let data: &MarkPersonMentionAsRead = self;
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
pub async fn mark_person_mention_as_read(
|
||||
data: Json<MarkPersonMentionAsRead>,
|
||||
context: Data<LemmyContext>,
|
||||
) -> Result<Json<PersonMentionResponse>, LemmyError> {
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||
|
||||
let person_mention_id = data.person_mention_id;
|
||||
let read_person_mention = PersonMention::read(&mut context.pool(), person_mention_id).await?;
|
||||
|
@ -46,8 +40,7 @@ impl Perform for MarkPersonMentionAsRead {
|
|||
let person_mention_view =
|
||||
PersonMentionView::read(&mut context.pool(), person_mention_id, Some(person_id)).await?;
|
||||
|
||||
Ok(PersonMentionResponse {
|
||||
Ok(Json(PersonMentionResponse {
|
||||
person_mention_view,
|
||||
})
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use crate::Perform;
|
||||
use actix_web::web::Data;
|
||||
use actix_web::web::{Data, Json, Query};
|
||||
use lemmy_api_common::{
|
||||
context::LemmyContext,
|
||||
person::{GetUnreadCount, GetUnreadCountResponse},
|
||||
|
@ -9,14 +8,12 @@ use lemmy_db_views::structs::PrivateMessageView;
|
|||
use lemmy_db_views_actor::structs::{CommentReplyView, PersonMentionView};
|
||||
use lemmy_utils::error::LemmyError;
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl Perform for GetUnreadCount {
|
||||
type Response = GetUnreadCountResponse;
|
||||
|
||||
#[tracing::instrument(skip(context))]
|
||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
|
||||
let data = self;
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
pub async fn unread_count(
|
||||
data: Query<GetUnreadCount>,
|
||||
context: Data<LemmyContext>,
|
||||
) -> Result<Json<GetUnreadCountResponse>, LemmyError> {
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||
|
||||
let person_id = local_user_view.person.id;
|
||||
|
||||
|
@ -27,10 +24,9 @@ impl Perform for GetUnreadCount {
|
|||
let private_messages =
|
||||
PrivateMessageView::get_unread_messages(&mut context.pool(), person_id).await?;
|
||||
|
||||
Ok(Self::Response {
|
||||
Ok(Json(GetUnreadCountResponse {
|
||||
replies,
|
||||
mentions,
|
||||
private_messages,
|
||||
})
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use crate::Perform;
|
||||
use actix_web::web::Data;
|
||||
use actix_web::web::{Data, Json};
|
||||
use lemmy_api_common::{
|
||||
context::LemmyContext,
|
||||
person::{GetReportCount, GetReportCountResponse},
|
||||
|
@ -8,17 +7,12 @@ use lemmy_api_common::{
|
|||
use lemmy_db_views::structs::{CommentReportView, PostReportView, PrivateMessageReportView};
|
||||
use lemmy_utils::error::LemmyError;
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl Perform for GetReportCount {
|
||||
type Response = GetReportCountResponse;
|
||||
|
||||
#[tracing::instrument(skip(context))]
|
||||
async fn perform(
|
||||
&self,
|
||||
context: &Data<LemmyContext>,
|
||||
) -> Result<GetReportCountResponse, LemmyError> {
|
||||
let data: &GetReportCount = self;
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
pub async fn report_count(
|
||||
data: Json<GetReportCount>,
|
||||
context: Data<LemmyContext>,
|
||||
) -> Result<Json<GetReportCountResponse>, LemmyError> {
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||
|
||||
let person_id = local_user_view.person.id;
|
||||
let admin = local_user_view.local_user.admin;
|
||||
|
@ -37,11 +31,10 @@ impl Perform for GetReportCount {
|
|||
None
|
||||
};
|
||||
|
||||
Ok(GetReportCountResponse {
|
||||
Ok(Json(GetReportCountResponse {
|
||||
community_id,
|
||||
comment_reports,
|
||||
post_reports,
|
||||
private_message_reports,
|
||||
})
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use crate::Perform;
|
||||
use actix_web::web::Data;
|
||||
use actix_web::web::{Data, Json};
|
||||
use lemmy_api_common::{
|
||||
context::LemmyContext,
|
||||
person::{PasswordReset, PasswordResetResponse},
|
||||
|
@ -9,17 +8,11 @@ use lemmy_db_schema::source::password_reset_request::PasswordResetRequest;
|
|||
use lemmy_db_views::structs::LocalUserView;
|
||||
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl Perform for PasswordReset {
|
||||
type Response = PasswordResetResponse;
|
||||
|
||||
#[tracing::instrument(skip(self, context))]
|
||||
async fn perform(
|
||||
&self,
|
||||
context: &Data<LemmyContext>,
|
||||
) -> Result<PasswordResetResponse, LemmyError> {
|
||||
let data: &PasswordReset = self;
|
||||
|
||||
#[tracing::instrument(skip(context))]
|
||||
pub async fn reset_password(
|
||||
data: Json<PasswordReset>,
|
||||
context: Data<LemmyContext>,
|
||||
) -> Result<Json<PasswordResetResponse>, LemmyError> {
|
||||
// Fetch that email
|
||||
let email = data.email.to_lowercase();
|
||||
let local_user_view = LocalUserView::find_by_email(&mut context.pool(), &email)
|
||||
|
@ -38,6 +31,5 @@ impl Perform for PasswordReset {
|
|||
|
||||
// Email the pure token to the user.
|
||||
send_password_reset_email(&local_user_view, &mut context.pool(), context.settings()).await?;
|
||||
Ok(PasswordResetResponse {})
|
||||
}
|
||||
Ok(Json(PasswordResetResponse {}))
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use crate::Perform;
|
||||
use actix_web::web::Data;
|
||||
use actix_web::web::{Data, Json};
|
||||
use lemmy_api_common::{
|
||||
context::LemmyContext,
|
||||
person::{LoginResponse, SaveUserSettings},
|
||||
|
@ -27,14 +26,12 @@ use lemmy_utils::{
|
|||
},
|
||||
};
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl Perform for SaveUserSettings {
|
||||
type Response = LoginResponse;
|
||||
|
||||
#[tracing::instrument(skip(context))]
|
||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<LoginResponse, LemmyError> {
|
||||
let data: &SaveUserSettings = self;
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
pub async fn save_user_settings(
|
||||
data: Json<SaveUserSettings>,
|
||||
context: Data<LemmyContext>,
|
||||
) -> Result<Json<LoginResponse>, LemmyError> {
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||
let site_view = SiteView::read_local(&mut context.pool()).await?;
|
||||
|
||||
let bio = sanitize_html_opt(&data.bio);
|
||||
|
@ -162,7 +159,7 @@ impl Perform for SaveUserSettings {
|
|||
};
|
||||
|
||||
// Return the jwt
|
||||
Ok(LoginResponse {
|
||||
Ok(Json(LoginResponse {
|
||||
jwt: Some(
|
||||
Claims::jwt(
|
||||
updated_local_user.id.0,
|
||||
|
@ -173,6 +170,5 @@ impl Perform for SaveUserSettings {
|
|||
),
|
||||
verify_email_sent: false,
|
||||
registration_created: false,
|
||||
})
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use crate::Perform;
|
||||
use actix_web::web::Data;
|
||||
use actix_web::web::{Data, Json};
|
||||
use lemmy_api_common::{
|
||||
context::LemmyContext,
|
||||
person::{VerifyEmail, VerifyEmailResponse},
|
||||
|
@ -13,12 +12,11 @@ use lemmy_db_schema::{
|
|||
};
|
||||
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl Perform for VerifyEmail {
|
||||
type Response = VerifyEmailResponse;
|
||||
|
||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
|
||||
let token = self.token.clone();
|
||||
pub async fn verify_email(
|
||||
data: Json<VerifyEmail>,
|
||||
context: Data<LemmyContext>,
|
||||
) -> Result<Json<VerifyEmailResponse>, LemmyError> {
|
||||
let token = data.token.clone();
|
||||
let verification = EmailVerification::read_for_token(&mut context.pool(), &token)
|
||||
.await
|
||||
.with_lemmy_type(LemmyErrorType::TokenNotFound)?;
|
||||
|
@ -36,6 +34,5 @@ impl Perform for VerifyEmail {
|
|||
|
||||
EmailVerification::delete_old_tokens_for_local_user(&mut context.pool(), local_user_id).await?;
|
||||
|
||||
Ok(VerifyEmailResponse {})
|
||||
}
|
||||
Ok(Json(VerifyEmailResponse {}))
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use crate::Perform;
|
||||
use actix_web::web::Data;
|
||||
use actix_web::web::{Data, Json};
|
||||
use lemmy_api_common::{
|
||||
context::LemmyContext,
|
||||
post::{GetSiteMetadata, GetSiteMetadataResponse},
|
||||
|
@ -7,19 +6,12 @@ use lemmy_api_common::{
|
|||
};
|
||||
use lemmy_utils::error::LemmyError;
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl Perform for GetSiteMetadata {
|
||||
type Response = GetSiteMetadataResponse;
|
||||
|
||||
#[tracing::instrument(skip(context))]
|
||||
async fn perform(
|
||||
&self,
|
||||
context: &Data<LemmyContext>,
|
||||
) -> Result<GetSiteMetadataResponse, LemmyError> {
|
||||
let data: &Self = self;
|
||||
|
||||
pub async fn get_link_metadata(
|
||||
data: Json<GetSiteMetadata>,
|
||||
context: Data<LemmyContext>,
|
||||
) -> Result<Json<GetSiteMetadataResponse>, LemmyError> {
|
||||
let metadata = fetch_site_metadata(context.client(), &data.url).await?;
|
||||
|
||||
Ok(GetSiteMetadataResponse { metadata })
|
||||
}
|
||||
Ok(Json(GetSiteMetadataResponse { metadata }))
|
||||
}
|
||||
|
|
|
@ -1,35 +1,32 @@
|
|||
use crate::Perform;
|
||||
use actix_web::web::Data;
|
||||
use actix_web::web::{Data, Json};
|
||||
use lemmy_api_common::{
|
||||
context::LemmyContext,
|
||||
post::{MarkPostAsRead, PostResponse},
|
||||
utils::{local_user_view_from_jwt, mark_post_as_read, mark_post_as_unread},
|
||||
utils,
|
||||
utils::local_user_view_from_jwt,
|
||||
};
|
||||
use lemmy_db_views::structs::PostView;
|
||||
use lemmy_utils::error::LemmyError;
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl Perform for MarkPostAsRead {
|
||||
type Response = PostResponse;
|
||||
|
||||
#[tracing::instrument(skip(context))]
|
||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
|
||||
let data = self;
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
pub async fn mark_post_as_read(
|
||||
data: Json<MarkPostAsRead>,
|
||||
context: Data<LemmyContext>,
|
||||
) -> Result<Json<PostResponse>, LemmyError> {
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||
|
||||
let post_id = data.post_id;
|
||||
let person_id = local_user_view.person.id;
|
||||
|
||||
// Mark the post as read / unread
|
||||
if data.read {
|
||||
mark_post_as_read(person_id, post_id, &mut context.pool()).await?;
|
||||
utils::mark_post_as_read(person_id, post_id, &mut context.pool()).await?;
|
||||
} else {
|
||||
mark_post_as_unread(person_id, post_id, &mut context.pool()).await?;
|
||||
utils::mark_post_as_unread(person_id, post_id, &mut context.pool()).await?;
|
||||
}
|
||||
|
||||
// Fetch it
|
||||
let post_view = PostView::read(&mut context.pool(), post_id, Some(person_id), false).await?;
|
||||
|
||||
Ok(Self::Response { post_view })
|
||||
}
|
||||
Ok(Json(PostResponse { post_view }))
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use crate::Perform;
|
||||
use actix_web::web::Data;
|
||||
use actix_web::web::{Data, Json};
|
||||
use lemmy_api_common::{
|
||||
context::LemmyContext,
|
||||
post::{PostResponse, SavePost},
|
||||
|
@ -12,14 +11,12 @@ use lemmy_db_schema::{
|
|||
use lemmy_db_views::structs::PostView;
|
||||
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl Perform for SavePost {
|
||||
type Response = PostResponse;
|
||||
|
||||
#[tracing::instrument(skip(context))]
|
||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<PostResponse, LemmyError> {
|
||||
let data: &SavePost = self;
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
pub async fn save_post(
|
||||
data: Json<SavePost>,
|
||||
context: Data<LemmyContext>,
|
||||
) -> Result<Json<PostResponse>, LemmyError> {
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||
|
||||
let post_saved_form = PostSavedForm {
|
||||
post_id: data.post_id,
|
||||
|
@ -43,6 +40,5 @@ impl Perform for SavePost {
|
|||
// Mark the post as read
|
||||
mark_post_as_read(person_id, post_id, &mut context.pool()).await?;
|
||||
|
||||
Ok(PostResponse { post_view })
|
||||
}
|
||||
Ok(Json(PostResponse { post_view }))
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use crate::Perform;
|
||||
use actix_web::web::Data;
|
||||
use actix_web::web::{Data, Json, Query};
|
||||
use lemmy_api_common::{
|
||||
context::LemmyContext,
|
||||
post::{ListPostReports, ListPostReportsResponse},
|
||||
|
@ -10,17 +9,12 @@ use lemmy_utils::error::LemmyError;
|
|||
|
||||
/// Lists post reports for a community if an id is supplied
|
||||
/// or returns all post reports for communities a user moderates
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl Perform for ListPostReports {
|
||||
type Response = ListPostReportsResponse;
|
||||
|
||||
#[tracing::instrument(skip(context))]
|
||||
async fn perform(
|
||||
&self,
|
||||
context: &Data<LemmyContext>,
|
||||
) -> Result<ListPostReportsResponse, LemmyError> {
|
||||
let data: &ListPostReports = self;
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
pub async fn list_post_reports(
|
||||
data: Query<ListPostReports>,
|
||||
context: Data<LemmyContext>,
|
||||
) -> Result<Json<ListPostReportsResponse>, LemmyError> {
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||
|
||||
let community_id = data.community_id;
|
||||
let unresolved_only = data.unresolved_only.unwrap_or_default();
|
||||
|
@ -36,6 +30,5 @@ impl Perform for ListPostReports {
|
|||
.list(&mut context.pool(), &local_user_view)
|
||||
.await?;
|
||||
|
||||
Ok(ListPostReportsResponse { post_reports })
|
||||
}
|
||||
Ok(Json(ListPostReportsResponse { post_reports }))
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use crate::Perform;
|
||||
use actix_web::web::Data;
|
||||
use actix_web::web::{Data, Json};
|
||||
use lemmy_api_common::{
|
||||
context::LemmyContext,
|
||||
post::{PostReportResponse, ResolvePostReport},
|
||||
|
@ -10,14 +9,12 @@ use lemmy_db_views::structs::PostReportView;
|
|||
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
||||
|
||||
/// Resolves or unresolves a post report and notifies the moderators of the community
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl Perform for ResolvePostReport {
|
||||
type Response = PostReportResponse;
|
||||
|
||||
#[tracing::instrument(skip(context))]
|
||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<PostReportResponse, LemmyError> {
|
||||
let data: &ResolvePostReport = self;
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
pub async fn resolve_post_report(
|
||||
data: Json<ResolvePostReport>,
|
||||
context: Data<LemmyContext>,
|
||||
) -> Result<Json<PostReportResponse>, LemmyError> {
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||
|
||||
let report_id = data.report_id;
|
||||
let person_id = local_user_view.person.id;
|
||||
|
@ -38,6 +35,5 @@ impl Perform for ResolvePostReport {
|
|||
|
||||
let post_report_view = PostReportView::read(&mut context.pool(), report_id, person_id).await?;
|
||||
|
||||
Ok(PostReportResponse { post_report_view })
|
||||
}
|
||||
Ok(Json(PostReportResponse { post_report_view }))
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use crate::Perform;
|
||||
use actix_web::web::Data;
|
||||
use actix_web::web::{Data, Json};
|
||||
use lemmy_api_common::{
|
||||
context::LemmyContext,
|
||||
private_message::{MarkPrivateMessageAsRead, PrivateMessageResponse},
|
||||
|
@ -12,22 +11,16 @@ use lemmy_db_schema::{
|
|||
use lemmy_db_views::structs::PrivateMessageView;
|
||||
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl Perform for MarkPrivateMessageAsRead {
|
||||
type Response = PrivateMessageResponse;
|
||||
|
||||
#[tracing::instrument(skip(context))]
|
||||
async fn perform(
|
||||
&self,
|
||||
context: &Data<LemmyContext>,
|
||||
) -> Result<PrivateMessageResponse, LemmyError> {
|
||||
let data: &MarkPrivateMessageAsRead = self;
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
pub async fn mark_pm_as_read(
|
||||
data: Json<MarkPrivateMessageAsRead>,
|
||||
context: Data<LemmyContext>,
|
||||
) -> Result<Json<PrivateMessageResponse>, LemmyError> {
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||
|
||||
// Checking permissions
|
||||
let private_message_id = data.private_message_id;
|
||||
let orig_private_message =
|
||||
PrivateMessage::read(&mut context.pool(), private_message_id).await?;
|
||||
let orig_private_message = PrivateMessage::read(&mut context.pool(), private_message_id).await?;
|
||||
if local_user_view.person.id != orig_private_message.recipient_id {
|
||||
Err(LemmyErrorType::CouldntUpdatePrivateMessage)?
|
||||
}
|
||||
|
@ -47,8 +40,7 @@ impl Perform for MarkPrivateMessageAsRead {
|
|||
.with_lemmy_type(LemmyErrorType::CouldntUpdatePrivateMessage)?;
|
||||
|
||||
let view = PrivateMessageView::read(&mut context.pool(), private_message_id).await?;
|
||||
Ok(PrivateMessageResponse {
|
||||
Ok(Json(PrivateMessageResponse {
|
||||
private_message_view: view,
|
||||
})
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
mod mark_read;
|
||||
pub mod mark_read;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::{check_report_reason, Perform};
|
||||
use actix_web::web::Data;
|
||||
use crate::check_report_reason;
|
||||
use actix_web::web::{Data, Json};
|
||||
use lemmy_api_common::{
|
||||
context::LemmyContext,
|
||||
private_message::{CreatePrivateMessageReport, PrivateMessageReportResponse},
|
||||
|
@ -16,20 +16,19 @@ use lemmy_db_schema::{
|
|||
use lemmy_db_views::structs::PrivateMessageReportView;
|
||||
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl Perform for CreatePrivateMessageReport {
|
||||
type Response = PrivateMessageReportResponse;
|
||||
|
||||
#[tracing::instrument(skip(context))]
|
||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
|
||||
let local_user_view = local_user_view_from_jwt(&self.auth, context).await?;
|
||||
pub async fn create_pm_report(
|
||||
data: Json<CreatePrivateMessageReport>,
|
||||
context: Data<LemmyContext>,
|
||||
) -> Result<Json<PrivateMessageReportResponse>, LemmyError> {
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||
let local_site = LocalSite::read(&mut context.pool()).await?;
|
||||
|
||||
let reason = sanitize_html(self.reason.trim());
|
||||
let reason = sanitize_html(data.reason.trim());
|
||||
check_report_reason(&reason, &local_site)?;
|
||||
|
||||
let person_id = local_user_view.person.id;
|
||||
let private_message_id = self.private_message_id;
|
||||
let private_message_id = data.private_message_id;
|
||||
let private_message = PrivateMessage::read(&mut context.pool(), private_message_id).await?;
|
||||
|
||||
let report_form = PrivateMessageReportForm {
|
||||
|
@ -59,8 +58,7 @@ impl Perform for CreatePrivateMessageReport {
|
|||
|
||||
// TODO: consider federating this
|
||||
|
||||
Ok(PrivateMessageReportResponse {
|
||||
Ok(Json(PrivateMessageReportResponse {
|
||||
private_message_report_view,
|
||||
})
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use crate::Perform;
|
||||
use actix_web::web::Data;
|
||||
use actix_web::web::{Data, Json, Query};
|
||||
use lemmy_api_common::{
|
||||
context::LemmyContext,
|
||||
private_message::{ListPrivateMessageReports, ListPrivateMessageReportsResponse},
|
||||
|
@ -8,19 +7,18 @@ use lemmy_api_common::{
|
|||
use lemmy_db_views::private_message_report_view::PrivateMessageReportQuery;
|
||||
use lemmy_utils::error::LemmyError;
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl Perform for ListPrivateMessageReports {
|
||||
type Response = ListPrivateMessageReportsResponse;
|
||||
|
||||
#[tracing::instrument(skip(context))]
|
||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
|
||||
let local_user_view = local_user_view_from_jwt(&self.auth, context).await?;
|
||||
pub async fn list_pm_reports(
|
||||
data: Query<ListPrivateMessageReports>,
|
||||
context: Data<LemmyContext>,
|
||||
) -> Result<Json<ListPrivateMessageReportsResponse>, LemmyError> {
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||
|
||||
is_admin(&local_user_view)?;
|
||||
|
||||
let unresolved_only = self.unresolved_only.unwrap_or_default();
|
||||
let page = self.page;
|
||||
let limit = self.limit;
|
||||
let unresolved_only = data.unresolved_only.unwrap_or_default();
|
||||
let page = data.page;
|
||||
let limit = data.limit;
|
||||
let private_message_reports = PrivateMessageReportQuery {
|
||||
unresolved_only,
|
||||
page,
|
||||
|
@ -29,8 +27,7 @@ impl Perform for ListPrivateMessageReports {
|
|||
.list(&mut context.pool())
|
||||
.await?;
|
||||
|
||||
Ok(ListPrivateMessageReportsResponse {
|
||||
Ok(Json(ListPrivateMessageReportsResponse {
|
||||
private_message_reports,
|
||||
})
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
mod create;
|
||||
mod list;
|
||||
mod resolve;
|
||||
pub mod create;
|
||||
pub mod list;
|
||||
pub mod resolve;
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use crate::Perform;
|
||||
use actix_web::web::Data;
|
||||
use actix_web::web::{Data, Json};
|
||||
use lemmy_api_common::{
|
||||
context::LemmyContext,
|
||||
private_message::{PrivateMessageReportResponse, ResolvePrivateMessageReport},
|
||||
|
@ -9,19 +8,18 @@ use lemmy_db_schema::{source::private_message_report::PrivateMessageReport, trai
|
|||
use lemmy_db_views::structs::PrivateMessageReportView;
|
||||
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl Perform for ResolvePrivateMessageReport {
|
||||
type Response = PrivateMessageReportResponse;
|
||||
|
||||
#[tracing::instrument(skip(context))]
|
||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
|
||||
let local_user_view = local_user_view_from_jwt(&self.auth, context).await?;
|
||||
pub async fn resolve_pm_report(
|
||||
data: Json<ResolvePrivateMessageReport>,
|
||||
context: Data<LemmyContext>,
|
||||
) -> Result<Json<PrivateMessageReportResponse>, LemmyError> {
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||
|
||||
is_admin(&local_user_view)?;
|
||||
|
||||
let report_id = self.report_id;
|
||||
let report_id = data.report_id;
|
||||
let person_id = local_user_view.person.id;
|
||||
if self.resolved {
|
||||
if data.resolved {
|
||||
PrivateMessageReport::resolve(&mut context.pool(), report_id, person_id)
|
||||
.await
|
||||
.with_lemmy_type(LemmyErrorType::CouldntResolveReport)?;
|
||||
|
@ -34,8 +32,7 @@ impl Perform for ResolvePrivateMessageReport {
|
|||
let private_message_report_view =
|
||||
PrivateMessageReportView::read(&mut context.pool(), report_id).await?;
|
||||
|
||||
Ok(PrivateMessageReportResponse {
|
||||
Ok(Json(PrivateMessageReportResponse {
|
||||
private_message_report_view,
|
||||
})
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
|
|
@ -1,25 +1,21 @@
|
|||
use crate::Perform;
|
||||
use actix_web::web::Data;
|
||||
use actix_web::web::{Data, Json};
|
||||
use lemmy_api_common::{
|
||||
context::LemmyContext,
|
||||
site::{GetFederatedInstances, GetFederatedInstancesResponse},
|
||||
site::GetFederatedInstancesResponse,
|
||||
utils::build_federated_instances,
|
||||
};
|
||||
use lemmy_db_views::structs::SiteView;
|
||||
use lemmy_utils::error::LemmyError;
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl Perform for GetFederatedInstances {
|
||||
type Response = GetFederatedInstancesResponse;
|
||||
|
||||
#[tracing::instrument(skip(context))]
|
||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
|
||||
pub async fn get_federated_instances(
|
||||
context: Data<LemmyContext>,
|
||||
) -> Result<Json<GetFederatedInstancesResponse>, LemmyError> {
|
||||
let site_view = SiteView::read_local(&mut context.pool()).await?;
|
||||
let federated_instances =
|
||||
build_federated_instances(&site_view.local_site, &mut context.pool()).await?;
|
||||
|
||||
Ok(Self::Response {
|
||||
Ok(Json(GetFederatedInstancesResponse {
|
||||
federated_instances,
|
||||
})
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use crate::Perform;
|
||||
use actix_web::web::Data;
|
||||
use actix_web::web::{Data, Json};
|
||||
use lemmy_api_common::{
|
||||
context::LemmyContext,
|
||||
site::{GetSiteResponse, LeaveAdmin},
|
||||
|
@ -22,14 +21,12 @@ use lemmy_utils::{
|
|||
version,
|
||||
};
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl Perform for LeaveAdmin {
|
||||
type Response = GetSiteResponse;
|
||||
|
||||
#[tracing::instrument(skip(context))]
|
||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<GetSiteResponse, LemmyError> {
|
||||
let data: &LeaveAdmin = self;
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
pub async fn leave_admin(
|
||||
data: Json<LeaveAdmin>,
|
||||
context: Data<LemmyContext>,
|
||||
) -> Result<Json<GetSiteResponse>, LemmyError> {
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||
|
||||
is_admin(&local_user_view)?;
|
||||
|
||||
|
@ -69,7 +66,7 @@ impl Perform for LeaveAdmin {
|
|||
let custom_emojis =
|
||||
CustomEmojiView::get_all(&mut context.pool(), site_view.local_site.id).await?;
|
||||
|
||||
Ok(GetSiteResponse {
|
||||
Ok(Json(GetSiteResponse {
|
||||
site_view,
|
||||
admins,
|
||||
version: version::VERSION.to_string(),
|
||||
|
@ -78,6 +75,5 @@ impl Perform for LeaveAdmin {
|
|||
discussion_languages,
|
||||
taglines,
|
||||
custom_emojis,
|
||||
})
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
mod federated_instances;
|
||||
mod leave_admin;
|
||||
mod mod_log;
|
||||
mod purge;
|
||||
mod registration_applications;
|
||||
pub mod federated_instances;
|
||||
pub mod leave_admin;
|
||||
pub mod mod_log;
|
||||
pub mod purge;
|
||||
pub mod registration_applications;
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use crate::Perform;
|
||||
use actix_web::web::Data;
|
||||
use actix_web::web::{Data, Json, Query};
|
||||
use lemmy_api_common::{
|
||||
context::LemmyContext,
|
||||
site::{GetModlog, GetModlogResponse},
|
||||
|
@ -31,15 +30,12 @@ use lemmy_db_views_moderator::structs::{
|
|||
use lemmy_utils::error::LemmyError;
|
||||
use ModlogActionType::*;
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl Perform for GetModlog {
|
||||
type Response = GetModlogResponse;
|
||||
|
||||
#[tracing::instrument(skip(context))]
|
||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<GetModlogResponse, LemmyError> {
|
||||
let data: &GetModlog = self;
|
||||
|
||||
let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await;
|
||||
pub async fn get_mod_log(
|
||||
data: Query<GetModlog>,
|
||||
context: Data<LemmyContext>,
|
||||
) -> Result<Json<GetModlogResponse>, LemmyError> {
|
||||
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?;
|
||||
|
||||
check_private_instance(&local_user_view, &local_site)?;
|
||||
|
@ -96,9 +92,7 @@ impl Perform for GetModlog {
|
|||
};
|
||||
|
||||
let banned_from_community = match type_ {
|
||||
All | ModBanFromCommunity => {
|
||||
ModBanFromCommunityView::list(&mut context.pool(), params).await?
|
||||
}
|
||||
All | ModBanFromCommunity => ModBanFromCommunityView::list(&mut context.pool(), params).await?,
|
||||
_ => Default::default(),
|
||||
};
|
||||
|
||||
|
@ -176,7 +170,7 @@ impl Perform for GetModlog {
|
|||
};
|
||||
|
||||
// Return the jwt
|
||||
Ok(GetModlogResponse {
|
||||
Ok(Json(GetModlogResponse {
|
||||
removed_posts,
|
||||
locked_posts,
|
||||
featured_posts,
|
||||
|
@ -192,6 +186,5 @@ impl Perform for GetModlog {
|
|||
admin_purged_posts,
|
||||
admin_purged_comments,
|
||||
hidden_communities,
|
||||
})
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use crate::Perform;
|
||||
use actix_web::web::Data;
|
||||
use actix_web::web::{Data, Json};
|
||||
use lemmy_api_common::{
|
||||
context::LemmyContext,
|
||||
site::{PurgeComment, PurgeItemResponse},
|
||||
|
@ -14,14 +13,12 @@ use lemmy_db_schema::{
|
|||
};
|
||||
use lemmy_utils::error::LemmyError;
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl Perform for PurgeComment {
|
||||
type Response = PurgeItemResponse;
|
||||
|
||||
#[tracing::instrument(skip(context))]
|
||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
|
||||
let data: &Self = self;
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
pub async fn purge_comment(
|
||||
data: Json<PurgeComment>,
|
||||
context: Data<LemmyContext>,
|
||||
) -> Result<Json<PurgeItemResponse>, LemmyError> {
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||
|
||||
// Only let admin purge an item
|
||||
is_admin(&local_user_view)?;
|
||||
|
@ -47,6 +44,5 @@ impl Perform for PurgeComment {
|
|||
|
||||
AdminPurgeComment::create(&mut context.pool(), &form).await?;
|
||||
|
||||
Ok(PurgeItemResponse { success: true })
|
||||
}
|
||||
Ok(Json(PurgeItemResponse { success: true }))
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use crate::Perform;
|
||||
use actix_web::web::Data;
|
||||
use actix_web::web::{Data, Json};
|
||||
use lemmy_api_common::{
|
||||
context::LemmyContext,
|
||||
request::purge_image_from_pictrs,
|
||||
|
@ -15,14 +14,12 @@ use lemmy_db_schema::{
|
|||
};
|
||||
use lemmy_utils::error::LemmyError;
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl Perform for PurgeCommunity {
|
||||
type Response = PurgeItemResponse;
|
||||
|
||||
#[tracing::instrument(skip(context))]
|
||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
|
||||
let data: &Self = self;
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
pub async fn purge_community(
|
||||
data: Json<PurgeCommunity>,
|
||||
context: Data<LemmyContext>,
|
||||
) -> Result<Json<PurgeItemResponse>, LemmyError> {
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||
|
||||
// Only let admin purge an item
|
||||
is_admin(&local_user_view)?;
|
||||
|
@ -33,14 +30,14 @@ impl Perform for PurgeCommunity {
|
|||
let community = Community::read(&mut context.pool(), community_id).await?;
|
||||
|
||||
if let Some(banner) = community.banner {
|
||||
purge_image_from_pictrs(&banner, context).await.ok();
|
||||
purge_image_from_pictrs(&banner, &context).await.ok();
|
||||
}
|
||||
|
||||
if let Some(icon) = community.icon {
|
||||
purge_image_from_pictrs(&icon, context).await.ok();
|
||||
purge_image_from_pictrs(&icon, &context).await.ok();
|
||||
}
|
||||
|
||||
purge_image_posts_for_community(community_id, context).await?;
|
||||
purge_image_posts_for_community(community_id, &context).await?;
|
||||
|
||||
Community::delete(&mut context.pool(), community_id).await?;
|
||||
|
||||
|
@ -53,6 +50,5 @@ impl Perform for PurgeCommunity {
|
|||
|
||||
AdminPurgeCommunity::create(&mut context.pool(), &form).await?;
|
||||
|
||||
Ok(PurgeItemResponse { success: true })
|
||||
}
|
||||
Ok(Json(PurgeItemResponse { success: true }))
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
mod comment;
|
||||
mod community;
|
||||
mod person;
|
||||
mod post;
|
||||
pub mod comment;
|
||||
pub mod community;
|
||||
pub mod person;
|
||||
pub mod post;
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use crate::Perform;
|
||||
use actix_web::web::Data;
|
||||
use actix_web::web::{Data, Json};
|
||||
use lemmy_api_common::{
|
||||
context::LemmyContext,
|
||||
request::purge_image_from_pictrs,
|
||||
|
@ -15,14 +14,12 @@ use lemmy_db_schema::{
|
|||
};
|
||||
use lemmy_utils::error::LemmyError;
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl Perform for PurgePerson {
|
||||
type Response = PurgeItemResponse;
|
||||
|
||||
#[tracing::instrument(skip(context))]
|
||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
|
||||
let data: &Self = self;
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
pub async fn purge_person(
|
||||
data: Json<PurgePerson>,
|
||||
context: Data<LemmyContext>,
|
||||
) -> Result<Json<PurgeItemResponse>, LemmyError> {
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||
|
||||
// Only let admin purge an item
|
||||
is_admin(&local_user_view)?;
|
||||
|
@ -32,14 +29,14 @@ impl Perform for PurgePerson {
|
|||
let person = Person::read(&mut context.pool(), person_id).await?;
|
||||
|
||||
if let Some(banner) = person.banner {
|
||||
purge_image_from_pictrs(&banner, context).await.ok();
|
||||
purge_image_from_pictrs(&banner, &context).await.ok();
|
||||
}
|
||||
|
||||
if let Some(avatar) = person.avatar {
|
||||
purge_image_from_pictrs(&avatar, context).await.ok();
|
||||
purge_image_from_pictrs(&avatar, &context).await.ok();
|
||||
}
|
||||
|
||||
purge_image_posts_for_person(person_id, context).await?;
|
||||
purge_image_posts_for_person(person_id, &context).await?;
|
||||
|
||||
Person::delete(&mut context.pool(), person_id).await?;
|
||||
|
||||
|
@ -52,6 +49,5 @@ impl Perform for PurgePerson {
|
|||
|
||||
AdminPurgePerson::create(&mut context.pool(), &form).await?;
|
||||
|
||||
Ok(PurgeItemResponse { success: true })
|
||||
}
|
||||
Ok(Json(PurgeItemResponse { success: true }))
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use crate::Perform;
|
||||
use actix_web::web::Data;
|
||||
use actix_web::web::{Data, Json};
|
||||
use lemmy_api_common::{
|
||||
context::LemmyContext,
|
||||
request::purge_image_from_pictrs,
|
||||
|
@ -15,14 +14,12 @@ use lemmy_db_schema::{
|
|||
};
|
||||
use lemmy_utils::error::LemmyError;
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl Perform for PurgePost {
|
||||
type Response = PurgeItemResponse;
|
||||
|
||||
#[tracing::instrument(skip(context))]
|
||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
|
||||
let data: &Self = self;
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
pub async fn purge_post(
|
||||
data: Json<PurgePost>,
|
||||
context: Data<LemmyContext>,
|
||||
) -> Result<Json<PurgeItemResponse>, LemmyError> {
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||
|
||||
// Only let admin purge an item
|
||||
is_admin(&local_user_view)?;
|
||||
|
@ -34,11 +31,11 @@ impl Perform for PurgePost {
|
|||
|
||||
// Purge image
|
||||
if let Some(url) = post.url {
|
||||
purge_image_from_pictrs(&url, context).await.ok();
|
||||
purge_image_from_pictrs(&url, &context).await.ok();
|
||||
}
|
||||
// Purge thumbnail
|
||||
if let Some(thumbnail_url) = post.thumbnail_url {
|
||||
purge_image_from_pictrs(&thumbnail_url, context).await.ok();
|
||||
purge_image_from_pictrs(&thumbnail_url, &context).await.ok();
|
||||
}
|
||||
|
||||
let community_id = post.community_id;
|
||||
|
@ -55,6 +52,5 @@ impl Perform for PurgePost {
|
|||
|
||||
AdminPurgePost::create(&mut context.pool(), &form).await?;
|
||||
|
||||
Ok(PurgeItemResponse { success: true })
|
||||
}
|
||||
Ok(Json(PurgeItemResponse { success: true }))
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use crate::Perform;
|
||||
use actix_web::web::Data;
|
||||
use actix_web::web::{Data, Json};
|
||||
use lemmy_api_common::{
|
||||
context::LemmyContext,
|
||||
site::{ApproveRegistrationApplication, RegistrationApplicationResponse},
|
||||
|
@ -16,13 +15,11 @@ use lemmy_db_schema::{
|
|||
use lemmy_db_views::structs::{LocalUserView, RegistrationApplicationView};
|
||||
use lemmy_utils::error::LemmyError;
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl Perform for ApproveRegistrationApplication {
|
||||
type Response = RegistrationApplicationResponse;
|
||||
|
||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
|
||||
let data = self;
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
pub async fn approve_registration_application(
|
||||
data: Json<ApproveRegistrationApplication>,
|
||||
context: Data<LemmyContext>,
|
||||
) -> Result<Json<RegistrationApplicationResponse>, LemmyError> {
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||
|
||||
let app_id = data.id;
|
||||
|
||||
|
@ -61,8 +58,7 @@ impl Perform for ApproveRegistrationApplication {
|
|||
let registration_application =
|
||||
RegistrationApplicationView::read(&mut context.pool(), app_id).await?;
|
||||
|
||||
Ok(Self::Response {
|
||||
Ok(Json(RegistrationApplicationResponse {
|
||||
registration_application,
|
||||
})
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use crate::Perform;
|
||||
use actix_web::web::Data;
|
||||
use actix_web::web::{Data, Json, Query};
|
||||
use lemmy_api_common::{
|
||||
context::LemmyContext,
|
||||
site::{ListRegistrationApplications, ListRegistrationApplicationsResponse},
|
||||
|
@ -10,13 +9,11 @@ use lemmy_db_views::registration_application_view::RegistrationApplicationQuery;
|
|||
use lemmy_utils::error::LemmyError;
|
||||
|
||||
/// Lists registration applications, filterable by undenied only.
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl Perform for ListRegistrationApplications {
|
||||
type Response = ListRegistrationApplicationsResponse;
|
||||
|
||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
|
||||
let data = self;
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
pub async fn list_registration_applications(
|
||||
data: Query<ListRegistrationApplications>,
|
||||
context: Data<LemmyContext>,
|
||||
) -> Result<Json<ListRegistrationApplicationsResponse>, LemmyError> {
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||
let local_site = LocalSite::read(&mut context.pool()).await?;
|
||||
|
||||
// Make sure user is an admin
|
||||
|
@ -36,8 +33,7 @@ impl Perform for ListRegistrationApplications {
|
|||
.list(&mut context.pool())
|
||||
.await?;
|
||||
|
||||
Ok(Self::Response {
|
||||
Ok(Json(ListRegistrationApplicationsResponse {
|
||||
registration_applications,
|
||||
})
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
mod approve;
|
||||
mod list;
|
||||
mod unread_count;
|
||||
pub mod approve;
|
||||
pub mod list;
|
||||
pub mod unread_count;
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use crate::Perform;
|
||||
use actix_web::web::Data;
|
||||
use actix_web::web::{Data, Json, Query};
|
||||
use lemmy_api_common::{
|
||||
context::LemmyContext,
|
||||
site::{GetUnreadRegistrationApplicationCount, GetUnreadRegistrationApplicationCountResponse},
|
||||
|
@ -9,13 +8,11 @@ use lemmy_db_schema::source::local_site::LocalSite;
|
|||
use lemmy_db_views::structs::RegistrationApplicationView;
|
||||
use lemmy_utils::error::LemmyError;
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl Perform for GetUnreadRegistrationApplicationCount {
|
||||
type Response = GetUnreadRegistrationApplicationCountResponse;
|
||||
|
||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
|
||||
let data = self;
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
pub async fn get_unread_registration_application_count(
|
||||
data: Query<GetUnreadRegistrationApplicationCount>,
|
||||
context: Data<LemmyContext>,
|
||||
) -> Result<Json<GetUnreadRegistrationApplicationCountResponse>, LemmyError> {
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||
let local_site = LocalSite::read(&mut context.pool()).await?;
|
||||
|
||||
// Only let admins do this
|
||||
|
@ -24,11 +21,9 @@ impl Perform for GetUnreadRegistrationApplicationCount {
|
|||
let verified_email_only = local_site.require_email_verification;
|
||||
|
||||
let registration_applications =
|
||||
RegistrationApplicationView::get_unread_count(&mut context.pool(), verified_email_only)
|
||||
.await?;
|
||||
RegistrationApplicationView::get_unread_count(&mut context.pool(), verified_email_only).await?;
|
||||
|
||||
Ok(Self::Response {
|
||||
Ok(Json(GetUnreadRegistrationApplicationCountResponse {
|
||||
registration_applications,
|
||||
})
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ Here is an example using [reqwest](https://crates.io/crates/reqwest):
|
|||
print!("{:?}", &json);
|
||||
```
|
||||
|
||||
As you can see, each API endpoint needs a parameter type ( GetPosts), path (/post/list) and response type (GetPostsResponse). You can find the paths and parameter types from [this file](https://github.com/LemmyNet/lemmy/blob/main/src/api_routes_http.rs). For the response types you need to look through the crates [lemmy_api](https://github.com/LemmyNet/lemmy/tree/main/crates/api/src) and [lemmy_api_crud](https://github.com/LemmyNet/lemmy/tree/main/crates/api_crud/src) for the place where Perform/PerformCrud is implemented for the parameter type. The response type is specified as a type parameter on the trait.
|
||||
As you can see, each API endpoint needs a parameter type ( GetPosts), path (/post/list) and response type (GetPostsResponse). You can find the paths and handler methods from [this file](https://github.com/LemmyNet/lemmy/blob/main/src/api_routes_http.rs). The parameter type and response type are defined on each handler method.
|
||||
|
||||
For a real example of a Lemmy API client, look at [lemmyBB](https://github.com/LemmyNet/lemmyBB/tree/main/src/api).
|
||||
|
||||
|
|
|
@ -51,15 +51,6 @@ pub struct Register {
|
|||
pub answer: Option<String>,
|
||||
}
|
||||
|
||||
#[skip_serializing_none]
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
||||
#[cfg_attr(feature = "full", derive(TS))]
|
||||
#[cfg_attr(feature = "full", ts(export))]
|
||||
/// Fetches a Captcha item.
|
||||
pub struct GetCaptcha {
|
||||
pub auth: Option<Sensitive<String>>,
|
||||
}
|
||||
|
||||
#[skip_serializing_none]
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
#[cfg_attr(feature = "full", derive(TS))]
|
||||
|
|
|
@ -301,15 +301,6 @@ pub struct GetSiteResponse {
|
|||
pub custom_emojis: Vec<CustomEmojiView>,
|
||||
}
|
||||
|
||||
#[skip_serializing_none]
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
#[cfg_attr(feature = "full", derive(TS))]
|
||||
#[cfg_attr(feature = "full", ts(export))]
|
||||
/// Fetches the federated instances for your site.
|
||||
pub struct GetFederatedInstances {
|
||||
pub auth: Option<Sensitive<String>>,
|
||||
}
|
||||
|
||||
#[skip_serializing_none]
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
#[cfg_attr(feature = "full", derive(TS))]
|
||||
|
|
|
@ -65,7 +65,6 @@ pub mod community;
|
|||
pub mod create_or_update;
|
||||
pub mod deletion;
|
||||
pub mod following;
|
||||
pub mod unfederated;
|
||||
pub mod voting;
|
||||
|
||||
/// Amount of time that the list of dead instances is cached. This is only updated once a day,
|
||||
|
|
|
@ -1,320 +0,0 @@
|
|||
use crate::SendActivity;
|
||||
use lemmy_api_common::{
|
||||
comment::{
|
||||
CommentReportResponse,
|
||||
CommentResponse,
|
||||
DistinguishComment,
|
||||
GetComment,
|
||||
ListCommentReports,
|
||||
ListCommentReportsResponse,
|
||||
ResolveCommentReport,
|
||||
SaveComment,
|
||||
},
|
||||
community::{
|
||||
CommunityResponse,
|
||||
CreateCommunity,
|
||||
GetCommunityResponse,
|
||||
ListCommunities,
|
||||
ListCommunitiesResponse,
|
||||
TransferCommunity,
|
||||
},
|
||||
custom_emoji::{
|
||||
CreateCustomEmoji,
|
||||
CustomEmojiResponse,
|
||||
DeleteCustomEmoji,
|
||||
DeleteCustomEmojiResponse,
|
||||
EditCustomEmoji,
|
||||
},
|
||||
person::{
|
||||
AddAdmin,
|
||||
AddAdminResponse,
|
||||
BannedPersonsResponse,
|
||||
BlockPerson,
|
||||
BlockPersonResponse,
|
||||
ChangePassword,
|
||||
CommentReplyResponse,
|
||||
GetBannedPersons,
|
||||
GetCaptcha,
|
||||
GetCaptchaResponse,
|
||||
GetPersonMentions,
|
||||
GetPersonMentionsResponse,
|
||||
GetReplies,
|
||||
GetRepliesResponse,
|
||||
GetReportCount,
|
||||
GetReportCountResponse,
|
||||
GetUnreadCount,
|
||||
GetUnreadCountResponse,
|
||||
Login,
|
||||
LoginResponse,
|
||||
MarkAllAsRead,
|
||||
MarkCommentReplyAsRead,
|
||||
MarkPersonMentionAsRead,
|
||||
PasswordChangeAfterReset,
|
||||
PasswordReset,
|
||||
PasswordResetResponse,
|
||||
PersonMentionResponse,
|
||||
Register,
|
||||
SaveUserSettings,
|
||||
VerifyEmail,
|
||||
VerifyEmailResponse,
|
||||
},
|
||||
post::{
|
||||
GetPost,
|
||||
GetPostResponse,
|
||||
GetSiteMetadata,
|
||||
GetSiteMetadataResponse,
|
||||
ListPostReports,
|
||||
ListPostReportsResponse,
|
||||
MarkPostAsRead,
|
||||
PostReportResponse,
|
||||
PostResponse,
|
||||
ResolvePostReport,
|
||||
SavePost,
|
||||
},
|
||||
private_message::{
|
||||
CreatePrivateMessageReport,
|
||||
GetPrivateMessages,
|
||||
ListPrivateMessageReports,
|
||||
ListPrivateMessageReportsResponse,
|
||||
MarkPrivateMessageAsRead,
|
||||
PrivateMessageReportResponse,
|
||||
PrivateMessageResponse,
|
||||
PrivateMessagesResponse,
|
||||
ResolvePrivateMessageReport,
|
||||
},
|
||||
site::{
|
||||
ApproveRegistrationApplication,
|
||||
CreateSite,
|
||||
EditSite,
|
||||
GetFederatedInstances,
|
||||
GetFederatedInstancesResponse,
|
||||
GetModlog,
|
||||
GetModlogResponse,
|
||||
GetSite,
|
||||
GetSiteResponse,
|
||||
GetUnreadRegistrationApplicationCount,
|
||||
GetUnreadRegistrationApplicationCountResponse,
|
||||
LeaveAdmin,
|
||||
ListRegistrationApplications,
|
||||
ListRegistrationApplicationsResponse,
|
||||
PurgeComment,
|
||||
PurgeCommunity,
|
||||
PurgeItemResponse,
|
||||
PurgePerson,
|
||||
PurgePost,
|
||||
RegistrationApplicationResponse,
|
||||
SiteResponse,
|
||||
},
|
||||
};
|
||||
|
||||
impl SendActivity for Register {
|
||||
type Response = LoginResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for GetPrivateMessages {
|
||||
type Response = PrivateMessagesResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for CreateSite {
|
||||
type Response = SiteResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for EditSite {
|
||||
type Response = SiteResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for GetSite {
|
||||
type Response = GetSiteResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for ListCommunities {
|
||||
type Response = ListCommunitiesResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for CreateCommunity {
|
||||
type Response = CommunityResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for GetPost {
|
||||
type Response = GetPostResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for GetComment {
|
||||
type Response = CommentResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for Login {
|
||||
type Response = LoginResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for GetCaptcha {
|
||||
type Response = GetCaptchaResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for GetReplies {
|
||||
type Response = GetRepliesResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for AddAdmin {
|
||||
type Response = AddAdminResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for GetUnreadRegistrationApplicationCount {
|
||||
type Response = GetUnreadRegistrationApplicationCountResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for ListRegistrationApplications {
|
||||
type Response = ListRegistrationApplicationsResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for ApproveRegistrationApplication {
|
||||
type Response = RegistrationApplicationResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for GetBannedPersons {
|
||||
type Response = BannedPersonsResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for BlockPerson {
|
||||
type Response = BlockPersonResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for GetPersonMentions {
|
||||
type Response = GetPersonMentionsResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for MarkPersonMentionAsRead {
|
||||
type Response = PersonMentionResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for MarkCommentReplyAsRead {
|
||||
type Response = CommentReplyResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for MarkAllAsRead {
|
||||
type Response = GetRepliesResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for PasswordReset {
|
||||
type Response = PasswordResetResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for PasswordChangeAfterReset {
|
||||
type Response = LoginResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for SaveUserSettings {
|
||||
type Response = LoginResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for ChangePassword {
|
||||
type Response = LoginResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for GetReportCount {
|
||||
type Response = GetReportCountResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for GetUnreadCount {
|
||||
type Response = GetUnreadCountResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for VerifyEmail {
|
||||
type Response = VerifyEmailResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for MarkPrivateMessageAsRead {
|
||||
type Response = PrivateMessageResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for CreatePrivateMessageReport {
|
||||
type Response = PrivateMessageReportResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for ResolvePrivateMessageReport {
|
||||
type Response = PrivateMessageReportResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for ListPrivateMessageReports {
|
||||
type Response = ListPrivateMessageReportsResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for GetModlog {
|
||||
type Response = GetModlogResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for PurgePerson {
|
||||
type Response = PurgeItemResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for PurgeCommunity {
|
||||
type Response = PurgeItemResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for PurgePost {
|
||||
type Response = PurgeItemResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for PurgeComment {
|
||||
type Response = PurgeItemResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for TransferCommunity {
|
||||
type Response = GetCommunityResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for LeaveAdmin {
|
||||
type Response = GetSiteResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for MarkPostAsRead {
|
||||
type Response = PostResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for SavePost {
|
||||
type Response = PostResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for ListPostReports {
|
||||
type Response = ListPostReportsResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for ResolvePostReport {
|
||||
type Response = PostReportResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for GetSiteMetadata {
|
||||
type Response = GetSiteMetadataResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for SaveComment {
|
||||
type Response = CommentResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for DistinguishComment {
|
||||
type Response = CommentResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for ListCommentReports {
|
||||
type Response = ListCommentReportsResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for ResolveCommentReport {
|
||||
type Response = CommentReportResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for CreateCustomEmoji {
|
||||
type Response = CustomEmojiResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for EditCustomEmoji {
|
||||
type Response = CustomEmojiResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for DeleteCustomEmoji {
|
||||
type Response = DeleteCustomEmojiResponse;
|
||||
}
|
||||
|
||||
impl SendActivity for GetFederatedInstances {
|
||||
type Response = GetFederatedInstancesResponse;
|
||||
}
|
|
@ -194,16 +194,3 @@ async fn insert_received_activity(
|
|||
ReceivedActivity::create(&mut data.pool(), &ap_id.clone().into()).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
pub trait SendActivity: Sync {
|
||||
type Response: Sync + Send + Clone;
|
||||
|
||||
async fn send_activity(
|
||||
_request: &Self,
|
||||
_response: &Self::Response,
|
||||
_context: &Data<LemmyContext>,
|
||||
) -> Result<(), LemmyError> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use actix_web::{guard, web, Error, HttpResponse, Result};
|
||||
use actix_web::{guard, web};
|
||||
use lemmy_api::{
|
||||
comment::{distinguish::distinguish_comment, like::like_comment, save::save_comment},
|
||||
comment_report::{
|
||||
|
@ -12,53 +12,66 @@ use lemmy_api::{
|
|||
block::block_community,
|
||||
follow::follow_community,
|
||||
hide::hide_community,
|
||||
transfer::transfer_community,
|
||||
},
|
||||
local_user::{ban_person::ban_from_site, notifications::mark_reply_read::mark_reply_as_read},
|
||||
post::{feature::feature_post, like::like_post, lock::lock_post},
|
||||
post_report::create::create_post_report,
|
||||
sitemap::get_sitemap,
|
||||
Perform,
|
||||
};
|
||||
use lemmy_api_common::{
|
||||
community::TransferCommunity,
|
||||
context::LemmyContext,
|
||||
person::{
|
||||
AddAdmin,
|
||||
BlockPerson,
|
||||
ChangePassword,
|
||||
GetBannedPersons,
|
||||
GetCaptcha,
|
||||
GetPersonMentions,
|
||||
GetReplies,
|
||||
GetReportCount,
|
||||
GetUnreadCount,
|
||||
Login,
|
||||
MarkAllAsRead,
|
||||
MarkPersonMentionAsRead,
|
||||
PasswordChangeAfterReset,
|
||||
PasswordReset,
|
||||
SaveUserSettings,
|
||||
VerifyEmail,
|
||||
local_user::{
|
||||
add_admin::add_admin,
|
||||
ban_person::ban_from_site,
|
||||
block::block_person,
|
||||
change_password::change_password,
|
||||
change_password_after_reset::change_password_after_reset,
|
||||
get_captcha::get_captcha,
|
||||
list_banned::list_banned_users,
|
||||
login::login,
|
||||
notifications::{
|
||||
list_mentions::list_mentions,
|
||||
list_replies::list_replies,
|
||||
mark_all_read::mark_all_notifications_read,
|
||||
mark_mention_read::mark_person_mention_as_read,
|
||||
mark_reply_read::mark_reply_as_read,
|
||||
unread_count::unread_count,
|
||||
},
|
||||
post::{GetSiteMetadata, ListPostReports, MarkPostAsRead, ResolvePostReport, SavePost},
|
||||
private_message::{
|
||||
CreatePrivateMessageReport,
|
||||
ListPrivateMessageReports,
|
||||
MarkPrivateMessageAsRead,
|
||||
ResolvePrivateMessageReport,
|
||||
report_count::report_count,
|
||||
reset_password::reset_password,
|
||||
save_settings::save_user_settings,
|
||||
verify_email::verify_email,
|
||||
},
|
||||
post::{
|
||||
feature::feature_post,
|
||||
get_link_metadata::get_link_metadata,
|
||||
like::like_post,
|
||||
lock::lock_post,
|
||||
mark_read::mark_post_as_read,
|
||||
save::save_post,
|
||||
},
|
||||
post_report::{
|
||||
create::create_post_report,
|
||||
list::list_post_reports,
|
||||
resolve::resolve_post_report,
|
||||
},
|
||||
private_message::mark_read::mark_pm_as_read,
|
||||
private_message_report::{
|
||||
create::create_pm_report,
|
||||
list::list_pm_reports,
|
||||
resolve::resolve_pm_report,
|
||||
},
|
||||
site::{
|
||||
ApproveRegistrationApplication,
|
||||
GetFederatedInstances,
|
||||
GetModlog,
|
||||
GetUnreadRegistrationApplicationCount,
|
||||
LeaveAdmin,
|
||||
ListRegistrationApplications,
|
||||
PurgeComment,
|
||||
PurgeCommunity,
|
||||
PurgePerson,
|
||||
PurgePost,
|
||||
federated_instances::get_federated_instances,
|
||||
leave_admin::leave_admin,
|
||||
mod_log::get_mod_log,
|
||||
purge::{
|
||||
comment::purge_comment,
|
||||
community::purge_community,
|
||||
person::purge_person,
|
||||
post::purge_post,
|
||||
},
|
||||
registration_applications::{
|
||||
approve::approve_registration_application,
|
||||
list::list_registration_applications,
|
||||
unread_count::get_unread_registration_application_count,
|
||||
},
|
||||
},
|
||||
sitemap::get_sitemap,
|
||||
};
|
||||
use lemmy_api_crud::{
|
||||
comment::{
|
||||
|
@ -96,19 +109,15 @@ use lemmy_api_crud::{
|
|||
site::{create::create_site, read::get_site, update::update_site},
|
||||
user::{create::register, delete::delete_account},
|
||||
};
|
||||
use lemmy_apub::{
|
||||
api::{
|
||||
use lemmy_apub::api::{
|
||||
list_comments::list_comments,
|
||||
list_posts::list_posts,
|
||||
read_community::get_community,
|
||||
read_person::read_person,
|
||||
resolve_object::resolve_object,
|
||||
search::search,
|
||||
},
|
||||
SendActivity,
|
||||
};
|
||||
use lemmy_utils::{rate_limit::RateLimitCell, spawn_try_task, SYNCHRONOUS_FEDERATION};
|
||||
use serde::Deserialize;
|
||||
use lemmy_utils::rate_limit::RateLimitCell;
|
||||
|
||||
pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) {
|
||||
cfg.service(
|
||||
|
@ -125,7 +134,7 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) {
|
|||
.service(
|
||||
web::resource("/modlog")
|
||||
.wrap(rate_limit.message())
|
||||
.route(web::get().to(route_get::<GetModlog>)),
|
||||
.route(web::get().to(get_mod_log)),
|
||||
)
|
||||
.service(
|
||||
web::resource("/search")
|
||||
|
@ -156,14 +165,14 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) {
|
|||
.route("/delete", web::post().to(delete_community))
|
||||
// Mod Actions
|
||||
.route("/remove", web::post().to(remove_community))
|
||||
.route("/transfer", web::post().to(route_post::<TransferCommunity>))
|
||||
.route("/transfer", web::post().to(transfer_community))
|
||||
.route("/ban_user", web::post().to(ban_from_community))
|
||||
.route("/mod", web::post().to(add_mod_to_community)),
|
||||
)
|
||||
.service(
|
||||
web::scope("/federated_instances")
|
||||
.wrap(rate_limit.message())
|
||||
.route("", web::get().to(route_get::<GetFederatedInstances>)),
|
||||
.route("", web::get().to(get_federated_instances)),
|
||||
)
|
||||
// Post
|
||||
.service(
|
||||
|
@ -180,25 +189,16 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) {
|
|||
.route("", web::put().to(update_post))
|
||||
.route("/delete", web::post().to(delete_post))
|
||||
.route("/remove", web::post().to(remove_post))
|
||||
.route(
|
||||
"/mark_as_read",
|
||||
web::post().to(route_post::<MarkPostAsRead>),
|
||||
)
|
||||
.route("/mark_as_read", web::post().to(mark_post_as_read))
|
||||
.route("/lock", web::post().to(lock_post))
|
||||
.route("/feature", web::post().to(feature_post))
|
||||
.route("/list", web::get().to(list_posts))
|
||||
.route("/like", web::post().to(like_post))
|
||||
.route("/save", web::put().to(route_post::<SavePost>))
|
||||
.route("/save", web::put().to(save_post))
|
||||
.route("/report", web::post().to(create_post_report))
|
||||
.route(
|
||||
"/report/resolve",
|
||||
web::put().to(route_post::<ResolvePostReport>),
|
||||
)
|
||||
.route("/report/list", web::get().to(route_get::<ListPostReports>))
|
||||
.route(
|
||||
"/site_metadata",
|
||||
web::get().to(route_get::<GetSiteMetadata>),
|
||||
),
|
||||
.route("/report/resolve", web::put().to(resolve_post_report))
|
||||
.route("/report/list", web::get().to(list_post_reports))
|
||||
.route("/site_metadata", web::get().to(get_link_metadata)),
|
||||
)
|
||||
// Comment
|
||||
.service(
|
||||
|
@ -232,22 +232,10 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) {
|
|||
.route("", web::post().to(create_private_message))
|
||||
.route("", web::put().to(update_private_message))
|
||||
.route("/delete", web::post().to(delete_private_message))
|
||||
.route(
|
||||
"/mark_as_read",
|
||||
web::post().to(route_post::<MarkPrivateMessageAsRead>),
|
||||
)
|
||||
.route(
|
||||
"/report",
|
||||
web::post().to(route_post::<CreatePrivateMessageReport>),
|
||||
)
|
||||
.route(
|
||||
"/report/resolve",
|
||||
web::put().to(route_post::<ResolvePrivateMessageReport>),
|
||||
)
|
||||
.route(
|
||||
"/report/list",
|
||||
web::get().to(route_get::<ListPrivateMessageReports>),
|
||||
),
|
||||
.route("/mark_as_read", web::post().to(mark_pm_as_read))
|
||||
.route("/report", web::post().to(create_pm_report))
|
||||
.route("/report/resolve", web::put().to(resolve_pm_report))
|
||||
.route("/report/list", web::get().to(list_pm_reports)),
|
||||
)
|
||||
// User
|
||||
.service(
|
||||
|
@ -262,75 +250,66 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) {
|
|||
// Handle captcha separately
|
||||
web::resource("/user/get_captcha")
|
||||
.wrap(rate_limit.post())
|
||||
.route(web::get().to(route_get::<GetCaptcha>)),
|
||||
.route(web::get().to(get_captcha)),
|
||||
)
|
||||
// User actions
|
||||
.service(
|
||||
web::scope("/user")
|
||||
.wrap(rate_limit.message())
|
||||
.route("", web::get().to(read_person))
|
||||
.route("/mention", web::get().to(route_get::<GetPersonMentions>))
|
||||
.route("/mention", web::get().to(list_mentions))
|
||||
.route(
|
||||
"/mention/mark_as_read",
|
||||
web::post().to(route_post::<MarkPersonMentionAsRead>),
|
||||
web::post().to(mark_person_mention_as_read),
|
||||
)
|
||||
.route("/replies", web::get().to(route_get::<GetReplies>))
|
||||
.route("/replies", web::get().to(list_replies))
|
||||
// Admin action. I don't like that it's in /user
|
||||
.route("/ban", web::post().to(ban_from_site))
|
||||
.route("/banned", web::get().to(route_get::<GetBannedPersons>))
|
||||
.route("/block", web::post().to(route_post::<BlockPerson>))
|
||||
.route("/banned", web::get().to(list_banned_users))
|
||||
.route("/block", web::post().to(block_person))
|
||||
// Account actions. I don't like that they're in /user maybe /accounts
|
||||
.route("/login", web::post().to(route_post::<Login>))
|
||||
.route("/login", web::post().to(login))
|
||||
.route("/delete_account", web::post().to(delete_account))
|
||||
.route(
|
||||
"/password_reset",
|
||||
web::post().to(route_post::<PasswordReset>),
|
||||
)
|
||||
.route("/password_reset", web::post().to(reset_password))
|
||||
.route(
|
||||
"/password_change",
|
||||
web::post().to(route_post::<PasswordChangeAfterReset>),
|
||||
web::post().to(change_password_after_reset),
|
||||
)
|
||||
// mark_all_as_read feels off being in this section as well
|
||||
.route(
|
||||
"/mark_all_as_read",
|
||||
web::post().to(route_post::<MarkAllAsRead>),
|
||||
web::post().to(mark_all_notifications_read),
|
||||
)
|
||||
.route(
|
||||
"/save_user_settings",
|
||||
web::put().to(route_post::<SaveUserSettings>),
|
||||
)
|
||||
.route(
|
||||
"/change_password",
|
||||
web::put().to(route_post::<ChangePassword>),
|
||||
)
|
||||
.route("/report_count", web::get().to(route_get::<GetReportCount>))
|
||||
.route("/unread_count", web::get().to(route_get::<GetUnreadCount>))
|
||||
.route("/verify_email", web::post().to(route_post::<VerifyEmail>))
|
||||
.route("/leave_admin", web::post().to(route_post::<LeaveAdmin>)),
|
||||
.route("/save_user_settings", web::put().to(save_user_settings))
|
||||
.route("/change_password", web::put().to(change_password))
|
||||
.route("/report_count", web::get().to(report_count))
|
||||
.route("/unread_count", web::get().to(unread_count))
|
||||
.route("/verify_email", web::post().to(verify_email))
|
||||
.route("/leave_admin", web::post().to(leave_admin)),
|
||||
)
|
||||
// Admin Actions
|
||||
.service(
|
||||
web::scope("/admin")
|
||||
.wrap(rate_limit.message())
|
||||
.route("/add", web::post().to(route_post::<AddAdmin>))
|
||||
.route("/add", web::post().to(add_admin))
|
||||
.route(
|
||||
"/registration_application/count",
|
||||
web::get().to(route_get::<GetUnreadRegistrationApplicationCount>),
|
||||
web::get().to(get_unread_registration_application_count),
|
||||
)
|
||||
.route(
|
||||
"/registration_application/list",
|
||||
web::get().to(route_get::<ListRegistrationApplications>),
|
||||
web::get().to(list_registration_applications),
|
||||
)
|
||||
.route(
|
||||
"/registration_application/approve",
|
||||
web::put().to(route_post::<ApproveRegistrationApplication>),
|
||||
web::put().to(approve_registration_application),
|
||||
)
|
||||
.service(
|
||||
web::scope("/purge")
|
||||
.route("/person", web::post().to(route_post::<PurgePerson>))
|
||||
.route("/community", web::post().to(route_post::<PurgeCommunity>))
|
||||
.route("/post", web::post().to(route_post::<PurgePost>))
|
||||
.route("/comment", web::post().to(route_post::<PurgeComment>)),
|
||||
.route("/person", web::post().to(purge_person))
|
||||
.route("/community", web::post().to(purge_community))
|
||||
.route("/post", web::post().to(purge_post))
|
||||
.route("/comment", web::post().to(purge_comment)),
|
||||
),
|
||||
)
|
||||
.service(
|
||||
|
@ -347,59 +326,3 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) {
|
|||
.route("", web::get().to(get_sitemap)),
|
||||
);
|
||||
}
|
||||
|
||||
async fn perform<'a, Data>(
|
||||
data: Data,
|
||||
context: web::Data<LemmyContext>,
|
||||
apub_data: activitypub_federation::config::Data<LemmyContext>,
|
||||
) -> Result<HttpResponse, Error>
|
||||
where
|
||||
Data: Perform
|
||||
+ SendActivity<Response = <Data as Perform>::Response>
|
||||
+ Clone
|
||||
+ Deserialize<'a>
|
||||
+ Send
|
||||
+ 'static,
|
||||
{
|
||||
let res = data.perform(&context).await?;
|
||||
let res_clone = res.clone();
|
||||
let fed_task = async move { SendActivity::send_activity(&data, &res_clone, &apub_data).await };
|
||||
if *SYNCHRONOUS_FEDERATION {
|
||||
fed_task.await?;
|
||||
} else {
|
||||
spawn_try_task(fed_task);
|
||||
}
|
||||
Ok(HttpResponse::Ok().json(&res))
|
||||
}
|
||||
|
||||
async fn route_get<'a, Data>(
|
||||
data: web::Query<Data>,
|
||||
context: web::Data<LemmyContext>,
|
||||
apub_data: activitypub_federation::config::Data<LemmyContext>,
|
||||
) -> Result<HttpResponse, Error>
|
||||
where
|
||||
Data: Perform
|
||||
+ SendActivity<Response = <Data as Perform>::Response>
|
||||
+ Clone
|
||||
+ Deserialize<'a>
|
||||
+ Send
|
||||
+ 'static,
|
||||
{
|
||||
perform::<Data>(data.0, context, apub_data).await
|
||||
}
|
||||
|
||||
async fn route_post<'a, Data>(
|
||||
data: web::Json<Data>,
|
||||
context: web::Data<LemmyContext>,
|
||||
apub_data: activitypub_federation::config::Data<LemmyContext>,
|
||||
) -> Result<HttpResponse, Error>
|
||||
where
|
||||
Data: Perform
|
||||
+ SendActivity<Response = <Data as Perform>::Response>
|
||||
+ Clone
|
||||
+ Deserialize<'a>
|
||||
+ Send
|
||||
+ 'static,
|
||||
{
|
||||
perform::<Data>(data.0, context, apub_data).await
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue