Dont return error in case optional auth is invalid (#2879)

* Dont return error in case optional auth is invalid

* fixes
This commit is contained in:
Nutomic 2023-05-25 16:50:07 +02:00 committed by GitHub
parent 4a70502007
commit a5707328cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
92 changed files with 271 additions and 354 deletions

View file

@ -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();
});

View file

@ -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<ConnectionId>,
) -> Result<CommentResponse, LemmyError> {
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?;

View file

@ -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<CommentResponse, LemmyError> {
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::<LocalUserId>::new();

View file

@ -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<ConnectionId>,
) -> Result<CommentResponse, LemmyError> {
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,

View file

@ -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<ConnectionId>,
) -> Result<CommentReportResponse, LemmyError> {
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();

View file

@ -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<ConnectionId>,
) -> Result<ListCommentReportsResponse, LemmyError> {
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;

View file

@ -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<ConnectionId>,
) -> Result<CommentReportResponse, LemmyError> {
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;

View file

@ -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<ConnectionId>,
) -> Result<AddModToCommunityResponse, LemmyError> {
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;

View file

@ -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<ConnectionId>,
) -> Result<BanFromCommunityResponse, LemmyError> {
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;

View file

@ -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<ConnectionId>,
) -> Result<BlockCommunityResponse, LemmyError> {
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;

View file

@ -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<ConnectionId>,
) -> Result<CommunityResponse, LemmyError> {
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?;

View file

@ -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()

View file

@ -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<ConnectionId>,
) -> Result<GetCommunityResponse, LemmyError> {
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;

View file

@ -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<ConnectionId>,
) -> Result<AddAdminResponse, LemmyError> {
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)?;

View file

@ -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<ConnectionId>,
) -> Result<BanPersonResponse, LemmyError> {
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)?;

View file

@ -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<ConnectionId>,
) -> Result<BlockPersonResponse, LemmyError> {
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;

View file

@ -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<ConnectionId>,
) -> Result<LoginResponse, LemmyError> {
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)?;

View file

@ -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<ConnectionId>,
) -> Result<Self::Response, LemmyError> {
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)?;

View file

@ -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<ConnectionId>,
) -> Result<GetPersonMentionsResponse, LemmyError> {
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;

View file

@ -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<ConnectionId>,
) -> Result<GetRepliesResponse, LemmyError> {
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;

View file

@ -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<ConnectionId>,
) -> Result<GetRepliesResponse, LemmyError> {
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

View file

@ -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<ConnectionId>,
) -> Result<PersonMentionResponse, LemmyError> {
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?;

View file

@ -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<ConnectionId>,
) -> Result<CommentReplyResponse, LemmyError> {
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?;

View file

@ -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<ConnectionId>,
) -> Result<Self::Response, LemmyError> {
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;

View file

@ -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<ConnectionId>,
) -> Result<GetReportCountResponse, LemmyError> {
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;

View file

@ -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<ConnectionId>,
) -> Result<LoginResponse, LemmyError> {
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)?;

View file

@ -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<ConnectionId>,
) -> Result<PostResponse, LemmyError> {
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?;

View file

@ -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<ConnectionId>,
) -> Result<PostResponse, LemmyError> {
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

View file

@ -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<ConnectionId>,
) -> Result<PostResponse, LemmyError> {
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?;

View file

@ -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<ConnectionId>,
) -> Result<Self::Response, LemmyError> {
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;

View file

@ -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<ConnectionId>,
) -> Result<PostResponse, LemmyError> {
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,

View file

@ -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<ConnectionId>,
) -> Result<PostReportResponse, LemmyError> {
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();

View file

@ -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<ConnectionId>,
) -> Result<ListPostReportsResponse, LemmyError> {
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;

View file

@ -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<ConnectionId>,
) -> Result<PostReportResponse, LemmyError> {
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;

View file

@ -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<ConnectionId>,
) -> Result<PrivateMessageResponse, LemmyError> {
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;

View file

@ -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<LemmyContext>,
websocket_id: Option<ConnectionId>,
) -> Result<Self::Response, LemmyError> {
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();

View file

@ -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<LemmyContext>,
_websocket_id: Option<ConnectionId>,
) -> Result<Self::Response, LemmyError> {
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)?;

View file

@ -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<LemmyContext>,
websocket_id: Option<ConnectionId>,
) -> Result<Self::Response, LemmyError> {
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)?;

View file

@ -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<ConnectionId>,
) -> Result<GetSiteResponse, LemmyError> {
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)?;

View file

@ -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<GetModlogResponse, LemmyError> {
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)?;

View file

