Convert all Result<..., LemmyError> into LemmyResult<...> Fixes #4613 (#4614)

* Convert all Result<..., LemmyError> into LemmyResult<...> Fixes #4613

* Fixing clippy.
This commit is contained in:
Dessalines 2024-04-10 10:14:11 -04:00 committed by GitHub
parent d5622a65f8
commit 5dea21d531
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
181 changed files with 591 additions and 672 deletions

View file

@ -9,14 +9,14 @@ use lemmy_db_schema::{
traits::Crud, traits::Crud,
}; };
use lemmy_db_views::structs::{CommentView, LocalUserView}; use lemmy_db_views::structs::{CommentView, LocalUserView};
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult};
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
pub async fn distinguish_comment( pub async fn distinguish_comment(
data: Json<DistinguishComment>, data: Json<DistinguishComment>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<CommentResponse>, LemmyError> { ) -> LemmyResult<Json<CommentResponse>> {
let orig_comment = CommentView::read(&mut context.pool(), data.comment_id, None).await?; let orig_comment = CommentView::read(&mut context.pool(), data.comment_id, None).await?;
check_community_user_action( check_community_user_action(

View file

@ -17,7 +17,7 @@ use lemmy_db_schema::{
traits::Likeable, traits::Likeable,
}; };
use lemmy_db_views::structs::{CommentView, LocalUserView}; use lemmy_db_views::structs::{CommentView, LocalUserView};
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult};
use std::ops::Deref; use std::ops::Deref;
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
@ -25,7 +25,7 @@ pub async fn like_comment(
data: Json<CreateCommentLike>, data: Json<CreateCommentLike>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<CommentResponse>, LemmyError> { ) -> LemmyResult<Json<CommentResponse>> {
let local_site = LocalSite::read(&mut context.pool()).await?; let local_site = LocalSite::read(&mut context.pool()).await?;
let mut recipient_ids = Vec::<LocalUserId>::new(); let mut recipient_ids = Vec::<LocalUserId>::new();

View file

@ -5,7 +5,7 @@ use lemmy_api_common::{
utils::is_mod_or_admin, utils::is_mod_or_admin,
}; };
use lemmy_db_views::structs::{CommentView, LocalUserView, VoteView}; use lemmy_db_views::structs::{CommentView, LocalUserView, VoteView};
use lemmy_utils::error::LemmyError; use lemmy_utils::error::LemmyResult;
/// Lists likes for a comment /// Lists likes for a comment
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
@ -13,7 +13,7 @@ pub async fn list_comment_likes(
data: Query<ListCommentLikes>, data: Query<ListCommentLikes>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<ListCommentLikesResponse>, LemmyError> { ) -> LemmyResult<Json<ListCommentLikesResponse>> {
let comment_view = CommentView::read( let comment_view = CommentView::read(
&mut context.pool(), &mut context.pool(),
data.comment_id, data.comment_id,

View file

@ -8,14 +8,14 @@ use lemmy_db_schema::{
traits::Saveable, traits::Saveable,
}; };
use lemmy_db_views::structs::{CommentView, LocalUserView}; use lemmy_db_views::structs::{CommentView, LocalUserView};
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult};
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
pub async fn save_comment( pub async fn save_comment(
data: Json<SaveComment>, data: Json<SaveComment>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<CommentResponse>, LemmyError> { ) -> LemmyResult<Json<CommentResponse>> {
let comment_saved_form = CommentSavedForm { let comment_saved_form = CommentSavedForm {
comment_id: data.comment_id, comment_id: data.comment_id,
person_id: local_user_view.person.id, person_id: local_user_view.person.id,

View file

@ -19,7 +19,7 @@ use lemmy_db_schema::{
traits::Reportable, traits::Reportable,
}; };
use lemmy_db_views::structs::{CommentReportView, CommentView, LocalUserView}; use lemmy_db_views::structs::{CommentReportView, CommentView, LocalUserView};
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult};
/// Creates a comment report and notifies the moderators of the community /// Creates a comment report and notifies the moderators of the community
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
@ -27,7 +27,7 @@ pub async fn create_comment_report(
data: Json<CreateCommentReport>, data: Json<CreateCommentReport>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<CommentReportResponse>, LemmyError> { ) -> LemmyResult<Json<CommentReportResponse>> {
let local_site = LocalSite::read(&mut context.pool()).await?; let local_site = LocalSite::read(&mut context.pool()).await?;
let reason = data.reason.trim().to_string(); let reason = data.reason.trim().to_string();

View file

@ -5,7 +5,7 @@ use lemmy_api_common::{
utils::check_community_mod_of_any_or_admin_action, utils::check_community_mod_of_any_or_admin_action,
}; };
use lemmy_db_views::{comment_report_view::CommentReportQuery, structs::LocalUserView}; use lemmy_db_views::{comment_report_view::CommentReportQuery, structs::LocalUserView};
use lemmy_utils::error::LemmyError; use lemmy_utils::error::LemmyResult;
/// 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
@ -14,7 +14,7 @@ pub async fn list_comment_reports(
data: Query<ListCommentReports>, data: Query<ListCommentReports>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<ListCommentReportsResponse>, LemmyError> { ) -> LemmyResult<Json<ListCommentReportsResponse>> {
let community_id = data.community_id; let community_id = data.community_id;
let comment_id = data.comment_id; let comment_id = data.comment_id;
let unresolved_only = data.unresolved_only.unwrap_or_default(); let unresolved_only = data.unresolved_only.unwrap_or_default();

View file

@ -6,7 +6,7 @@ use lemmy_api_common::{
}; };
use lemmy_db_schema::{source::comment_report::CommentReport, traits::Reportable}; use lemmy_db_schema::{source::comment_report::CommentReport, traits::Reportable};
use lemmy_db_views::structs::{CommentReportView, LocalUserView}; use lemmy_db_views::structs::{CommentReportView, LocalUserView};
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult};
/// 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
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
@ -14,7 +14,7 @@ pub async fn resolve_comment_report(
data: Json<ResolveCommentReport>, data: Json<ResolveCommentReport>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<CommentReportResponse>, LemmyError> { ) -> LemmyResult<Json<CommentReportResponse>> {
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;
let report = CommentReportView::read(&mut context.pool(), report_id, person_id).await?; let report = CommentReportView::read(&mut context.pool(), report_id, person_id).await?;

View file

@ -15,14 +15,14 @@ use lemmy_db_schema::{
}; };
use lemmy_db_views::structs::LocalUserView; use lemmy_db_views::structs::LocalUserView;
use lemmy_db_views_actor::structs::CommunityModeratorView; use lemmy_db_views_actor::structs::CommunityModeratorView;
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult};
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
pub async fn add_mod_to_community( pub async fn add_mod_to_community(
data: Json<AddModToCommunity>, data: Json<AddModToCommunity>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<AddModToCommunityResponse>, LemmyError> { ) -> LemmyResult<Json<AddModToCommunityResponse>> {
let community_id = data.community_id; let community_id = data.community_id;
// Verify that only mods or admins can add mod // Verify that only mods or admins can add mod

View file

@ -21,7 +21,7 @@ use lemmy_db_schema::{
use lemmy_db_views::structs::LocalUserView; use lemmy_db_views::structs::LocalUserView;
use lemmy_db_views_actor::structs::PersonView; use lemmy_db_views_actor::structs::PersonView;
use lemmy_utils::{ use lemmy_utils::{
error::{LemmyError, LemmyErrorExt, LemmyErrorType}, error::{LemmyErrorExt, LemmyErrorType, LemmyResult},
utils::validation::is_valid_body_field, utils::validation::is_valid_body_field,
}; };
@ -30,7 +30,7 @@ pub async fn ban_from_community(
data: Json<BanFromCommunity>, data: Json<BanFromCommunity>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<BanFromCommunityResponse>, LemmyError> { ) -> LemmyResult<Json<BanFromCommunityResponse>> {
let banned_person_id = data.person_id; let banned_person_id = data.person_id;
let remove_data = data.remove_data.unwrap_or(false); let remove_data = data.remove_data.unwrap_or(false);
let expires = check_expire_time(data.expires)?; let expires = check_expire_time(data.expires)?;

View file

@ -14,14 +14,14 @@ use lemmy_db_schema::{
}; };
use lemmy_db_views::structs::LocalUserView; use lemmy_db_views::structs::LocalUserView;
use lemmy_db_views_actor::structs::CommunityView; use lemmy_db_views_actor::structs::CommunityView;
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult};
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
pub async fn block_community( pub async fn block_community(
data: Json<BlockCommunity>, data: Json<BlockCommunity>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<BlockCommunityResponse>, LemmyError> { ) -> LemmyResult<Json<BlockCommunityResponse>> {
let community_id = data.community_id; let community_id = data.community_id;
let person_id = local_user_view.person.id; let person_id = local_user_view.person.id;
let community_block_form = CommunityBlockForm { let community_block_form = CommunityBlockForm {

View file

@ -15,14 +15,14 @@ use lemmy_db_schema::{
}; };
use lemmy_db_views::structs::LocalUserView; use lemmy_db_views::structs::LocalUserView;
use lemmy_db_views_actor::structs::CommunityView; use lemmy_db_views_actor::structs::CommunityView;
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult};
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
pub async fn follow_community( pub async fn follow_community(
data: Json<FollowCommunity>, data: Json<FollowCommunity>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<CommunityResponse>, LemmyError> { ) -> LemmyResult<Json<CommunityResponse>> {
let community = Community::read(&mut context.pool(), data.community_id).await?; let community = Community::read(&mut context.pool(), data.community_id).await?;
let mut community_follower_form = CommunityFollowerForm { let mut community_follower_form = CommunityFollowerForm {
community_id: community.id, community_id: community.id,

View file

@ -15,14 +15,14 @@ use lemmy_db_schema::{
traits::Crud, traits::Crud,
}; };
use lemmy_db_views::structs::LocalUserView; use lemmy_db_views::structs::LocalUserView;
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult};
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
pub async fn hide_community( pub async fn hide_community(
data: Json<HideCommunity>, data: Json<HideCommunity>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<SuccessResponse>, LemmyError> { ) -> LemmyResult<Json<SuccessResponse>> {
// Verify its a admin (only admin can hide or unhide it) // Verify its a admin (only admin can hide or unhide it)
is_admin(&local_user_view)?; is_admin(&local_user_view)?;

View file

@ -15,7 +15,7 @@ use lemmy_db_schema::{
use lemmy_db_views::structs::LocalUserView; use lemmy_db_views::structs::LocalUserView;
use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView}; use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView};
use lemmy_utils::{ use lemmy_utils::{
error::{LemmyError, LemmyErrorExt, LemmyErrorType}, error::{LemmyErrorExt, LemmyErrorType, LemmyResult},
location_info, location_info,
}; };
@ -26,7 +26,7 @@ pub async fn transfer_community(
data: Json<TransferCommunity>, data: Json<TransferCommunity>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<GetCommunityResponse>, LemmyError> { ) -> LemmyResult<Json<GetCommunityResponse>> {
let community_id = data.community_id; let community_id = data.community_id;
let mut community_mods = let mut community_mods =
CommunityModeratorView::for_community(&mut context.pool(), community_id).await?; CommunityModeratorView::for_community(&mut context.pool(), community_id).await?;

View file

@ -26,7 +26,7 @@ use lemmy_db_schema::{
}; };
use lemmy_db_views::structs::LocalUserView; use lemmy_db_views::structs::LocalUserView;
use lemmy_utils::{ use lemmy_utils::{
error::{LemmyError, LemmyErrorExt, LemmyErrorExt2, LemmyErrorType, LemmyResult}, error::{LemmyErrorExt, LemmyErrorExt2, LemmyErrorType, LemmyResult},
utils::slurs::check_slurs, utils::slurs::check_slurs,
}; };
use std::io::Cursor; use std::io::Cursor;
@ -44,7 +44,7 @@ pub mod site;
pub mod sitemap; pub mod sitemap;
/// Converts the captcha to a base64 encoded wav audio file /// Converts the captcha to a base64 encoded wav audio file
pub(crate) fn captcha_as_wav_base64(captcha: &Captcha) -> Result<String, LemmyError> { pub(crate) fn captcha_as_wav_base64(captcha: &Captcha) -> LemmyResult<String> {
let letters = captcha.as_wav(); let letters = captcha.as_wav();
// Decode each wav file, concatenate the samples // Decode each wav file, concatenate the samples
@ -78,7 +78,7 @@ pub(crate) fn captcha_as_wav_base64(captcha: &Captcha) -> Result<String, LemmyEr
} }
/// Check size of report /// Check size of report
pub(crate) fn check_report_reason(reason: &str, local_site: &LocalSite) -> Result<(), LemmyError> { pub(crate) fn check_report_reason(reason: &str, local_site: &LocalSite) -> LemmyResult<()> {
let slur_regex = &local_site_to_slur_regex(local_site); let slur_regex = &local_site_to_slur_regex(local_site);
check_slurs(reason, slur_regex)?; check_slurs(reason, slur_regex)?;
@ -91,7 +91,7 @@ pub(crate) fn check_report_reason(reason: &str, local_site: &LocalSite) -> Resul
} }
} }
pub fn read_auth_token(req: &HttpRequest) -> Result<Option<String>, LemmyError> { pub fn read_auth_token(req: &HttpRequest) -> LemmyResult<Option<String>> {
// Try reading jwt from auth header // Try reading jwt from auth header
if let Ok(header) = Authorization::<Bearer>::parse(req) { if let Ok(header) = Authorization::<Bearer>::parse(req) {
Ok(Some(header.as_ref().token().to_string())) Ok(Some(header.as_ref().token().to_string()))
@ -135,7 +135,7 @@ pub(crate) fn generate_totp_2fa_secret() -> String {
Secret::generate_secret().to_string() Secret::generate_secret().to_string()
} }
fn build_totp_2fa(hostname: &str, username: &str, secret: &str) -> Result<TOTP, LemmyError> { fn build_totp_2fa(hostname: &str, username: &str, secret: &str) -> LemmyResult<TOTP> {
let sec = Secret::Raw(secret.as_bytes().to_vec()); let sec = Secret::Raw(secret.as_bytes().to_vec());
let sec_bytes = sec let sec_bytes = sec
.to_bytes() .to_bytes()
@ -248,7 +248,7 @@ pub(crate) async fn ban_nonlocal_user_from_local_communities(
pub async fn local_user_view_from_jwt( pub async fn local_user_view_from_jwt(
jwt: &str, jwt: &str,
context: &LemmyContext, context: &LemmyContext,
) -> Result<LocalUserView, LemmyError> { ) -> LemmyResult<LocalUserView> {
let local_user_id = Claims::validate(jwt, context) let local_user_id = Claims::validate(jwt, context)
.await .await
.with_lemmy_type(LemmyErrorType::NotLoggedIn)?; .with_lemmy_type(LemmyErrorType::NotLoggedIn)?;

View file

@ -13,14 +13,14 @@ use lemmy_db_schema::{
}; };
use lemmy_db_views::structs::LocalUserView; use lemmy_db_views::structs::LocalUserView;
use lemmy_db_views_actor::structs::PersonView; use lemmy_db_views_actor::structs::PersonView;
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult};
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
pub async fn add_admin( pub async fn add_admin(
data: Json<AddAdmin>, data: Json<AddAdmin>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<AddAdminResponse>, LemmyError> { ) -> LemmyResult<Json<AddAdminResponse>> {
// Make sure user is an admin // Make sure user is an admin
is_admin(&local_user_view)?; is_admin(&local_user_view)?;

View file

@ -18,7 +18,7 @@ use lemmy_db_schema::{
use lemmy_db_views::structs::LocalUserView; use lemmy_db_views::structs::LocalUserView;
use lemmy_db_views_actor::structs::PersonView; use lemmy_db_views_actor::structs::PersonView;
use lemmy_utils::{ use lemmy_utils::{
error::{LemmyError, LemmyErrorExt, LemmyErrorType}, error::{LemmyErrorExt, LemmyErrorType, LemmyResult},
utils::validation::is_valid_body_field, utils::validation::is_valid_body_field,
}; };
@ -27,7 +27,7 @@ pub async fn ban_from_site(
data: Json<BanPerson>, data: Json<BanPerson>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<BanPersonResponse>, LemmyError> { ) -> LemmyResult<Json<BanPersonResponse>> {
// Make sure user is an admin // Make sure user is an admin
is_admin(&local_user_view)?; is_admin(&local_user_view)?;

View file

@ -9,14 +9,14 @@ use lemmy_db_schema::{
}; };
use lemmy_db_views::structs::LocalUserView; use lemmy_db_views::structs::LocalUserView;
use lemmy_db_views_actor::structs::PersonView; use lemmy_db_views_actor::structs::PersonView;
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult};
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
pub async fn block_person( pub async fn block_person(
data: Json<BlockPerson>, data: Json<BlockPerson>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<BlockPersonResponse>, LemmyError> { ) -> LemmyResult<Json<BlockPersonResponse>> {
let target_id = data.person_id; let target_id = data.person_id;
let person_id = local_user_view.person.id; let person_id = local_user_view.person.id;

View file

@ -11,7 +11,7 @@ use lemmy_api_common::{
}; };
use lemmy_db_schema::source::{local_user::LocalUser, login_token::LoginToken}; use lemmy_db_schema::source::{local_user::LocalUser, login_token::LoginToken};
use lemmy_db_views::structs::LocalUserView; use lemmy_db_views::structs::LocalUserView;
use lemmy_utils::error::{LemmyError, LemmyErrorType}; use lemmy_utils::error::{LemmyErrorType, LemmyResult};
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
pub async fn change_password( pub async fn change_password(
@ -19,7 +19,7 @@ pub async fn change_password(
req: HttpRequest, req: HttpRequest,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<LoginResponse>, LemmyError> { ) -> LemmyResult<Json<LoginResponse>> {
password_length_check(&data.new_password)?; password_length_check(&data.new_password)?;
// Make sure passwords match // Make sure passwords match

View file

@ -10,13 +10,13 @@ use lemmy_db_schema::source::{
login_token::LoginToken, login_token::LoginToken,
password_reset_request::PasswordResetRequest, password_reset_request::PasswordResetRequest,
}; };
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult};
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
pub async fn change_password_after_reset( pub async fn change_password_after_reset(
data: Json<PasswordChangeAfterReset>, data: Json<PasswordChangeAfterReset>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
) -> Result<Json<SuccessResponse>, LemmyError> { ) -> LemmyResult<Json<SuccessResponse>> {
// Fetch the user_id from the token // Fetch the user_id from the token
let token = data.token.clone(); let token = data.token.clone();
let local_user_id = PasswordResetRequest::read_from_token(&mut context.pool(), &token) let local_user_id = PasswordResetRequest::read_from_token(&mut context.pool(), &token)

View file

@ -8,7 +8,7 @@ use lemmy_api_common::{
}; };
use lemmy_db_schema::source::local_user::{LocalUser, LocalUserUpdateForm}; use lemmy_db_schema::source::local_user::{LocalUser, LocalUserUpdateForm};
use lemmy_db_views::structs::{LocalUserView, SiteView}; use lemmy_db_views::structs::{LocalUserView, SiteView};
use lemmy_utils::error::{LemmyError, LemmyErrorType}; use lemmy_utils::error::{LemmyErrorType, LemmyResult};
/// Generate a new secret for two-factor-authentication. Afterwards you need to call [toggle_totp] /// Generate a new secret for two-factor-authentication. Afterwards you need to call [toggle_totp]
/// to enable it. This can only be called if 2FA is currently disabled. /// to enable it. This can only be called if 2FA is currently disabled.
@ -16,7 +16,7 @@ use lemmy_utils::error::{LemmyError, LemmyErrorType};
pub async fn generate_totp_secret( pub async fn generate_totp_secret(
local_user_view: LocalUserView, local_user_view: LocalUserView,
context: Data<LemmyContext>, context: Data<LemmyContext>,
) -> Result<Json<GenerateTotpSecretResponse>, LemmyError> { ) -> LemmyResult<Json<GenerateTotpSecretResponse>> {
let site_view = SiteView::read_local(&mut context.pool()).await?; let site_view = SiteView::read_local(&mut context.pool()).await?;
if local_user_view.local_user.totp_2fa_enabled { if local_user_view.local_user.totp_2fa_enabled {

View file

@ -17,10 +17,10 @@ use lemmy_db_schema::source::{
captcha_answer::{CaptchaAnswer, CaptchaAnswerForm}, captcha_answer::{CaptchaAnswer, CaptchaAnswerForm},
local_site::LocalSite, local_site::LocalSite,
}; };
use lemmy_utils::error::LemmyError; use lemmy_utils::error::LemmyResult;
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
pub async fn get_captcha(context: Data<LemmyContext>) -> Result<HttpResponse, LemmyError> { pub async fn get_captcha(context: Data<LemmyContext>) -> LemmyResult<HttpResponse> {
let local_site = LocalSite::read(&mut context.pool()).await?; let local_site = LocalSite::read(&mut context.pool()).await?;
let mut res = HttpResponseBuilder::new(StatusCode::OK); let mut res = HttpResponseBuilder::new(StatusCode::OK);
res.insert_header(CacheControl(vec![CacheDirective::NoStore])); res.insert_header(CacheControl(vec![CacheDirective::NoStore]));

View file

@ -2,12 +2,12 @@ use actix_web::web::{Data, Json};
use lemmy_api_common::{context::LemmyContext, person::BannedPersonsResponse, utils::is_admin}; use lemmy_api_common::{context::LemmyContext, person::BannedPersonsResponse, utils::is_admin};
use lemmy_db_views::structs::LocalUserView; use lemmy_db_views::structs::LocalUserView;
use lemmy_db_views_actor::structs::PersonView; use lemmy_db_views_actor::structs::PersonView;
use lemmy_utils::error::LemmyError; use lemmy_utils::error::LemmyResult;
pub async fn list_banned_users( pub async fn list_banned_users(
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<BannedPersonsResponse>, LemmyError> { ) -> LemmyResult<Json<BannedPersonsResponse>> {
// Make sure user is an admin // Make sure user is an admin
is_admin(&local_user_view)?; is_admin(&local_user_view)?;

View file

@ -2,12 +2,12 @@ use actix_web::web::{Data, Json};
use lemmy_api_common::context::LemmyContext; use lemmy_api_common::context::LemmyContext;
use lemmy_db_schema::source::login_token::LoginToken; use lemmy_db_schema::source::login_token::LoginToken;
use lemmy_db_views::structs::LocalUserView; use lemmy_db_views::structs::LocalUserView;
use lemmy_utils::error::LemmyError; use lemmy_utils::error::LemmyResult;
pub async fn list_logins( pub async fn list_logins(
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<Vec<LoginToken>>, LemmyError> { ) -> LemmyResult<Json<Vec<LoginToken>>> {
let logins = LoginToken::list(&mut context.pool(), local_user_view.local_user.id).await?; let logins = LoginToken::list(&mut context.pool(), local_user_view.local_user.id).await?;
Ok(Json(logins)) Ok(Json(logins))

View file

@ -5,14 +5,14 @@ use lemmy_api_common::{
}; };
use lemmy_db_schema::source::images::LocalImage; use lemmy_db_schema::source::images::LocalImage;
use lemmy_db_views::structs::LocalUserView; use lemmy_db_views::structs::LocalUserView;
use lemmy_utils::error::LemmyError; use lemmy_utils::error::LemmyResult;
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
pub async fn list_media( pub async fn list_media(
data: Query<ListMedia>, data: Query<ListMedia>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<ListMediaResponse>, LemmyError> { ) -> LemmyResult<Json<ListMediaResponse>> {
let page = data.page; let page = data.page;
let limit = data.limit; let limit = data.limit;
let images = LocalImage::get_all_paged_by_local_user_id( let images = LocalImage::get_all_paged_by_local_user_id(

View file

@ -16,14 +16,14 @@ use lemmy_db_schema::{
RegistrationMode, RegistrationMode,
}; };
use lemmy_db_views::structs::{LocalUserView, SiteView}; use lemmy_db_views::structs::{LocalUserView, SiteView};
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult};
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
pub async fn login( pub async fn login(
data: Json<Login>, data: Json<Login>,
req: HttpRequest, req: HttpRequest,
context: Data<LemmyContext>, context: Data<LemmyContext>,
) -> Result<Json<LoginResponse>, LemmyError> { ) -> LemmyResult<Json<LoginResponse>> {
let site_view = SiteView::read_local(&mut context.pool()).await?; let site_view = SiteView::read_local(&mut context.pool()).await?;
// Fetch that username / email // Fetch that username / email
@ -70,7 +70,7 @@ async fn check_registration_application(
local_user_view: &LocalUserView, local_user_view: &LocalUserView,
local_site: &LocalSite, local_site: &LocalSite,
pool: &mut DbPool<'_>, pool: &mut DbPool<'_>,
) -> Result<(), LemmyError> { ) -> LemmyResult<()> {
if (local_site.registration_mode == RegistrationMode::RequireApplication if (local_site.registration_mode == RegistrationMode::RequireApplication
|| local_site.registration_mode == RegistrationMode::Closed) || local_site.registration_mode == RegistrationMode::Closed)
&& !local_user_view.local_user.accepted_application && !local_user_view.local_user.accepted_application

View file

@ -5,14 +5,14 @@ use lemmy_api_common::{
}; };
use lemmy_db_views::structs::LocalUserView; use lemmy_db_views::structs::LocalUserView;
use lemmy_db_views_actor::person_mention_view::PersonMentionQuery; use lemmy_db_views_actor::person_mention_view::PersonMentionQuery;
use lemmy_utils::error::LemmyError; use lemmy_utils::error::LemmyResult;
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
pub async fn list_mentions( pub async fn list_mentions(
data: Query<GetPersonMentions>, data: Query<GetPersonMentions>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<GetPersonMentionsResponse>, LemmyError> { ) -> LemmyResult<Json<GetPersonMentionsResponse>> {
let sort = data.sort; let sort = data.sort;
let page = data.page; let page = data.page;
let limit = data.limit; let limit = data.limit;

View file

@ -5,14 +5,14 @@ use lemmy_api_common::{
}; };
use lemmy_db_views::structs::LocalUserView; use lemmy_db_views::structs::LocalUserView;
use lemmy_db_views_actor::comment_reply_view::CommentReplyQuery; use lemmy_db_views_actor::comment_reply_view::CommentReplyQuery;
use lemmy_utils::error::LemmyError; use lemmy_utils::error::LemmyResult;
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
pub async fn list_replies( pub async fn list_replies(
data: Query<GetReplies>, data: Query<GetReplies>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<GetRepliesResponse>, LemmyError> { ) -> LemmyResult<Json<GetRepliesResponse>> {
let sort = data.sort; let sort = data.sort;
let page = data.page; let page = data.page;
let limit = data.limit; let limit = data.limit;

View file

@ -6,13 +6,13 @@ use lemmy_db_schema::source::{
private_message::PrivateMessage, private_message::PrivateMessage,
}; };
use lemmy_db_views::structs::LocalUserView; use lemmy_db_views::structs::LocalUserView;
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult};
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
pub async fn mark_all_notifications_read( pub async fn mark_all_notifications_read(
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<GetRepliesResponse>, LemmyError> { ) -> LemmyResult<Json<GetRepliesResponse>> {
let person_id = local_user_view.person.id; let person_id = local_user_view.person.id;
// Mark all comment_replies as read // Mark all comment_replies as read

View file

@ -9,14 +9,14 @@ use lemmy_db_schema::{
}; };
use lemmy_db_views::structs::LocalUserView; use lemmy_db_views::structs::LocalUserView;
use lemmy_db_views_actor::structs::PersonMentionView; use lemmy_db_views_actor::structs::PersonMentionView;
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult};
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
pub async fn mark_person_mention_as_read( pub async fn mark_person_mention_as_read(
data: Json<MarkPersonMentionAsRead>, data: Json<MarkPersonMentionAsRead>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<PersonMentionResponse>, LemmyError> { ) -> LemmyResult<Json<PersonMentionResponse>> {
let person_mention_id = data.person_mention_id; let person_mention_id = data.person_mention_id;
let read_person_mention = PersonMention::read(&mut context.pool(), person_mention_id).await?; let read_person_mention = PersonMention::read(&mut context.pool(), person_mention_id).await?;

View file

@ -9,14 +9,14 @@ use lemmy_db_schema::{
}; };
use lemmy_db_views::structs::LocalUserView; use lemmy_db_views::structs::LocalUserView;
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::{LemmyErrorExt, LemmyErrorType, LemmyResult};
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
pub async fn mark_reply_as_read( pub async fn mark_reply_as_read(
data: Json<MarkCommentReplyAsRead>, data: Json<MarkCommentReplyAsRead>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<CommentReplyResponse>, LemmyError> { ) -> LemmyResult<Json<CommentReplyResponse>> {
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?;

View file

@ -2,13 +2,13 @@ use actix_web::web::{Data, Json};
use lemmy_api_common::{context::LemmyContext, person::GetUnreadCountResponse}; use lemmy_api_common::{context::LemmyContext, person::GetUnreadCountResponse};
use lemmy_db_views::structs::{LocalUserView, PrivateMessageView}; use lemmy_db_views::structs::{LocalUserView, PrivateMessageView};
use lemmy_db_views_actor::structs::{CommentReplyView, PersonMentionView}; use lemmy_db_views_actor::structs::{CommentReplyView, PersonMentionView};
use lemmy_utils::error::LemmyError; use lemmy_utils::error::LemmyResult;
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
pub async fn unread_count( pub async fn unread_count(
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<GetUnreadCountResponse>, LemmyError> { ) -> LemmyResult<Json<GetUnreadCountResponse>> {
let person_id = local_user_view.person.id; let person_id = local_user_view.person.id;
let replies = CommentReplyView::get_unread_replies(&mut context.pool(), person_id).await?; let replies = CommentReplyView::get_unread_replies(&mut context.pool(), person_id).await?;

View file

@ -10,14 +10,14 @@ use lemmy_db_views::structs::{
PostReportView, PostReportView,
PrivateMessageReportView, PrivateMessageReportView,
}; };
use lemmy_utils::error::LemmyError; use lemmy_utils::error::LemmyResult;
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
pub async fn report_count( pub async fn report_count(
data: Query<GetReportCount>, data: Query<GetReportCount>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<GetReportCountResponse>, LemmyError> { ) -> LemmyResult<Json<GetReportCountResponse>> {
let person_id = local_user_view.person.id; let person_id = local_user_view.person.id;
let admin = local_user_view.local_user.admin; let admin = local_user_view.local_user.admin;
let community_id = data.community_id; let community_id = data.community_id;

View file

@ -25,7 +25,7 @@ use lemmy_db_schema::{
}; };
use lemmy_db_views::structs::{LocalUserView, SiteView}; use lemmy_db_views::structs::{LocalUserView, SiteView};
use lemmy_utils::{ use lemmy_utils::{
error::{LemmyError, LemmyErrorType}, error::{LemmyErrorType, LemmyResult},
utils::validation::{is_valid_bio_field, is_valid_display_name, is_valid_matrix_id}, utils::validation::{is_valid_bio_field, is_valid_display_name, is_valid_matrix_id},
}; };
@ -34,7 +34,7 @@ pub async fn save_user_settings(
data: Json<SaveUserSettings>, data: Json<SaveUserSettings>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<SuccessResponse>, LemmyError> { ) -> LemmyResult<Json<SuccessResponse>> {
let site_view = SiteView::read_local(&mut context.pool()).await?; let site_view = SiteView::read_local(&mut context.pool()).await?;
let slur_regex = local_site_to_slur_regex(&site_view.local_site); let slur_regex = local_site_to_slur_regex(&site_view.local_site);

View file

@ -6,7 +6,7 @@ use lemmy_api_common::{
}; };
use lemmy_db_schema::source::local_user::{LocalUser, LocalUserUpdateForm}; use lemmy_db_schema::source::local_user::{LocalUser, LocalUserUpdateForm};
use lemmy_db_views::structs::LocalUserView; use lemmy_db_views::structs::LocalUserView;
use lemmy_utils::error::LemmyError; use lemmy_utils::error::LemmyResult;
/// Enable or disable two-factor-authentication. The current setting is determined from /// Enable or disable two-factor-authentication. The current setting is determined from
/// [LocalUser.totp_2fa_enabled]. /// [LocalUser.totp_2fa_enabled].
@ -21,7 +21,7 @@ pub async fn update_totp(
data: Json<UpdateTotp>, data: Json<UpdateTotp>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
context: Data<LemmyContext>, context: Data<LemmyContext>,
) -> Result<Json<UpdateTotpResponse>, LemmyError> { ) -> LemmyResult<Json<UpdateTotpResponse>> {
check_totp_2fa_valid( check_totp_2fa_valid(
&local_user_view, &local_user_view,
&Some(data.totp_token.clone()), &Some(data.totp_token.clone()),

View file

@ -4,7 +4,7 @@ use actix_web::{
HttpRequest, HttpRequest,
}; };
use lemmy_api_common::{context::LemmyContext, SuccessResponse}; use lemmy_api_common::{context::LemmyContext, SuccessResponse};
use lemmy_utils::error::{LemmyError, LemmyErrorType}; use lemmy_utils::error::{LemmyErrorType, LemmyResult};
/// Returns an error message if the auth token is invalid for any reason. Necessary because other /// Returns an error message if the auth token is invalid for any reason. Necessary because other
/// endpoints silently treat any call with invalid auth as unauthenticated. /// endpoints silently treat any call with invalid auth as unauthenticated.
@ -12,7 +12,7 @@ use lemmy_utils::error::{LemmyError, LemmyErrorType};
pub async fn validate_auth( pub async fn validate_auth(
req: HttpRequest, req: HttpRequest,
context: Data<LemmyContext>, context: Data<LemmyContext>,
) -> Result<Json<SuccessResponse>, LemmyError> { ) -> LemmyResult<Json<SuccessResponse>> {
let jwt = read_auth_token(&req)?; let jwt = read_auth_token(&req)?;
if let Some(jwt) = jwt { if let Some(jwt) = jwt {
local_user_view_from_jwt(&jwt, &context).await?; local_user_view_from_jwt(&jwt, &context).await?;

View file

@ -16,14 +16,14 @@ use lemmy_db_schema::{
PostFeatureType, PostFeatureType,
}; };
use lemmy_db_views::structs::LocalUserView; use lemmy_db_views::structs::LocalUserView;
use lemmy_utils::error::LemmyError; use lemmy_utils::error::LemmyResult;
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
pub async fn feature_post( pub async fn feature_post(
data: Json<FeaturePost>, data: Json<FeaturePost>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<PostResponse>, LemmyError> { ) -> LemmyResult<Json<PostResponse>> {
let post_id = data.post_id; let post_id = data.post_id;
let orig_post = Post::read(&mut context.pool(), post_id).await?; let orig_post = Post::read(&mut context.pool(), post_id).await?;

View file

@ -4,13 +4,13 @@ use lemmy_api_common::{
post::{GetSiteMetadata, GetSiteMetadataResponse}, post::{GetSiteMetadata, GetSiteMetadataResponse},
request::fetch_link_metadata, request::fetch_link_metadata,
}; };
use lemmy_utils::error::LemmyError; use lemmy_utils::error::LemmyResult;
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
pub async fn get_link_metadata( pub async fn get_link_metadata(
data: Query<GetSiteMetadata>, data: Query<GetSiteMetadata>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
) -> Result<Json<GetSiteMetadataResponse>, LemmyError> { ) -> LemmyResult<Json<GetSiteMetadataResponse>> {
let metadata = fetch_link_metadata(&data.url, false, &context).await?; let metadata = fetch_link_metadata(&data.url, false, &context).await?;
Ok(Json(GetSiteMetadataResponse { metadata })) Ok(Json(GetSiteMetadataResponse { metadata }))

View file

@ -2,7 +2,7 @@ use actix_web::web::{Data, Json};
use lemmy_api_common::{context::LemmyContext, post::HidePost, SuccessResponse}; use lemmy_api_common::{context::LemmyContext, post::HidePost, SuccessResponse};
use lemmy_db_schema::source::post::PostHide; use lemmy_db_schema::source::post::PostHide;
use lemmy_db_views::structs::LocalUserView; use lemmy_db_views::structs::LocalUserView;
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType, MAX_API_PARAM_ELEMENTS}; use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult, MAX_API_PARAM_ELEMENTS};
use std::collections::HashSet; use std::collections::HashSet;
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
@ -10,7 +10,7 @@ pub async fn hide_post(
data: Json<HidePost>, data: Json<HidePost>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<SuccessResponse>, LemmyError> { ) -> LemmyResult<Json<SuccessResponse>> {
let post_ids = HashSet::from_iter(data.post_ids.clone()); let post_ids = HashSet::from_iter(data.post_ids.clone());
if post_ids.len() > MAX_API_PARAM_ELEMENTS { if post_ids.len() > MAX_API_PARAM_ELEMENTS {

View file

@ -21,7 +21,7 @@ use lemmy_db_schema::{
traits::{Crud, Likeable}, traits::{Crud, Likeable},
}; };
use lemmy_db_views::structs::LocalUserView; use lemmy_db_views::structs::LocalUserView;
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult};
use std::ops::Deref; use std::ops::Deref;
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
@ -29,7 +29,7 @@ pub async fn like_post(
data: Json<CreatePostLike>, data: Json<CreatePostLike>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<PostResponse>, LemmyError> { ) -> LemmyResult<Json<PostResponse>> {
let local_site = LocalSite::read(&mut context.pool()).await?; let local_site = LocalSite::read(&mut context.pool()).await?;
// Don't do a downvote if site has downvotes disabled // Don't do a downvote if site has downvotes disabled

View file

@ -6,7 +6,7 @@ use lemmy_api_common::{
}; };
use lemmy_db_schema::{source::post::Post, traits::Crud}; use lemmy_db_schema::{source::post::Post, traits::Crud};
use lemmy_db_views::structs::{LocalUserView, VoteView}; use lemmy_db_views::structs::{LocalUserView, VoteView};
use lemmy_utils::error::LemmyError; use lemmy_utils::error::LemmyResult;
/// Lists likes for a post /// Lists likes for a post
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
@ -14,7 +14,7 @@ pub async fn list_post_likes(
data: Query<ListPostLikes>, data: Query<ListPostLikes>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<ListPostLikesResponse>, LemmyError> { ) -> LemmyResult<Json<ListPostLikesResponse>> {
let post = Post::read(&mut context.pool(), data.post_id).await?; let post = Post::read(&mut context.pool(), data.post_id).await?;
is_mod_or_admin( is_mod_or_admin(
&mut context.pool(), &mut context.pool(),

View file

@ -15,14 +15,14 @@ use lemmy_db_schema::{
traits::Crud, traits::Crud,
}; };
use lemmy_db_views::structs::LocalUserView; use lemmy_db_views::structs::LocalUserView;
use lemmy_utils::error::LemmyError; use lemmy_utils::error::LemmyResult;
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
pub async fn lock_post( pub async fn lock_post(
data: Json<LockPost>, data: Json<LockPost>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<PostResponse>, LemmyError> { ) -> LemmyResult<Json<PostResponse>> {
let post_id = data.post_id; let post_id = data.post_id;
let orig_post = Post::read(&mut context.pool(), post_id).await?; let orig_post = Post::read(&mut context.pool(), post_id).await?;

View file

@ -2,7 +2,7 @@ use actix_web::web::{Data, Json};
use lemmy_api_common::{context::LemmyContext, post::MarkPostAsRead, SuccessResponse}; use lemmy_api_common::{context::LemmyContext, post::MarkPostAsRead, SuccessResponse};
use lemmy_db_schema::source::post::PostRead; use lemmy_db_schema::source::post::PostRead;
use lemmy_db_views::structs::LocalUserView; use lemmy_db_views::structs::LocalUserView;
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType, MAX_API_PARAM_ELEMENTS}; use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult, MAX_API_PARAM_ELEMENTS};
use std::collections::HashSet; use std::collections::HashSet;
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
@ -10,7 +10,7 @@ pub async fn mark_post_as_read(
data: Json<MarkPostAsRead>, data: Json<MarkPostAsRead>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<SuccessResponse>, LemmyError> { ) -> LemmyResult<Json<SuccessResponse>> {
let post_ids = HashSet::from_iter(data.post_ids.clone()); let post_ids = HashSet::from_iter(data.post_ids.clone());
if post_ids.len() > MAX_API_PARAM_ELEMENTS { if post_ids.len() > MAX_API_PARAM_ELEMENTS {

View file

@ -9,14 +9,14 @@ use lemmy_db_schema::{
traits::Saveable, traits::Saveable,
}; };
use lemmy_db_views::structs::{LocalUserView, PostView}; use lemmy_db_views::structs::{LocalUserView, PostView};
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult};
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
pub async fn save_post( pub async fn save_post(
data: Json<SavePost>, data: Json<SavePost>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<PostResponse>, LemmyError> { ) -> LemmyResult<Json<PostResponse>> {
let post_saved_form = PostSavedForm { let post_saved_form = PostSavedForm {
post_id: data.post_id, post_id: data.post_id,
person_id: local_user_view.person.id, person_id: local_user_view.person.id,

View file

@ -19,7 +19,7 @@ use lemmy_db_schema::{
traits::Reportable, traits::Reportable,
}; };
use lemmy_db_views::structs::{LocalUserView, PostReportView, PostView}; use lemmy_db_views::structs::{LocalUserView, PostReportView, PostView};
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult};
/// Creates a post report and notifies the moderators of the community /// Creates a post report and notifies the moderators of the community
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
@ -27,7 +27,7 @@ pub async fn create_post_report(
data: Json<CreatePostReport>, data: Json<CreatePostReport>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<PostReportResponse>, LemmyError> { ) -> LemmyResult<Json<PostReportResponse>> {
let local_site = LocalSite::read(&mut context.pool()).await?; let local_site = LocalSite::read(&mut context.pool()).await?;
let reason = data.reason.trim().to_string(); let reason = data.reason.trim().to_string();

View file

@ -5,7 +5,7 @@ use lemmy_api_common::{
utils::check_community_mod_of_any_or_admin_action, utils::check_community_mod_of_any_or_admin_action,
}; };
use lemmy_db_views::{post_report_view::PostReportQuery, structs::LocalUserView}; use lemmy_db_views::{post_report_view::PostReportQuery, structs::LocalUserView};
use lemmy_utils::error::LemmyError; use lemmy_utils::error::LemmyResult;
/// Lists post reports for a community if an id is supplied /// Lists post reports for a community if an id is supplied
/// or returns all post reports for communities a user moderates /// or returns all post reports for communities a user moderates
@ -14,7 +14,7 @@ pub async fn list_post_reports(
data: Query<ListPostReports>, data: Query<ListPostReports>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<ListPostReportsResponse>, LemmyError> { ) -> LemmyResult<Json<ListPostReportsResponse>> {
let community_id = data.community_id; let community_id = data.community_id;
let post_id = data.post_id; let post_id = data.post_id;
let unresolved_only = data.unresolved_only.unwrap_or_default(); let unresolved_only = data.unresolved_only.unwrap_or_default();

View file

@ -6,7 +6,7 @@ use lemmy_api_common::{
}; };
use lemmy_db_schema::{source::post_report::PostReport, traits::Reportable}; use lemmy_db_schema::{source::post_report::PostReport, traits::Reportable};
use lemmy_db_views::structs::{LocalUserView, PostReportView}; use lemmy_db_views::structs::{LocalUserView, PostReportView};
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult};
/// Resolves or unresolves a post report and notifies the moderators of the community /// Resolves or unresolves a post report and notifies the moderators of the community
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
@ -14,7 +14,7 @@ pub async fn resolve_post_report(
data: Json<ResolvePostReport>, data: Json<ResolvePostReport>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<PostReportResponse>, LemmyError> { ) -> LemmyResult<Json<PostReportResponse>> {
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;
let report = PostReportView::read(&mut context.pool(), report_id, person_id).await?; let report = PostReportView::read(&mut context.pool(), report_id, person_id).await?;

View file

@ -8,14 +8,14 @@ use lemmy_db_schema::{
traits::Crud, traits::Crud,
}; };
use lemmy_db_views::structs::{LocalUserView, PrivateMessageView}; use lemmy_db_views::structs::{LocalUserView, PrivateMessageView};
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult};
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
pub async fn mark_pm_as_read( pub async fn mark_pm_as_read(
data: Json<MarkPrivateMessageAsRead>, data: Json<MarkPrivateMessageAsRead>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<PrivateMessageResponse>, LemmyError> { ) -> LemmyResult<Json<PrivateMessageResponse>> {
// Checking permissions // Checking permissions
let private_message_id = data.private_message_id; 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?;

View file

@ -14,14 +14,14 @@ use lemmy_db_schema::{
traits::{Crud, Reportable}, traits::{Crud, Reportable},
}; };
use lemmy_db_views::structs::{LocalUserView, PrivateMessageReportView}; use lemmy_db_views::structs::{LocalUserView, PrivateMessageReportView};
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult};
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
pub async fn create_pm_report( pub async fn create_pm_report(
data: Json<CreatePrivateMessageReport>, data: Json<CreatePrivateMessageReport>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<PrivateMessageReportResponse>, LemmyError> { ) -> LemmyResult<Json<PrivateMessageReportResponse>> {
let local_site = LocalSite::read(&mut context.pool()).await?; let local_site = LocalSite::read(&mut context.pool()).await?;
let reason = data.reason.trim().to_string(); let reason = data.reason.trim().to_string();

View file

@ -8,14 +8,14 @@ use lemmy_db_views::{
private_message_report_view::PrivateMessageReportQuery, private_message_report_view::PrivateMessageReportQuery,
structs::LocalUserView, structs::LocalUserView,
}; };
use lemmy_utils::error::LemmyError; use lemmy_utils::error::LemmyResult;
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
pub async fn list_pm_reports( pub async fn list_pm_reports(
data: Query<ListPrivateMessageReports>, data: Query<ListPrivateMessageReports>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<ListPrivateMessageReportsResponse>, LemmyError> { ) -> LemmyResult<Json<ListPrivateMessageReportsResponse>> {
is_admin(&local_user_view)?; is_admin(&local_user_view)?;
let unresolved_only = data.unresolved_only.unwrap_or_default(); let unresolved_only = data.unresolved_only.unwrap_or_default();

View file

@ -6,14 +6,14 @@ use lemmy_api_common::{
}; };
use lemmy_db_schema::{source::private_message_report::PrivateMessageReport, traits::Reportable}; use lemmy_db_schema::{source::private_message_report::PrivateMessageReport, traits::Reportable};
use lemmy_db_views::structs::{LocalUserView, PrivateMessageReportView}; use lemmy_db_views::structs::{LocalUserView, PrivateMessageReportView};
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult};
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
pub async fn resolve_pm_report( pub async fn resolve_pm_report(
data: Json<ResolvePrivateMessageReport>, data: Json<ResolvePrivateMessageReport>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<PrivateMessageReportResponse>, LemmyError> { ) -> LemmyResult<Json<PrivateMessageReportResponse>> {
is_admin(&local_user_view)?; is_admin(&local_user_view)?;
let report_id = data.report_id; let report_id = data.report_id;

View file

@ -9,14 +9,14 @@ use lemmy_db_schema::{
traits::Blockable, traits::Blockable,
}; };
use lemmy_db_views::structs::LocalUserView; use lemmy_db_views::structs::LocalUserView;
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult};
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
pub async fn block_instance( pub async fn block_instance(
data: Json<BlockInstance>, data: Json<BlockInstance>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
context: Data<LemmyContext>, context: Data<LemmyContext>,
) -> Result<Json<BlockInstanceResponse>, LemmyError> { ) -> LemmyResult<Json<BlockInstanceResponse>> {
let instance_id = data.instance_id; let instance_id = data.instance_id;
let person_id = local_user_view.person.id; let person_id = local_user_view.person.id;
if local_user_view.person.instance_id == instance_id { if local_user_view.person.instance_id == instance_id {

View file

@ -5,12 +5,12 @@ use lemmy_api_common::{
utils::build_federated_instances, utils::build_federated_instances,
}; };
use lemmy_db_views::structs::SiteView; use lemmy_db_views::structs::SiteView;
use lemmy_utils::error::LemmyError; use lemmy_utils::error::LemmyResult;
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
pub async fn get_federated_instances( pub async fn get_federated_instances(
context: Data<LemmyContext>, context: Data<LemmyContext>,
) -> Result<Json<GetFederatedInstancesResponse>, LemmyError> { ) -> LemmyResult<Json<GetFederatedInstancesResponse>> {
let site_view = SiteView::read_local(&mut context.pool()).await?; let site_view = SiteView::read_local(&mut context.pool()).await?;
let federated_instances = let federated_instances =
build_federated_instances(&site_view.local_site, &mut context.pool()).await?; build_federated_instances(&site_view.local_site, &mut context.pool()).await?;

View file

@ -14,7 +14,7 @@ use lemmy_db_schema::{
use lemmy_db_views::structs::{CustomEmojiView, LocalUserView, SiteView}; use lemmy_db_views::structs::{CustomEmojiView, LocalUserView, SiteView};
use lemmy_db_views_actor::structs::PersonView; use lemmy_db_views_actor::structs::PersonView;
use lemmy_utils::{ use lemmy_utils::{
error::{LemmyError, LemmyErrorType}, error::{LemmyErrorType, LemmyResult},
VERSION, VERSION,
}; };
@ -22,7 +22,7 @@ use lemmy_utils::{
pub async fn leave_admin( pub async fn leave_admin(
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<GetSiteResponse>, LemmyError> { ) -> LemmyResult<Json<GetSiteResponse>> {
is_admin(&local_user_view)?; is_admin(&local_user_view)?;
// Make sure there isn't just one admin (so if one leaves, there will still be one left) // Make sure there isn't just one admin (so if one leaves, there will still be one left)

View file

@ -6,14 +6,14 @@ use lemmy_api_common::{
}; };
use lemmy_db_schema::source::images::LocalImage; use lemmy_db_schema::source::images::LocalImage;
use lemmy_db_views::structs::LocalUserView; use lemmy_db_views::structs::LocalUserView;
use lemmy_utils::error::LemmyError; use lemmy_utils::error::LemmyResult;
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
pub async fn list_all_media( pub async fn list_all_media(
data: Query<ListMedia>, data: Query<ListMedia>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<ListMediaResponse>, LemmyError> { ) -> LemmyResult<Json<ListMediaResponse>> {
// Only let admins view all media // Only let admins view all media
is_admin(&local_user_view)?; is_admin(&local_user_view)?;

View file

@ -24,7 +24,7 @@ use lemmy_db_views_moderator::structs::{
ModTransferCommunityView, ModTransferCommunityView,
ModlogListParams, ModlogListParams,
}; };
use lemmy_utils::error::LemmyError; use lemmy_utils::error::LemmyResult;
use ModlogActionType::*; use ModlogActionType::*;
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
@ -32,7 +32,7 @@ pub async fn get_mod_log(
data: Query<GetModlog>, data: Query<GetModlog>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: Option<LocalUserView>, local_user_view: Option<LocalUserView>,
) -> Result<Json<GetModlogResponse>, LemmyError> { ) -> LemmyResult<Json<GetModlogResponse>> {
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)?;

View file

@ -15,14 +15,14 @@ use lemmy_db_schema::{
traits::Crud, traits::Crud,
}; };
use lemmy_db_views::structs::{CommentView, LocalUserView}; use lemmy_db_views::structs::{CommentView, LocalUserView};
use lemmy_utils::error::LemmyError; use lemmy_utils::error::LemmyResult;
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
pub async fn purge_comment( pub async fn purge_comment(
data: Json<PurgeComment>, data: Json<PurgeComment>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<SuccessResponse>, LemmyError> { ) -> LemmyResult<Json<SuccessResponse>> {
// Only let admin purge an item // Only let admin purge an item
is_admin(&local_user_view)?; is_admin(&local_user_view)?;

View file

@ -16,14 +16,14 @@ use lemmy_db_schema::{
traits::Crud, traits::Crud,
}; };
use lemmy_db_views::structs::LocalUserView; use lemmy_db_views::structs::LocalUserView;
use lemmy_utils::error::LemmyError; use lemmy_utils::error::LemmyResult;
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
pub async fn purge_community( pub async fn purge_community(
data: Json<PurgeCommunity>, data: Json<PurgeCommunity>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<SuccessResponse>, LemmyError> { ) -> LemmyResult<Json<SuccessResponse>> {
// Only let admin purge an item // Only let admin purge an item
is_admin(&local_user_view)?; is_admin(&local_user_view)?;

View file

@ -16,14 +16,14 @@ use lemmy_db_schema::{
traits::Crud, traits::Crud,
}; };
use lemmy_db_views::structs::LocalUserView; use lemmy_db_views::structs::LocalUserView;
use lemmy_utils::error::LemmyError; use lemmy_utils::error::LemmyResult;
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
pub async fn purge_person( pub async fn purge_person(
data: Json<PurgePerson>, data: Json<PurgePerson>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<SuccessResponse>, LemmyError> { ) -> LemmyResult<Json<SuccessResponse>> {
// Only let admin purge an item // Only let admin purge an item
is_admin(&local_user_view)?; is_admin(&local_user_view)?;

View file

@ -16,14 +16,14 @@ use lemmy_db_schema::{
traits::Crud, traits::Crud,
}; };
use lemmy_db_views::structs::LocalUserView; use lemmy_db_views::structs::LocalUserView;
use lemmy_utils::error::LemmyError; use lemmy_utils::error::LemmyResult;
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
pub async fn purge_post( pub async fn purge_post(
data: Json<PurgePost>, data: Json<PurgePost>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<SuccessResponse>, LemmyError> { ) -> LemmyResult<Json<SuccessResponse>> {
// Only let admin purge an item // Only let admin purge an item
is_admin(&local_user_view)?; is_admin(&local_user_view)?;

View file

@ -13,13 +13,13 @@ use lemmy_db_schema::{
utils::diesel_option_overwrite, utils::diesel_option_overwrite,
}; };
use lemmy_db_views::structs::{LocalUserView, RegistrationApplicationView}; use lemmy_db_views::structs::{LocalUserView, RegistrationApplicationView};
use lemmy_utils::error::LemmyError; use lemmy_utils::error::LemmyResult;
pub async fn approve_registration_application( pub async fn approve_registration_application(
data: Json<ApproveRegistrationApplication>, data: Json<ApproveRegistrationApplication>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<RegistrationApplicationResponse>, LemmyError> { ) -> LemmyResult<Json<RegistrationApplicationResponse>> {
let app_id = data.id; let app_id = data.id;
// Only let admins do this // Only let admins do this

View file

@ -9,14 +9,14 @@ use lemmy_db_views::{
registration_application_view::RegistrationApplicationQuery, registration_application_view::RegistrationApplicationQuery,
structs::LocalUserView, structs::LocalUserView,
}; };
use lemmy_utils::error::LemmyError; use lemmy_utils::error::LemmyResult;
/// Lists registration applications, filterable by undenied only. /// Lists registration applications, filterable by undenied only.
pub async fn list_registration_applications( pub async fn list_registration_applications(
data: Query<ListRegistrationApplications>, data: Query<ListRegistrationApplications>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<ListRegistrationApplicationsResponse>, LemmyError> { ) -> LemmyResult<Json<ListRegistrationApplicationsResponse>> {
let local_site = LocalSite::read(&mut context.pool()).await?; let local_site = LocalSite::read(&mut context.pool()).await?;
// Make sure user is an admin // Make sure user is an admin

View file

@ -6,12 +6,12 @@ use lemmy_api_common::{
}; };
use lemmy_db_schema::source::local_site::LocalSite; use lemmy_db_schema::source::local_site::LocalSite;
use lemmy_db_views::structs::{LocalUserView, RegistrationApplicationView}; use lemmy_db_views::structs::{LocalUserView, RegistrationApplicationView};
use lemmy_utils::error::LemmyError; use lemmy_utils::error::LemmyResult;
pub async fn get_unread_registration_application_count( pub async fn get_unread_registration_application_count(
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<GetUnreadRegistrationApplicationCountResponse>, LemmyError> { ) -> LemmyResult<Json<GetUnreadRegistrationApplicationCountResponse>> {
let local_site = LocalSite::read(&mut context.pool()).await?; let local_site = LocalSite::read(&mut context.pool()).await?;
// Only let admins do this // Only let admins do this

View file

@ -25,7 +25,7 @@ use lemmy_db_schema::{
use lemmy_db_views::structs::{CommentView, LocalUserView, PostView}; use lemmy_db_views::structs::{CommentView, LocalUserView, PostView};
use lemmy_db_views_actor::structs::CommunityView; use lemmy_db_views_actor::structs::CommunityView;
use lemmy_utils::{ use lemmy_utils::{
error::LemmyError, error::LemmyResult,
utils::{markdown::markdown_to_html, mention::MentionData}, utils::{markdown::markdown_to_html, mention::MentionData},
}; };
@ -34,7 +34,7 @@ pub async fn build_comment_response(
comment_id: CommentId, comment_id: CommentId,
local_user_view: Option<LocalUserView>, local_user_view: Option<LocalUserView>,
recipient_ids: Vec<LocalUserId>, recipient_ids: Vec<LocalUserId>,
) -> Result<CommentResponse, LemmyError> { ) -> LemmyResult<CommentResponse> {
let person_id = local_user_view.map(|l| l.person.id); let person_id = local_user_view.map(|l| l.person.id);
let comment_view = CommentView::read(&mut context.pool(), comment_id, person_id).await?; let comment_view = CommentView::read(&mut context.pool(), comment_id, person_id).await?;
Ok(CommentResponse { Ok(CommentResponse {
@ -47,7 +47,7 @@ pub async fn build_community_response(
context: &LemmyContext, context: &LemmyContext,
local_user_view: LocalUserView, local_user_view: LocalUserView,
community_id: CommunityId, community_id: CommunityId,
) -> Result<Json<CommunityResponse>, LemmyError> { ) -> LemmyResult<Json<CommunityResponse>> {
let is_mod_or_admin = is_mod_or_admin(&mut context.pool(), &local_user_view.person, community_id) let is_mod_or_admin = is_mod_or_admin(&mut context.pool(), &local_user_view.person, community_id)
.await .await
.is_ok(); .is_ok();
@ -72,7 +72,7 @@ pub async fn build_post_response(
community_id: CommunityId, community_id: CommunityId,
person: &Person, person: &Person,
post_id: PostId, post_id: PostId,
) -> Result<Json<PostResponse>, LemmyError> { ) -> LemmyResult<Json<PostResponse>> {
let is_mod_or_admin = is_mod_or_admin(&mut context.pool(), person, community_id) let is_mod_or_admin = is_mod_or_admin(&mut context.pool(), person, community_id)
.await .await
.is_ok(); .is_ok();
@ -94,7 +94,7 @@ pub async fn send_local_notifs(
person: &Person, person: &Person,
do_send_email: bool, do_send_email: bool,
context: &LemmyContext, context: &LemmyContext,
) -> Result<Vec<LocalUserId>, LemmyError> { ) -> LemmyResult<Vec<LocalUserId>> {
let mut recipient_ids = Vec::new(); let mut recipient_ids = Vec::new();
let inbox_link = format!("{}/inbox", context.settings().get_protocol_and_hostname()); let inbox_link = format!("{}/inbox", context.settings().get_protocol_and_hostname());

View file

@ -16,7 +16,7 @@ use lemmy_db_schema::{
}, },
}; };
use lemmy_utils::{ use lemmy_utils::{
error::{LemmyError, LemmyErrorType}, error::{LemmyError, LemmyErrorType, LemmyResult},
settings::structs::{PictrsImageMode, Settings}, settings::structs::{PictrsImageMode, Settings},
spawn_try_task, spawn_try_task,
REQWEST_TIMEOUT, REQWEST_TIMEOUT,
@ -46,7 +46,7 @@ pub async fn fetch_link_metadata(
url: &Url, url: &Url,
generate_thumbnail: bool, generate_thumbnail: bool,
context: &LemmyContext, context: &LemmyContext,
) -> Result<LinkMetadata, LemmyError> { ) -> LemmyResult<LinkMetadata> {
info!("Fetching site metadata for url: {}", url); info!("Fetching site metadata for url: {}", url);
let response = context.client().get(url.as_str()).send().await?; let response = context.client().get(url.as_str()).send().await?;
@ -132,7 +132,7 @@ pub fn generate_post_link_metadata(
} }
/// Extract site metadata from HTML Opengraph attributes. /// Extract site metadata from HTML Opengraph attributes.
fn extract_opengraph_data(html_bytes: &[u8], url: &Url) -> Result<OpenGraphData, LemmyError> { fn extract_opengraph_data(html_bytes: &[u8], url: &Url) -> LemmyResult<OpenGraphData> {
let html = String::from_utf8_lossy(html_bytes); let html = String::from_utf8_lossy(html_bytes);
// Make sure the first line is doctype html // Make sure the first line is doctype html
@ -240,10 +240,7 @@ struct PictrsPurgeResponse {
/// - It might fail due to image being not local /// - It might fail due to image being not local
/// - It might not be an image /// - It might not be an image
/// - Pictrs might not be set up /// - Pictrs might not be set up
pub async fn purge_image_from_pictrs( pub async fn purge_image_from_pictrs(image_url: &Url, context: &LemmyContext) -> LemmyResult<()> {
image_url: &Url,
context: &LemmyContext,
) -> Result<(), LemmyError> {
is_image_content_type(context.client(), image_url).await?; is_image_content_type(context.client(), image_url).await?;
let alias = image_url let alias = image_url
@ -278,7 +275,7 @@ pub async fn delete_image_from_pictrs(
alias: &str, alias: &str,
delete_token: &str, delete_token: &str,
context: &LemmyContext, context: &LemmyContext,
) -> Result<(), LemmyError> { ) -> LemmyResult<()> {
let pictrs_config = context.settings().pictrs_config()?; let pictrs_config = context.settings().pictrs_config()?;
let url = format!( let url = format!(
"{}image/delete/{}/{}", "{}image/delete/{}/{}",
@ -296,10 +293,7 @@ pub async fn delete_image_from_pictrs(
/// Retrieves the image with local pict-rs and generates a thumbnail. Returns the thumbnail url. /// Retrieves the image with local pict-rs and generates a thumbnail. Returns the thumbnail url.
#[tracing::instrument(skip_all)] #[tracing::instrument(skip_all)]
async fn generate_pictrs_thumbnail( async fn generate_pictrs_thumbnail(image_url: &Url, context: &LemmyContext) -> LemmyResult<Url> {
image_url: &Url,
context: &LemmyContext,
) -> Result<Url, LemmyError> {
let pictrs_config = context.settings().pictrs_config()?; let pictrs_config = context.settings().pictrs_config()?;
match pictrs_config.image_mode() { match pictrs_config.image_mode() {
@ -349,7 +343,7 @@ async fn generate_pictrs_thumbnail(
// TODO: get rid of this by reading content type from db // TODO: get rid of this by reading content type from db
#[tracing::instrument(skip_all)] #[tracing::instrument(skip_all)]
async fn is_image_content_type(client: &ClientWithMiddleware, url: &Url) -> Result<(), LemmyError> { async fn is_image_content_type(client: &ClientWithMiddleware, url: &Url) -> LemmyResult<()> {
let response = client.get(url.as_str()).send().await?; let response = client.get(url.as_str()).send().await?;
if response if response
.headers() .headers()
@ -369,7 +363,7 @@ pub async fn replace_image(
new_image: &Option<String>, new_image: &Option<String>,
old_image: &Option<DbUrl>, old_image: &Option<DbUrl>,
context: &Data<LemmyContext>, context: &Data<LemmyContext>,
) -> Result<(), LemmyError> { ) -> LemmyResult<()> {
if new_image.is_some() { if new_image.is_some() {
// Ignore errors because image may be stored externally. // Ignore errors because image may be stored externally.
if let Some(avatar) = &old_image { if let Some(avatar) = &old_image {

View file

@ -60,7 +60,7 @@ pub async fn is_mod_or_admin(
pool: &mut DbPool<'_>, pool: &mut DbPool<'_>,
person: &Person, person: &Person,
community_id: CommunityId, community_id: CommunityId,
) -> Result<(), LemmyError> { ) -> LemmyResult<()> {
check_user_valid(person)?; check_user_valid(person)?;
let is_mod_or_admin = CommunityView::is_mod_or_admin(pool, person.id, community_id).await?; let is_mod_or_admin = CommunityView::is_mod_or_admin(pool, person.id, community_id).await?;
@ -76,7 +76,7 @@ pub async fn is_mod_or_admin_opt(
pool: &mut DbPool<'_>, pool: &mut DbPool<'_>,
local_user_view: Option<&LocalUserView>, local_user_view: Option<&LocalUserView>,
community_id: Option<CommunityId>, community_id: Option<CommunityId>,
) -> Result<(), LemmyError> { ) -> LemmyResult<()> {
if let Some(local_user_view) = local_user_view { if let Some(local_user_view) = local_user_view {
if let Some(community_id) = community_id { if let Some(community_id) = community_id {
is_mod_or_admin(pool, &local_user_view.person, community_id).await is_mod_or_admin(pool, &local_user_view.person, community_id).await
@ -108,7 +108,7 @@ pub async fn check_community_mod_of_any_or_admin_action(
} }
} }
pub fn is_admin(local_user_view: &LocalUserView) -> Result<(), LemmyError> { pub fn is_admin(local_user_view: &LocalUserView) -> LemmyResult<()> {
check_user_valid(&local_user_view.person)?; check_user_valid(&local_user_view.person)?;
if !local_user_view.local_user.admin { if !local_user_view.local_user.admin {
Err(LemmyErrorType::NotAnAdmin)? Err(LemmyErrorType::NotAnAdmin)?
@ -122,7 +122,7 @@ pub fn is_admin(local_user_view: &LocalUserView) -> Result<(), LemmyError> {
pub fn is_top_mod( pub fn is_top_mod(
local_user_view: &LocalUserView, local_user_view: &LocalUserView,
community_mods: &[CommunityModeratorView], community_mods: &[CommunityModeratorView],
) -> Result<(), LemmyError> { ) -> LemmyResult<()> {
check_user_valid(&local_user_view.person)?; check_user_valid(&local_user_view.person)?;
if local_user_view.person.id if local_user_view.person.id
!= community_mods != community_mods
@ -137,7 +137,7 @@ pub fn is_top_mod(
} }
#[tracing::instrument(skip_all)] #[tracing::instrument(skip_all)]
pub async fn get_post(post_id: PostId, pool: &mut DbPool<'_>) -> Result<Post, LemmyError> { pub async fn get_post(post_id: PostId, pool: &mut DbPool<'_>) -> LemmyResult<Post> {
Post::read(pool, post_id) Post::read(pool, post_id)
.await .await
.with_lemmy_type(LemmyErrorType::CouldntFindPost) .with_lemmy_type(LemmyErrorType::CouldntFindPost)
@ -148,14 +148,14 @@ pub async fn mark_post_as_read(
person_id: PersonId, person_id: PersonId,
post_id: PostId, post_id: PostId,
pool: &mut DbPool<'_>, pool: &mut DbPool<'_>,
) -> Result<(), LemmyError> { ) -> LemmyResult<()> {
PostRead::mark_as_read(pool, HashSet::from([post_id]), person_id) PostRead::mark_as_read(pool, HashSet::from([post_id]), person_id)
.await .await
.with_lemmy_type(LemmyErrorType::CouldntMarkPostAsRead)?; .with_lemmy_type(LemmyErrorType::CouldntMarkPostAsRead)?;
Ok(()) Ok(())
} }
pub fn check_user_valid(person: &Person) -> Result<(), LemmyError> { pub fn check_user_valid(person: &Person) -> LemmyResult<()> {
// Check for a site ban // Check for a site ban
if person.banned { if person.banned {
Err(LemmyErrorType::SiteBan)? Err(LemmyErrorType::SiteBan)?
@ -230,7 +230,7 @@ pub async fn check_community_mod_action(
} }
/// Don't allow creating reports for removed / deleted posts /// Don't allow creating reports for removed / deleted posts
pub fn check_post_deleted_or_removed(post: &Post) -> Result<(), LemmyError> { pub fn check_post_deleted_or_removed(post: &Post) -> LemmyResult<()> {
if post.deleted || post.removed { if post.deleted || post.removed {
Err(LemmyErrorType::Deleted)? Err(LemmyErrorType::Deleted)?
} else { } else {
@ -238,7 +238,7 @@ pub fn check_post_deleted_or_removed(post: &Post) -> Result<(), LemmyError> {
} }
} }
pub fn check_comment_deleted_or_removed(comment: &Comment) -> Result<(), LemmyError> { pub fn check_comment_deleted_or_removed(comment: &Comment) -> LemmyResult<()> {
if comment.deleted || comment.removed { if comment.deleted || comment.removed {
Err(LemmyErrorType::Deleted)? Err(LemmyErrorType::Deleted)?
} else { } else {
@ -252,7 +252,7 @@ pub async fn check_person_block(
my_id: PersonId, my_id: PersonId,
potential_blocker_id: PersonId, potential_blocker_id: PersonId,
pool: &mut DbPool<'_>, pool: &mut DbPool<'_>,
) -> Result<(), LemmyError> { ) -> LemmyResult<()> {
let is_blocked = PersonBlock::read(pool, potential_blocker_id, my_id).await?; let is_blocked = PersonBlock::read(pool, potential_blocker_id, my_id).await?;
if is_blocked { if is_blocked {
Err(LemmyErrorType::PersonIsBlocked)? Err(LemmyErrorType::PersonIsBlocked)?
@ -267,7 +267,7 @@ async fn check_community_block(
community_id: CommunityId, community_id: CommunityId,
person_id: PersonId, person_id: PersonId,
pool: &mut DbPool<'_>, pool: &mut DbPool<'_>,
) -> Result<(), LemmyError> { ) -> LemmyResult<()> {
let is_blocked = CommunityBlock::read(pool, person_id, community_id).await?; let is_blocked = CommunityBlock::read(pool, person_id, community_id).await?;
if is_blocked { if is_blocked {
Err(LemmyErrorType::CommunityIsBlocked)? Err(LemmyErrorType::CommunityIsBlocked)?
@ -282,7 +282,7 @@ async fn check_instance_block(
instance_id: InstanceId, instance_id: InstanceId,
person_id: PersonId, person_id: PersonId,
pool: &mut DbPool<'_>, pool: &mut DbPool<'_>,
) -> Result<(), LemmyError> { ) -> LemmyResult<()> {
let is_blocked = InstanceBlock::read(pool, person_id, instance_id).await?; let is_blocked = InstanceBlock::read(pool, person_id, instance_id).await?;
if is_blocked { if is_blocked {
Err(LemmyErrorType::InstanceIsBlocked)? Err(LemmyErrorType::InstanceIsBlocked)?
@ -298,7 +298,7 @@ pub async fn check_person_instance_community_block(
community_instance_id: InstanceId, community_instance_id: InstanceId,
community_id: CommunityId, community_id: CommunityId,
pool: &mut DbPool<'_>, pool: &mut DbPool<'_>,
) -> Result<(), LemmyError> { ) -> LemmyResult<()> {
check_person_block(my_id, potential_blocker_id, pool).await?; check_person_block(my_id, potential_blocker_id, pool).await?;
check_instance_block(community_instance_id, potential_blocker_id, pool).await?; check_instance_block(community_instance_id, potential_blocker_id, pool).await?;
check_community_block(community_id, potential_blocker_id, pool).await?; check_community_block(community_id, potential_blocker_id, pool).await?;
@ -306,7 +306,7 @@ pub async fn check_person_instance_community_block(
} }
#[tracing::instrument(skip_all)] #[tracing::instrument(skip_all)]
pub fn check_downvotes_enabled(score: i16, local_site: &LocalSite) -> Result<(), LemmyError> { pub fn check_downvotes_enabled(score: i16, local_site: &LocalSite) -> LemmyResult<()> {
if score == -1 && !local_site.enable_downvotes { if score == -1 && !local_site.enable_downvotes {
Err(LemmyErrorType::DownvotesAreDisabled)? Err(LemmyErrorType::DownvotesAreDisabled)?
} else { } else {
@ -316,7 +316,7 @@ pub fn check_downvotes_enabled(score: i16, local_site: &LocalSite) -> Result<(),
/// Dont allow bots to do certain actions, like voting /// Dont allow bots to do certain actions, like voting
#[tracing::instrument(skip_all)] #[tracing::instrument(skip_all)]
pub fn check_bot_account(person: &Person) -> Result<(), LemmyError> { pub fn check_bot_account(person: &Person) -> LemmyResult<()> {
if person.bot_account { if person.bot_account {
Err(LemmyErrorType::InvalidBotAction)? Err(LemmyErrorType::InvalidBotAction)?
} else { } else {
@ -328,7 +328,7 @@ pub fn check_bot_account(person: &Person) -> Result<(), LemmyError> {
pub fn check_private_instance( pub fn check_private_instance(
local_user_view: &Option<LocalUserView>, local_user_view: &Option<LocalUserView>,
local_site: &LocalSite, local_site: &LocalSite,
) -> Result<(), LemmyError> { ) -> LemmyResult<()> {
if local_user_view.is_none() && local_site.private_instance { if local_user_view.is_none() && local_site.private_instance {
Err(LemmyErrorType::InstanceIsPrivate)? Err(LemmyErrorType::InstanceIsPrivate)?
} else { } else {
@ -340,7 +340,7 @@ pub fn check_private_instance(
pub async fn build_federated_instances( pub async fn build_federated_instances(
local_site: &LocalSite, local_site: &LocalSite,
pool: &mut DbPool<'_>, pool: &mut DbPool<'_>,
) -> Result<Option<FederatedInstances>, LemmyError> { ) -> LemmyResult<Option<FederatedInstances>> {
if local_site.federation_enabled { if local_site.federation_enabled {
let mut linked = Vec::new(); let mut linked = Vec::new();
let mut allowed = Vec::new(); let mut allowed = Vec::new();
@ -375,7 +375,7 @@ pub async fn build_federated_instances(
} }
/// Checks the password length /// Checks the password length
pub fn password_length_check(pass: &str) -> Result<(), LemmyError> { pub fn password_length_check(pass: &str) -> LemmyResult<()> {
if !(10..=60).contains(&pass.chars().count()) { if !(10..=60).contains(&pass.chars().count()) {
Err(LemmyErrorType::InvalidPassword)? Err(LemmyErrorType::InvalidPassword)?
} else { } else {
@ -384,7 +384,7 @@ pub fn password_length_check(pass: &str) -> Result<(), LemmyError> {
} }
/// Checks for a honeypot. If this field is filled, fail the rest of the function /// Checks for a honeypot. If this field is filled, fail the rest of the function
pub fn honeypot_check(honeypot: &Option<String>) -> Result<(), LemmyError> { pub fn honeypot_check(honeypot: &Option<String>) -> LemmyResult<()> {
if honeypot.is_some() && honeypot != &Some(String::new()) { if honeypot.is_some() && honeypot != &Some(String::new()) {
Err(LemmyErrorType::HoneypotFailed)? Err(LemmyErrorType::HoneypotFailed)?
} else { } else {
@ -422,7 +422,7 @@ pub async fn send_password_reset_email(
user: &LocalUserView, user: &LocalUserView,
pool: &mut DbPool<'_>, pool: &mut DbPool<'_>,
settings: &Settings, settings: &Settings,
) -> Result<(), LemmyError> { ) -> LemmyResult<()> {
// Generate a random token // Generate a random token
let token = uuid::Uuid::new_v4().to_string(); let token = uuid::Uuid::new_v4().to_string();
@ -447,7 +447,7 @@ pub async fn send_verification_email(
new_email: &str, new_email: &str,
pool: &mut DbPool<'_>, pool: &mut DbPool<'_>,
settings: &Settings, settings: &Settings,
) -> Result<(), LemmyError> { ) -> LemmyResult<()> {
let form = EmailVerificationForm { let form = EmailVerificationForm {
local_user_id: user.local_user.id, local_user_id: user.local_user.id,
email: new_email.to_string(), email: new_email.to_string(),
@ -564,7 +564,7 @@ pub async fn get_url_blocklist(context: &LemmyContext) -> LemmyResult<RegexSet>
pub async fn send_application_approved_email( pub async fn send_application_approved_email(
user: &LocalUserView, user: &LocalUserView,
settings: &Settings, settings: &Settings,
) -> Result<(), LemmyError> { ) -> LemmyResult<()> {
let email = &user.local_user.email.clone().expect("email"); let email = &user.local_user.email.clone().expect("email");
let lang = get_interface_language(user); let lang = get_interface_language(user);
let subject = lang.registration_approved_subject(&user.person.actor_id); let subject = lang.registration_approved_subject(&user.person.actor_id);
@ -577,7 +577,7 @@ pub async fn send_new_applicant_email_to_admins(
applicant_username: &str, applicant_username: &str,
pool: &mut DbPool<'_>, pool: &mut DbPool<'_>,
settings: &Settings, settings: &Settings,
) -> Result<(), LemmyError> { ) -> LemmyResult<()> {
// Collect the admins with emails // Collect the admins with emails
let admins = LocalUserView::list_admins_with_emails(pool).await?; let admins = LocalUserView::list_admins_with_emails(pool).await?;
@ -602,7 +602,7 @@ pub async fn send_new_report_email_to_admins(
reported_username: &str, reported_username: &str,
pool: &mut DbPool<'_>, pool: &mut DbPool<'_>,
settings: &Settings, settings: &Settings,
) -> Result<(), LemmyError> { ) -> LemmyResult<()> {
// Collect the admins with emails // Collect the admins with emails
let admins = LocalUserView::list_admins_with_emails(pool).await?; let admins = LocalUserView::list_admins_with_emails(pool).await?;
@ -618,9 +618,7 @@ pub async fn send_new_report_email_to_admins(
Ok(()) Ok(())
} }
pub fn check_private_instance_and_federation_enabled( pub fn check_private_instance_and_federation_enabled(local_site: &LocalSite) -> LemmyResult<()> {
local_site: &LocalSite,
) -> Result<(), LemmyError> {
if local_site.private_instance && local_site.federation_enabled { if local_site.private_instance && local_site.federation_enabled {
Err(LemmyErrorType::CantEnablePrivateInstanceAndFederationTogether)? Err(LemmyErrorType::CantEnablePrivateInstanceAndFederationTogether)?
} else { } else {
@ -634,7 +632,7 @@ pub fn check_private_instance_and_federation_enabled(
pub async fn read_site_for_actor( pub async fn read_site_for_actor(
actor_id: DbUrl, actor_id: DbUrl,
context: &LemmyContext, context: &LemmyContext,
) -> Result<Option<Site>, LemmyError> { ) -> LemmyResult<Option<Site>> {
let site_id = Site::instance_actor_id_from_url(actor_id.clone().into()); let site_id = Site::instance_actor_id_from_url(actor_id.clone().into());
let site = Site::read_from_apub_id(&mut context.pool(), &site_id.into()).await?; let site = Site::read_from_apub_id(&mut context.pool(), &site_id.into()).await?;
Ok(site) Ok(site)
@ -643,7 +641,7 @@ pub async fn read_site_for_actor(
pub async fn purge_image_posts_for_person( pub async fn purge_image_posts_for_person(
banned_person_id: PersonId, banned_person_id: PersonId,
context: &LemmyContext, context: &LemmyContext,
) -> Result<(), LemmyError> { ) -> LemmyResult<()> {
let pool = &mut context.pool(); let pool = &mut context.pool();
let posts = Post::fetch_pictrs_posts_for_creator(pool, banned_person_id).await?; let posts = Post::fetch_pictrs_posts_for_creator(pool, banned_person_id).await?;
for post in posts { for post in posts {
@ -661,10 +659,7 @@ pub async fn purge_image_posts_for_person(
} }
/// Delete a local_user's images /// Delete a local_user's images
async fn delete_local_user_images( async fn delete_local_user_images(person_id: PersonId, context: &LemmyContext) -> LemmyResult<()> {
person_id: PersonId,
context: &LemmyContext,
) -> Result<(), LemmyError> {
if let Ok(local_user) = LocalUserView::read_person(&mut context.pool(), person_id).await { if let Ok(local_user) = LocalUserView::read_person(&mut context.pool(), person_id).await {
let pictrs_uploads = let pictrs_uploads =
LocalImage::get_all_by_local_user_id(&mut context.pool(), local_user.local_user.id).await?; LocalImage::get_all_by_local_user_id(&mut context.pool(), local_user.local_user.id).await?;
@ -682,7 +677,7 @@ async fn delete_local_user_images(
pub async fn purge_image_posts_for_community( pub async fn purge_image_posts_for_community(
banned_community_id: CommunityId, banned_community_id: CommunityId,
context: &LemmyContext, context: &LemmyContext,
) -> Result<(), LemmyError> { ) -> LemmyResult<()> {
let pool = &mut context.pool(); let pool = &mut context.pool();
let posts = Post::fetch_pictrs_posts_for_community(pool, banned_community_id).await?; let posts = Post::fetch_pictrs_posts_for_community(pool, banned_community_id).await?;
for post in posts { for post in posts {
@ -702,7 +697,7 @@ pub async fn purge_image_posts_for_community(
pub async fn remove_user_data( pub async fn remove_user_data(
banned_person_id: PersonId, banned_person_id: PersonId,
context: &LemmyContext, context: &LemmyContext,
) -> Result<(), LemmyError> { ) -> LemmyResult<()> {
let pool = &mut context.pool(); let pool = &mut context.pool();
// Purge user images // Purge user images
let person = Person::read(pool, banned_person_id).await?; let person = Person::read(pool, banned_person_id).await?;
@ -785,7 +780,7 @@ pub async fn remove_user_data_in_community(
community_id: CommunityId, community_id: CommunityId,
banned_person_id: PersonId, banned_person_id: PersonId,
pool: &mut DbPool<'_>, pool: &mut DbPool<'_>,
) -> Result<(), LemmyError> { ) -> LemmyResult<()> {
// Posts // Posts
Post::update_removed_for_creator(pool, banned_person_id, Some(community_id), true).await?; Post::update_removed_for_creator(pool, banned_person_id, Some(community_id), true).await?;
@ -815,10 +810,7 @@ pub async fn remove_user_data_in_community(
Ok(()) Ok(())
} }
pub async fn purge_user_account( pub async fn purge_user_account(person_id: PersonId, context: &LemmyContext) -> LemmyResult<()> {
person_id: PersonId,
context: &LemmyContext,
) -> Result<(), LemmyError> {
let pool = &mut context.pool(); let pool = &mut context.pool();
let person = Person::read(pool, person_id).await?; let person = Person::read(pool, person_id).await?;
@ -888,7 +880,7 @@ pub fn generate_inbox_url(actor_id: &DbUrl) -> Result<DbUrl, ParseError> {
Ok(Url::parse(&format!("{actor_id}/inbox"))?.into()) Ok(Url::parse(&format!("{actor_id}/inbox"))?.into())
} }
pub fn generate_shared_inbox_url(settings: &Settings) -> Result<DbUrl, LemmyError> { pub fn generate_shared_inbox_url(settings: &Settings) -> LemmyResult<DbUrl> {
let url = format!("{}/inbox", settings.get_protocol_and_hostname()); let url = format!("{}/inbox", settings.get_protocol_and_hostname());
Ok(Url::parse(&url)?.into()) Ok(Url::parse(&url)?.into())
} }
@ -901,7 +893,7 @@ pub fn generate_featured_url(actor_id: &DbUrl) -> Result<DbUrl, ParseError> {
Ok(Url::parse(&format!("{actor_id}/featured"))?.into()) Ok(Url::parse(&format!("{actor_id}/featured"))?.into())
} }
pub fn generate_moderators_url(community_id: &DbUrl) -> Result<DbUrl, LemmyError> { pub fn generate_moderators_url(community_id: &DbUrl) -> LemmyResult<DbUrl> {
Ok(Url::parse(&format!("{community_id}/moderators"))?.into()) Ok(Url::parse(&format!("{community_id}/moderators"))?.into())
} }

View file

@ -30,7 +30,7 @@ use lemmy_db_schema::{
}; };
use lemmy_db_views::structs::LocalUserView; use lemmy_db_views::structs::LocalUserView;
use lemmy_utils::{ use lemmy_utils::{
error::{LemmyError, LemmyErrorExt, LemmyErrorType}, error::{LemmyErrorExt, LemmyErrorType, LemmyResult},
utils::{mention::scrape_text_for_mentions, validation::is_valid_body_field}, utils::{mention::scrape_text_for_mentions, validation::is_valid_body_field},
}; };
@ -41,7 +41,7 @@ pub async fn create_comment(
data: Json<CreateComment>, data: Json<CreateComment>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<CommentResponse>, LemmyError> { ) -> LemmyResult<Json<CommentResponse>> {
let local_site = LocalSite::read(&mut context.pool()).await?; let local_site = LocalSite::read(&mut context.pool()).await?;
let slur_regex = local_site_to_slur_regex(&local_site); let slur_regex = local_site_to_slur_regex(&local_site);
@ -207,7 +207,7 @@ pub async fn create_comment(
)) ))
} }
pub fn check_comment_depth(comment: &Comment) -> Result<(), LemmyError> { pub fn check_comment_depth(comment: &Comment) -> LemmyResult<()> {
let path = &comment.path.0; let path = &comment.path.0;
let length = path.split('.').count(); let length = path.split('.').count();
if length > MAX_COMMENT_DEPTH_LIMIT { if length > MAX_COMMENT_DEPTH_LIMIT {

View file

@ -12,14 +12,14 @@ use lemmy_db_schema::{
traits::Crud, traits::Crud,
}; };
use lemmy_db_views::structs::{CommentView, LocalUserView}; use lemmy_db_views::structs::{CommentView, LocalUserView};
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult};
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
pub async fn delete_comment( pub async fn delete_comment(
data: Json<DeleteComment>, data: Json<DeleteComment>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<CommentResponse>, LemmyError> { ) -> LemmyResult<Json<CommentResponse>> {
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?;

View file

@ -7,14 +7,14 @@ use lemmy_api_common::{
}; };
use lemmy_db_schema::source::local_site::LocalSite; use lemmy_db_schema::source::local_site::LocalSite;
use lemmy_db_views::structs::LocalUserView; use lemmy_db_views::structs::LocalUserView;
use lemmy_utils::error::LemmyError; use lemmy_utils::error::LemmyResult;
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
pub async fn get_comment( pub async fn get_comment(
data: Query<GetComment>, data: Query<GetComment>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: Option<LocalUserView>, local_user_view: Option<LocalUserView>,
) -> Result<Json<CommentResponse>, LemmyError> { ) -> LemmyResult<Json<CommentResponse>> {
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)?;

View file

@ -16,14 +16,14 @@ use lemmy_db_schema::{
traits::{Crud, Reportable}, traits::{Crud, Reportable},
}; };
use lemmy_db_views::structs::{CommentView, LocalUserView}; use lemmy_db_views::structs::{CommentView, LocalUserView};
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult};
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
pub async fn remove_comment( pub async fn remove_comment(
data: Json<RemoveComment>, data: Json<RemoveComment>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<CommentResponse>, LemmyError> { ) -> LemmyResult<Json<CommentResponse>> {
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?;

View file

@ -23,7 +23,7 @@ use lemmy_db_schema::{
}; };
use lemmy_db_views::structs::{CommentView, LocalUserView}; use lemmy_db_views::structs::{CommentView, LocalUserView};
use lemmy_utils::{ use lemmy_utils::{
error::{LemmyError, LemmyErrorExt, LemmyErrorType}, error::{LemmyErrorExt, LemmyErrorType, LemmyResult},
utils::{mention::scrape_text_for_mentions, validation::is_valid_body_field}, utils::{mention::scrape_text_for_mentions, validation::is_valid_body_field},
}; };
@ -32,7 +32,7 @@ pub async fn update_comment(
data: Json<EditComment>, data: Json<EditComment>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<CommentResponse>, LemmyError> { ) -> LemmyResult<Json<CommentResponse>> {
let local_site = LocalSite::read(&mut context.pool()).await?; let local_site = LocalSite::read(&mut context.pool()).await?;
let comment_id = data.comment_id; let comment_id = data.comment_id;

View file

@ -33,7 +33,7 @@ use lemmy_db_schema::{
}; };
use lemmy_db_views::structs::{LocalUserView, SiteView}; use lemmy_db_views::structs::{LocalUserView, SiteView};
use lemmy_utils::{ use lemmy_utils::{
error::{LemmyError, LemmyErrorExt, LemmyErrorType}, error::{LemmyErrorExt, LemmyErrorType, LemmyResult},
utils::{ utils::{
slurs::check_slurs, slurs::check_slurs,
validation::{is_valid_actor_name, is_valid_body_field}, validation::{is_valid_actor_name, is_valid_body_field},
@ -45,7 +45,7 @@ pub async fn create_community(
data: Json<CreateCommunity>, data: Json<CreateCommunity>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<CommunityResponse>, LemmyError> { ) -> LemmyResult<Json<CommunityResponse>> {
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;

View file

@ -13,14 +13,14 @@ use lemmy_db_schema::{
}; };
use lemmy_db_views::structs::LocalUserView; use lemmy_db_views::structs::LocalUserView;
use lemmy_db_views_actor::structs::CommunityModeratorView; use lemmy_db_views_actor::structs::CommunityModeratorView;
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult};
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
pub async fn delete_community( pub async fn delete_community(
data: Json<DeleteCommunity>, data: Json<DeleteCommunity>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<CommunityResponse>, LemmyError> { ) -> LemmyResult<Json<CommunityResponse>> {
// Fetch the community mods // Fetch the community mods
let community_id = data.community_id; let community_id = data.community_id;
let community_mods = let community_mods =

View file

@ -6,14 +6,14 @@ use lemmy_api_common::{
}; };
use lemmy_db_views::structs::{LocalUserView, SiteView}; use lemmy_db_views::structs::{LocalUserView, SiteView};
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::LemmyResult;
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
pub async fn list_communities( pub async fn list_communities(
data: Query<ListCommunities>, data: Query<ListCommunities>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: Option<LocalUserView>, local_user_view: Option<LocalUserView>,
) -> Result<Json<ListCommunitiesResponse>, LemmyError> { ) -> LemmyResult<Json<ListCommunitiesResponse>> {
let local_site = SiteView::read_local(&mut context.pool()).await?; let local_site = SiteView::read_local(&mut context.pool()).await?;
let is_admin = local_user_view let is_admin = local_user_view
.as_ref() .as_ref()

View file

@ -15,14 +15,14 @@ use lemmy_db_schema::{
traits::Crud, traits::Crud,
}; };
use lemmy_db_views::structs::LocalUserView; use lemmy_db_views::structs::LocalUserView;
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult};
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
pub async fn remove_community( pub async fn remove_community(
data: Json<RemoveCommunity>, data: Json<RemoveCommunity>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<CommunityResponse>, LemmyError> { ) -> LemmyResult<Json<CommunityResponse>> {
check_community_mod_action( check_community_mod_action(
&local_user_view.person, &local_user_view.person,
data.community_id, data.community_id,

View file

@ -25,7 +25,7 @@ use lemmy_db_schema::{
}; };
use lemmy_db_views::structs::LocalUserView; use lemmy_db_views::structs::LocalUserView;
use lemmy_utils::{ use lemmy_utils::{
error::{LemmyError, LemmyErrorExt, LemmyErrorType}, error::{LemmyErrorExt, LemmyErrorType, LemmyResult},
utils::{slurs::check_slurs_opt, validation::is_valid_body_field}, utils::{slurs::check_slurs_opt, validation::is_valid_body_field},
}; };
@ -34,7 +34,7 @@ pub async fn update_community(
data: Json<EditCommunity>, data: Json<EditCommunity>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<CommunityResponse>, LemmyError> { ) -> LemmyResult<Json<CommunityResponse>> {
let local_site = LocalSite::read(&mut context.pool()).await?; let local_site = LocalSite::read(&mut context.pool()).await?;
let slur_regex = local_site_to_slur_regex(&local_site); let slur_regex = local_site_to_slur_regex(&local_site);

View file

@ -11,14 +11,14 @@ use lemmy_db_schema::source::{
local_site::LocalSite, local_site::LocalSite,
}; };
use lemmy_db_views::structs::{CustomEmojiView, LocalUserView}; use lemmy_db_views::structs::{CustomEmojiView, LocalUserView};
use lemmy_utils::error::LemmyError; use lemmy_utils::error::LemmyResult;
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
pub async fn create_custom_emoji( pub async fn create_custom_emoji(
data: Json<CreateCustomEmoji>, data: Json<CreateCustomEmoji>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<CustomEmojiResponse>, LemmyError> { ) -> LemmyResult<Json<CustomEmojiResponse>> {
let local_site = LocalSite::read(&mut context.pool()).await?; let local_site = LocalSite::read(&mut context.pool()).await?;
// Make sure user is an admin // Make sure user is an admin
is_admin(&local_user_view)?; is_admin(&local_user_view)?;

View file

@ -8,14 +8,14 @@ use lemmy_api_common::{
}; };
use lemmy_db_schema::source::custom_emoji::CustomEmoji; use lemmy_db_schema::source::custom_emoji::CustomEmoji;
use lemmy_db_views::structs::LocalUserView; use lemmy_db_views::structs::LocalUserView;
use lemmy_utils::error::LemmyError; use lemmy_utils::error::LemmyResult;
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
pub async fn delete_custom_emoji( pub async fn delete_custom_emoji(
data: Json<DeleteCustomEmoji>, data: Json<DeleteCustomEmoji>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<SuccessResponse>, LemmyError> { ) -> LemmyResult<Json<SuccessResponse>> {
// Make sure user is an admin // Make sure user is an admin
is_admin(&local_user_view)?; is_admin(&local_user_view)?;

View file

@ -11,14 +11,14 @@ use lemmy_db_schema::source::{
local_site::LocalSite, local_site::LocalSite,
}; };
use lemmy_db_views::structs::{CustomEmojiView, LocalUserView}; use lemmy_db_views::structs::{CustomEmojiView, LocalUserView};
use lemmy_utils::error::LemmyError; use lemmy_utils::error::LemmyResult;
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
pub async fn update_custom_emoji( pub async fn update_custom_emoji(
data: Json<EditCustomEmoji>, data: Json<EditCustomEmoji>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<CustomEmojiResponse>, LemmyError> { ) -> LemmyResult<Json<CustomEmojiResponse>> {
let local_site = LocalSite::read(&mut context.pool()).await?; let local_site = LocalSite::read(&mut context.pool()).await?;
// Make sure user is an admin // Make sure user is an admin
is_admin(&local_user_view)?; is_admin(&local_user_view)?;

View file

@ -32,7 +32,7 @@ use lemmy_db_schema::{
use lemmy_db_views::structs::LocalUserView; use lemmy_db_views::structs::LocalUserView;
use lemmy_db_views_actor::structs::CommunityModeratorView; use lemmy_db_views_actor::structs::CommunityModeratorView;
use lemmy_utils::{ use lemmy_utils::{
error::{LemmyError, LemmyErrorExt, LemmyErrorType}, error::{LemmyErrorExt, LemmyErrorType, LemmyResult},
spawn_try_task, spawn_try_task,
utils::{ utils::{
slurs::check_slurs, slurs::check_slurs,
@ -55,7 +55,7 @@ pub async fn create_post(
data: Json<CreatePost>, data: Json<CreatePost>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<PostResponse>, LemmyError> { ) -> LemmyResult<Json<PostResponse>> {
let local_site = LocalSite::read(&mut context.pool()).await?; let local_site = LocalSite::read(&mut context.pool()).await?;
honeypot_check(&data.honeypot)?; honeypot_check(&data.honeypot)?;

View file

@ -12,14 +12,14 @@ use lemmy_db_schema::{
traits::Crud, traits::Crud,
}; };
use lemmy_db_views::structs::LocalUserView; use lemmy_db_views::structs::LocalUserView;
use lemmy_utils::error::{LemmyError, LemmyErrorType}; use lemmy_utils::error::{LemmyErrorType, LemmyResult};
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
pub async fn delete_post( pub async fn delete_post(
data: Json<DeletePost>, data: Json<DeletePost>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<PostResponse>, LemmyError> { ) -> LemmyResult<Json<PostResponse>> {
let post_id = data.post_id; let post_id = data.post_id;
let orig_post = Post::read(&mut context.pool(), post_id).await?; let orig_post = Post::read(&mut context.pool(), post_id).await?;

View file

@ -14,14 +14,14 @@ use lemmy_db_views::{
structs::{LocalUserView, PostView, SiteView}, structs::{LocalUserView, PostView, SiteView},
}; };
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::{LemmyErrorExt, LemmyErrorType, LemmyResult};
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
pub async fn get_post( pub async fn get_post(
data: Query<GetPost>, data: Query<GetPost>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: Option<LocalUserView>, local_user_view: Option<LocalUserView>,
) -> Result<Json<GetPostResponse>, LemmyError> { ) -> LemmyResult<Json<GetPostResponse>> {
let local_site = SiteView::read_local(&mut context.pool()).await?; let local_site = SiteView::read_local(&mut context.pool()).await?;
check_private_instance(&local_user_view, &local_site.local_site)?; check_private_instance(&local_user_view, &local_site.local_site)?;

View file

@ -16,14 +16,14 @@ use lemmy_db_schema::{
traits::{Crud, Reportable}, traits::{Crud, Reportable},
}; };
use lemmy_db_views::structs::LocalUserView; use lemmy_db_views::structs::LocalUserView;
use lemmy_utils::error::LemmyError; use lemmy_utils::error::LemmyResult;
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
pub async fn remove_post( pub async fn remove_post(
data: Json<RemovePost>, data: Json<RemovePost>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<PostResponse>, LemmyError> { ) -> LemmyResult<Json<PostResponse>> {
let post_id = data.post_id; let post_id = data.post_id;
let orig_post = Post::read(&mut context.pool(), post_id).await?; let orig_post = Post::read(&mut context.pool(), post_id).await?;

View file

@ -25,7 +25,7 @@ use lemmy_db_schema::{
}; };
use lemmy_db_views::structs::LocalUserView; use lemmy_db_views::structs::LocalUserView;
use lemmy_utils::{ use lemmy_utils::{
error::{LemmyError, LemmyErrorExt, LemmyErrorType}, error::{LemmyErrorExt, LemmyErrorType, LemmyResult},
utils::{ utils::{
slurs::check_slurs_opt, slurs::check_slurs_opt,
validation::{ validation::{
@ -45,7 +45,7 @@ pub async fn update_post(
data: Json<EditPost>, data: Json<EditPost>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<PostResponse>, LemmyError> { ) -> LemmyResult<Json<PostResponse>> {
let local_site = LocalSite::read(&mut context.pool()).await?; let local_site = LocalSite::read(&mut context.pool()).await?;
// TODO No good way to handle a clear. // TODO No good way to handle a clear.

View file

@ -24,7 +24,7 @@ use lemmy_db_schema::{
}; };
use lemmy_db_views::structs::{LocalUserView, PrivateMessageView}; use lemmy_db_views::structs::{LocalUserView, PrivateMessageView};
use lemmy_utils::{ use lemmy_utils::{
error::{LemmyError, LemmyErrorExt, LemmyErrorType}, error::{LemmyErrorExt, LemmyErrorType, LemmyResult},
utils::{markdown::markdown_to_html, validation::is_valid_body_field}, utils::{markdown::markdown_to_html, validation::is_valid_body_field},
}; };
@ -33,7 +33,7 @@ pub async fn create_private_message(
data: Json<CreatePrivateMessage>, data: Json<CreatePrivateMessage>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<PrivateMessageResponse>, LemmyError> { ) -> LemmyResult<Json<PrivateMessageResponse>> {
let local_site = LocalSite::read(&mut context.pool()).await?; let local_site = LocalSite::read(&mut context.pool()).await?;
let slur_regex = local_site_to_slur_regex(&local_site); let slur_regex = local_site_to_slur_regex(&local_site);

View file

@ -10,14 +10,14 @@ use lemmy_db_schema::{
traits::Crud, traits::Crud,
}; };
use lemmy_db_views::structs::{LocalUserView, PrivateMessageView}; use lemmy_db_views::structs::{LocalUserView, PrivateMessageView};
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult};
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
pub async fn delete_private_message( pub async fn delete_private_message(
data: Json<DeletePrivateMessage>, data: Json<DeletePrivateMessage>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<PrivateMessageResponse>, LemmyError> { ) -> LemmyResult<Json<PrivateMessageResponse>> {
// Checking permissions // Checking permissions
let private_message_id = data.private_message_id; 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?;

View file

@ -4,14 +4,14 @@ use lemmy_api_common::{
private_message::{GetPrivateMessages, PrivateMessagesResponse}, private_message::{GetPrivateMessages, PrivateMessagesResponse},
}; };
use lemmy_db_views::{private_message_view::PrivateMessageQuery, structs::LocalUserView}; use lemmy_db_views::{private_message_view::PrivateMessageQuery, structs::LocalUserView};
use lemmy_utils::error::LemmyError; use lemmy_utils::error::LemmyResult;
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
pub async fn get_private_message( pub async fn get_private_message(
data: Query<GetPrivateMessages>, data: Query<GetPrivateMessages>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<PrivateMessagesResponse>, LemmyError> { ) -> LemmyResult<Json<PrivateMessagesResponse>> {
let person_id = local_user_view.person.id; let person_id = local_user_view.person.id;
let page = data.page; let page = data.page;

View file

@ -16,7 +16,7 @@ use lemmy_db_schema::{
}; };
use lemmy_db_views::structs::{LocalUserView, PrivateMessageView}; use lemmy_db_views::structs::{LocalUserView, PrivateMessageView};
use lemmy_utils::{ use lemmy_utils::{
error::{LemmyError, LemmyErrorExt, LemmyErrorType}, error::{LemmyErrorExt, LemmyErrorType, LemmyResult},
utils::validation::is_valid_body_field, utils::validation::is_valid_body_field,
}; };
@ -25,7 +25,7 @@ pub async fn update_private_message(
data: Json<EditPrivateMessage>, data: Json<EditPrivateMessage>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<PrivateMessageResponse>, LemmyError> { ) -> LemmyResult<Json<PrivateMessageResponse>> {
let local_site = LocalSite::read(&mut context.pool()).await?; let local_site = LocalSite::read(&mut context.pool()).await?;
// Checking permissions // Checking permissions

View file

@ -27,7 +27,7 @@ use lemmy_db_schema::{
}; };
use lemmy_db_views::structs::{LocalUserView, SiteView}; use lemmy_db_views::structs::{LocalUserView, SiteView};
use lemmy_utils::{ use lemmy_utils::{
error::{LemmyError, LemmyErrorType, LemmyResult}, error::{LemmyErrorType, LemmyResult},
utils::{ utils::{
slurs::{check_slurs, check_slurs_opt}, slurs::{check_slurs, check_slurs_opt},
validation::{ validation::{
@ -46,7 +46,7 @@ pub async fn create_site(
data: Json<CreateSite>, data: Json<CreateSite>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<SiteResponse>, LemmyError> { ) -> LemmyResult<Json<SiteResponse>> {
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...

View file

@ -19,7 +19,7 @@ use lemmy_db_views_actor::structs::{
PersonView, PersonView,
}; };
use lemmy_utils::{ use lemmy_utils::{
error::{LemmyError, LemmyErrorExt, LemmyErrorType}, error::{LemmyError, LemmyErrorExt, LemmyErrorType, LemmyResult},
CACHE_DURATION_API, CACHE_DURATION_API,
VERSION, VERSION,
}; };
@ -30,7 +30,7 @@ use once_cell::sync::Lazy;
pub async fn get_site( pub async fn get_site(
local_user_view: Option<LocalUserView>, local_user_view: Option<LocalUserView>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
) -> Result<Json<GetSiteResponse>, LemmyError> { ) -> LemmyResult<Json<GetSiteResponse>> {
static CACHE: Lazy<Cache<(), GetSiteResponse>> = Lazy::new(|| { static CACHE: Lazy<Cache<(), GetSiteResponse>> = Lazy::new(|| {
Cache::builder() Cache::builder()
.max_capacity(1) .max_capacity(1)

View file

@ -32,7 +32,7 @@ use lemmy_db_schema::{
}; };
use lemmy_db_views::structs::{LocalUserView, SiteView}; use lemmy_db_views::structs::{LocalUserView, SiteView};
use lemmy_utils::{ use lemmy_utils::{
error::{LemmyError, LemmyErrorExt, LemmyErrorType, LemmyResult}, error::{LemmyErrorExt, LemmyErrorType, LemmyResult},
utils::{ utils::{
slurs::check_slurs_opt, slurs::check_slurs_opt,
validation::{ validation::{
@ -51,7 +51,7 @@ pub async fn update_site(
data: Json<EditSite>, data: Json<EditSite>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<SiteResponse>, LemmyError> { ) -> LemmyResult<Json<SiteResponse>> {
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;

View file

@ -31,7 +31,7 @@ use lemmy_db_schema::{
}; };
use lemmy_db_views::structs::{LocalUserView, SiteView}; use lemmy_db_views::structs::{LocalUserView, SiteView};
use lemmy_utils::{ use lemmy_utils::{
error::{LemmyError, LemmyErrorExt, LemmyErrorType}, error::{LemmyErrorExt, LemmyErrorType, LemmyResult},
utils::{ utils::{
slurs::{check_slurs, check_slurs_opt}, slurs::{check_slurs, check_slurs_opt},
validation::is_valid_actor_name, validation::is_valid_actor_name,
@ -44,7 +44,7 @@ pub async fn register(
data: Json<Register>, data: Json<Register>,
req: HttpRequest, req: HttpRequest,
context: Data<LemmyContext>, context: Data<LemmyContext>,
) -> Result<Json<LoginResponse>, LemmyError> { ) -> LemmyResult<Json<LoginResponse>> {
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 require_registration_application = let require_registration_application =

View file

@ -39,7 +39,7 @@ use lemmy_db_schema::{
}, },
traits::{Bannable, Crud, Followable}, traits::{Bannable, Crud, Followable},
}; };
use lemmy_utils::error::LemmyError; use lemmy_utils::error::{LemmyError, LemmyResult};
use url::Url; use url::Url;
impl BlockUser { impl BlockUser {
@ -51,7 +51,7 @@ impl BlockUser {
reason: Option<String>, reason: Option<String>,
expires: Option<DateTime<Utc>>, expires: Option<DateTime<Utc>>,
context: &Data<LemmyContext>, context: &Data<LemmyContext>,
) -> Result<BlockUser, LemmyError> { ) -> LemmyResult<BlockUser> {
let audience = if let SiteOrCommunity::Community(c) = target { let audience = if let SiteOrCommunity::Community(c) = target {
Some(c.id().into()) Some(c.id().into())
} else { } else {
@ -85,7 +85,7 @@ impl BlockUser {
reason: Option<String>, reason: Option<String>,
expires: Option<DateTime<Utc>>, expires: Option<DateTime<Utc>>,
context: &Data<LemmyContext>, context: &Data<LemmyContext>,
) -> Result<(), LemmyError> { ) -> LemmyResult<()> {
let block = BlockUser::new( let block = BlockUser::new(
target, target,
user, user,
@ -125,7 +125,7 @@ impl ActivityHandler for BlockUser {
} }
#[tracing::instrument(skip_all)] #[tracing::instrument(skip_all)]
async fn verify(&self, context: &Data<LemmyContext>) -> Result<(), LemmyError> { async fn verify(&self, context: &Data<LemmyContext>) -> LemmyResult<()> {
verify_is_public(&self.to, &self.cc)?; verify_is_public(&self.to, &self.cc)?;
match self.target.dereference(context).await? { match self.target.dereference(context).await? {
SiteOrCommunity::Site(site) => { SiteOrCommunity::Site(site) => {
@ -148,7 +148,7 @@ impl ActivityHandler for BlockUser {
} }
#[tracing::instrument(skip_all)] #[tracing::instrument(skip_all)]
async fn receive(self, context: &Data<LemmyContext>) -> Result<(), LemmyError> { async fn receive(self, context: &Data<LemmyContext>) -> LemmyResult<()> {
insert_received_activity(&self.id, context).await?; insert_received_activity(&self.id, context).await?;
let expires = self.expires.or(self.end_time).map(Into::into); let expires = self.expires.or(self.end_time).map(Into::into);
let mod_person = self.actor.dereference(context).await?; let mod_person = self.actor.dereference(context).await?;

View file

@ -58,10 +58,7 @@ impl Object for SiteOrCommunity {
} }
#[tracing::instrument(skip_all)] #[tracing::instrument(skip_all)]
async fn read_from_id( async fn read_from_id(object_id: Url, data: &Data<Self::DataType>) -> LemmyResult<Option<Self>>
object_id: Url,
data: &Data<Self::DataType>,
) -> Result<Option<Self>, LemmyError>
where where
Self: Sized, Self: Sized,
{ {
@ -74,11 +71,11 @@ impl Object for SiteOrCommunity {
}) })
} }
async fn delete(self, _data: &Data<Self::DataType>) -> Result<(), LemmyError> { async fn delete(self, _data: &Data<Self::DataType>) -> LemmyResult<()> {
unimplemented!() unimplemented!()
} }
async fn into_json(self, _data: &Data<Self::DataType>) -> Result<Self::Kind, LemmyError> { async fn into_json(self, _data: &Data<Self::DataType>) -> LemmyResult<Self::Kind> {
unimplemented!() unimplemented!()
} }
@ -87,7 +84,7 @@ impl Object for SiteOrCommunity {
apub: &Self::Kind, apub: &Self::Kind,
expected_domain: &Url, expected_domain: &Url,
data: &Data<Self::DataType>, data: &Data<Self::DataType>,
) -> Result<(), LemmyError> { ) -> LemmyResult<()> {
match apub { match apub {
InstanceOrGroup::Instance(i) => ApubSite::verify(i, expected_domain, data).await, InstanceOrGroup::Instance(i) => ApubSite::verify(i, expected_domain, data).await,
InstanceOrGroup::Group(g) => ApubCommunity::verify(g, expected_domain, data).await, InstanceOrGroup::Group(g) => ApubCommunity::verify(g, expected_domain, data).await,
@ -95,7 +92,7 @@ impl Object for SiteOrCommunity {
} }
#[tracing::instrument(skip_all)] #[tracing::instrument(skip_all)]
async fn from_json(apub: Self::Kind, data: &Data<Self::DataType>) -> Result<Self, LemmyError> async fn from_json(apub: Self::Kind, data: &Data<Self::DataType>) -> LemmyResult<Self>
where where
Self: Sized, Self: Sized,
{ {
@ -117,10 +114,7 @@ impl SiteOrCommunity {
} }
} }
async fn generate_cc( async fn generate_cc(target: &SiteOrCommunity, pool: &mut DbPool<'_>) -> LemmyResult<Vec<Url>> {
target: &SiteOrCommunity,
pool: &mut DbPool<'_>,
) -> Result<Vec<Url>, LemmyError> {
Ok(match target { Ok(match target {
SiteOrCommunity::Site(_) => Site::read_remote_sites(pool) SiteOrCommunity::Site(_) => Site::read_remote_sites(pool)
.await? .await?
@ -139,7 +133,7 @@ pub(crate) async fn send_ban_from_site(
ban: bool, ban: bool,
expires: Option<i64>, expires: Option<i64>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
) -> Result<(), LemmyError> { ) -> LemmyResult<()> {
let site = SiteOrCommunity::Site(SiteView::read_local(&mut context.pool()).await?.site.into()); let site = SiteOrCommunity::Site(SiteView::read_local(&mut context.pool()).await?.site.into());
let expires = check_expire_time(expires)?; let expires = check_expire_time(expires)?;

View file

@ -27,7 +27,7 @@ use lemmy_db_schema::{
}, },
traits::{Bannable, Crud}, traits::{Bannable, Crud},
}; };
use lemmy_utils::error::LemmyError; use lemmy_utils::error::{LemmyError, LemmyResult};
use url::Url; use url::Url;
impl UndoBlockUser { impl UndoBlockUser {
@ -38,7 +38,7 @@ impl UndoBlockUser {
mod_: &ApubPerson, mod_: &ApubPerson,
reason: Option<String>, reason: Option<String>,
context: &Data<LemmyContext>, context: &Data<LemmyContext>,
) -> Result<(), LemmyError> { ) -> LemmyResult<()> {
let block = BlockUser::new(target, user, mod_, None, reason, None, context).await?; let block = BlockUser::new(target, user, mod_, None, reason, None, context).await?;
let audience = if let SiteOrCommunity::Community(c) = target { let audience = if let SiteOrCommunity::Community(c) = target {
Some(c.id().into()) Some(c.id().into())
@ -88,7 +88,7 @@ impl ActivityHandler for UndoBlockUser {
} }
#[tracing::instrument(skip_all)] #[tracing::instrument(skip_all)]
async fn verify(&self, context: &Data<LemmyContext>) -> Result<(), LemmyError> { async fn verify(&self, context: &Data<LemmyContext>) -> LemmyResult<()> {
verify_is_public(&self.to, &self.cc)?; verify_is_public(&self.to, &self.cc)?;
verify_domains_match(self.actor.inner(), self.object.actor.inner())?; verify_domains_match(self.actor.inner(), self.object.actor.inner())?;
self.object.verify(context).await?; self.object.verify(context).await?;
@ -96,7 +96,7 @@ impl ActivityHandler for UndoBlockUser {
} }
#[tracing::instrument(skip_all)] #[tracing::instrument(skip_all)]
async fn receive(self, context: &Data<LemmyContext>) -> Result<(), LemmyError> { async fn receive(self, context: &Data<LemmyContext>) -> LemmyResult<()> {
insert_received_activity(&self.id, context).await?; insert_received_activity(&self.id, context).await?;
let expires = self.object.expires.or(self.object.end_time).map(Into::into); let expires = self.object.expires.or(self.object.end_time).map(Into::into);
let mod_person = self.actor.dereference(context).await?; let mod_person = self.actor.dereference(context).await?;

View file

@ -82,7 +82,7 @@ impl AnnounceActivity {
object: RawAnnouncableActivities, object: RawAnnouncableActivities,
community: &ApubCommunity, community: &ApubCommunity,
context: &Data<LemmyContext>, context: &Data<LemmyContext>,
) -> Result<AnnounceActivity, LemmyError> { ) -> LemmyResult<AnnounceActivity> {
let inner_kind = object let inner_kind = object
.other .other
.get("type") .get("type")
@ -105,7 +105,7 @@ impl AnnounceActivity {
object: RawAnnouncableActivities, object: RawAnnouncableActivities,
community: &ApubCommunity, community: &ApubCommunity,
context: &Data<LemmyContext>, context: &Data<LemmyContext>,
) -> Result<(), LemmyError> { ) -> LemmyResult<()> {
let announce = AnnounceActivity::new(object.clone(), community, context)?; let announce = AnnounceActivity::new(object.clone(), community, context)?;
let inboxes = ActivitySendTargets::to_local_community_followers(community.id); let inboxes = ActivitySendTargets::to_local_community_followers(community.id);
send_lemmy_activity(context, announce, community, inboxes.clone(), false).await?; send_lemmy_activity(context, announce, community, inboxes.clone(), false).await?;
@ -148,13 +148,13 @@ impl ActivityHandler for AnnounceActivity {
} }
#[tracing::instrument(skip_all)] #[tracing::instrument(skip_all)]
async fn verify(&self, _context: &Data<Self::DataType>) -> Result<(), LemmyError> { async fn verify(&self, _context: &Data<Self::DataType>) -> LemmyResult<()> {
verify_is_public(&self.to, &self.cc)?; verify_is_public(&self.to, &self.cc)?;
Ok(()) Ok(())
} }
#[tracing::instrument(skip_all)] #[tracing::instrument(skip_all)]
async fn receive(self, context: &Data<Self::DataType>) -> Result<(), LemmyError> { async fn receive(self, context: &Data<Self::DataType>) -> LemmyResult<()> {
insert_received_activity(&self.id, context).await?; insert_received_activity(&self.id, context).await?;
let object: AnnouncableActivities = self.object.object(context).await?.try_into()?; let object: AnnouncableActivities = self.object.object(context).await?.try_into()?;

View file

@ -36,7 +36,7 @@ use lemmy_db_schema::{
}, },
traits::{Crud, Joinable}, traits::{Crud, Joinable},
}; };
use lemmy_utils::error::LemmyError; use lemmy_utils::error::{LemmyError, LemmyResult};
use url::Url; use url::Url;
impl CollectionAdd { impl CollectionAdd {
@ -46,7 +46,7 @@ impl CollectionAdd {
added_mod: &ApubPerson, added_mod: &ApubPerson,
actor: &ApubPerson, actor: &ApubPerson,
context: &Data<LemmyContext>, context: &Data<LemmyContext>,
) -> Result<(), LemmyError> { ) -> LemmyResult<()> {
let id = generate_activity_id( let id = generate_activity_id(
AddType::Add, AddType::Add,
&context.settings().get_protocol_and_hostname(), &context.settings().get_protocol_and_hostname(),
@ -72,7 +72,7 @@ impl CollectionAdd {
featured_post: &ApubPost, featured_post: &ApubPost,
actor: &ApubPerson, actor: &ApubPerson,
context: &Data<LemmyContext>, context: &Data<LemmyContext>,
) -> Result<(), LemmyError> { ) -> LemmyResult<()> {
let id = generate_activity_id( let id = generate_activity_id(
AddType::Add, AddType::Add,
&context.settings().get_protocol_and_hostname(), &context.settings().get_protocol_and_hostname(),
@ -114,7 +114,7 @@ impl ActivityHandler for CollectionAdd {
} }
#[tracing::instrument(skip_all)] #[tracing::instrument(skip_all)]
async fn verify(&self, context: &Data<Self::DataType>) -> Result<(), LemmyError> { async fn verify(&self, context: &Data<Self::DataType>) -> LemmyResult<()> {
verify_is_public(&self.to, &self.cc)?; verify_is_public(&self.to, &self.cc)?;
let community = self.community(context).await?; let community = self.community(context).await?;
verify_person_in_community(&self.actor, &community, context).await?; verify_person_in_community(&self.actor, &community, context).await?;
@ -123,7 +123,7 @@ impl ActivityHandler for CollectionAdd {
} }
#[tracing::instrument(skip_all)] #[tracing::instrument(skip_all)]
async fn receive(self, context: &Data<Self::DataType>) -> Result<(), LemmyError> { async fn receive(self, context: &Data<Self::DataType>) -> LemmyResult<()> {
insert_received_activity(&self.id, context).await?; insert_received_activity(&self.id, context).await?;
let (community, collection_type) = let (community, collection_type) =
Community::get_by_collection_url(&mut context.pool(), &self.target.into()).await?; Community::get_by_collection_url(&mut context.pool(), &self.target.into()).await?;
@ -179,7 +179,7 @@ pub(crate) async fn send_add_mod_to_community(
updated_mod_id: PersonId, updated_mod_id: PersonId,
added: bool, added: bool,
context: Data<LemmyContext>, context: Data<LemmyContext>,
) -> Result<(), LemmyError> { ) -> LemmyResult<()> {
let actor: ApubPerson = actor.into(); let actor: ApubPerson = actor.into();
let community: ApubCommunity = Community::read(&mut context.pool(), community_id) let community: ApubCommunity = Community::read(&mut context.pool(), community_id)
.await? .await?
@ -199,7 +199,7 @@ pub(crate) async fn send_feature_post(
actor: Person, actor: Person,
featured: bool, featured: bool,
context: Data<LemmyContext>, context: Data<LemmyContext>,
) -> Result<(), LemmyError> { ) -> LemmyResult<()> {
let actor: ApubPerson = actor.into(); let actor: ApubPerson = actor.into();
let post: ApubPost = post.into(); let post: ApubPost = post.into();
let community = Community::read(&mut context.pool(), post.community_id) let community = Community::read(&mut context.pool(), post.community_id)

View file

@ -31,7 +31,7 @@ use lemmy_db_schema::{
}, },
traits::{Crud, Joinable}, traits::{Crud, Joinable},
}; };
use lemmy_utils::error::LemmyError; use lemmy_utils::error::{LemmyError, LemmyResult};
use url::Url; use url::Url;
impl CollectionRemove { impl CollectionRemove {
@ -41,7 +41,7 @@ impl CollectionRemove {
removed_mod: &ApubPerson, removed_mod: &ApubPerson,
actor: &ApubPerson, actor: &ApubPerson,
context: &Data<LemmyContext>, context: &Data<LemmyContext>,
) -> Result<(), LemmyError> { ) -> LemmyResult<()> {
let id = generate_activity_id( let id = generate_activity_id(
RemoveType::Remove, RemoveType::Remove,
&context.settings().get_protocol_and_hostname(), &context.settings().get_protocol_and_hostname(),
@ -67,7 +67,7 @@ impl CollectionRemove {
featured_post: &ApubPost, featured_post: &ApubPost,
actor: &ApubPerson, actor: &ApubPerson,
context: &Data<LemmyContext>, context: &Data<LemmyContext>,
) -> Result<(), LemmyError> { ) -> LemmyResult<()> {
let id = generate_activity_id( let id = generate_activity_id(
RemoveType::Remove, RemoveType::Remove,
&context.settings().get_protocol_and_hostname(), &context.settings().get_protocol_and_hostname(),
@ -109,7 +109,7 @@ impl ActivityHandler for CollectionRemove {
} }
#[tracing::instrument(skip_all)] #[tracing::instrument(skip_all)]
async fn verify(&self, context: &Data<Self::DataType>) -> Result<(), LemmyError> { async fn verify(&self, context: &Data<Self::DataType>) -> LemmyResult<()> {
verify_is_public(&self.to, &self.cc)?; verify_is_public(&self.to, &self.cc)?;
let community = self.community(context).await?; let community = self.community(context).await?;
verify_person_in_community(&self.actor, &community, context).await?; verify_person_in_community(&self.actor, &community, context).await?;
@ -118,7 +118,7 @@ impl ActivityHandler for CollectionRemove {
} }
#[tracing::instrument(skip_all)] #[tracing::instrument(skip_all)]
async fn receive(self, context: &Data<Self::DataType>) -> Result<(), LemmyError> { async fn receive(self, context: &Data<Self::DataType>) -> LemmyResult<()> {
insert_received_activity(&self.id, context).await?; insert_received_activity(&self.id, context).await?;
let (community, collection_type) = let (community, collection_type) =
Community::get_by_collection_url(&mut context.pool(), &self.target.into()).await?; Community::get_by_collection_url(&mut context.pool(), &self.target.into()).await?;

View file

@ -31,7 +31,7 @@ use lemmy_db_schema::{
}, },
traits::Crud, traits::Crud,
}; };
use lemmy_utils::error::LemmyError; use lemmy_utils::error::{LemmyError, LemmyResult};
use url::Url; use url::Url;
#[async_trait::async_trait] #[async_trait::async_trait]
@ -106,7 +106,7 @@ pub(crate) async fn send_lock_post(
actor: Person, actor: Person,
locked: bool, locked: bool,
context: Data<LemmyContext>, context: Data<LemmyContext>,
) -> Result<(), LemmyError> { ) -> LemmyResult<()> {
let community: ApubCommunity = Community::read(&mut context.pool(), post.community_id) let community: ApubCommunity = Community::read(&mut context.pool(), post.community_id)
.await? .await?
.into(); .into();

View file

@ -10,7 +10,7 @@ use lemmy_db_schema::{
source::{activity::ActivitySendTargets, person::PersonFollower}, source::{activity::ActivitySendTargets, person::PersonFollower},
CommunityVisibility, CommunityVisibility,
}; };
use lemmy_utils::error::LemmyError; use lemmy_utils::error::LemmyResult;
pub mod announce; pub mod announce;
pub mod collection_add; pub mod collection_add;
@ -39,7 +39,7 @@ pub(crate) async fn send_activity_in_community(
extra_inboxes: ActivitySendTargets, extra_inboxes: ActivitySendTargets,
is_mod_action: bool, is_mod_action: bool,
context: &Data<LemmyContext>, context: &Data<LemmyContext>,
) -> Result<(), LemmyError> { ) -> LemmyResult<()> {
// If community is local only, don't send anything out // If community is local only, don't send anything out
if community.visibility != CommunityVisibility::Public { if community.visibility != CommunityVisibility::Public {
return Ok(()); return Ok(());

View file

@ -29,7 +29,7 @@ use lemmy_db_schema::{
}, },
traits::{Crud, Reportable}, traits::{Crud, Reportable},
}; };
use lemmy_utils::error::LemmyError; use lemmy_utils::error::{LemmyError, LemmyResult};
use url::Url; use url::Url;
impl Report { impl Report {
@ -40,7 +40,7 @@ impl Report {
community: Community, community: Community,
reason: String, reason: String,
context: Data<LemmyContext>, context: Data<LemmyContext>,
) -> Result<(), LemmyError> { ) -> LemmyResult<()> {
let actor: ApubPerson = actor.into(); let actor: ApubPerson = actor.into();
let community: ApubCommunity = community.into(); let community: ApubCommunity = community.into();
let kind = FlagType::Flag; let kind = FlagType::Flag;
@ -94,14 +94,14 @@ impl ActivityHandler for Report {
} }
#[tracing::instrument(skip_all)] #[tracing::instrument(skip_all)]
async fn verify(&self, context: &Data<Self::DataType>) -> Result<(), LemmyError> { async fn verify(&self, context: &Data<Self::DataType>) -> LemmyResult<()> {
let community = self.community(context).await?; let community = self.community(context).await?;
verify_person_in_community(&self.actor, &community, context).await?; verify_person_in_community(&self.actor, &community, context).await?;
Ok(()) Ok(())
} }
#[tracing::instrument(skip_all)] #[tracing::instrument(skip_all)]
async fn receive(self, context: &Data<Self::DataType>) -> Result<(), LemmyError> { async fn receive(self, context: &Data<Self::DataType>) -> LemmyResult<()> {
insert_received_activity(&self.id, context).await?; insert_received_activity(&self.id, context).await?;
let actor = self.actor.dereference(context).await?; let actor = self.actor.dereference(context).await?;
let reason = self.reason()?; let reason = self.reason()?;

Some files were not shown because too many files have changed in this diff Show more