saveUserSettingsFederated,
setupLogins,
} from "./shared";
+import { LemmyHttp } from "lemmy-js-client";
+import { GetPosts } from "lemmy-js-client/dist/types/GetPosts";
beforeAll(async () => {
await setupLogins();
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();
+});
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},
_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?;
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::{
) -> 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();
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},
_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,
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::{
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();
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};
_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;
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};
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;
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::{
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;
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,
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;
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::{
_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;
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::{
_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?;
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::{
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()
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::{
_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;
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::{
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)?;
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::{
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)?;
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},
_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;
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};
_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)?;
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};
_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)?;
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};
_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;
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};
_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;
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,
_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
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},
_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?;
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},
_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?;
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};
_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;
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};
_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;
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::{
_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)?;
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,
};
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?;
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,
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
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,
};
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?;
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};
_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;
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},
_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,
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::{
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();
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};
_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;
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};
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;
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::{
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;
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::{
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();
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};
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)?;
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::{
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)?;
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::{
_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)?;
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},
) -> 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)?;
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::{
_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?;
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::{
_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?;
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::{
_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?;
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::{
_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?;
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::{
_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;
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;
_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
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;
_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
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::{
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 {
-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},
person_block::PersonBlock,
post::{Post, PostRead, PostReadForm},
registration_application::RegistrationApplication,
- secret::Secret,
},
traits::{Crud, Readable},
utils::DbPool,
.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,
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,
}
}
-#[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>,
) -> 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,
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,
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(
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::{
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?;
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;
_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)?;
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::{
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?;
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::{
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;
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,
},
};
_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;
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::{
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;
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;
_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());
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::{
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)?;
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::{
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)?;
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},
_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
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};
_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)?;
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},
_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
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,
},
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);
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::{
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?;
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,
_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)?;
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::{
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?;
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::{
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();
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,
},
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(
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::{
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;
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};
_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;
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::{
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
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,
},
};
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);
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,
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 {
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;
})
}
}
+
+#[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,
+ }
+}
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,
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;
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};
_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(
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},
_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);
_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();
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,
_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();
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,
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::{
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,
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::{
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(),
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(),
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};
_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
}
_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
}
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;
_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,
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::{
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(
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(
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());
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(),
_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(
_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(
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::{
_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
}
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;
_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?
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::{
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();
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},
_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)?;
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;
_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)?;
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::{
_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() {
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},
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());
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};
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)?;
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},
) -> 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)?;
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;
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()
{