From: Nutomic Date: Thu, 25 May 2023 14:50:07 +0000 (+0200) Subject: Dont return error in case optional auth is invalid (#2879) X-Git-Url: http://these/git/%7B%60%24%7BwebArchiveUrl%7D/%22%7B%7D/%22https:/nerdica.net/static/%7BmarkdownHelpUrl%7D?a=commitdiff_plain;h=a5707328cff0133373491ef8e8908faeefacfa30;p=lemmy.git Dont return error in case optional auth is invalid (#2879) * Dont return error in case optional auth is invalid * fixes --- diff --git a/api_tests/src/user.spec.ts b/api_tests/src/user.spec.ts index 204dc727..afe21d1a 100644 --- a/api_tests/src/user.spec.ts +++ b/api_tests/src/user.spec.ts @@ -18,6 +18,8 @@ import { saveUserSettingsFederated, setupLogins, } from "./shared"; +import { LemmyHttp } from "lemmy-js-client"; +import { GetPosts } from "lemmy-js-client/dist/types/GetPosts"; beforeAll(async () => { await setupLogins(); @@ -95,3 +97,19 @@ test("Delete user", async () => { expect((await resolvePost(alpha, remotePost)).post).toBeUndefined(); expect((await resolveComment(alpha, remoteComment)).comment).toBeUndefined(); }); + +test("Requests with invalid auth should be treated as unauthenticated", async () => { + let invalid_auth: API = { + client: new LemmyHttp("http://127.0.0.1:8541"), + auth: "invalid", + }; + let site = await getSite(invalid_auth); + expect(site.my_user).toBeUndefined(); + expect(site.site_view).toBeDefined(); + + let form: GetPosts = { + auth: "invalid", + }; + let posts = invalid_auth.client.getPosts(form); + expect((await posts).posts).toBeDefined(); +}); diff --git a/crates/api/src/comment/distinguish.rs b/crates/api/src/comment/distinguish.rs index cf51107f..73e1469e 100644 --- a/crates/api/src/comment/distinguish.rs +++ b/crates/api/src/comment/distinguish.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ comment::{CommentResponse, DistinguishComment}, context::LemmyContext, - utils::{check_community_ban, get_local_user_view_from_jwt, is_mod_or_admin}, + utils::{check_community_ban, is_mod_or_admin, local_user_view_from_jwt}, }; use lemmy_db_schema::{ source::comment::{Comment, CommentUpdateForm}, @@ -23,8 +23,7 @@ impl Perform for DistinguishComment { _websocket_id: Option, ) -> Result { let data: &DistinguishComment = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; let comment_id = data.comment_id; let orig_comment = CommentView::read(context.pool(), comment_id, None).await?; diff --git a/crates/api/src/comment/like.rs b/crates/api/src/comment/like.rs index 6946b60c..b6e7e504 100644 --- a/crates/api/src/comment/like.rs +++ b/crates/api/src/comment/like.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ comment::{CommentResponse, CreateCommentLike}, context::LemmyContext, - utils::{check_community_ban, check_downvotes_enabled, get_local_user_view_from_jwt}, + utils::{check_community_ban, check_downvotes_enabled, local_user_view_from_jwt}, websocket::UserOperation, }; use lemmy_db_schema::{ @@ -30,8 +30,7 @@ impl Perform for CreateCommentLike { ) -> Result { let data: &CreateCommentLike = self; let local_site = LocalSite::read(context.pool()).await?; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; let mut recipient_ids = Vec::::new(); diff --git a/crates/api/src/comment/save.rs b/crates/api/src/comment/save.rs index 03051f6c..d52b3322 100644 --- a/crates/api/src/comment/save.rs +++ b/crates/api/src/comment/save.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ comment::{CommentResponse, SaveComment}, context::LemmyContext, - utils::get_local_user_view_from_jwt, + utils::local_user_view_from_jwt, }; use lemmy_db_schema::{ source::comment::{CommentSaved, CommentSavedForm}, @@ -23,8 +23,7 @@ impl Perform for SaveComment { _websocket_id: Option, ) -> Result { let data: &SaveComment = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; let comment_saved_form = CommentSavedForm { comment_id: data.comment_id, diff --git a/crates/api/src/comment_report/create.rs b/crates/api/src/comment_report/create.rs index fe2471ed..8d016bf5 100644 --- a/crates/api/src/comment_report/create.rs +++ b/crates/api/src/comment_report/create.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ comment::{CommentReportResponse, CreateCommentReport}, context::LemmyContext, - utils::{check_community_ban, get_local_user_view_from_jwt, send_new_report_email_to_admins}, + utils::{check_community_ban, local_user_view_from_jwt, send_new_report_email_to_admins}, websocket::UserOperation, }; use lemmy_db_schema::{ @@ -28,8 +28,7 @@ impl Perform for CreateCommentReport { websocket_id: Option, ) -> Result { let data: &CreateCommentReport = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; let local_site = LocalSite::read(context.pool()).await?; let reason = self.reason.trim(); diff --git a/crates/api/src/comment_report/list.rs b/crates/api/src/comment_report/list.rs index 8aa3fcbc..2cd9ca1b 100644 --- a/crates/api/src/comment_report/list.rs +++ b/crates/api/src/comment_report/list.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ comment::{ListCommentReports, ListCommentReportsResponse}, context::LemmyContext, - utils::get_local_user_view_from_jwt, + utils::local_user_view_from_jwt, }; use lemmy_db_views::comment_report_view::CommentReportQuery; use lemmy_utils::{error::LemmyError, ConnectionId}; @@ -21,8 +21,7 @@ impl Perform for ListCommentReports { _websocket_id: Option, ) -> Result { let data: &ListCommentReports = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; let person_id = local_user_view.person.id; let admin = local_user_view.person.admin; diff --git a/crates/api/src/comment_report/resolve.rs b/crates/api/src/comment_report/resolve.rs index f5fd6b12..4ba45481 100644 --- a/crates/api/src/comment_report/resolve.rs +++ b/crates/api/src/comment_report/resolve.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ comment::{CommentReportResponse, ResolveCommentReport}, context::LemmyContext, - utils::{get_local_user_view_from_jwt, is_mod_or_admin}, + utils::{is_mod_or_admin, local_user_view_from_jwt}, websocket::UserOperation, }; use lemmy_db_schema::{source::comment_report::CommentReport, traits::Reportable}; @@ -22,8 +22,7 @@ impl Perform for ResolveCommentReport { websocket_id: Option, ) -> Result { let data: &ResolveCommentReport = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; let report_id = data.report_id; let person_id = local_user_view.person.id; diff --git a/crates/api/src/community/add_mod.rs b/crates/api/src/community/add_mod.rs index 7052f7cd..80c470de 100644 --- a/crates/api/src/community/add_mod.rs +++ b/crates/api/src/community/add_mod.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ community::{AddModToCommunity, AddModToCommunityResponse}, context::LemmyContext, - utils::{get_local_user_view_from_jwt, is_mod_or_admin}, + utils::{is_mod_or_admin, local_user_view_from_jwt}, websocket::UserOperation, }; use lemmy_db_schema::{ @@ -27,8 +27,7 @@ impl Perform for AddModToCommunity { websocket_id: Option, ) -> Result { let data: &AddModToCommunity = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; let community_id = data.community_id; diff --git a/crates/api/src/community/ban.rs b/crates/api/src/community/ban.rs index c19df91f..47cb6798 100644 --- a/crates/api/src/community/ban.rs +++ b/crates/api/src/community/ban.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ community::{BanFromCommunity, BanFromCommunityResponse}, context::LemmyContext, - utils::{get_local_user_view_from_jwt, is_mod_or_admin, remove_user_data_in_community}, + utils::{is_mod_or_admin, local_user_view_from_jwt, remove_user_data_in_community}, websocket::{ handlers::messages::SendCommunityRoomMessage, serialize_websocket_message, @@ -40,8 +40,7 @@ impl Perform for BanFromCommunity { websocket_id: Option, ) -> Result { let data: &BanFromCommunity = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; let community_id = data.community_id; let banned_person_id = data.person_id; diff --git a/crates/api/src/community/block.rs b/crates/api/src/community/block.rs index 58dabf1c..21112971 100644 --- a/crates/api/src/community/block.rs +++ b/crates/api/src/community/block.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ community::{BlockCommunity, BlockCommunityResponse}, context::LemmyContext, - utils::get_local_user_view_from_jwt, + utils::local_user_view_from_jwt, }; use lemmy_db_schema::{ source::{ @@ -26,8 +26,7 @@ impl Perform for BlockCommunity { _websocket_id: Option, ) -> Result { let data: &BlockCommunity = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; let community_id = data.community_id; let person_id = local_user_view.person.id; diff --git a/crates/api/src/community/follow.rs b/crates/api/src/community/follow.rs index b519d214..9e4efb33 100644 --- a/crates/api/src/community/follow.rs +++ b/crates/api/src/community/follow.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ community::{CommunityResponse, FollowCommunity}, context::LemmyContext, - utils::{check_community_ban, check_community_deleted_or_removed, get_local_user_view_from_jwt}, + utils::{check_community_ban, check_community_deleted_or_removed, local_user_view_from_jwt}, }; use lemmy_db_schema::{ source::{ @@ -26,8 +26,7 @@ impl Perform for FollowCommunity { _websocket_id: Option, ) -> Result { let data: &FollowCommunity = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; let community_id = data.community_id; let community = Community::read(context.pool(), community_id).await?; diff --git a/crates/api/src/community/hide.rs b/crates/api/src/community/hide.rs index 8e181157..e33bf32c 100644 --- a/crates/api/src/community/hide.rs +++ b/crates/api/src/community/hide.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ community::{CommunityResponse, HideCommunity}, context::LemmyContext, - utils::{get_local_user_view_from_jwt, is_admin}, + utils::{is_admin, local_user_view_from_jwt}, websocket::UserOperationCrud, }; use lemmy_db_schema::{ @@ -28,8 +28,7 @@ impl Perform for HideCommunity { let data: &HideCommunity = self; // Verify its a admin (only admin can hide or unhide it) - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; is_admin(&local_user_view)?; let community_form = CommunityUpdateForm::builder() diff --git a/crates/api/src/community/transfer.rs b/crates/api/src/community/transfer.rs index d96ba848..def3df0f 100644 --- a/crates/api/src/community/transfer.rs +++ b/crates/api/src/community/transfer.rs @@ -4,7 +4,7 @@ use anyhow::Context; use lemmy_api_common::{ community::{GetCommunityResponse, TransferCommunity}, context::LemmyContext, - utils::{get_local_user_view_from_jwt, is_admin, is_top_mod}, + utils::{is_admin, is_top_mod, local_user_view_from_jwt}, }; use lemmy_db_schema::{ source::{ @@ -29,8 +29,7 @@ impl Perform for TransferCommunity { _websocket_id: Option, ) -> Result { let data: &TransferCommunity = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; // Fetch the community mods let community_id = data.community_id; diff --git a/crates/api/src/local_user/add_admin.rs b/crates/api/src/local_user/add_admin.rs index ad8b67e1..5de58465 100644 --- a/crates/api/src/local_user/add_admin.rs +++ b/crates/api/src/local_user/add_admin.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ context::LemmyContext, person::{AddAdmin, AddAdminResponse}, - utils::{get_local_user_view_from_jwt, is_admin}, + utils::{is_admin, local_user_view_from_jwt}, websocket::UserOperation, }; use lemmy_db_schema::{ @@ -27,8 +27,7 @@ impl Perform for AddAdmin { websocket_id: Option, ) -> Result { let data: &AddAdmin = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; // Make sure user is an admin is_admin(&local_user_view)?; diff --git a/crates/api/src/local_user/ban_person.rs b/crates/api/src/local_user/ban_person.rs index d2b78043..014f98b8 100644 --- a/crates/api/src/local_user/ban_person.rs +++ b/crates/api/src/local_user/ban_person.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ context::LemmyContext, person::{BanPerson, BanPersonResponse}, - utils::{get_local_user_view_from_jwt, is_admin, remove_user_data}, + utils::{is_admin, local_user_view_from_jwt, remove_user_data}, websocket::UserOperation, }; use lemmy_db_schema::{ @@ -31,8 +31,7 @@ impl Perform for BanPerson { websocket_id: Option, ) -> Result { let data: &BanPerson = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; // Make sure user is an admin is_admin(&local_user_view)?; diff --git a/crates/api/src/local_user/block.rs b/crates/api/src/local_user/block.rs index 6dbf7cff..5a4c9dca 100644 --- a/crates/api/src/local_user/block.rs +++ b/crates/api/src/local_user/block.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ context::LemmyContext, person::{BlockPerson, BlockPersonResponse}, - utils::get_local_user_view_from_jwt, + utils::local_user_view_from_jwt, }; use lemmy_db_schema::{ source::person_block::{PersonBlock, PersonBlockForm}, @@ -23,8 +23,7 @@ impl Perform for BlockPerson { _websocket_id: Option, ) -> Result { let data: &BlockPerson = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; let target_id = data.person_id; let person_id = local_user_view.person.id; diff --git a/crates/api/src/local_user/change_password.rs b/crates/api/src/local_user/change_password.rs index 2d0fd30e..2b486a5e 100644 --- a/crates/api/src/local_user/change_password.rs +++ b/crates/api/src/local_user/change_password.rs @@ -4,7 +4,7 @@ use bcrypt::verify; use lemmy_api_common::{ context::LemmyContext, person::{ChangePassword, LoginResponse}, - utils::{get_local_user_view_from_jwt, password_length_check}, + utils::{local_user_view_from_jwt, password_length_check}, }; use lemmy_db_schema::source::local_user::LocalUser; use lemmy_utils::{claims::Claims, error::LemmyError, ConnectionId}; @@ -20,8 +20,7 @@ impl Perform for ChangePassword { _websocket_id: Option, ) -> Result { let data: &ChangePassword = self; - let local_user_view = - get_local_user_view_from_jwt(data.auth.as_ref(), context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(data.auth.as_ref(), context).await?; password_length_check(&data.new_password)?; diff --git a/crates/api/src/local_user/list_banned.rs b/crates/api/src/local_user/list_banned.rs index 3fd19f55..e1d0f6e7 100644 --- a/crates/api/src/local_user/list_banned.rs +++ b/crates/api/src/local_user/list_banned.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ context::LemmyContext, person::{BannedPersonsResponse, GetBannedPersons}, - utils::{get_local_user_view_from_jwt, is_admin}, + utils::{is_admin, local_user_view_from_jwt}, }; use lemmy_db_views_actor::structs::PersonView; use lemmy_utils::{error::LemmyError, ConnectionId}; @@ -18,8 +18,7 @@ impl Perform for GetBannedPersons { _websocket_id: Option, ) -> Result { let data: &GetBannedPersons = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; // Make sure user is an admin is_admin(&local_user_view)?; diff --git a/crates/api/src/local_user/notifications/list_mentions.rs b/crates/api/src/local_user/notifications/list_mentions.rs index c03e9d16..fbafdb52 100644 --- a/crates/api/src/local_user/notifications/list_mentions.rs +++ b/crates/api/src/local_user/notifications/list_mentions.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ context::LemmyContext, person::{GetPersonMentions, GetPersonMentionsResponse}, - utils::get_local_user_view_from_jwt, + utils::local_user_view_from_jwt, }; use lemmy_db_views_actor::person_mention_view::PersonMentionQuery; use lemmy_utils::{error::LemmyError, ConnectionId}; @@ -19,8 +19,7 @@ impl Perform for GetPersonMentions { _websocket_id: Option, ) -> Result { let data: &GetPersonMentions = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; let sort = data.sort; let page = data.page; diff --git a/crates/api/src/local_user/notifications/list_replies.rs b/crates/api/src/local_user/notifications/list_replies.rs index 585db5e9..797b6f8d 100644 --- a/crates/api/src/local_user/notifications/list_replies.rs +++ b/crates/api/src/local_user/notifications/list_replies.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ context::LemmyContext, person::{GetReplies, GetRepliesResponse}, - utils::get_local_user_view_from_jwt, + utils::local_user_view_from_jwt, }; use lemmy_db_views_actor::comment_reply_view::CommentReplyQuery; use lemmy_utils::{error::LemmyError, ConnectionId}; @@ -19,8 +19,7 @@ impl Perform for GetReplies { _websocket_id: Option, ) -> Result { let data: &GetReplies = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; let sort = data.sort; let page = data.page; diff --git a/crates/api/src/local_user/notifications/mark_all_read.rs b/crates/api/src/local_user/notifications/mark_all_read.rs index 2515715b..dfda897a 100644 --- a/crates/api/src/local_user/notifications/mark_all_read.rs +++ b/crates/api/src/local_user/notifications/mark_all_read.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ context::LemmyContext, person::{GetRepliesResponse, MarkAllAsRead}, - utils::get_local_user_view_from_jwt, + utils::local_user_view_from_jwt, }; use lemmy_db_schema::source::{ comment_reply::CommentReply, @@ -23,8 +23,7 @@ impl Perform for MarkAllAsRead { _websocket_id: Option, ) -> Result { let data: &MarkAllAsRead = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; let person_id = local_user_view.person.id; // Mark all comment_replies as read diff --git a/crates/api/src/local_user/notifications/mark_mention_read.rs b/crates/api/src/local_user/notifications/mark_mention_read.rs index a3a75d92..80781e72 100644 --- a/crates/api/src/local_user/notifications/mark_mention_read.rs +++ b/crates/api/src/local_user/notifications/mark_mention_read.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ context::LemmyContext, person::{MarkPersonMentionAsRead, PersonMentionResponse}, - utils::get_local_user_view_from_jwt, + utils::local_user_view_from_jwt, }; use lemmy_db_schema::{ source::person_mention::{PersonMention, PersonMentionUpdateForm}, @@ -23,8 +23,7 @@ impl Perform for MarkPersonMentionAsRead { _websocket_id: Option, ) -> Result { let data: &MarkPersonMentionAsRead = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; let person_mention_id = data.person_mention_id; let read_person_mention = PersonMention::read(context.pool(), person_mention_id).await?; diff --git a/crates/api/src/local_user/notifications/mark_reply_read.rs b/crates/api/src/local_user/notifications/mark_reply_read.rs index 3921e769..1e3fad19 100644 --- a/crates/api/src/local_user/notifications/mark_reply_read.rs +++ b/crates/api/src/local_user/notifications/mark_reply_read.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ context::LemmyContext, person::{CommentReplyResponse, MarkCommentReplyAsRead}, - utils::get_local_user_view_from_jwt, + utils::local_user_view_from_jwt, }; use lemmy_db_schema::{ source::comment_reply::{CommentReply, CommentReplyUpdateForm}, @@ -23,8 +23,7 @@ impl Perform for MarkCommentReplyAsRead { _websocket_id: Option, ) -> Result { let data = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; let comment_reply_id = data.comment_reply_id; let read_comment_reply = CommentReply::read(context.pool(), comment_reply_id).await?; diff --git a/crates/api/src/local_user/notifications/unread_count.rs b/crates/api/src/local_user/notifications/unread_count.rs index 715ccd28..523e9a73 100644 --- a/crates/api/src/local_user/notifications/unread_count.rs +++ b/crates/api/src/local_user/notifications/unread_count.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ context::LemmyContext, person::{GetUnreadCount, GetUnreadCountResponse}, - utils::get_local_user_view_from_jwt, + utils::local_user_view_from_jwt, }; use lemmy_db_views::structs::PrivateMessageView; use lemmy_db_views_actor::structs::{CommentReplyView, PersonMentionView}; @@ -20,8 +20,7 @@ impl Perform for GetUnreadCount { _websocket_id: Option, ) -> Result { let data = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; let person_id = local_user_view.person.id; diff --git a/crates/api/src/local_user/report_count.rs b/crates/api/src/local_user/report_count.rs index b59a0649..b2f4912c 100644 --- a/crates/api/src/local_user/report_count.rs +++ b/crates/api/src/local_user/report_count.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ context::LemmyContext, person::{GetReportCount, GetReportCountResponse}, - utils::get_local_user_view_from_jwt, + utils::local_user_view_from_jwt, }; use lemmy_db_views::structs::{CommentReportView, PostReportView, PrivateMessageReportView}; use lemmy_utils::{error::LemmyError, ConnectionId}; @@ -19,8 +19,7 @@ impl Perform for GetReportCount { _websocket_id: Option, ) -> Result { let data: &GetReportCount = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; let person_id = local_user_view.person.id; let admin = local_user_view.person.admin; diff --git a/crates/api/src/local_user/save_settings.rs b/crates/api/src/local_user/save_settings.rs index 0221d0ce..a0408612 100644 --- a/crates/api/src/local_user/save_settings.rs +++ b/crates/api/src/local_user/save_settings.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ context::LemmyContext, person::{LoginResponse, SaveUserSettings}, - utils::{get_local_user_view_from_jwt, send_verification_email}, + utils::{local_user_view_from_jwt, send_verification_email}, }; use lemmy_db_schema::{ source::{ @@ -39,8 +39,7 @@ impl Perform for SaveUserSettings { _websocket_id: Option, ) -> Result { let data: &SaveUserSettings = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; let site_view = SiteView::read_local(context.pool()).await?; let avatar = diesel_option_overwrite_to_url(&data.avatar)?; diff --git a/crates/api/src/post/feature.rs b/crates/api/src/post/feature.rs index e1dd1e3d..6d9f05f0 100644 --- a/crates/api/src/post/feature.rs +++ b/crates/api/src/post/feature.rs @@ -6,9 +6,9 @@ use lemmy_api_common::{ utils::{ check_community_ban, check_community_deleted_or_removed, - get_local_user_view_from_jwt, is_admin, is_mod_or_admin, + local_user_view_from_jwt, }, websocket::UserOperation, }; @@ -33,8 +33,7 @@ impl Perform for FeaturePost { websocket_id: Option, ) -> Result { let data: &FeaturePost = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; let post_id = data.post_id; let orig_post = Post::read(context.pool(), post_id).await?; diff --git a/crates/api/src/post/like.rs b/crates/api/src/post/like.rs index 9fa480a5..2413a983 100644 --- a/crates/api/src/post/like.rs +++ b/crates/api/src/post/like.rs @@ -7,7 +7,7 @@ use lemmy_api_common::{ check_community_ban, check_community_deleted_or_removed, check_downvotes_enabled, - get_local_user_view_from_jwt, + local_user_view_from_jwt, mark_post_as_read, }, websocket::UserOperation, @@ -32,8 +32,7 @@ impl Perform for CreatePostLike { websocket_id: Option, ) -> Result { let data: &CreatePostLike = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; let local_site = LocalSite::read(context.pool()).await?; // Don't do a downvote if site has downvotes disabled diff --git a/crates/api/src/post/lock.rs b/crates/api/src/post/lock.rs index cd7db908..42643640 100644 --- a/crates/api/src/post/lock.rs +++ b/crates/api/src/post/lock.rs @@ -6,8 +6,8 @@ use lemmy_api_common::{ utils::{ check_community_ban, check_community_deleted_or_removed, - get_local_user_view_from_jwt, is_mod_or_admin, + local_user_view_from_jwt, }, websocket::UserOperation, }; @@ -31,8 +31,7 @@ impl Perform for LockPost { websocket_id: Option, ) -> Result { let data: &LockPost = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; let post_id = data.post_id; let orig_post = Post::read(context.pool(), post_id).await?; diff --git a/crates/api/src/post/mark_read.rs b/crates/api/src/post/mark_read.rs index 858d71d2..e53d7a78 100644 --- a/crates/api/src/post/mark_read.rs +++ b/crates/api/src/post/mark_read.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ context::LemmyContext, post::{MarkPostAsRead, PostResponse}, - utils::{get_local_user_view_from_jwt, mark_post_as_read, mark_post_as_unread}, + utils::{local_user_view_from_jwt, mark_post_as_read, mark_post_as_unread}, }; use lemmy_db_views::structs::PostView; use lemmy_utils::{error::LemmyError, ConnectionId}; @@ -19,8 +19,7 @@ impl Perform for MarkPostAsRead { _websocket_id: Option, ) -> Result { let data = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; let post_id = data.post_id; let person_id = local_user_view.person.id; diff --git a/crates/api/src/post/save.rs b/crates/api/src/post/save.rs index e0c7c816..f3ef6319 100644 --- a/crates/api/src/post/save.rs +++ b/crates/api/src/post/save.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ context::LemmyContext, post::{PostResponse, SavePost}, - utils::{get_local_user_view_from_jwt, mark_post_as_read}, + utils::{local_user_view_from_jwt, mark_post_as_read}, }; use lemmy_db_schema::{ source::post::{PostSaved, PostSavedForm}, @@ -23,8 +23,7 @@ impl Perform for SavePost { _websocket_id: Option, ) -> Result { let data: &SavePost = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; let post_saved_form = PostSavedForm { post_id: data.post_id, diff --git a/crates/api/src/post_report/create.rs b/crates/api/src/post_report/create.rs index 423f8b81..092f1cd8 100644 --- a/crates/api/src/post_report/create.rs +++ b/crates/api/src/post_report/create.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ context::LemmyContext, post::{CreatePostReport, PostReportResponse}, - utils::{check_community_ban, get_local_user_view_from_jwt, send_new_report_email_to_admins}, + utils::{check_community_ban, local_user_view_from_jwt, send_new_report_email_to_admins}, websocket::UserOperation, }; use lemmy_db_schema::{ @@ -28,8 +28,7 @@ impl Perform for CreatePostReport { websocket_id: Option, ) -> Result { let data: &CreatePostReport = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; let local_site = LocalSite::read(context.pool()).await?; let reason = self.reason.trim(); diff --git a/crates/api/src/post_report/list.rs b/crates/api/src/post_report/list.rs index 2feed7ed..f5927042 100644 --- a/crates/api/src/post_report/list.rs +++ b/crates/api/src/post_report/list.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ context::LemmyContext, post::{ListPostReports, ListPostReportsResponse}, - utils::get_local_user_view_from_jwt, + utils::local_user_view_from_jwt, }; use lemmy_db_views::post_report_view::PostReportQuery; use lemmy_utils::{error::LemmyError, ConnectionId}; @@ -21,8 +21,7 @@ impl Perform for ListPostReports { _websocket_id: Option, ) -> Result { let data: &ListPostReports = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; let person_id = local_user_view.person.id; let admin = local_user_view.person.admin; diff --git a/crates/api/src/post_report/resolve.rs b/crates/api/src/post_report/resolve.rs index 0426262d..80290b2a 100644 --- a/crates/api/src/post_report/resolve.rs +++ b/crates/api/src/post_report/resolve.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ context::LemmyContext, post::{PostReportResponse, ResolvePostReport}, - utils::{get_local_user_view_from_jwt, is_mod_or_admin}, + utils::{is_mod_or_admin, local_user_view_from_jwt}, websocket::UserOperation, }; use lemmy_db_schema::{source::post_report::PostReport, traits::Reportable}; @@ -22,8 +22,7 @@ impl Perform for ResolvePostReport { websocket_id: Option, ) -> Result { let data: &ResolvePostReport = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; let report_id = data.report_id; let person_id = local_user_view.person.id; diff --git a/crates/api/src/private_message/mark_read.rs b/crates/api/src/private_message/mark_read.rs index ba5cf8ea..bf373e99 100644 --- a/crates/api/src/private_message/mark_read.rs +++ b/crates/api/src/private_message/mark_read.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ context::LemmyContext, private_message::{MarkPrivateMessageAsRead, PrivateMessageResponse}, - utils::get_local_user_view_from_jwt, + utils::local_user_view_from_jwt, websocket::UserOperation, }; use lemmy_db_schema::{ @@ -23,8 +23,7 @@ impl Perform for MarkPrivateMessageAsRead { websocket_id: Option, ) -> Result { let data: &MarkPrivateMessageAsRead = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; // Checking permissions let private_message_id = data.private_message_id; diff --git a/crates/api/src/private_message_report/create.rs b/crates/api/src/private_message_report/create.rs index 2a132b6f..a9ca0291 100644 --- a/crates/api/src/private_message_report/create.rs +++ b/crates/api/src/private_message_report/create.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ context::LemmyContext, private_message::{CreatePrivateMessageReport, PrivateMessageReportResponse}, - utils::{get_local_user_view_from_jwt, send_new_report_email_to_admins}, + utils::{local_user_view_from_jwt, send_new_report_email_to_admins}, websocket::UserOperation, }; use lemmy_db_schema::{ @@ -28,8 +28,7 @@ impl Perform for CreatePrivateMessageReport { context: &Data, websocket_id: Option, ) -> Result { - let local_user_view = - get_local_user_view_from_jwt(&self.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&self.auth, context).await?; let local_site = LocalSite::read(context.pool()).await?; let reason = self.reason.trim(); diff --git a/crates/api/src/private_message_report/list.rs b/crates/api/src/private_message_report/list.rs index 98c2d926..69b3dbf9 100644 --- a/crates/api/src/private_message_report/list.rs +++ b/crates/api/src/private_message_report/list.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ context::LemmyContext, private_message::{ListPrivateMessageReports, ListPrivateMessageReportsResponse}, - utils::{get_local_user_view_from_jwt, is_admin}, + utils::{is_admin, local_user_view_from_jwt}, }; use lemmy_db_views::private_message_report_view::PrivateMessageReportQuery; use lemmy_utils::{error::LemmyError, ConnectionId}; @@ -18,8 +18,7 @@ impl Perform for ListPrivateMessageReports { context: &Data, _websocket_id: Option, ) -> Result { - let local_user_view = - get_local_user_view_from_jwt(&self.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&self.auth, context).await?; is_admin(&local_user_view)?; diff --git a/crates/api/src/private_message_report/resolve.rs b/crates/api/src/private_message_report/resolve.rs index 9fe014c0..09e3b251 100644 --- a/crates/api/src/private_message_report/resolve.rs +++ b/crates/api/src/private_message_report/resolve.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ context::LemmyContext, private_message::{PrivateMessageReportResponse, ResolvePrivateMessageReport}, - utils::{get_local_user_view_from_jwt, is_admin}, + utils::{is_admin, local_user_view_from_jwt}, websocket::UserOperation, }; use lemmy_db_schema::{ @@ -24,8 +24,7 @@ impl Perform for ResolvePrivateMessageReport { context: &Data, websocket_id: Option, ) -> Result { - let local_user_view = - get_local_user_view_from_jwt(&self.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&self.auth, context).await?; is_admin(&local_user_view)?; diff --git a/crates/api/src/site/leave_admin.rs b/crates/api/src/site/leave_admin.rs index 4cec5fc4..a7c0941d 100644 --- a/crates/api/src/site/leave_admin.rs +++ b/crates/api/src/site/leave_admin.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ context::LemmyContext, site::{GetSiteResponse, LeaveAdmin}, - utils::{get_local_user_view_from_jwt, is_admin}, + utils::{is_admin, local_user_view_from_jwt}, }; use lemmy_db_schema::{ source::{ @@ -30,8 +30,7 @@ impl Perform for LeaveAdmin { _websocket_id: Option, ) -> Result { let data: &LeaveAdmin = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; is_admin(&local_user_view)?; diff --git a/crates/api/src/site/mod_log.rs b/crates/api/src/site/mod_log.rs index ec3ee0f7..dcb5f5ed 100644 --- a/crates/api/src/site/mod_log.rs +++ b/crates/api/src/site/mod_log.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ context::LemmyContext, site::{GetModlog, GetModlogResponse}, - utils::{check_private_instance, get_local_user_view_from_jwt_opt, is_admin, is_mod_or_admin}, + utils::{check_private_instance, is_admin, is_mod_or_admin, local_user_view_from_jwt_opt}, }; use lemmy_db_schema::{ newtypes::{CommunityId, PersonId}, @@ -43,9 +43,7 @@ impl Perform for GetModlog { ) -> Result { let data: &GetModlog = self; - let local_user_view = - get_local_user_view_from_jwt_opt(data.auth.as_ref(), context.pool(), context.secret()) - .await?; + let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await; let local_site = LocalSite::read(context.pool()).await?; check_private_instance(&local_user_view, &local_site)?; diff --git a/crates/api/src/site/purge/comment.rs b/crates/api/src/site/purge/comment.rs index 9664a628..f4ba4509 100644 --- a/crates/api/src/site/purge/comment.rs +++ b/crates/api/src/site/purge/comment.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ context::LemmyContext, site::{PurgeComment, PurgeItemResponse}, - utils::{get_local_user_view_from_jwt, is_top_admin}, + utils::{is_top_admin, local_user_view_from_jwt}, }; use lemmy_db_schema::{ source::{ @@ -25,8 +25,7 @@ impl Perform for PurgeComment { _websocket_id: Option, ) -> Result { let data: &Self = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; // Only let the top admin purge an item is_top_admin(context.pool(), local_user_view.person.id).await?; diff --git a/crates/api/src/site/purge/community.rs b/crates/api/src/site/purge/community.rs index abc4ff32..5bdf62e7 100644 --- a/crates/api/src/site/purge/community.rs +++ b/crates/api/src/site/purge/community.rs @@ -4,7 +4,7 @@ use lemmy_api_common::{ context::LemmyContext, request::purge_image_from_pictrs, site::{PurgeCommunity, PurgeItemResponse}, - utils::{get_local_user_view_from_jwt, is_top_admin, purge_image_posts_for_community}, + utils::{is_top_admin, local_user_view_from_jwt, purge_image_posts_for_community}, }; use lemmy_db_schema::{ source::{ @@ -26,8 +26,7 @@ impl Perform for PurgeCommunity { _websocket_id: Option, ) -> Result { let data: &Self = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; // Only let the top admin purge an item is_top_admin(context.pool(), local_user_view.person.id).await?; diff --git a/crates/api/src/site/purge/person.rs b/crates/api/src/site/purge/person.rs index 94c80a92..896dc783 100644 --- a/crates/api/src/site/purge/person.rs +++ b/crates/api/src/site/purge/person.rs @@ -4,7 +4,7 @@ use lemmy_api_common::{ context::LemmyContext, request::purge_image_from_pictrs, site::{PurgeItemResponse, PurgePerson}, - utils::{get_local_user_view_from_jwt, is_top_admin, purge_image_posts_for_person}, + utils::{is_top_admin, local_user_view_from_jwt, purge_image_posts_for_person}, }; use lemmy_db_schema::{ source::{ @@ -26,8 +26,7 @@ impl Perform for PurgePerson { _websocket_id: Option, ) -> Result { let data: &Self = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; // Only let the top admin purge an item is_top_admin(context.pool(), local_user_view.person.id).await?; diff --git a/crates/api/src/site/purge/post.rs b/crates/api/src/site/purge/post.rs index 27f90818..c04fc560 100644 --- a/crates/api/src/site/purge/post.rs +++ b/crates/api/src/site/purge/post.rs @@ -4,7 +4,7 @@ use lemmy_api_common::{ context::LemmyContext, request::purge_image_from_pictrs, site::{PurgeItemResponse, PurgePost}, - utils::{get_local_user_view_from_jwt, is_top_admin}, + utils::{is_top_admin, local_user_view_from_jwt}, }; use lemmy_db_schema::{ source::{ @@ -26,8 +26,7 @@ impl Perform for PurgePost { _websocket_id: Option, ) -> Result { let data: &Self = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; // Only let the top admin purge an item is_top_admin(context.pool(), local_user_view.person.id).await?; diff --git a/crates/api/src/site/registration_applications/approve.rs b/crates/api/src/site/registration_applications/approve.rs index 61a68689..edba7f2b 100644 --- a/crates/api/src/site/registration_applications/approve.rs +++ b/crates/api/src/site/registration_applications/approve.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ context::LemmyContext, site::{ApproveRegistrationApplication, RegistrationApplicationResponse}, - utils::{get_local_user_view_from_jwt, is_admin, send_application_approved_email}, + utils::{is_admin, local_user_view_from_jwt, send_application_approved_email}, }; use lemmy_db_schema::{ source::{ @@ -26,8 +26,7 @@ impl Perform for ApproveRegistrationApplication { _websocket_id: Option, ) -> Result { let data = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; let app_id = data.id; diff --git a/crates/api/src/site/registration_applications/list.rs b/crates/api/src/site/registration_applications/list.rs index 7be2e2e8..b5a366e1 100644 --- a/crates/api/src/site/registration_applications/list.rs +++ b/crates/api/src/site/registration_applications/list.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ context::LemmyContext, site::{ListRegistrationApplications, ListRegistrationApplicationsResponse}, - utils::{get_local_user_view_from_jwt, is_admin}, + utils::{is_admin, local_user_view_from_jwt}, }; use lemmy_db_schema::source::local_site::LocalSite; use lemmy_db_views::registration_application_view::RegistrationApplicationQuery; @@ -20,8 +20,7 @@ impl Perform for ListRegistrationApplications { _websocket_id: Option, ) -> Result { let data = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; let local_site = LocalSite::read(context.pool()).await?; // Make sure user is an admin diff --git a/crates/api/src/site/registration_applications/unread_count.rs b/crates/api/src/site/registration_applications/unread_count.rs index fe33d17c..72490e48 100644 --- a/crates/api/src/site/registration_applications/unread_count.rs +++ b/crates/api/src/site/registration_applications/unread_count.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ context::LemmyContext, site::{GetUnreadRegistrationApplicationCount, GetUnreadRegistrationApplicationCountResponse}, - utils::{get_local_user_view_from_jwt, is_admin}, + utils::{is_admin, local_user_view_from_jwt}, }; use lemmy_db_schema::source::local_site::LocalSite; use lemmy_db_views::structs::RegistrationApplicationView; @@ -19,8 +19,7 @@ impl Perform for GetUnreadRegistrationApplicationCount { _websocket_id: Option, ) -> Result { let data = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; let local_site = LocalSite::read(context.pool()).await?; // Only let admins do this diff --git a/crates/api/src/websocket.rs b/crates/api/src/websocket.rs index 522991ae..0552c190 100644 --- a/crates/api/src/websocket.rs +++ b/crates/api/src/websocket.rs @@ -2,7 +2,7 @@ use crate::Perform; use actix_web::web::Data; use lemmy_api_common::{ context::LemmyContext, - utils::get_local_user_view_from_jwt, + utils::local_user_view_from_jwt, websocket::{ handlers::join_rooms::{JoinCommunityRoom, JoinModRoom, JoinPostRoom, JoinUserRoom}, structs::{ @@ -30,8 +30,7 @@ impl Perform for UserJoin { websocket_id: Option, ) -> Result { let data: &UserJoin = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; if let Some(id) = websocket_id { context.chat_server().do_send(JoinUserRoom { diff --git a/crates/api_common/src/utils.rs b/crates/api_common/src/utils.rs index 75f878fc..522a3564 100644 --- a/crates/api_common/src/utils.rs +++ b/crates/api_common/src/utils.rs @@ -1,6 +1,12 @@ -use crate::{request::purge_image_from_pictrs, sensitive::Sensitive, site::FederatedInstances}; +use crate::{ + context::LemmyContext, + request::purge_image_from_pictrs, + sensitive::Sensitive, + site::FederatedInstances, +}; use anyhow::Context; use chrono::NaiveDateTime; +use futures::try_join; use lemmy_db_schema::{ impls::person::is_banned, newtypes::{CommunityId, DbUrl, LocalUserId, PersonId, PostId}, @@ -16,7 +22,6 @@ use lemmy_db_schema::{ person_block::PersonBlock, post::{Post, PostRead, PostReadForm}, registration_application::RegistrationApplication, - secret::Secret, }, traits::{Crud, Readable}, utils::DbPool, @@ -141,18 +146,16 @@ pub async fn mark_post_as_unread( .map_err(|e| LemmyError::from_error_message(e, "couldnt_mark_post_as_read")) } -// TODO: this should simply take LemmyContext as param #[tracing::instrument(skip_all)] -pub async fn get_local_user_view_from_jwt( +pub async fn local_user_view_from_jwt( jwt: &str, - pool: &DbPool, - secret: &Secret, + context: &LemmyContext, ) -> Result { - let claims = Claims::decode(jwt, &secret.jwt_secret) + let claims = Claims::decode(jwt, &context.secret().jwt_secret) .map_err(|e| e.with_message("not_logged_in"))? .claims; let local_user_id = LocalUserId(claims.sub); - let local_user_view = LocalUserView::read(pool, local_user_id).await?; + let local_user_view = LocalUserView::read(context.pool(), local_user_id).await?; check_user_valid( local_user_view.person.banned, local_user_view.person.ban_expires, @@ -164,6 +167,14 @@ pub async fn get_local_user_view_from_jwt( Ok(local_user_view) } +#[tracing::instrument(skip_all)] +pub async fn local_user_view_from_jwt_opt( + jwt: Option<&Sensitive>, + context: &LemmyContext, +) -> Option { + local_user_view_from_jwt(jwt?, context).await.ok() +} + /// Checks if user's token was issued before user's password reset. pub fn check_validator_time( validator_time: &NaiveDateTime, @@ -177,44 +188,6 @@ pub fn check_validator_time( } } -#[tracing::instrument(skip_all)] -pub async fn get_local_user_view_from_jwt_opt( - jwt: Option<&Sensitive>, - pool: &DbPool, - secret: &Secret, -) -> Result, LemmyError> { - match jwt { - Some(jwt) => Ok(Some(get_local_user_view_from_jwt(jwt, pool, secret).await?)), - None => Ok(None), - } -} - -#[tracing::instrument(skip_all)] -pub async fn get_local_user_settings_view_from_jwt_opt( - jwt: Option<&Sensitive>, - pool: &DbPool, - secret: &Secret, -) -> Result, LemmyError> { - match jwt { - Some(jwt) => { - let claims = Claims::decode(jwt.as_ref(), &secret.jwt_secret) - .map_err(|e| e.with_message("not_logged_in"))? - .claims; - let local_user_id = LocalUserId(claims.sub); - let local_user_view = LocalUserView::read(pool, local_user_id).await?; - check_user_valid( - local_user_view.person.banned, - local_user_view.person.ban_expires, - local_user_view.person.deleted, - )?; - - check_validator_time(&local_user_view.local_user.validator_time, &claims)?; - - Ok(Some(local_user_view)) - } - None => Ok(None), - } -} pub fn check_user_valid( banned: bool, ban_expires: Option, @@ -314,9 +287,11 @@ pub async fn build_federated_instances( ) -> Result, LemmyError> { if local_site.federation_enabled { // TODO I hate that this requires 3 queries - let linked = Instance::linked(pool).await?; - let allowed = Instance::allowlist(pool).await?; - let blocked = Instance::blocklist(pool).await?; + let (linked, allowed, blocked) = try_join!( + Instance::linked(pool), + Instance::allowlist(pool), + Instance::blocklist(pool) + )?; Ok(Some(FederatedInstances { linked, diff --git a/crates/api_crud/src/comment/create.rs b/crates/api_crud/src/comment/create.rs index 103c71ce..8909444d 100644 --- a/crates/api_crud/src/comment/create.rs +++ b/crates/api_crud/src/comment/create.rs @@ -8,9 +8,9 @@ use lemmy_api_common::{ check_community_deleted_or_removed, check_post_deleted_or_removed, generate_local_apub_endpoint, - get_local_user_view_from_jwt, get_post, local_site_to_slur_regex, + local_user_view_from_jwt, EndpointType, }, websocket::UserOperationCrud, @@ -46,8 +46,7 @@ impl PerformCrud for CreateComment { websocket_id: Option, ) -> Result { let data: &CreateComment = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; let local_site = LocalSite::read(context.pool()).await?; let content_slurs_removed = remove_slurs( diff --git a/crates/api_crud/src/comment/delete.rs b/crates/api_crud/src/comment/delete.rs index a96b4cc7..cde4ab62 100644 --- a/crates/api_crud/src/comment/delete.rs +++ b/crates/api_crud/src/comment/delete.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ comment::{CommentResponse, DeleteComment}, context::LemmyContext, - utils::{check_community_ban, get_local_user_view_from_jwt}, + utils::{check_community_ban, local_user_view_from_jwt}, websocket::UserOperationCrud, }; use lemmy_db_schema::{ @@ -27,8 +27,7 @@ impl PerformCrud for DeleteComment { websocket_id: Option, ) -> Result { let data: &DeleteComment = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; let comment_id = data.comment_id; let orig_comment = CommentView::read(context.pool(), comment_id, None).await?; diff --git a/crates/api_crud/src/comment/read.rs b/crates/api_crud/src/comment/read.rs index c0136f06..bd37eb77 100644 --- a/crates/api_crud/src/comment/read.rs +++ b/crates/api_crud/src/comment/read.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ comment::{CommentResponse, GetComment}, context::LemmyContext, - utils::{check_private_instance, get_local_user_view_from_jwt_opt}, + utils::{check_private_instance, local_user_view_from_jwt_opt}, }; use lemmy_db_schema::source::local_site::LocalSite; use lemmy_db_views::structs::CommentView; @@ -20,9 +20,7 @@ impl PerformCrud for GetComment { _websocket_id: Option, ) -> Result { let data = self; - let local_user_view = - get_local_user_view_from_jwt_opt(data.auth.as_ref(), context.pool(), context.secret()) - .await?; + let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await; let local_site = LocalSite::read(context.pool()).await?; check_private_instance(&local_user_view, &local_site)?; diff --git a/crates/api_crud/src/comment/remove.rs b/crates/api_crud/src/comment/remove.rs index add01aa3..b8834df8 100644 --- a/crates/api_crud/src/comment/remove.rs +++ b/crates/api_crud/src/comment/remove.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ comment::{CommentResponse, RemoveComment}, context::LemmyContext, - utils::{check_community_ban, get_local_user_view_from_jwt, is_mod_or_admin}, + utils::{check_community_ban, is_mod_or_admin, local_user_view_from_jwt}, websocket::UserOperationCrud, }; use lemmy_db_schema::{ @@ -28,8 +28,7 @@ impl PerformCrud for RemoveComment { websocket_id: Option, ) -> Result { let data: &RemoveComment = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; let comment_id = data.comment_id; let orig_comment = CommentView::read(context.pool(), comment_id, None).await?; diff --git a/crates/api_crud/src/comment/update.rs b/crates/api_crud/src/comment/update.rs index 1d6d0869..e74d5c4e 100644 --- a/crates/api_crud/src/comment/update.rs +++ b/crates/api_crud/src/comment/update.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ comment::{CommentResponse, EditComment}, context::LemmyContext, - utils::{check_community_ban, get_local_user_view_from_jwt, local_site_to_slur_regex}, + utils::{check_community_ban, local_site_to_slur_regex, local_user_view_from_jwt}, websocket::UserOperationCrud, }; use lemmy_db_schema::{ @@ -37,8 +37,7 @@ impl PerformCrud for EditComment { websocket_id: Option, ) -> Result { let data: &EditComment = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; let local_site = LocalSite::read(context.pool()).await?; let comment_id = data.comment_id; diff --git a/crates/api_crud/src/community/create.rs b/crates/api_crud/src/community/create.rs index e2e80b84..fbc557b7 100644 --- a/crates/api_crud/src/community/create.rs +++ b/crates/api_crud/src/community/create.rs @@ -9,9 +9,9 @@ use lemmy_api_common::{ generate_inbox_url, generate_local_apub_endpoint, generate_shared_inbox_url, - get_local_user_view_from_jwt, is_admin, local_site_to_slur_regex, + local_user_view_from_jwt, EndpointType, }, }; @@ -52,8 +52,7 @@ impl PerformCrud for CreateCommunity { _websocket_id: Option, ) -> Result { let data: &CreateCommunity = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; let site_view = SiteView::read_local(context.pool()).await?; let local_site = site_view.local_site; diff --git a/crates/api_crud/src/community/delete.rs b/crates/api_crud/src/community/delete.rs index 7ce685d8..9909f5cd 100644 --- a/crates/api_crud/src/community/delete.rs +++ b/crates/api_crud/src/community/delete.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ community::{CommunityResponse, DeleteCommunity}, context::LemmyContext, - utils::{get_local_user_view_from_jwt, is_top_mod}, + utils::{is_top_mod, local_user_view_from_jwt}, websocket::UserOperationCrud, }; use lemmy_db_schema::{ @@ -24,8 +24,7 @@ impl PerformCrud for DeleteCommunity { websocket_id: Option, ) -> Result { let data: &DeleteCommunity = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; // Fetch the community mods let community_id = data.community_id; diff --git a/crates/api_crud/src/community/list.rs b/crates/api_crud/src/community/list.rs index ef4c46d8..e620e160 100644 --- a/crates/api_crud/src/community/list.rs +++ b/crates/api_crud/src/community/list.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ community::{ListCommunities, ListCommunitiesResponse}, context::LemmyContext, - utils::{check_private_instance, get_local_user_view_from_jwt_opt, is_admin}, + utils::{check_private_instance, is_admin, local_user_view_from_jwt_opt}, }; use lemmy_db_schema::source::local_site::LocalSite; use lemmy_db_views_actor::community_view::CommunityQuery; @@ -20,9 +20,7 @@ impl PerformCrud for ListCommunities { _websocket_id: Option, ) -> Result { let data: &ListCommunities = self; - let local_user_view = - get_local_user_view_from_jwt_opt(data.auth.as_ref(), context.pool(), context.secret()) - .await?; + let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await; let local_site = LocalSite::read(context.pool()).await?; let is_admin = local_user_view.as_ref().map(|luv| is_admin(luv).is_ok()); diff --git a/crates/api_crud/src/community/remove.rs b/crates/api_crud/src/community/remove.rs index f7914762..9a905b87 100644 --- a/crates/api_crud/src/community/remove.rs +++ b/crates/api_crud/src/community/remove.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ community::{CommunityResponse, RemoveCommunity}, context::LemmyContext, - utils::{get_local_user_view_from_jwt, is_admin}, + utils::{is_admin, local_user_view_from_jwt}, websocket::UserOperationCrud, }; use lemmy_db_schema::{ @@ -26,8 +26,7 @@ impl PerformCrud for RemoveCommunity { websocket_id: Option, ) -> Result { let data: &RemoveCommunity = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; // Verify its an admin (only an admin can remove a community) is_admin(&local_user_view)?; diff --git a/crates/api_crud/src/community/update.rs b/crates/api_crud/src/community/update.rs index 200c5f2c..9d56ce8a 100644 --- a/crates/api_crud/src/community/update.rs +++ b/crates/api_crud/src/community/update.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ community::{CommunityResponse, EditCommunity}, context::LemmyContext, - utils::{get_local_user_view_from_jwt, local_site_to_slur_regex}, + utils::{local_site_to_slur_regex, local_user_view_from_jwt}, websocket::UserOperationCrud, }; use lemmy_db_schema::{ @@ -34,8 +34,7 @@ impl PerformCrud for EditCommunity { websocket_id: Option, ) -> Result { let data: &EditCommunity = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; let local_site = LocalSite::read(context.pool()).await?; let icon = diesel_option_overwrite_to_url(&data.icon)?; diff --git a/crates/api_crud/src/custom_emoji/create.rs b/crates/api_crud/src/custom_emoji/create.rs index 42b6c5d9..33337945 100644 --- a/crates/api_crud/src/custom_emoji/create.rs +++ b/crates/api_crud/src/custom_emoji/create.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ context::LemmyContext, custom_emoji::{CreateCustomEmoji, CustomEmojiResponse}, - utils::{get_local_user_view_from_jwt, is_admin}, + utils::{is_admin, local_user_view_from_jwt}, }; use lemmy_db_schema::source::{ custom_emoji::{CustomEmoji, CustomEmojiInsertForm}, @@ -24,8 +24,7 @@ impl PerformCrud for CreateCustomEmoji { _websocket_id: Option, ) -> Result { let data: &CreateCustomEmoji = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; let local_site = LocalSite::read(context.pool()).await?; // Make sure user is an admin diff --git a/crates/api_crud/src/custom_emoji/delete.rs b/crates/api_crud/src/custom_emoji/delete.rs index db8c973e..dcca8839 100644 --- a/crates/api_crud/src/custom_emoji/delete.rs +++ b/crates/api_crud/src/custom_emoji/delete.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ context::LemmyContext, custom_emoji::{DeleteCustomEmoji, DeleteCustomEmojiResponse}, - utils::{get_local_user_view_from_jwt, is_admin}, + utils::{is_admin, local_user_view_from_jwt}, }; use lemmy_db_schema::source::custom_emoji::CustomEmoji; use lemmy_utils::{error::LemmyError, ConnectionId}; @@ -19,8 +19,7 @@ impl PerformCrud for DeleteCustomEmoji { _websocket_id: Option, ) -> Result { let data: &DeleteCustomEmoji = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; // Make sure user is an admin is_admin(&local_user_view)?; diff --git a/crates/api_crud/src/custom_emoji/update.rs b/crates/api_crud/src/custom_emoji/update.rs index 6233cbe3..67a2bed9 100644 --- a/crates/api_crud/src/custom_emoji/update.rs +++ b/crates/api_crud/src/custom_emoji/update.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ context::LemmyContext, custom_emoji::{CustomEmojiResponse, EditCustomEmoji}, - utils::{get_local_user_view_from_jwt, is_admin}, + utils::{is_admin, local_user_view_from_jwt}, }; use lemmy_db_schema::source::{ custom_emoji::{CustomEmoji, CustomEmojiUpdateForm}, @@ -24,8 +24,7 @@ impl PerformCrud for EditCustomEmoji { _websocket_id: Option, ) -> Result { let data: &EditCustomEmoji = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; let local_site = LocalSite::read(context.pool()).await?; // Make sure user is an admin diff --git a/crates/api_crud/src/post/create.rs b/crates/api_crud/src/post/create.rs index 1a885184..e0c1a5d1 100644 --- a/crates/api_crud/src/post/create.rs +++ b/crates/api_crud/src/post/create.rs @@ -8,9 +8,9 @@ use lemmy_api_common::{ check_community_ban, check_community_deleted_or_removed, generate_local_apub_endpoint, - get_local_user_view_from_jwt, honeypot_check, local_site_to_slur_regex, + local_user_view_from_jwt, mark_post_as_read, EndpointType, }, @@ -50,8 +50,7 @@ impl PerformCrud for CreatePost { websocket_id: Option, ) -> Result { let data: &CreatePost = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; let local_site = LocalSite::read(context.pool()).await?; let slur_regex = local_site_to_slur_regex(&local_site); diff --git a/crates/api_crud/src/post/delete.rs b/crates/api_crud/src/post/delete.rs index fae5b009..82efeaa1 100644 --- a/crates/api_crud/src/post/delete.rs +++ b/crates/api_crud/src/post/delete.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ context::LemmyContext, post::{DeletePost, PostResponse}, - utils::{check_community_ban, check_community_deleted_or_removed, get_local_user_view_from_jwt}, + utils::{check_community_ban, check_community_deleted_or_removed, local_user_view_from_jwt}, websocket::UserOperationCrud, }; use lemmy_db_schema::{ @@ -23,8 +23,7 @@ impl PerformCrud for DeletePost { websocket_id: Option, ) -> Result { let data: &DeletePost = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; let post_id = data.post_id; let orig_post = Post::read(context.pool(), post_id).await?; diff --git a/crates/api_crud/src/post/read.rs b/crates/api_crud/src/post/read.rs index eadb6d11..cda2f65b 100644 --- a/crates/api_crud/src/post/read.rs +++ b/crates/api_crud/src/post/read.rs @@ -5,8 +5,8 @@ use lemmy_api_common::{ post::{GetPost, GetPostResponse}, utils::{ check_private_instance, - get_local_user_view_from_jwt_opt, is_mod_or_admin_opt, + local_user_view_from_jwt_opt, mark_post_as_read, }, websocket::handlers::online_users::GetPostUsersOnline, @@ -31,9 +31,7 @@ impl PerformCrud for GetPost { _websocket_id: Option, ) -> Result { let data: &GetPost = self; - let local_user_view = - get_local_user_view_from_jwt_opt(data.auth.as_ref(), context.pool(), context.secret()) - .await?; + let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await; let local_site = LocalSite::read(context.pool()).await?; check_private_instance(&local_user_view, &local_site)?; diff --git a/crates/api_crud/src/post/remove.rs b/crates/api_crud/src/post/remove.rs index b53a468e..9081d911 100644 --- a/crates/api_crud/src/post/remove.rs +++ b/crates/api_crud/src/post/remove.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ context::LemmyContext, post::{PostResponse, RemovePost}, - utils::{check_community_ban, get_local_user_view_from_jwt, is_mod_or_admin}, + utils::{check_community_ban, is_mod_or_admin, local_user_view_from_jwt}, websocket::UserOperationCrud, }; use lemmy_db_schema::{ @@ -26,8 +26,7 @@ impl PerformCrud for RemovePost { websocket_id: Option, ) -> Result { let data: &RemovePost = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; let post_id = data.post_id; let orig_post = Post::read(context.pool(), post_id).await?; diff --git a/crates/api_crud/src/post/update.rs b/crates/api_crud/src/post/update.rs index 8f5c442f..2bd101c0 100644 --- a/crates/api_crud/src/post/update.rs +++ b/crates/api_crud/src/post/update.rs @@ -4,7 +4,7 @@ use lemmy_api_common::{ context::LemmyContext, post::{EditPost, PostResponse}, request::fetch_site_data, - utils::{check_community_ban, get_local_user_view_from_jwt, local_site_to_slur_regex}, + utils::{check_community_ban, local_site_to_slur_regex, local_user_view_from_jwt}, websocket::UserOperationCrud, }; use lemmy_db_schema::{ @@ -36,8 +36,7 @@ impl PerformCrud for EditPost { websocket_id: Option, ) -> Result { let data: &EditPost = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; let local_site = LocalSite::read(context.pool()).await?; let data_url = data.url.as_ref(); diff --git a/crates/api_crud/src/private_message/create.rs b/crates/api_crud/src/private_message/create.rs index 48fa8402..6fd36900 100644 --- a/crates/api_crud/src/private_message/create.rs +++ b/crates/api_crud/src/private_message/create.rs @@ -7,8 +7,8 @@ use lemmy_api_common::{ check_person_block, generate_local_apub_endpoint, get_interface_language, - get_local_user_view_from_jwt, local_site_to_slur_regex, + local_user_view_from_jwt, send_email_to_user, EndpointType, }, @@ -39,8 +39,7 @@ impl PerformCrud for CreatePrivateMessage { websocket_id: Option, ) -> Result { let data: &CreatePrivateMessage = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; let local_site = LocalSite::read(context.pool()).await?; let content_slurs_removed = remove_slurs( diff --git a/crates/api_crud/src/private_message/delete.rs b/crates/api_crud/src/private_message/delete.rs index e6a643a7..f494edff 100644 --- a/crates/api_crud/src/private_message/delete.rs +++ b/crates/api_crud/src/private_message/delete.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ context::LemmyContext, private_message::{DeletePrivateMessage, PrivateMessageResponse}, - utils::get_local_user_view_from_jwt, + utils::local_user_view_from_jwt, websocket::UserOperationCrud, }; use lemmy_db_schema::{ @@ -23,8 +23,7 @@ impl PerformCrud for DeletePrivateMessage { websocket_id: Option, ) -> Result { let data: &DeletePrivateMessage = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; // Checking permissions let private_message_id = data.private_message_id; diff --git a/crates/api_crud/src/private_message/read.rs b/crates/api_crud/src/private_message/read.rs index c9a37753..da2bc690 100644 --- a/crates/api_crud/src/private_message/read.rs +++ b/crates/api_crud/src/private_message/read.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ context::LemmyContext, private_message::{GetPrivateMessages, PrivateMessagesResponse}, - utils::get_local_user_view_from_jwt, + utils::local_user_view_from_jwt, }; use lemmy_db_views::private_message_view::PrivateMessageQuery; use lemmy_utils::{error::LemmyError, ConnectionId}; @@ -19,8 +19,7 @@ impl PerformCrud for GetPrivateMessages { _websocket_id: Option, ) -> Result { let data: &GetPrivateMessages = self; - let local_user_view = - get_local_user_view_from_jwt(data.auth.as_ref(), context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(data.auth.as_ref(), context).await?; let person_id = local_user_view.person.id; let page = data.page; diff --git a/crates/api_crud/src/private_message/update.rs b/crates/api_crud/src/private_message/update.rs index 6a6bfa21..a485a509 100644 --- a/crates/api_crud/src/private_message/update.rs +++ b/crates/api_crud/src/private_message/update.rs @@ -3,7 +3,7 @@ use actix_web::web::Data; use lemmy_api_common::{ context::LemmyContext, private_message::{EditPrivateMessage, PrivateMessageResponse}, - utils::{get_local_user_view_from_jwt, local_site_to_slur_regex}, + utils::{local_site_to_slur_regex, local_user_view_from_jwt}, websocket::UserOperationCrud, }; use lemmy_db_schema::{ @@ -31,8 +31,7 @@ impl PerformCrud for EditPrivateMessage { websocket_id: Option, ) -> Result { let data: &EditPrivateMessage = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; let local_site = LocalSite::read(context.pool()).await?; // Checking permissions diff --git a/crates/api_crud/src/site/create.rs b/crates/api_crud/src/site/create.rs index d45caaa8..0f3e8c56 100644 --- a/crates/api_crud/src/site/create.rs +++ b/crates/api_crud/src/site/create.rs @@ -6,10 +6,10 @@ use lemmy_api_common::{ site::{CreateSite, SiteResponse}, utils::{ generate_site_inbox_url, - get_local_user_view_from_jwt, is_admin, local_site_rate_limit_to_rate_limit_config, local_site_to_slur_regex, + local_user_view_from_jwt, site_description_length_check, }, }; @@ -52,8 +52,7 @@ impl PerformCrud for CreateSite { return Err(LemmyError::from_message("site_already_exists")); }; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; let sidebar = diesel_option_overwrite(&data.sidebar); let description = diesel_option_overwrite(&data.description); diff --git a/crates/api_crud/src/site/read.rs b/crates/api_crud/src/site/read.rs index fc74ecae..1e40cabd 100644 --- a/crates/api_crud/src/site/read.rs +++ b/crates/api_crud/src/site/read.rs @@ -2,16 +2,20 @@ use crate::PerformCrud; use actix_web::web::Data; use lemmy_api_common::{ context::LemmyContext, + sensitive::Sensitive, site::{GetSite, GetSiteResponse, MyUserInfo}, - utils::get_local_user_settings_view_from_jwt_opt, + utils::{check_user_valid, check_validator_time}, websocket::handlers::online_users::GetUsersOnline, }; -use lemmy_db_schema::source::{ - actor_language::{LocalUserLanguage, SiteLanguage}, - language::Language, - tagline::Tagline, +use lemmy_db_schema::{ + newtypes::LocalUserId, + source::{ + actor_language::{LocalUserLanguage, SiteLanguage}, + language::Language, + tagline::Tagline, + }, }; -use lemmy_db_views::structs::{CustomEmojiView, SiteView}; +use lemmy_db_views::structs::{CustomEmojiView, LocalUserView, SiteView}; use lemmy_db_views_actor::structs::{ CommunityBlockView, CommunityFollowerView, @@ -19,7 +23,7 @@ use lemmy_db_views_actor::structs::{ PersonBlockView, PersonView, }; -use lemmy_utils::{error::LemmyError, version, ConnectionId}; +use lemmy_utils::{claims::Claims, error::LemmyError, version, ConnectionId}; #[async_trait::async_trait(?Send)] impl PerformCrud for GetSite { @@ -40,12 +44,8 @@ impl PerformCrud for GetSite { let online = context.chat_server().send(GetUsersOnline).await?; // Build the local user - let my_user = if let Some(local_user_view) = get_local_user_settings_view_from_jwt_opt( - data.auth.as_ref(), - context.pool(), - context.secret(), - ) - .await? + let my_user = if let Some(local_user_view) = + local_user_settings_view_from_jwt_opt(data.auth.as_ref(), context).await { let person_id = local_user_view.person.id; let local_user_id = local_user_view.local_user.id; @@ -102,3 +102,32 @@ impl PerformCrud for GetSite { }) } } + +#[tracing::instrument(skip_all)] +async fn local_user_settings_view_from_jwt_opt( + jwt: Option<&Sensitive>, + context: &LemmyContext, +) -> Option { + match jwt { + Some(jwt) => { + let claims = Claims::decode(jwt.as_ref(), &context.secret().jwt_secret) + .ok()? + .claims; + let local_user_id = LocalUserId(claims.sub); + let local_user_view = LocalUserView::read(context.pool(), local_user_id) + .await + .ok()?; + check_user_valid( + local_user_view.person.banned, + local_user_view.person.ban_expires, + local_user_view.person.deleted, + ) + .ok()?; + + check_validator_time(&local_user_view.local_user.validator_time, &claims).ok()?; + + Some(local_user_view) + } + None => None, + } +} diff --git a/crates/api_crud/src/site/update.rs b/crates/api_crud/src/site/update.rs index 03ff5901..693be690 100644 --- a/crates/api_crud/src/site/update.rs +++ b/crates/api_crud/src/site/update.rs @@ -4,10 +4,10 @@ use lemmy_api_common::{ context::LemmyContext, site::{EditSite, SiteResponse}, utils::{ - get_local_user_view_from_jwt, is_admin, local_site_rate_limit_to_rate_limit_config, local_site_to_slur_regex, + local_user_view_from_jwt, site_description_length_check, }, websocket::UserOperationCrud, @@ -46,8 +46,7 @@ impl PerformCrud for EditSite { websocket_id: Option, ) -> Result { let data: &EditSite = self; - let local_user_view = - get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; let site_view = SiteView::read_local(context.pool()).await?; let local_site = site_view.local_site; let site = site_view.site; diff --git a/crates/api_crud/src/user/delete.rs b/crates/api_crud/src/user/delete.rs index b49695ea..731f9072 100644 --- a/crates/api_crud/src/user/delete.rs +++ b/crates/api_crud/src/user/delete.rs @@ -4,7 +4,7 @@ use bcrypt::verify; use lemmy_api_common::{ context::LemmyContext, person::{DeleteAccount, DeleteAccountResponse}, - utils::get_local_user_view_from_jwt, + utils::local_user_view_from_jwt, }; use lemmy_utils::{error::LemmyError, ConnectionId}; @@ -19,8 +19,7 @@ impl PerformCrud for DeleteAccount { _websocket_id: Option, ) -> Result { let data = self; - let local_user_view = - get_local_user_view_from_jwt(data.auth.as_ref(), context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(data.auth.as_ref(), context).await?; // Verify the password let valid: bool = verify( diff --git a/crates/apub/src/activities/block/mod.rs b/crates/apub/src/activities/block/mod.rs index a1315bb7..a791ea40 100644 --- a/crates/apub/src/activities/block/mod.rs +++ b/crates/apub/src/activities/block/mod.rs @@ -16,7 +16,7 @@ use lemmy_api_common::{ community::{BanFromCommunity, BanFromCommunityResponse}, context::LemmyContext, person::{BanPerson, BanPersonResponse}, - utils::get_local_user_view_from_jwt, + utils::local_user_view_from_jwt, }; use lemmy_db_schema::{ source::{community::Community, person::Person, site::Site}, @@ -138,8 +138,7 @@ impl SendActivity for BanPerson { _response: &Self::Response, context: &Data, ) -> Result<(), LemmyError> { - let local_user_view = - get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&request.auth, context).await?; let person = Person::read(context.pool(), request.person_id).await?; let site = SiteOrCommunity::Site(SiteView::read_local(context.pool()).await?.site.into()); let expires = request.expires.map(naive_from_unix); @@ -182,8 +181,7 @@ impl SendActivity for BanFromCommunity { _response: &Self::Response, context: &Data, ) -> Result<(), LemmyError> { - let local_user_view = - get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&request.auth, context).await?; let community: ApubCommunity = Community::read(context.pool(), request.community_id) .await? .into(); diff --git a/crates/apub/src/activities/community/collection_add.rs b/crates/apub/src/activities/community/collection_add.rs index dfab0baf..afe8387f 100644 --- a/crates/apub/src/activities/community/collection_add.rs +++ b/crates/apub/src/activities/community/collection_add.rs @@ -29,7 +29,7 @@ use lemmy_api_common::{ community::{AddModToCommunity, AddModToCommunityResponse}, context::LemmyContext, post::{FeaturePost, PostResponse}, - utils::{generate_featured_url, generate_moderators_url, get_local_user_view_from_jwt}, + utils::{generate_featured_url, generate_moderators_url, local_user_view_from_jwt}, }; use lemmy_db_schema::{ impls::community::CollectionType, @@ -177,8 +177,7 @@ impl SendActivity for AddModToCommunity { _response: &Self::Response, context: &Data, ) -> Result<(), LemmyError> { - let local_user_view = - get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&request.auth, context).await?; let community: ApubCommunity = Community::read(context.pool(), request.community_id) .await? .into(); @@ -214,8 +213,7 @@ impl SendActivity for FeaturePost { response: &Self::Response, context: &Data, ) -> Result<(), LemmyError> { - let local_user_view = - get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&request.auth, context).await?; // Deprecated, for backwards compatibility with 0.17 CreateOrUpdatePage::send( &response.post_view.post, diff --git a/crates/apub/src/activities/community/lock_page.rs b/crates/apub/src/activities/community/lock_page.rs index 498c3a32..26326efc 100644 --- a/crates/apub/src/activities/community/lock_page.rs +++ b/crates/apub/src/activities/community/lock_page.rs @@ -27,7 +27,7 @@ use activitypub_federation::{ use lemmy_api_common::{ context::LemmyContext, post::{LockPost, PostResponse}, - utils::get_local_user_view_from_jwt, + utils::local_user_view_from_jwt, }; use lemmy_db_schema::{ source::{ @@ -115,8 +115,7 @@ impl SendActivity for LockPost { response: &Self::Response, context: &Data, ) -> Result<(), LemmyError> { - let local_user_view = - get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&request.auth, context).await?; // For backwards compat with 0.17 CreateOrUpdatePage::send( &response.post_view.post, diff --git a/crates/apub/src/activities/community/report.rs b/crates/apub/src/activities/community/report.rs index 9830be13..aaa1e510 100644 --- a/crates/apub/src/activities/community/report.rs +++ b/crates/apub/src/activities/community/report.rs @@ -16,7 +16,7 @@ use lemmy_api_common::{ comment::{CommentReportResponse, CreateCommentReport}, context::LemmyContext, post::{CreatePostReport, PostReportResponse}, - utils::get_local_user_view_from_jwt, + utils::local_user_view_from_jwt, websocket::UserOperation, }; use lemmy_db_schema::{ @@ -39,8 +39,7 @@ impl SendActivity for CreatePostReport { response: &Self::Response, context: &Data, ) -> Result<(), LemmyError> { - let local_user_view = - get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&request.auth, context).await?; Report::send( ObjectId::from(response.post_report_view.post.ap_id.clone()), &local_user_view.person.into(), @@ -61,8 +60,7 @@ impl SendActivity for CreateCommentReport { response: &Self::Response, context: &Data, ) -> Result<(), LemmyError> { - let local_user_view = - get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&request.auth, context).await?; Report::send( ObjectId::from(response.comment_report_view.comment.ap_id.clone()), &local_user_view.person.into(), diff --git a/crates/apub/src/activities/community/update.rs b/crates/apub/src/activities/community/update.rs index 85581e2a..5cf1881a 100644 --- a/crates/apub/src/activities/community/update.rs +++ b/crates/apub/src/activities/community/update.rs @@ -20,7 +20,7 @@ use activitypub_federation::{ use lemmy_api_common::{ community::{CommunityResponse, EditCommunity, HideCommunity}, context::LemmyContext, - utils::get_local_user_view_from_jwt, + utils::local_user_view_from_jwt, websocket::UserOperationCrud, }; use lemmy_db_schema::{source::community::Community, traits::Crud}; @@ -36,8 +36,7 @@ impl SendActivity for EditCommunity { _response: &Self::Response, context: &Data, ) -> Result<(), LemmyError> { - let local_user_view = - get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&request.auth, context).await?; let community = Community::read(context.pool(), request.community_id).await?; UpdateCommunity::send(community.into(), &local_user_view.person.into(), context).await } @@ -123,8 +122,7 @@ impl SendActivity for HideCommunity { _response: &Self::Response, context: &Data, ) -> Result<(), LemmyError> { - let local_user_view = - get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&request.auth, context).await?; let community = Community::read(context.pool(), request.community_id).await?; UpdateCommunity::send(community.into(), &local_user_view.person.into(), context).await } diff --git a/crates/apub/src/activities/deletion/delete_user.rs b/crates/apub/src/activities/deletion/delete_user.rs index e5c1021c..11be132e 100644 --- a/crates/apub/src/activities/deletion/delete_user.rs +++ b/crates/apub/src/activities/deletion/delete_user.rs @@ -14,7 +14,7 @@ use activitypub_federation::{ use lemmy_api_common::{ context::LemmyContext, person::{DeleteAccount, DeleteAccountResponse}, - utils::{delete_user_account, get_local_user_view_from_jwt}, + utils::{delete_user_account, local_user_view_from_jwt}, }; use lemmy_utils::error::LemmyError; use url::Url; @@ -28,8 +28,7 @@ impl SendActivity for DeleteAccount { _response: &Self::Response, context: &Data, ) -> Result<(), LemmyError> { - let local_user_view = - get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&request.auth, context).await?; let actor: ApubPerson = local_user_view.person.into(); delete_user_account( actor.id, diff --git a/crates/apub/src/activities/deletion/mod.rs b/crates/apub/src/activities/deletion/mod.rs index 690b1d3a..ea6f4a67 100644 --- a/crates/apub/src/activities/deletion/mod.rs +++ b/crates/apub/src/activities/deletion/mod.rs @@ -34,7 +34,7 @@ use lemmy_api_common::{ context::LemmyContext, post::{DeletePost, PostResponse, RemovePost}, private_message::{DeletePrivateMessage, PrivateMessageResponse}, - utils::get_local_user_view_from_jwt, + utils::local_user_view_from_jwt, websocket::UserOperationCrud, }; use lemmy_db_schema::{ @@ -64,8 +64,7 @@ impl SendActivity for DeletePost { response: &Self::Response, context: &Data, ) -> Result<(), LemmyError> { - let local_user_view = - get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&request.auth, context).await?; let community = Community::read(context.pool(), response.post_view.community.id).await?; let deletable = DeletableObjects::Post(response.post_view.post.clone().into()); send_apub_delete_in_community( @@ -89,8 +88,7 @@ impl SendActivity for RemovePost { response: &Self::Response, context: &Data, ) -> Result<(), LemmyError> { - let local_user_view = - get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&request.auth, context).await?; let community = Community::read(context.pool(), response.post_view.community.id).await?; let deletable = DeletableObjects::Post(response.post_view.post.clone().into()); send_apub_delete_in_community( @@ -132,8 +130,7 @@ impl SendActivity for RemoveComment { response: &Self::Response, context: &Data, ) -> Result<(), LemmyError> { - let local_user_view = - get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&request.auth, context).await?; let comment = Comment::read(context.pool(), request.comment_id).await?; let community = Community::read(context.pool(), response.comment_view.community.id).await?; let deletable = DeletableObjects::Comment(comment.into()); @@ -158,8 +155,7 @@ impl SendActivity for DeletePrivateMessage { response: &Self::Response, context: &Data, ) -> Result<(), LemmyError> { - let local_user_view = - get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&request.auth, context).await?; send_apub_delete_private_message( &local_user_view.person.into(), response.private_message_view.private_message.clone(), @@ -179,8 +175,7 @@ impl SendActivity for DeleteCommunity { _response: &Self::Response, context: &Data, ) -> Result<(), LemmyError> { - let local_user_view = - get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&request.auth, context).await?; let community = Community::read(context.pool(), request.community_id).await?; let deletable = DeletableObjects::Community(community.clone().into()); send_apub_delete_in_community( @@ -204,8 +199,7 @@ impl SendActivity for RemoveCommunity { _response: &Self::Response, context: &Data, ) -> Result<(), LemmyError> { - let local_user_view = - get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&request.auth, context).await?; let community = Community::read(context.pool(), request.community_id).await?; let deletable = DeletableObjects::Community(community.clone().into()); send_apub_delete_in_community( diff --git a/crates/apub/src/activities/following/follow.rs b/crates/apub/src/activities/following/follow.rs index 4e2acd51..8a785da0 100644 --- a/crates/apub/src/activities/following/follow.rs +++ b/crates/apub/src/activities/following/follow.rs @@ -24,7 +24,7 @@ use activitypub_federation::{ use lemmy_api_common::{ community::{BlockCommunity, BlockCommunityResponse}, context::LemmyContext, - utils::get_local_user_view_from_jwt, + utils::local_user_view_from_jwt, }; use lemmy_db_schema::{ source::{ @@ -138,8 +138,7 @@ impl SendActivity for BlockCommunity { _response: &Self::Response, context: &Data, ) -> Result<(), LemmyError> { - let local_user_view = - get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&request.auth, context).await?; let community = Community::read(context.pool(), request.community_id).await?; UndoFollow::send(&local_user_view.person.into(), &community.into(), context).await } diff --git a/crates/apub/src/activities/following/mod.rs b/crates/apub/src/activities/following/mod.rs index 5b9d98b4..a4c2fd67 100644 --- a/crates/apub/src/activities/following/mod.rs +++ b/crates/apub/src/activities/following/mod.rs @@ -7,7 +7,7 @@ use activitypub_federation::config::Data; use lemmy_api_common::{ community::{CommunityResponse, FollowCommunity}, context::LemmyContext, - utils::get_local_user_view_from_jwt, + utils::local_user_view_from_jwt, }; use lemmy_db_schema::{source::community::Community, traits::Crud}; use lemmy_utils::error::LemmyError; @@ -25,8 +25,7 @@ impl SendActivity for FollowCommunity { _response: &Self::Response, context: &Data, ) -> Result<(), LemmyError> { - let local_user_view = - get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&request.auth, context).await?; let person = local_user_view.person.clone().into(); let community: ApubCommunity = Community::read(context.pool(), request.community_id) .await? diff --git a/crates/apub/src/activities/voting/mod.rs b/crates/apub/src/activities/voting/mod.rs index 89832148..60015b13 100644 --- a/crates/apub/src/activities/voting/mod.rs +++ b/crates/apub/src/activities/voting/mod.rs @@ -15,7 +15,7 @@ use lemmy_api_common::{ context::LemmyContext, post::{CreatePostLike, PostResponse}, sensitive::Sensitive, - utils::get_local_user_view_from_jwt, + utils::local_user_view_from_jwt, websocket::UserOperation, }; use lemmy_db_schema::{ @@ -85,7 +85,7 @@ async fn send_activity( context: &Data, ) -> Result<(), LemmyError> { let community = Community::read(context.pool(), community_id).await?.into(); - let local_user_view = get_local_user_view_from_jwt(jwt, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(jwt, context).await?; let actor = Person::read(context.pool(), local_user_view.person.id) .await? .into(); diff --git a/crates/apub/src/api/list_comments.rs b/crates/apub/src/api/list_comments.rs index bc0010ab..f697a735 100644 --- a/crates/apub/src/api/list_comments.rs +++ b/crates/apub/src/api/list_comments.rs @@ -7,7 +7,7 @@ use activitypub_federation::config::Data; use lemmy_api_common::{ comment::{GetComments, GetCommentsResponse}, context::LemmyContext, - utils::{check_private_instance, get_local_user_view_from_jwt_opt}, + utils::{check_private_instance, local_user_view_from_jwt_opt}, }; use lemmy_db_schema::{ source::{comment::Comment, community::Community, local_site::LocalSite}, @@ -27,9 +27,7 @@ impl PerformApub for GetComments { _websocket_id: Option, ) -> Result { let data: &GetComments = self; - let local_user_view = - get_local_user_view_from_jwt_opt(data.auth.as_ref(), context.pool(), context.secret()) - .await?; + let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await; let local_site = LocalSite::read(context.pool()).await?; check_private_instance(&local_user_view, &local_site)?; diff --git a/crates/apub/src/api/list_posts.rs b/crates/apub/src/api/list_posts.rs index 7859f754..58c31b2e 100644 --- a/crates/apub/src/api/list_posts.rs +++ b/crates/apub/src/api/list_posts.rs @@ -7,7 +7,7 @@ use activitypub_federation::config::Data; use lemmy_api_common::{ context::LemmyContext, post::{GetPosts, GetPostsResponse}, - utils::{check_private_instance, get_local_user_view_from_jwt_opt, is_mod_or_admin_opt}, + utils::{check_private_instance, is_mod_or_admin_opt, local_user_view_from_jwt_opt}, }; use lemmy_db_schema::source::{community::Community, local_site::LocalSite}; use lemmy_db_views::post_view::PostQuery; @@ -24,9 +24,7 @@ impl PerformApub for GetPosts { _websocket_id: Option, ) -> Result { let data: &GetPosts = self; - let local_user_view = - get_local_user_view_from_jwt_opt(data.auth.as_ref(), context.pool(), context.secret()) - .await?; + let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await; let local_site = LocalSite::read(context.pool()).await?; check_private_instance(&local_user_view, &local_site)?; diff --git a/crates/apub/src/api/read_community.rs b/crates/apub/src/api/read_community.rs index e01c7bda..53469cf8 100644 --- a/crates/apub/src/api/read_community.rs +++ b/crates/apub/src/api/read_community.rs @@ -7,7 +7,7 @@ use activitypub_federation::config::Data; use lemmy_api_common::{ community::{GetCommunity, GetCommunityResponse}, context::LemmyContext, - utils::{check_private_instance, get_local_user_view_from_jwt_opt, is_mod_or_admin_opt}, + utils::{check_private_instance, is_mod_or_admin_opt, local_user_view_from_jwt_opt}, websocket::handlers::online_users::GetCommunityUsersOnline, }; use lemmy_db_schema::source::{ @@ -30,9 +30,7 @@ impl PerformApub for GetCommunity { _websocket_id: Option, ) -> Result { let data: &GetCommunity = self; - let local_user_view = - get_local_user_view_from_jwt_opt(data.auth.as_ref(), context.pool(), context.secret()) - .await?; + let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await; let local_site = LocalSite::read(context.pool()).await?; if data.name.is_none() && data.id.is_none() { diff --git a/crates/apub/src/api/read_person.rs b/crates/apub/src/api/read_person.rs index 95d9ecc0..9d453ace 100644 --- a/crates/apub/src/api/read_person.rs +++ b/crates/apub/src/api/read_person.rs @@ -3,7 +3,7 @@ use activitypub_federation::config::Data; use lemmy_api_common::{ context::LemmyContext, person::{GetPersonDetails, GetPersonDetailsResponse}, - utils::{check_private_instance, get_local_user_view_from_jwt_opt, is_admin}, + utils::{check_private_instance, is_admin, local_user_view_from_jwt_opt}, }; use lemmy_db_schema::{ source::{local_site::LocalSite, person::Person}, @@ -30,9 +30,7 @@ impl PerformApub for GetPersonDetails { return Err(LemmyError::from_message("no_id_given")); } - let local_user_view = - get_local_user_view_from_jwt_opt(data.auth.as_ref(), context.pool(), context.secret()) - .await?; + let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await; let local_site = LocalSite::read(context.pool()).await?; let is_admin = local_user_view.as_ref().map(|luv| is_admin(luv).is_ok()); diff --git a/crates/apub/src/api/resolve_object.rs b/crates/apub/src/api/resolve_object.rs index f0cb15e3..193494dd 100644 --- a/crates/apub/src/api/resolve_object.rs +++ b/crates/apub/src/api/resolve_object.rs @@ -7,7 +7,7 @@ use diesel::NotFound; use lemmy_api_common::{ context::LemmyContext, site::{ResolveObject, ResolveObjectResponse}, - utils::{check_private_instance, get_local_user_view_from_jwt}, + utils::{check_private_instance, local_user_view_from_jwt}, }; use lemmy_db_schema::{newtypes::PersonId, source::local_site::LocalSite, utils::DbPool}; use lemmy_db_views::structs::{CommentView, PostView}; @@ -24,8 +24,7 @@ impl PerformApub for ResolveObject { context: &Data, _websocket_id: Option, ) -> Result { - let local_user_view = - get_local_user_view_from_jwt(&self.auth, context.pool(), context.secret()).await?; + let local_user_view = local_user_view_from_jwt(&self.auth, context).await?; let local_site = LocalSite::read(context.pool()).await?; let person_id = local_user_view.person.id; check_private_instance(&Some(local_user_view), &local_site)?; diff --git a/crates/apub/src/api/search.rs b/crates/apub/src/api/search.rs index 212e037f..6cbd6b1e 100644 --- a/crates/apub/src/api/search.rs +++ b/crates/apub/src/api/search.rs @@ -7,7 +7,7 @@ use activitypub_federation::config::Data; use lemmy_api_common::{ context::LemmyContext, site::{Search, SearchResponse}, - utils::{check_private_instance, get_local_user_view_from_jwt_opt, is_admin}, + utils::{check_private_instance, is_admin, local_user_view_from_jwt_opt}, }; use lemmy_db_schema::{ source::{community::Community, local_site::LocalSite}, @@ -30,9 +30,7 @@ impl PerformApub for Search { ) -> Result { let data: &Search = self; - let local_user_view = - get_local_user_view_from_jwt_opt(data.auth.as_ref(), context.pool(), context.secret()) - .await?; + let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await; let local_site = LocalSite::read(context.pool()).await?; check_private_instance(&local_user_view, &local_site)?; diff --git a/crates/routes/src/images.rs b/crates/routes/src/images.rs index cd6555d7..9b7801f2 100644 --- a/crates/routes/src/images.rs +++ b/crates/routes/src/images.rs @@ -11,7 +11,7 @@ use actix_web::{ HttpResponse, }; use futures::stream::{Stream, StreamExt}; -use lemmy_api_common::{context::LemmyContext, utils::get_local_user_view_from_jwt}; +use lemmy_api_common::{context::LemmyContext, utils::local_user_view_from_jwt}; use lemmy_db_schema::source::local_site::LocalSite; use lemmy_utils::{claims::Claims, rate_limit::RateLimitCell, REQWEST_TIMEOUT}; use reqwest::Body; @@ -136,7 +136,7 @@ async fn full_res( let jwt = req .cookie("jwt") .expect("No auth header for picture access"); - if get_local_user_view_from_jwt(jwt.value(), context.pool(), context.secret()) + if local_user_view_from_jwt(jwt.value(), &context) .await .is_err() {