@ -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<ConnectionId>,
) -> Result<Self::Response, LemmyError> {
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?;

View file

@ -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<ConnectionId>,
) -> Result<Self::Response, LemmyError> {
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?;

View file

@ -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<ConnectionId>,
) -> Result<Self::Response, LemmyError> {
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?;

View file

@ -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<ConnectionId>,
) -> Result<Self::Response, LemmyError> {
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?;

View file

@ -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<ConnectionId>,
) -> Result<Self::Response, LemmyError> {
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;

View file

@ -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<ConnectionId>,
) -> Result<Self::Response, LemmyError> {
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

View file

@ -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<ConnectionId>,
) -> Result<Self::Response, LemmyError> {
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

View file

@ -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<ConnectionId>,
) -> Result<UserJoinResponse, LemmyError> {
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 {

View file

@ -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<LocalUserView, LemmyError> {
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<String>>,
context: &LemmyContext,
) -> Option<LocalUserView> {
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<String>>,
pool: &DbPool,
secret: &Secret,
) -> Result<Option<LocalUserView>, 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<String>>,
pool: &DbPool,
secret: &Secret,
) -> Result<Option<LocalUserView>, 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<NaiveDateTime>,
@ -314,9 +287,11 @@ pub async fn build_federated_instances(
) -> Result<Option<FederatedInstances>, 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,

View file

@ -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<ConnectionId>,
) -> Result<CommentResponse, LemmyError> {
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(

View file

@ -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<ConnectionId>,
) -> Result<CommentResponse, LemmyError> {
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?;

View file

@ -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<ConnectionId>,
) -> Result<Self::Response, LemmyError> {
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)?;

View file

@ -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<ConnectionId>,
) -> Result<CommentResponse, LemmyError> {
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?;

View file

@ -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<ConnectionId>,
) -> Result<CommentResponse, LemmyError> {
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;

View file

@ -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<ConnectionId>,
) -> Result<CommunityResponse, LemmyError> {
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;

View file

@ -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<ConnectionId>,
) -> Result<CommunityResponse, LemmyError> {
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;

View file

@ -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<ConnectionId>,
) -> Result<ListCommunitiesResponse, LemmyError> {
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());

View file

@ -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<ConnectionId>,
) -> Result<CommunityResponse, LemmyError> {
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)?;

View file

@ -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<ConnectionId>,
) -> Result<CommunityResponse, LemmyError> {
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)?;

View file

@ -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<ConnectionId>,
) -> Result<CustomEmojiResponse, LemmyError> {
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

View file

@ -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<ConnectionId>,
) -> Result<DeleteCustomEmojiResponse, LemmyError> {
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)?;

View file

@ -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<ConnectionId>,
) -> Result<CustomEmojiResponse, LemmyError> {
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

View file

@ -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<ConnectionId>,
) -> Result<PostResponse, LemmyError> {
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);

View file

@ -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<ConnectionId>,
) -> Result<PostResponse, LemmyError> {
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?;

View file

@ -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<ConnectionId>,
) -> Result<GetPostResponse, LemmyError> {
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)?;

View file

@ -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<ConnectionId>,
) -> Result<PostResponse, LemmyError> {
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?;

View file

@ -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<ConnectionId>,
) -> Result<PostResponse, LemmyError> {
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();

View file

@ -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<ConnectionId>,
) -> Result<PrivateMessageResponse, LemmyError> {
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(

View file

@ -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<ConnectionId>,
) -> Result<PrivateMessageResponse, LemmyError> {
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;

View file

@ -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<ConnectionId>,
) -> Result<PrivateMessagesResponse, LemmyError> {
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;

View file

@ -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<ConnectionId>,
) -> Result<PrivateMessageResponse, LemmyError> {
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

View file

@ -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);

View file

@ -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<String>>,
context: &LemmyContext,
) -> Option<LocalUserView> {
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,
}
}

View file

@ -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<ConnectionId>,
) -> Result<SiteResponse, LemmyError> {
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;

View file

@ -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<ConnectionId>,
) -> Result<Self::Response, LemmyError> {
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(

View file

@ -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<LemmyContext>,
) -> 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<LemmyContext>,
) -> 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();

View file

@ -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<LemmyContext>,
) -> 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<LemmyContext>,
) -> 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,

View file

@ -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<LemmyContext>,
) -> 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,

View file

@ -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<LemmyContext>,
) -> 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<LemmyContext>,
) -> 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(),

View file

@ -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<LemmyContext>,
) -> 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<LemmyContext>,
) -> 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
}

View file

@ -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<LemmyContext>,
) -> 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,

View file

@ -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<LemmyContext>,
) -> 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<LemmyContext>,
) -> 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<LemmyContext>,
) -> 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<LemmyContext>,
) -> 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<LemmyContext>,
) -> 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<LemmyContext>,
) -> 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(

View file

@ -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<LemmyContext>,
) -> 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
}

View file

@ -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<LemmyContext>,
) -> 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?

View file

@ -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<LemmyContext>,
) -> 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();

View file

@ -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<ConnectionId>,
) -> Result<GetCommentsResponse, LemmyError> {
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)?;

View file

@ -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<ConnectionId>,
) -> Result<GetPostsResponse, LemmyError> {
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)?;

View file

@ -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<ConnectionId>,
) -> Result<GetCommunityResponse, LemmyError> {
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() {

View file

@ -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());

View file

@ -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<LemmyContext>,
_websocket_id: Option<ConnectionId>,
) -> Result<ResolveObjectResponse, LemmyError> {
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)?;

View file

@ -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<SearchResponse, LemmyError> {
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)?;

View file

@ -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()
{