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:
parent
4a70502007
commit
a5707328cf
92 changed files with 271 additions and 354 deletions
|
@ -18,6 +18,8 @@ import {
|
||||||
saveUserSettingsFederated,
|
saveUserSettingsFederated,
|
||||||
setupLogins,
|
setupLogins,
|
||||||
} from "./shared";
|
} from "./shared";
|
||||||
|
import { LemmyHttp } from "lemmy-js-client";
|
||||||
|
import { GetPosts } from "lemmy-js-client/dist/types/GetPosts";
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
await setupLogins();
|
await setupLogins();
|
||||||
|
@ -95,3 +97,19 @@ test("Delete user", async () => {
|
||||||
expect((await resolvePost(alpha, remotePost)).post).toBeUndefined();
|
expect((await resolvePost(alpha, remotePost)).post).toBeUndefined();
|
||||||
expect((await resolveComment(alpha, remoteComment)).comment).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();
|
||||||
|
});
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
comment::{CommentResponse, DistinguishComment},
|
comment::{CommentResponse, DistinguishComment},
|
||||||
context::LemmyContext,
|
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::{
|
use lemmy_db_schema::{
|
||||||
source::comment::{Comment, CommentUpdateForm},
|
source::comment::{Comment, CommentUpdateForm},
|
||||||
|
@ -23,8 +23,7 @@ impl Perform for DistinguishComment {
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<CommentResponse, LemmyError> {
|
) -> Result<CommentResponse, LemmyError> {
|
||||||
let data: &DistinguishComment = self;
|
let data: &DistinguishComment = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
|
|
||||||
let comment_id = data.comment_id;
|
let comment_id = data.comment_id;
|
||||||
let orig_comment = CommentView::read(context.pool(), comment_id, None).await?;
|
let orig_comment = CommentView::read(context.pool(), comment_id, None).await?;
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
comment::{CommentResponse, CreateCommentLike},
|
comment::{CommentResponse, CreateCommentLike},
|
||||||
context::LemmyContext,
|
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,
|
websocket::UserOperation,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
|
@ -30,8 +30,7 @@ impl Perform for CreateCommentLike {
|
||||||
) -> Result<CommentResponse, LemmyError> {
|
) -> Result<CommentResponse, LemmyError> {
|
||||||
let data: &CreateCommentLike = self;
|
let data: &CreateCommentLike = self;
|
||||||
let local_site = LocalSite::read(context.pool()).await?;
|
let local_site = LocalSite::read(context.pool()).await?;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
|
|
||||||
let mut recipient_ids = Vec::<LocalUserId>::new();
|
let mut recipient_ids = Vec::<LocalUserId>::new();
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
comment::{CommentResponse, SaveComment},
|
comment::{CommentResponse, SaveComment},
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
utils::get_local_user_view_from_jwt,
|
utils::local_user_view_from_jwt,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::comment::{CommentSaved, CommentSavedForm},
|
source::comment::{CommentSaved, CommentSavedForm},
|
||||||
|
@ -23,8 +23,7 @@ impl Perform for SaveComment {
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<CommentResponse, LemmyError> {
|
) -> Result<CommentResponse, LemmyError> {
|
||||||
let data: &SaveComment = self;
|
let data: &SaveComment = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
|
|
||||||
let comment_saved_form = CommentSavedForm {
|
let comment_saved_form = CommentSavedForm {
|
||||||
comment_id: data.comment_id,
|
comment_id: data.comment_id,
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
comment::{CommentReportResponse, CreateCommentReport},
|
comment::{CommentReportResponse, CreateCommentReport},
|
||||||
context::LemmyContext,
|
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,
|
websocket::UserOperation,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
|
@ -28,8 +28,7 @@ impl Perform for CreateCommentReport {
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<CommentReportResponse, LemmyError> {
|
) -> Result<CommentReportResponse, LemmyError> {
|
||||||
let data: &CreateCommentReport = self;
|
let data: &CreateCommentReport = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
let local_site = LocalSite::read(context.pool()).await?;
|
let local_site = LocalSite::read(context.pool()).await?;
|
||||||
|
|
||||||
let reason = self.reason.trim();
|
let reason = self.reason.trim();
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
comment::{ListCommentReports, ListCommentReportsResponse},
|
comment::{ListCommentReports, ListCommentReportsResponse},
|
||||||
context::LemmyContext,
|
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_db_views::comment_report_view::CommentReportQuery;
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
|
@ -21,8 +21,7 @@ impl Perform for ListCommentReports {
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<ListCommentReportsResponse, LemmyError> {
|
) -> Result<ListCommentReportsResponse, LemmyError> {
|
||||||
let data: &ListCommentReports = self;
|
let data: &ListCommentReports = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
|
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
let admin = local_user_view.person.admin;
|
let admin = local_user_view.person.admin;
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
comment::{CommentReportResponse, ResolveCommentReport},
|
comment::{CommentReportResponse, ResolveCommentReport},
|
||||||
context::LemmyContext,
|
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,
|
websocket::UserOperation,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{source::comment_report::CommentReport, traits::Reportable};
|
use lemmy_db_schema::{source::comment_report::CommentReport, traits::Reportable};
|
||||||
|
@ -22,8 +22,7 @@ impl Perform for ResolveCommentReport {
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<CommentReportResponse, LemmyError> {
|
) -> Result<CommentReportResponse, LemmyError> {
|
||||||
let data: &ResolveCommentReport = self;
|
let data: &ResolveCommentReport = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
|
|
||||||
let report_id = data.report_id;
|
let report_id = data.report_id;
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
community::{AddModToCommunity, AddModToCommunityResponse},
|
community::{AddModToCommunity, AddModToCommunityResponse},
|
||||||
context::LemmyContext,
|
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,
|
websocket::UserOperation,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
|
@ -27,8 +27,7 @@ impl Perform for AddModToCommunity {
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<AddModToCommunityResponse, LemmyError> {
|
) -> Result<AddModToCommunityResponse, LemmyError> {
|
||||||
let data: &AddModToCommunity = self;
|
let data: &AddModToCommunity = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
|
|
||||||
let community_id = data.community_id;
|
let community_id = data.community_id;
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
community::{BanFromCommunity, BanFromCommunityResponse},
|
community::{BanFromCommunity, BanFromCommunityResponse},
|
||||||
context::LemmyContext,
|
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::{
|
websocket::{
|
||||||
handlers::messages::SendCommunityRoomMessage,
|
handlers::messages::SendCommunityRoomMessage,
|
||||||
serialize_websocket_message,
|
serialize_websocket_message,
|
||||||
|
@ -40,8 +40,7 @@ impl Perform for BanFromCommunity {
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<BanFromCommunityResponse, LemmyError> {
|
) -> Result<BanFromCommunityResponse, LemmyError> {
|
||||||
let data: &BanFromCommunity = self;
|
let data: &BanFromCommunity = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
|
|
||||||
let community_id = data.community_id;
|
let community_id = data.community_id;
|
||||||
let banned_person_id = data.person_id;
|
let banned_person_id = data.person_id;
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
community::{BlockCommunity, BlockCommunityResponse},
|
community::{BlockCommunity, BlockCommunityResponse},
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
utils::get_local_user_view_from_jwt,
|
utils::local_user_view_from_jwt,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
|
@ -26,8 +26,7 @@ impl Perform for BlockCommunity {
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<BlockCommunityResponse, LemmyError> {
|
) -> Result<BlockCommunityResponse, LemmyError> {
|
||||||
let data: &BlockCommunity = self;
|
let data: &BlockCommunity = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
|
|
||||||
let community_id = data.community_id;
|
let community_id = data.community_id;
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
community::{CommunityResponse, FollowCommunity},
|
community::{CommunityResponse, FollowCommunity},
|
||||||
context::LemmyContext,
|
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::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
|
@ -26,8 +26,7 @@ impl Perform for FollowCommunity {
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<CommunityResponse, LemmyError> {
|
) -> Result<CommunityResponse, LemmyError> {
|
||||||
let data: &FollowCommunity = self;
|
let data: &FollowCommunity = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
|
|
||||||
let community_id = data.community_id;
|
let community_id = data.community_id;
|
||||||
let community = Community::read(context.pool(), community_id).await?;
|
let community = Community::read(context.pool(), community_id).await?;
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
community::{CommunityResponse, HideCommunity},
|
community::{CommunityResponse, HideCommunity},
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
utils::{get_local_user_view_from_jwt, is_admin},
|
utils::{is_admin, local_user_view_from_jwt},
|
||||||
websocket::UserOperationCrud,
|
websocket::UserOperationCrud,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
|
@ -28,8 +28,7 @@ impl Perform for HideCommunity {
|
||||||
let data: &HideCommunity = self;
|
let data: &HideCommunity = self;
|
||||||
|
|
||||||
// Verify its a admin (only admin can hide or unhide it)
|
// Verify its a admin (only admin can hide or unhide it)
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
is_admin(&local_user_view)?;
|
is_admin(&local_user_view)?;
|
||||||
|
|
||||||
let community_form = CommunityUpdateForm::builder()
|
let community_form = CommunityUpdateForm::builder()
|
||||||
|
|
|
@ -4,7 +4,7 @@ use anyhow::Context;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
community::{GetCommunityResponse, TransferCommunity},
|
community::{GetCommunityResponse, TransferCommunity},
|
||||||
context::LemmyContext,
|
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::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
|
@ -29,8 +29,7 @@ impl Perform for TransferCommunity {
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<GetCommunityResponse, LemmyError> {
|
) -> Result<GetCommunityResponse, LemmyError> {
|
||||||
let data: &TransferCommunity = self;
|
let data: &TransferCommunity = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
|
|
||||||
// Fetch the community mods
|
// Fetch the community mods
|
||||||
let community_id = data.community_id;
|
let community_id = data.community_id;
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
person::{AddAdmin, AddAdminResponse},
|
person::{AddAdmin, AddAdminResponse},
|
||||||
utils::{get_local_user_view_from_jwt, is_admin},
|
utils::{is_admin, local_user_view_from_jwt},
|
||||||
websocket::UserOperation,
|
websocket::UserOperation,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
|
@ -27,8 +27,7 @@ impl Perform for AddAdmin {
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<AddAdminResponse, LemmyError> {
|
) -> Result<AddAdminResponse, LemmyError> {
|
||||||
let data: &AddAdmin = self;
|
let data: &AddAdmin = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
|
|
||||||
// Make sure user is an admin
|
// Make sure user is an admin
|
||||||
is_admin(&local_user_view)?;
|
is_admin(&local_user_view)?;
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
person::{BanPerson, BanPersonResponse},
|
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,
|
websocket::UserOperation,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
|
@ -31,8 +31,7 @@ impl Perform for BanPerson {
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<BanPersonResponse, LemmyError> {
|
) -> Result<BanPersonResponse, LemmyError> {
|
||||||
let data: &BanPerson = self;
|
let data: &BanPerson = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
|
|
||||||
// Make sure user is an admin
|
// Make sure user is an admin
|
||||||
is_admin(&local_user_view)?;
|
is_admin(&local_user_view)?;
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
person::{BlockPerson, BlockPersonResponse},
|
person::{BlockPerson, BlockPersonResponse},
|
||||||
utils::get_local_user_view_from_jwt,
|
utils::local_user_view_from_jwt,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::person_block::{PersonBlock, PersonBlockForm},
|
source::person_block::{PersonBlock, PersonBlockForm},
|
||||||
|
@ -23,8 +23,7 @@ impl Perform for BlockPerson {
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<BlockPersonResponse, LemmyError> {
|
) -> Result<BlockPersonResponse, LemmyError> {
|
||||||
let data: &BlockPerson = self;
|
let data: &BlockPerson = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
|
|
||||||
let target_id = data.person_id;
|
let target_id = data.person_id;
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
|
|
|
@ -4,7 +4,7 @@ use bcrypt::verify;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
person::{ChangePassword, LoginResponse},
|
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_db_schema::source::local_user::LocalUser;
|
||||||
use lemmy_utils::{claims::Claims, error::LemmyError, ConnectionId};
|
use lemmy_utils::{claims::Claims, error::LemmyError, ConnectionId};
|
||||||
|
@ -20,8 +20,7 @@ impl Perform for ChangePassword {
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<LoginResponse, LemmyError> {
|
) -> Result<LoginResponse, LemmyError> {
|
||||||
let data: &ChangePassword = self;
|
let data: &ChangePassword = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(data.auth.as_ref(), context).await?;
|
||||||
get_local_user_view_from_jwt(data.auth.as_ref(), context.pool(), context.secret()).await?;
|
|
||||||
|
|
||||||
password_length_check(&data.new_password)?;
|
password_length_check(&data.new_password)?;
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
person::{BannedPersonsResponse, GetBannedPersons},
|
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_db_views_actor::structs::PersonView;
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
|
@ -18,8 +18,7 @@ impl Perform for GetBannedPersons {
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<Self::Response, LemmyError> {
|
) -> Result<Self::Response, LemmyError> {
|
||||||
let data: &GetBannedPersons = self;
|
let data: &GetBannedPersons = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
|
|
||||||
// Make sure user is an admin
|
// Make sure user is an admin
|
||||||
is_admin(&local_user_view)?;
|
is_admin(&local_user_view)?;
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
person::{GetPersonMentions, GetPersonMentionsResponse},
|
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_db_views_actor::person_mention_view::PersonMentionQuery;
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
|
@ -19,8 +19,7 @@ impl Perform for GetPersonMentions {
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<GetPersonMentionsResponse, LemmyError> {
|
) -> Result<GetPersonMentionsResponse, LemmyError> {
|
||||||
let data: &GetPersonMentions = self;
|
let data: &GetPersonMentions = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
|
|
||||||
let sort = data.sort;
|
let sort = data.sort;
|
||||||
let page = data.page;
|
let page = data.page;
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
person::{GetReplies, GetRepliesResponse},
|
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_db_views_actor::comment_reply_view::CommentReplyQuery;
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
|
@ -19,8 +19,7 @@ impl Perform for GetReplies {
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<GetRepliesResponse, LemmyError> {
|
) -> Result<GetRepliesResponse, LemmyError> {
|
||||||
let data: &GetReplies = self;
|
let data: &GetReplies = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
|
|
||||||
let sort = data.sort;
|
let sort = data.sort;
|
||||||
let page = data.page;
|
let page = data.page;
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
person::{GetRepliesResponse, MarkAllAsRead},
|
person::{GetRepliesResponse, MarkAllAsRead},
|
||||||
utils::get_local_user_view_from_jwt,
|
utils::local_user_view_from_jwt,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::source::{
|
use lemmy_db_schema::source::{
|
||||||
comment_reply::CommentReply,
|
comment_reply::CommentReply,
|
||||||
|
@ -23,8 +23,7 @@ impl Perform for MarkAllAsRead {
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<GetRepliesResponse, LemmyError> {
|
) -> Result<GetRepliesResponse, LemmyError> {
|
||||||
let data: &MarkAllAsRead = self;
|
let data: &MarkAllAsRead = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
|
|
||||||
// Mark all comment_replies as read
|
// Mark all comment_replies as read
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
person::{MarkPersonMentionAsRead, PersonMentionResponse},
|
person::{MarkPersonMentionAsRead, PersonMentionResponse},
|
||||||
utils::get_local_user_view_from_jwt,
|
utils::local_user_view_from_jwt,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::person_mention::{PersonMention, PersonMentionUpdateForm},
|
source::person_mention::{PersonMention, PersonMentionUpdateForm},
|
||||||
|
@ -23,8 +23,7 @@ impl Perform for MarkPersonMentionAsRead {
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<PersonMentionResponse, LemmyError> {
|
) -> Result<PersonMentionResponse, LemmyError> {
|
||||||
let data: &MarkPersonMentionAsRead = self;
|
let data: &MarkPersonMentionAsRead = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
|
|
||||||
let person_mention_id = data.person_mention_id;
|
let person_mention_id = data.person_mention_id;
|
||||||
let read_person_mention = PersonMention::read(context.pool(), person_mention_id).await?;
|
let read_person_mention = PersonMention::read(context.pool(), person_mention_id).await?;
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
person::{CommentReplyResponse, MarkCommentReplyAsRead},
|
person::{CommentReplyResponse, MarkCommentReplyAsRead},
|
||||||
utils::get_local_user_view_from_jwt,
|
utils::local_user_view_from_jwt,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::comment_reply::{CommentReply, CommentReplyUpdateForm},
|
source::comment_reply::{CommentReply, CommentReplyUpdateForm},
|
||||||
|
@ -23,8 +23,7 @@ impl Perform for MarkCommentReplyAsRead {
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<CommentReplyResponse, LemmyError> {
|
) -> Result<CommentReplyResponse, LemmyError> {
|
||||||
let data = self;
|
let data = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
|
|
||||||
let comment_reply_id = data.comment_reply_id;
|
let comment_reply_id = data.comment_reply_id;
|
||||||
let read_comment_reply = CommentReply::read(context.pool(), comment_reply_id).await?;
|
let read_comment_reply = CommentReply::read(context.pool(), comment_reply_id).await?;
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
person::{GetUnreadCount, GetUnreadCountResponse},
|
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::structs::PrivateMessageView;
|
||||||
use lemmy_db_views_actor::structs::{CommentReplyView, PersonMentionView};
|
use lemmy_db_views_actor::structs::{CommentReplyView, PersonMentionView};
|
||||||
|
@ -20,8 +20,7 @@ impl Perform for GetUnreadCount {
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<Self::Response, LemmyError> {
|
) -> Result<Self::Response, LemmyError> {
|
||||||
let data = self;
|
let data = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
|
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
person::{GetReportCount, GetReportCountResponse},
|
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_db_views::structs::{CommentReportView, PostReportView, PrivateMessageReportView};
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
|
@ -19,8 +19,7 @@ impl Perform for GetReportCount {
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<GetReportCountResponse, LemmyError> {
|
) -> Result<GetReportCountResponse, LemmyError> {
|
||||||
let data: &GetReportCount = self;
|
let data: &GetReportCount = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
|
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
let admin = local_user_view.person.admin;
|
let admin = local_user_view.person.admin;
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
person::{LoginResponse, SaveUserSettings},
|
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::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
|
@ -39,8 +39,7 @@ impl Perform for SaveUserSettings {
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<LoginResponse, LemmyError> {
|
) -> Result<LoginResponse, LemmyError> {
|
||||||
let data: &SaveUserSettings = self;
|
let data: &SaveUserSettings = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
let site_view = SiteView::read_local(context.pool()).await?;
|
let site_view = SiteView::read_local(context.pool()).await?;
|
||||||
|
|
||||||
let avatar = diesel_option_overwrite_to_url(&data.avatar)?;
|
let avatar = diesel_option_overwrite_to_url(&data.avatar)?;
|
||||||
|
|
|
@ -6,9 +6,9 @@ use lemmy_api_common::{
|
||||||
utils::{
|
utils::{
|
||||||
check_community_ban,
|
check_community_ban,
|
||||||
check_community_deleted_or_removed,
|
check_community_deleted_or_removed,
|
||||||
get_local_user_view_from_jwt,
|
|
||||||
is_admin,
|
is_admin,
|
||||||
is_mod_or_admin,
|
is_mod_or_admin,
|
||||||
|
local_user_view_from_jwt,
|
||||||
},
|
},
|
||||||
websocket::UserOperation,
|
websocket::UserOperation,
|
||||||
};
|
};
|
||||||
|
@ -33,8 +33,7 @@ impl Perform for FeaturePost {
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<PostResponse, LemmyError> {
|
) -> Result<PostResponse, LemmyError> {
|
||||||
let data: &FeaturePost = self;
|
let data: &FeaturePost = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
|
|
||||||
let post_id = data.post_id;
|
let post_id = data.post_id;
|
||||||
let orig_post = Post::read(context.pool(), post_id).await?;
|
let orig_post = Post::read(context.pool(), post_id).await?;
|
||||||
|
|
|
@ -7,7 +7,7 @@ use lemmy_api_common::{
|
||||||
check_community_ban,
|
check_community_ban,
|
||||||
check_community_deleted_or_removed,
|
check_community_deleted_or_removed,
|
||||||
check_downvotes_enabled,
|
check_downvotes_enabled,
|
||||||
get_local_user_view_from_jwt,
|
local_user_view_from_jwt,
|
||||||
mark_post_as_read,
|
mark_post_as_read,
|
||||||
},
|
},
|
||||||
websocket::UserOperation,
|
websocket::UserOperation,
|
||||||
|
@ -32,8 +32,7 @@ impl Perform for CreatePostLike {
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<PostResponse, LemmyError> {
|
) -> Result<PostResponse, LemmyError> {
|
||||||
let data: &CreatePostLike = self;
|
let data: &CreatePostLike = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
let local_site = LocalSite::read(context.pool()).await?;
|
let local_site = LocalSite::read(context.pool()).await?;
|
||||||
|
|
||||||
// Don't do a downvote if site has downvotes disabled
|
// Don't do a downvote if site has downvotes disabled
|
||||||
|
|
|
@ -6,8 +6,8 @@ use lemmy_api_common::{
|
||||||
utils::{
|
utils::{
|
||||||
check_community_ban,
|
check_community_ban,
|
||||||
check_community_deleted_or_removed,
|
check_community_deleted_or_removed,
|
||||||
get_local_user_view_from_jwt,
|
|
||||||
is_mod_or_admin,
|
is_mod_or_admin,
|
||||||
|
local_user_view_from_jwt,
|
||||||
},
|
},
|
||||||
websocket::UserOperation,
|
websocket::UserOperation,
|
||||||
};
|
};
|
||||||
|
@ -31,8 +31,7 @@ impl Perform for LockPost {
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<PostResponse, LemmyError> {
|
) -> Result<PostResponse, LemmyError> {
|
||||||
let data: &LockPost = self;
|
let data: &LockPost = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
|
|
||||||
let post_id = data.post_id;
|
let post_id = data.post_id;
|
||||||
let orig_post = Post::read(context.pool(), post_id).await?;
|
let orig_post = Post::read(context.pool(), post_id).await?;
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
post::{MarkPostAsRead, PostResponse},
|
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_db_views::structs::PostView;
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
|
@ -19,8 +19,7 @@ impl Perform for MarkPostAsRead {
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<Self::Response, LemmyError> {
|
) -> Result<Self::Response, LemmyError> {
|
||||||
let data = self;
|
let data = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
|
|
||||||
let post_id = data.post_id;
|
let post_id = data.post_id;
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
post::{PostResponse, SavePost},
|
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::{
|
use lemmy_db_schema::{
|
||||||
source::post::{PostSaved, PostSavedForm},
|
source::post::{PostSaved, PostSavedForm},
|
||||||
|
@ -23,8 +23,7 @@ impl Perform for SavePost {
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<PostResponse, LemmyError> {
|
) -> Result<PostResponse, LemmyError> {
|
||||||
let data: &SavePost = self;
|
let data: &SavePost = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
|
|
||||||
let post_saved_form = PostSavedForm {
|
let post_saved_form = PostSavedForm {
|
||||||
post_id: data.post_id,
|
post_id: data.post_id,
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
post::{CreatePostReport, PostReportResponse},
|
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,
|
websocket::UserOperation,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
|
@ -28,8 +28,7 @@ impl Perform for CreatePostReport {
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<PostReportResponse, LemmyError> {
|
) -> Result<PostReportResponse, LemmyError> {
|
||||||
let data: &CreatePostReport = self;
|
let data: &CreatePostReport = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
let local_site = LocalSite::read(context.pool()).await?;
|
let local_site = LocalSite::read(context.pool()).await?;
|
||||||
|
|
||||||
let reason = self.reason.trim();
|
let reason = self.reason.trim();
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
post::{ListPostReports, ListPostReportsResponse},
|
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_db_views::post_report_view::PostReportQuery;
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
|
@ -21,8 +21,7 @@ impl Perform for ListPostReports {
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<ListPostReportsResponse, LemmyError> {
|
) -> Result<ListPostReportsResponse, LemmyError> {
|
||||||
let data: &ListPostReports = self;
|
let data: &ListPostReports = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
|
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
let admin = local_user_view.person.admin;
|
let admin = local_user_view.person.admin;
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
post::{PostReportResponse, ResolvePostReport},
|
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,
|
websocket::UserOperation,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{source::post_report::PostReport, traits::Reportable};
|
use lemmy_db_schema::{source::post_report::PostReport, traits::Reportable};
|
||||||
|
@ -22,8 +22,7 @@ impl Perform for ResolvePostReport {
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<PostReportResponse, LemmyError> {
|
) -> Result<PostReportResponse, LemmyError> {
|
||||||
let data: &ResolvePostReport = self;
|
let data: &ResolvePostReport = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
|
|
||||||
let report_id = data.report_id;
|
let report_id = data.report_id;
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
private_message::{MarkPrivateMessageAsRead, PrivateMessageResponse},
|
private_message::{MarkPrivateMessageAsRead, PrivateMessageResponse},
|
||||||
utils::get_local_user_view_from_jwt,
|
utils::local_user_view_from_jwt,
|
||||||
websocket::UserOperation,
|
websocket::UserOperation,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
|
@ -23,8 +23,7 @@ impl Perform for MarkPrivateMessageAsRead {
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<PrivateMessageResponse, LemmyError> {
|
) -> Result<PrivateMessageResponse, LemmyError> {
|
||||||
let data: &MarkPrivateMessageAsRead = self;
|
let data: &MarkPrivateMessageAsRead = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
|
|
||||||
// Checking permissions
|
// Checking permissions
|
||||||
let private_message_id = data.private_message_id;
|
let private_message_id = data.private_message_id;
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
private_message::{CreatePrivateMessageReport, PrivateMessageReportResponse},
|
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,
|
websocket::UserOperation,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
|
@ -28,8 +28,7 @@ impl Perform for CreatePrivateMessageReport {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<Self::Response, LemmyError> {
|
) -> Result<Self::Response, LemmyError> {
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&self.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&self.auth, context.pool(), context.secret()).await?;
|
|
||||||
let local_site = LocalSite::read(context.pool()).await?;
|
let local_site = LocalSite::read(context.pool()).await?;
|
||||||
|
|
||||||
let reason = self.reason.trim();
|
let reason = self.reason.trim();
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
private_message::{ListPrivateMessageReports, ListPrivateMessageReportsResponse},
|
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_db_views::private_message_report_view::PrivateMessageReportQuery;
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
|
@ -18,8 +18,7 @@ impl Perform for ListPrivateMessageReports {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<Self::Response, LemmyError> {
|
) -> Result<Self::Response, LemmyError> {
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&self.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&self.auth, context.pool(), context.secret()).await?;
|
|
||||||
|
|
||||||
is_admin(&local_user_view)?;
|
is_admin(&local_user_view)?;
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
private_message::{PrivateMessageReportResponse, ResolvePrivateMessageReport},
|
private_message::{PrivateMessageReportResponse, ResolvePrivateMessageReport},
|
||||||
utils::{get_local_user_view_from_jwt, is_admin},
|
utils::{is_admin, local_user_view_from_jwt},
|
||||||
websocket::UserOperation,
|
websocket::UserOperation,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
|
@ -24,8 +24,7 @@ impl Perform for ResolvePrivateMessageReport {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<Self::Response, LemmyError> {
|
) -> Result<Self::Response, LemmyError> {
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&self.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&self.auth, context.pool(), context.secret()).await?;
|
|
||||||
|
|
||||||
is_admin(&local_user_view)?;
|
is_admin(&local_user_view)?;
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
site::{GetSiteResponse, LeaveAdmin},
|
site::{GetSiteResponse, LeaveAdmin},
|
||||||
utils::{get_local_user_view_from_jwt, is_admin},
|
utils::{is_admin, local_user_view_from_jwt},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
|
@ -30,8 +30,7 @@ impl Perform for LeaveAdmin {
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<GetSiteResponse, LemmyError> {
|
) -> Result<GetSiteResponse, LemmyError> {
|
||||||
let data: &LeaveAdmin = self;
|
let data: &LeaveAdmin = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
|
|
||||||
is_admin(&local_user_view)?;
|
is_admin(&local_user_view)?;
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
site::{GetModlog, GetModlogResponse},
|
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::{
|
use lemmy_db_schema::{
|
||||||
newtypes::{CommunityId, PersonId},
|
newtypes::{CommunityId, PersonId},
|
||||||
|
@ -43,9 +43,7 @@ impl Perform for GetModlog {
|
||||||
) -> Result<GetModlogResponse, LemmyError> {
|
) -> Result<GetModlogResponse, LemmyError> {
|
||||||
let data: &GetModlog = self;
|
let data: &GetModlog = self;
|
||||||
|
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await;
|
||||||
get_local_user_view_from_jwt_opt(data.auth.as_ref(), context.pool(), context.secret())
|
|
||||||
.await?;
|
|
||||||
let local_site = LocalSite::read(context.pool()).await?;
|
let local_site = LocalSite::read(context.pool()).await?;
|
||||||
|
|
||||||
check_private_instance(&local_user_view, &local_site)?;
|
check_private_instance(&local_user_view, &local_site)?;
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
site::{PurgeComment, PurgeItemResponse},
|
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::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
|
@ -25,8 +25,7 @@ impl Perform for PurgeComment {
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<Self::Response, LemmyError> {
|
) -> Result<Self::Response, LemmyError> {
|
||||||
let data: &Self = self;
|
let data: &Self = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
|
|
||||||
// Only let the top admin purge an item
|
// Only let the top admin purge an item
|
||||||
is_top_admin(context.pool(), local_user_view.person.id).await?;
|
is_top_admin(context.pool(), local_user_view.person.id).await?;
|
||||||
|
|
|
@ -4,7 +4,7 @@ use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
request::purge_image_from_pictrs,
|
request::purge_image_from_pictrs,
|
||||||
site::{PurgeCommunity, PurgeItemResponse},
|
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::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
|
@ -26,8 +26,7 @@ impl Perform for PurgeCommunity {
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<Self::Response, LemmyError> {
|
) -> Result<Self::Response, LemmyError> {
|
||||||
let data: &Self = self;
|
let data: &Self = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
|
|
||||||
// Only let the top admin purge an item
|
// Only let the top admin purge an item
|
||||||
is_top_admin(context.pool(), local_user_view.person.id).await?;
|
is_top_admin(context.pool(), local_user_view.person.id).await?;
|
||||||
|
|
|
@ -4,7 +4,7 @@ use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
request::purge_image_from_pictrs,
|
request::purge_image_from_pictrs,
|
||||||
site::{PurgeItemResponse, PurgePerson},
|
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::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
|
@ -26,8 +26,7 @@ impl Perform for PurgePerson {
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<Self::Response, LemmyError> {
|
) -> Result<Self::Response, LemmyError> {
|
||||||
let data: &Self = self;
|
let data: &Self = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
|
|
||||||
// Only let the top admin purge an item
|
// Only let the top admin purge an item
|
||||||
is_top_admin(context.pool(), local_user_view.person.id).await?;
|
is_top_admin(context.pool(), local_user_view.person.id).await?;
|
||||||
|
|
|
@ -4,7 +4,7 @@ use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
request::purge_image_from_pictrs,
|
request::purge_image_from_pictrs,
|
||||||
site::{PurgeItemResponse, PurgePost},
|
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::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
|
@ -26,8 +26,7 @@ impl Perform for PurgePost {
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<Self::Response, LemmyError> {
|
) -> Result<Self::Response, LemmyError> {
|
||||||
let data: &Self = self;
|
let data: &Self = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
|
|
||||||
// Only let the top admin purge an item
|
// Only let the top admin purge an item
|
||||||
is_top_admin(context.pool(), local_user_view.person.id).await?;
|
is_top_admin(context.pool(), local_user_view.person.id).await?;
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
site::{ApproveRegistrationApplication, RegistrationApplicationResponse},
|
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::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
|
@ -26,8 +26,7 @@ impl Perform for ApproveRegistrationApplication {
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<Self::Response, LemmyError> {
|
) -> Result<Self::Response, LemmyError> {
|
||||||
let data = self;
|
let data = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
|
|
||||||
let app_id = data.id;
|
let app_id = data.id;
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
site::{ListRegistrationApplications, ListRegistrationApplicationsResponse},
|
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_schema::source::local_site::LocalSite;
|
||||||
use lemmy_db_views::registration_application_view::RegistrationApplicationQuery;
|
use lemmy_db_views::registration_application_view::RegistrationApplicationQuery;
|
||||||
|
@ -20,8 +20,7 @@ impl Perform for ListRegistrationApplications {
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<Self::Response, LemmyError> {
|
) -> Result<Self::Response, LemmyError> {
|
||||||
let data = self;
|
let data = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
let local_site = LocalSite::read(context.pool()).await?;
|
let local_site = LocalSite::read(context.pool()).await?;
|
||||||
|
|
||||||
// Make sure user is an admin
|
// Make sure user is an admin
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
site::{GetUnreadRegistrationApplicationCount, GetUnreadRegistrationApplicationCountResponse},
|
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_schema::source::local_site::LocalSite;
|
||||||
use lemmy_db_views::structs::RegistrationApplicationView;
|
use lemmy_db_views::structs::RegistrationApplicationView;
|
||||||
|
@ -19,8 +19,7 @@ impl Perform for GetUnreadRegistrationApplicationCount {
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<Self::Response, LemmyError> {
|
) -> Result<Self::Response, LemmyError> {
|
||||||
let data = self;
|
let data = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
let local_site = LocalSite::read(context.pool()).await?;
|
let local_site = LocalSite::read(context.pool()).await?;
|
||||||
|
|
||||||
// Only let admins do this
|
// Only let admins do this
|
||||||
|
|
|
@ -2,7 +2,7 @@ use crate::Perform;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
utils::get_local_user_view_from_jwt,
|
utils::local_user_view_from_jwt,
|
||||||
websocket::{
|
websocket::{
|
||||||
handlers::join_rooms::{JoinCommunityRoom, JoinModRoom, JoinPostRoom, JoinUserRoom},
|
handlers::join_rooms::{JoinCommunityRoom, JoinModRoom, JoinPostRoom, JoinUserRoom},
|
||||||
structs::{
|
structs::{
|
||||||
|
@ -30,8 +30,7 @@ impl Perform for UserJoin {
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<UserJoinResponse, LemmyError> {
|
) -> Result<UserJoinResponse, LemmyError> {
|
||||||
let data: &UserJoin = self;
|
let data: &UserJoin = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
|
|
||||||
if let Some(id) = websocket_id {
|
if let Some(id) = websocket_id {
|
||||||
context.chat_server().do_send(JoinUserRoom {
|
context.chat_server().do_send(JoinUserRoom {
|
||||||
|
|
|
@ -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 anyhow::Context;
|
||||||
use chrono::NaiveDateTime;
|
use chrono::NaiveDateTime;
|
||||||
|
use futures::try_join;
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
impls::person::is_banned,
|
impls::person::is_banned,
|
||||||
newtypes::{CommunityId, DbUrl, LocalUserId, PersonId, PostId},
|
newtypes::{CommunityId, DbUrl, LocalUserId, PersonId, PostId},
|
||||||
|
@ -16,7 +22,6 @@ use lemmy_db_schema::{
|
||||||
person_block::PersonBlock,
|
person_block::PersonBlock,
|
||||||
post::{Post, PostRead, PostReadForm},
|
post::{Post, PostRead, PostReadForm},
|
||||||
registration_application::RegistrationApplication,
|
registration_application::RegistrationApplication,
|
||||||
secret::Secret,
|
|
||||||
},
|
},
|
||||||
traits::{Crud, Readable},
|
traits::{Crud, Readable},
|
||||||
utils::DbPool,
|
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"))
|
.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)]
|
#[tracing::instrument(skip_all)]
|
||||||
pub async fn get_local_user_view_from_jwt(
|
pub async fn local_user_view_from_jwt(
|
||||||
jwt: &str,
|
jwt: &str,
|
||||||
pool: &DbPool,
|
context: &LemmyContext,
|
||||||
secret: &Secret,
|
|
||||||
) -> Result<LocalUserView, LemmyError> {
|
) -> 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"))?
|
.map_err(|e| e.with_message("not_logged_in"))?
|
||||||
.claims;
|
.claims;
|
||||||
let local_user_id = LocalUserId(claims.sub);
|
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(
|
check_user_valid(
|
||||||
local_user_view.person.banned,
|
local_user_view.person.banned,
|
||||||
local_user_view.person.ban_expires,
|
local_user_view.person.ban_expires,
|
||||||
|
@ -164,6 +167,14 @@ pub async fn get_local_user_view_from_jwt(
|
||||||
Ok(local_user_view)
|
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.
|
/// Checks if user's token was issued before user's password reset.
|
||||||
pub fn check_validator_time(
|
pub fn check_validator_time(
|
||||||
validator_time: &NaiveDateTime,
|
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(
|
pub fn check_user_valid(
|
||||||
banned: bool,
|
banned: bool,
|
||||||
ban_expires: Option<NaiveDateTime>,
|
ban_expires: Option<NaiveDateTime>,
|
||||||
|
@ -314,9 +287,11 @@ pub async fn build_federated_instances(
|
||||||
) -> Result<Option<FederatedInstances>, LemmyError> {
|
) -> Result<Option<FederatedInstances>, LemmyError> {
|
||||||
if local_site.federation_enabled {
|
if local_site.federation_enabled {
|
||||||
// TODO I hate that this requires 3 queries
|
// TODO I hate that this requires 3 queries
|
||||||
let linked = Instance::linked(pool).await?;
|
let (linked, allowed, blocked) = try_join!(
|
||||||
let allowed = Instance::allowlist(pool).await?;
|
Instance::linked(pool),
|
||||||
let blocked = Instance::blocklist(pool).await?;
|
Instance::allowlist(pool),
|
||||||
|
Instance::blocklist(pool)
|
||||||
|
)?;
|
||||||
|
|
||||||
Ok(Some(FederatedInstances {
|
Ok(Some(FederatedInstances {
|
||||||
linked,
|
linked,
|
||||||
|
|
|
@ -8,9 +8,9 @@ use lemmy_api_common::{
|
||||||
check_community_deleted_or_removed,
|
check_community_deleted_or_removed,
|
||||||
check_post_deleted_or_removed,
|
check_post_deleted_or_removed,
|
||||||
generate_local_apub_endpoint,
|
generate_local_apub_endpoint,
|
||||||
get_local_user_view_from_jwt,
|
|
||||||
get_post,
|
get_post,
|
||||||
local_site_to_slur_regex,
|
local_site_to_slur_regex,
|
||||||
|
local_user_view_from_jwt,
|
||||||
EndpointType,
|
EndpointType,
|
||||||
},
|
},
|
||||||
websocket::UserOperationCrud,
|
websocket::UserOperationCrud,
|
||||||
|
@ -46,8 +46,7 @@ impl PerformCrud for CreateComment {
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<CommentResponse, LemmyError> {
|
) -> Result<CommentResponse, LemmyError> {
|
||||||
let data: &CreateComment = self;
|
let data: &CreateComment = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
let local_site = LocalSite::read(context.pool()).await?;
|
let local_site = LocalSite::read(context.pool()).await?;
|
||||||
|
|
||||||
let content_slurs_removed = remove_slurs(
|
let content_slurs_removed = remove_slurs(
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
comment::{CommentResponse, DeleteComment},
|
comment::{CommentResponse, DeleteComment},
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
utils::{check_community_ban, get_local_user_view_from_jwt},
|
utils::{check_community_ban, local_user_view_from_jwt},
|
||||||
websocket::UserOperationCrud,
|
websocket::UserOperationCrud,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
|
@ -27,8 +27,7 @@ impl PerformCrud for DeleteComment {
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<CommentResponse, LemmyError> {
|
) -> Result<CommentResponse, LemmyError> {
|
||||||
let data: &DeleteComment = self;
|
let data: &DeleteComment = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
|
|
||||||
let comment_id = data.comment_id;
|
let comment_id = data.comment_id;
|
||||||
let orig_comment = CommentView::read(context.pool(), comment_id, None).await?;
|
let orig_comment = CommentView::read(context.pool(), comment_id, None).await?;
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
comment::{CommentResponse, GetComment},
|
comment::{CommentResponse, GetComment},
|
||||||
context::LemmyContext,
|
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_schema::source::local_site::LocalSite;
|
||||||
use lemmy_db_views::structs::CommentView;
|
use lemmy_db_views::structs::CommentView;
|
||||||
|
@ -20,9 +20,7 @@ impl PerformCrud for GetComment {
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<Self::Response, LemmyError> {
|
) -> Result<Self::Response, LemmyError> {
|
||||||
let data = self;
|
let data = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await;
|
||||||
get_local_user_view_from_jwt_opt(data.auth.as_ref(), context.pool(), context.secret())
|
|
||||||
.await?;
|
|
||||||
let local_site = LocalSite::read(context.pool()).await?;
|
let local_site = LocalSite::read(context.pool()).await?;
|
||||||
|
|
||||||
check_private_instance(&local_user_view, &local_site)?;
|
check_private_instance(&local_user_view, &local_site)?;
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
comment::{CommentResponse, RemoveComment},
|
comment::{CommentResponse, RemoveComment},
|
||||||
context::LemmyContext,
|
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,
|
websocket::UserOperationCrud,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
|
@ -28,8 +28,7 @@ impl PerformCrud for RemoveComment {
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<CommentResponse, LemmyError> {
|
) -> Result<CommentResponse, LemmyError> {
|
||||||
let data: &RemoveComment = self;
|
let data: &RemoveComment = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
|
|
||||||
let comment_id = data.comment_id;
|
let comment_id = data.comment_id;
|
||||||
let orig_comment = CommentView::read(context.pool(), comment_id, None).await?;
|
let orig_comment = CommentView::read(context.pool(), comment_id, None).await?;
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
comment::{CommentResponse, EditComment},
|
comment::{CommentResponse, EditComment},
|
||||||
context::LemmyContext,
|
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,
|
websocket::UserOperationCrud,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
|
@ -37,8 +37,7 @@ impl PerformCrud for EditComment {
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<CommentResponse, LemmyError> {
|
) -> Result<CommentResponse, LemmyError> {
|
||||||
let data: &EditComment = self;
|
let data: &EditComment = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
let local_site = LocalSite::read(context.pool()).await?;
|
let local_site = LocalSite::read(context.pool()).await?;
|
||||||
|
|
||||||
let comment_id = data.comment_id;
|
let comment_id = data.comment_id;
|
||||||
|
|
|
@ -9,9 +9,9 @@ use lemmy_api_common::{
|
||||||
generate_inbox_url,
|
generate_inbox_url,
|
||||||
generate_local_apub_endpoint,
|
generate_local_apub_endpoint,
|
||||||
generate_shared_inbox_url,
|
generate_shared_inbox_url,
|
||||||
get_local_user_view_from_jwt,
|
|
||||||
is_admin,
|
is_admin,
|
||||||
local_site_to_slur_regex,
|
local_site_to_slur_regex,
|
||||||
|
local_user_view_from_jwt,
|
||||||
EndpointType,
|
EndpointType,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -52,8 +52,7 @@ impl PerformCrud for CreateCommunity {
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<CommunityResponse, LemmyError> {
|
) -> Result<CommunityResponse, LemmyError> {
|
||||||
let data: &CreateCommunity = self;
|
let data: &CreateCommunity = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
let site_view = SiteView::read_local(context.pool()).await?;
|
let site_view = SiteView::read_local(context.pool()).await?;
|
||||||
let local_site = site_view.local_site;
|
let local_site = site_view.local_site;
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
community::{CommunityResponse, DeleteCommunity},
|
community::{CommunityResponse, DeleteCommunity},
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
utils::{get_local_user_view_from_jwt, is_top_mod},
|
utils::{is_top_mod, local_user_view_from_jwt},
|
||||||
websocket::UserOperationCrud,
|
websocket::UserOperationCrud,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
|
@ -24,8 +24,7 @@ impl PerformCrud for DeleteCommunity {
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<CommunityResponse, LemmyError> {
|
) -> Result<CommunityResponse, LemmyError> {
|
||||||
let data: &DeleteCommunity = self;
|
let data: &DeleteCommunity = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
|
|
||||||
// Fetch the community mods
|
// Fetch the community mods
|
||||||
let community_id = data.community_id;
|
let community_id = data.community_id;
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
community::{ListCommunities, ListCommunitiesResponse},
|
community::{ListCommunities, ListCommunitiesResponse},
|
||||||
context::LemmyContext,
|
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_schema::source::local_site::LocalSite;
|
||||||
use lemmy_db_views_actor::community_view::CommunityQuery;
|
use lemmy_db_views_actor::community_view::CommunityQuery;
|
||||||
|
@ -20,9 +20,7 @@ impl PerformCrud for ListCommunities {
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<ListCommunitiesResponse, LemmyError> {
|
) -> Result<ListCommunitiesResponse, LemmyError> {
|
||||||
let data: &ListCommunities = self;
|
let data: &ListCommunities = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await;
|
||||||
get_local_user_view_from_jwt_opt(data.auth.as_ref(), context.pool(), context.secret())
|
|
||||||
.await?;
|
|
||||||
let local_site = LocalSite::read(context.pool()).await?;
|
let local_site = LocalSite::read(context.pool()).await?;
|
||||||
let is_admin = local_user_view.as_ref().map(|luv| is_admin(luv).is_ok());
|
let is_admin = local_user_view.as_ref().map(|luv| is_admin(luv).is_ok());
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
community::{CommunityResponse, RemoveCommunity},
|
community::{CommunityResponse, RemoveCommunity},
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
utils::{get_local_user_view_from_jwt, is_admin},
|
utils::{is_admin, local_user_view_from_jwt},
|
||||||
websocket::UserOperationCrud,
|
websocket::UserOperationCrud,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
|
@ -26,8 +26,7 @@ impl PerformCrud for RemoveCommunity {
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<CommunityResponse, LemmyError> {
|
) -> Result<CommunityResponse, LemmyError> {
|
||||||
let data: &RemoveCommunity = self;
|
let data: &RemoveCommunity = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
|
|
||||||
// Verify its an admin (only an admin can remove a community)
|
// Verify its an admin (only an admin can remove a community)
|
||||||
is_admin(&local_user_view)?;
|
is_admin(&local_user_view)?;
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
community::{CommunityResponse, EditCommunity},
|
community::{CommunityResponse, EditCommunity},
|
||||||
context::LemmyContext,
|
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,
|
websocket::UserOperationCrud,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
|
@ -34,8 +34,7 @@ impl PerformCrud for EditCommunity {
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<CommunityResponse, LemmyError> {
|
) -> Result<CommunityResponse, LemmyError> {
|
||||||
let data: &EditCommunity = self;
|
let data: &EditCommunity = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
let local_site = LocalSite::read(context.pool()).await?;
|
let local_site = LocalSite::read(context.pool()).await?;
|
||||||
|
|
||||||
let icon = diesel_option_overwrite_to_url(&data.icon)?;
|
let icon = diesel_option_overwrite_to_url(&data.icon)?;
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
custom_emoji::{CreateCustomEmoji, CustomEmojiResponse},
|
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::{
|
use lemmy_db_schema::source::{
|
||||||
custom_emoji::{CustomEmoji, CustomEmojiInsertForm},
|
custom_emoji::{CustomEmoji, CustomEmojiInsertForm},
|
||||||
|
@ -24,8 +24,7 @@ impl PerformCrud for CreateCustomEmoji {
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<CustomEmojiResponse, LemmyError> {
|
) -> Result<CustomEmojiResponse, LemmyError> {
|
||||||
let data: &CreateCustomEmoji = self;
|
let data: &CreateCustomEmoji = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
|
|
||||||
let local_site = LocalSite::read(context.pool()).await?;
|
let local_site = LocalSite::read(context.pool()).await?;
|
||||||
// Make sure user is an admin
|
// Make sure user is an admin
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
custom_emoji::{DeleteCustomEmoji, DeleteCustomEmojiResponse},
|
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_db_schema::source::custom_emoji::CustomEmoji;
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
|
@ -19,8 +19,7 @@ impl PerformCrud for DeleteCustomEmoji {
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<DeleteCustomEmojiResponse, LemmyError> {
|
) -> Result<DeleteCustomEmojiResponse, LemmyError> {
|
||||||
let data: &DeleteCustomEmoji = self;
|
let data: &DeleteCustomEmoji = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
|
|
||||||
// Make sure user is an admin
|
// Make sure user is an admin
|
||||||
is_admin(&local_user_view)?;
|
is_admin(&local_user_view)?;
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
custom_emoji::{CustomEmojiResponse, EditCustomEmoji},
|
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::{
|
use lemmy_db_schema::source::{
|
||||||
custom_emoji::{CustomEmoji, CustomEmojiUpdateForm},
|
custom_emoji::{CustomEmoji, CustomEmojiUpdateForm},
|
||||||
|
@ -24,8 +24,7 @@ impl PerformCrud for EditCustomEmoji {
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<CustomEmojiResponse, LemmyError> {
|
) -> Result<CustomEmojiResponse, LemmyError> {
|
||||||
let data: &EditCustomEmoji = self;
|
let data: &EditCustomEmoji = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
|
|
||||||
let local_site = LocalSite::read(context.pool()).await?;
|
let local_site = LocalSite::read(context.pool()).await?;
|
||||||
// Make sure user is an admin
|
// Make sure user is an admin
|
||||||
|
|
|
@ -8,9 +8,9 @@ use lemmy_api_common::{
|
||||||
check_community_ban,
|
check_community_ban,
|
||||||
check_community_deleted_or_removed,
|
check_community_deleted_or_removed,
|
||||||
generate_local_apub_endpoint,
|
generate_local_apub_endpoint,
|
||||||
get_local_user_view_from_jwt,
|
|
||||||
honeypot_check,
|
honeypot_check,
|
||||||
local_site_to_slur_regex,
|
local_site_to_slur_regex,
|
||||||
|
local_user_view_from_jwt,
|
||||||
mark_post_as_read,
|
mark_post_as_read,
|
||||||
EndpointType,
|
EndpointType,
|
||||||
},
|
},
|
||||||
|
@ -50,8 +50,7 @@ impl PerformCrud for CreatePost {
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<PostResponse, LemmyError> {
|
) -> Result<PostResponse, LemmyError> {
|
||||||
let data: &CreatePost = self;
|
let data: &CreatePost = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
let local_site = LocalSite::read(context.pool()).await?;
|
let local_site = LocalSite::read(context.pool()).await?;
|
||||||
|
|
||||||
let slur_regex = local_site_to_slur_regex(&local_site);
|
let slur_regex = local_site_to_slur_regex(&local_site);
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
post::{DeletePost, PostResponse},
|
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,
|
websocket::UserOperationCrud,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
|
@ -23,8 +23,7 @@ impl PerformCrud for DeletePost {
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<PostResponse, LemmyError> {
|
) -> Result<PostResponse, LemmyError> {
|
||||||
let data: &DeletePost = self;
|
let data: &DeletePost = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
|
|
||||||
let post_id = data.post_id;
|
let post_id = data.post_id;
|
||||||
let orig_post = Post::read(context.pool(), post_id).await?;
|
let orig_post = Post::read(context.pool(), post_id).await?;
|
||||||
|
|
|
@ -5,8 +5,8 @@ use lemmy_api_common::{
|
||||||
post::{GetPost, GetPostResponse},
|
post::{GetPost, GetPostResponse},
|
||||||
utils::{
|
utils::{
|
||||||
check_private_instance,
|
check_private_instance,
|
||||||
get_local_user_view_from_jwt_opt,
|
|
||||||
is_mod_or_admin_opt,
|
is_mod_or_admin_opt,
|
||||||
|
local_user_view_from_jwt_opt,
|
||||||
mark_post_as_read,
|
mark_post_as_read,
|
||||||
},
|
},
|
||||||
websocket::handlers::online_users::GetPostUsersOnline,
|
websocket::handlers::online_users::GetPostUsersOnline,
|
||||||
|
@ -31,9 +31,7 @@ impl PerformCrud for GetPost {
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<GetPostResponse, LemmyError> {
|
) -> Result<GetPostResponse, LemmyError> {
|
||||||
let data: &GetPost = self;
|
let data: &GetPost = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await;
|
||||||
get_local_user_view_from_jwt_opt(data.auth.as_ref(), context.pool(), context.secret())
|
|
||||||
.await?;
|
|
||||||
let local_site = LocalSite::read(context.pool()).await?;
|
let local_site = LocalSite::read(context.pool()).await?;
|
||||||
|
|
||||||
check_private_instance(&local_user_view, &local_site)?;
|
check_private_instance(&local_user_view, &local_site)?;
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
post::{PostResponse, RemovePost},
|
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,
|
websocket::UserOperationCrud,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
|
@ -26,8 +26,7 @@ impl PerformCrud for RemovePost {
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<PostResponse, LemmyError> {
|
) -> Result<PostResponse, LemmyError> {
|
||||||
let data: &RemovePost = self;
|
let data: &RemovePost = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
|
|
||||||
let post_id = data.post_id;
|
let post_id = data.post_id;
|
||||||
let orig_post = Post::read(context.pool(), post_id).await?;
|
let orig_post = Post::read(context.pool(), post_id).await?;
|
||||||
|
|
|
@ -4,7 +4,7 @@ use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
post::{EditPost, PostResponse},
|
post::{EditPost, PostResponse},
|
||||||
request::fetch_site_data,
|
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,
|
websocket::UserOperationCrud,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
|
@ -36,8 +36,7 @@ impl PerformCrud for EditPost {
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<PostResponse, LemmyError> {
|
) -> Result<PostResponse, LemmyError> {
|
||||||
let data: &EditPost = self;
|
let data: &EditPost = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
let local_site = LocalSite::read(context.pool()).await?;
|
let local_site = LocalSite::read(context.pool()).await?;
|
||||||
|
|
||||||
let data_url = data.url.as_ref();
|
let data_url = data.url.as_ref();
|
||||||
|
|
|
@ -7,8 +7,8 @@ use lemmy_api_common::{
|
||||||
check_person_block,
|
check_person_block,
|
||||||
generate_local_apub_endpoint,
|
generate_local_apub_endpoint,
|
||||||
get_interface_language,
|
get_interface_language,
|
||||||
get_local_user_view_from_jwt,
|
|
||||||
local_site_to_slur_regex,
|
local_site_to_slur_regex,
|
||||||
|
local_user_view_from_jwt,
|
||||||
send_email_to_user,
|
send_email_to_user,
|
||||||
EndpointType,
|
EndpointType,
|
||||||
},
|
},
|
||||||
|
@ -39,8 +39,7 @@ impl PerformCrud for CreatePrivateMessage {
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<PrivateMessageResponse, LemmyError> {
|
) -> Result<PrivateMessageResponse, LemmyError> {
|
||||||
let data: &CreatePrivateMessage = self;
|
let data: &CreatePrivateMessage = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
let local_site = LocalSite::read(context.pool()).await?;
|
let local_site = LocalSite::read(context.pool()).await?;
|
||||||
|
|
||||||
let content_slurs_removed = remove_slurs(
|
let content_slurs_removed = remove_slurs(
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
private_message::{DeletePrivateMessage, PrivateMessageResponse},
|
private_message::{DeletePrivateMessage, PrivateMessageResponse},
|
||||||
utils::get_local_user_view_from_jwt,
|
utils::local_user_view_from_jwt,
|
||||||
websocket::UserOperationCrud,
|
websocket::UserOperationCrud,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
|
@ -23,8 +23,7 @@ impl PerformCrud for DeletePrivateMessage {
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<PrivateMessageResponse, LemmyError> {
|
) -> Result<PrivateMessageResponse, LemmyError> {
|
||||||
let data: &DeletePrivateMessage = self;
|
let data: &DeletePrivateMessage = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
|
|
||||||
// Checking permissions
|
// Checking permissions
|
||||||
let private_message_id = data.private_message_id;
|
let private_message_id = data.private_message_id;
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
private_message::{GetPrivateMessages, PrivateMessagesResponse},
|
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_db_views::private_message_view::PrivateMessageQuery;
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
|
@ -19,8 +19,7 @@ impl PerformCrud for GetPrivateMessages {
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<PrivateMessagesResponse, LemmyError> {
|
) -> Result<PrivateMessagesResponse, LemmyError> {
|
||||||
let data: &GetPrivateMessages = self;
|
let data: &GetPrivateMessages = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(data.auth.as_ref(), context).await?;
|
||||||
get_local_user_view_from_jwt(data.auth.as_ref(), context.pool(), context.secret()).await?;
|
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
|
|
||||||
let page = data.page;
|
let page = data.page;
|
||||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
private_message::{EditPrivateMessage, PrivateMessageResponse},
|
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,
|
websocket::UserOperationCrud,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
|
@ -31,8 +31,7 @@ impl PerformCrud for EditPrivateMessage {
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<PrivateMessageResponse, LemmyError> {
|
) -> Result<PrivateMessageResponse, LemmyError> {
|
||||||
let data: &EditPrivateMessage = self;
|
let data: &EditPrivateMessage = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
let local_site = LocalSite::read(context.pool()).await?;
|
let local_site = LocalSite::read(context.pool()).await?;
|
||||||
|
|
||||||
// Checking permissions
|
// Checking permissions
|
||||||
|
|
|
@ -6,10 +6,10 @@ use lemmy_api_common::{
|
||||||
site::{CreateSite, SiteResponse},
|
site::{CreateSite, SiteResponse},
|
||||||
utils::{
|
utils::{
|
||||||
generate_site_inbox_url,
|
generate_site_inbox_url,
|
||||||
get_local_user_view_from_jwt,
|
|
||||||
is_admin,
|
is_admin,
|
||||||
local_site_rate_limit_to_rate_limit_config,
|
local_site_rate_limit_to_rate_limit_config,
|
||||||
local_site_to_slur_regex,
|
local_site_to_slur_regex,
|
||||||
|
local_user_view_from_jwt,
|
||||||
site_description_length_check,
|
site_description_length_check,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -52,8 +52,7 @@ impl PerformCrud for CreateSite {
|
||||||
return Err(LemmyError::from_message("site_already_exists"));
|
return Err(LemmyError::from_message("site_already_exists"));
|
||||||
};
|
};
|
||||||
|
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
|
|
||||||
let sidebar = diesel_option_overwrite(&data.sidebar);
|
let sidebar = diesel_option_overwrite(&data.sidebar);
|
||||||
let description = diesel_option_overwrite(&data.description);
|
let description = diesel_option_overwrite(&data.description);
|
||||||
|
|
|
@ -2,16 +2,20 @@ use crate::PerformCrud;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
|
sensitive::Sensitive,
|
||||||
site::{GetSite, GetSiteResponse, MyUserInfo},
|
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,
|
websocket::handlers::online_users::GetUsersOnline,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::source::{
|
use lemmy_db_schema::{
|
||||||
|
newtypes::LocalUserId,
|
||||||
|
source::{
|
||||||
actor_language::{LocalUserLanguage, SiteLanguage},
|
actor_language::{LocalUserLanguage, SiteLanguage},
|
||||||
language::Language,
|
language::Language,
|
||||||
tagline::Tagline,
|
tagline::Tagline,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::{CustomEmojiView, SiteView};
|
use lemmy_db_views::structs::{CustomEmojiView, LocalUserView, SiteView};
|
||||||
use lemmy_db_views_actor::structs::{
|
use lemmy_db_views_actor::structs::{
|
||||||
CommunityBlockView,
|
CommunityBlockView,
|
||||||
CommunityFollowerView,
|
CommunityFollowerView,
|
||||||
|
@ -19,7 +23,7 @@ use lemmy_db_views_actor::structs::{
|
||||||
PersonBlockView,
|
PersonBlockView,
|
||||||
PersonView,
|
PersonView,
|
||||||
};
|
};
|
||||||
use lemmy_utils::{error::LemmyError, version, ConnectionId};
|
use lemmy_utils::{claims::Claims, error::LemmyError, version, ConnectionId};
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl PerformCrud for GetSite {
|
impl PerformCrud for GetSite {
|
||||||
|
@ -40,12 +44,8 @@ impl PerformCrud for GetSite {
|
||||||
let online = context.chat_server().send(GetUsersOnline).await?;
|
let online = context.chat_server().send(GetUsersOnline).await?;
|
||||||
|
|
||||||
// Build the local user
|
// Build the local user
|
||||||
let my_user = if let Some(local_user_view) = get_local_user_settings_view_from_jwt_opt(
|
let my_user = if let Some(local_user_view) =
|
||||||
data.auth.as_ref(),
|
local_user_settings_view_from_jwt_opt(data.auth.as_ref(), context).await
|
||||||
context.pool(),
|
|
||||||
context.secret(),
|
|
||||||
)
|
|
||||||
.await?
|
|
||||||
{
|
{
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
let local_user_id = local_user_view.local_user.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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -4,10 +4,10 @@ use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
site::{EditSite, SiteResponse},
|
site::{EditSite, SiteResponse},
|
||||||
utils::{
|
utils::{
|
||||||
get_local_user_view_from_jwt,
|
|
||||||
is_admin,
|
is_admin,
|
||||||
local_site_rate_limit_to_rate_limit_config,
|
local_site_rate_limit_to_rate_limit_config,
|
||||||
local_site_to_slur_regex,
|
local_site_to_slur_regex,
|
||||||
|
local_user_view_from_jwt,
|
||||||
site_description_length_check,
|
site_description_length_check,
|
||||||
},
|
},
|
||||||
websocket::UserOperationCrud,
|
websocket::UserOperationCrud,
|
||||||
|
@ -46,8 +46,7 @@ impl PerformCrud for EditSite {
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<SiteResponse, LemmyError> {
|
) -> Result<SiteResponse, LemmyError> {
|
||||||
let data: &EditSite = self;
|
let data: &EditSite = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
|
||||||
let site_view = SiteView::read_local(context.pool()).await?;
|
let site_view = SiteView::read_local(context.pool()).await?;
|
||||||
let local_site = site_view.local_site;
|
let local_site = site_view.local_site;
|
||||||
let site = site_view.site;
|
let site = site_view.site;
|
||||||
|
|
|
@ -4,7 +4,7 @@ use bcrypt::verify;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
person::{DeleteAccount, DeleteAccountResponse},
|
person::{DeleteAccount, DeleteAccountResponse},
|
||||||
utils::get_local_user_view_from_jwt,
|
utils::local_user_view_from_jwt,
|
||||||
};
|
};
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
|
|
||||||
|
@ -19,8 +19,7 @@ impl PerformCrud for DeleteAccount {
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<Self::Response, LemmyError> {
|
) -> Result<Self::Response, LemmyError> {
|
||||||
let data = self;
|
let data = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(data.auth.as_ref(), context).await?;
|
||||||
get_local_user_view_from_jwt(data.auth.as_ref(), context.pool(), context.secret()).await?;
|
|
||||||
|
|
||||||
// Verify the password
|
// Verify the password
|
||||||
let valid: bool = verify(
|
let valid: bool = verify(
|
||||||
|
|
|
@ -16,7 +16,7 @@ use lemmy_api_common::{
|
||||||
community::{BanFromCommunity, BanFromCommunityResponse},
|
community::{BanFromCommunity, BanFromCommunityResponse},
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
person::{BanPerson, BanPersonResponse},
|
person::{BanPerson, BanPersonResponse},
|
||||||
utils::get_local_user_view_from_jwt,
|
utils::local_user_view_from_jwt,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{community::Community, person::Person, site::Site},
|
source::{community::Community, person::Person, site::Site},
|
||||||
|
@ -138,8 +138,7 @@ impl SendActivity for BanPerson {
|
||||||
_response: &Self::Response,
|
_response: &Self::Response,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?;
|
|
||||||
let person = Person::read(context.pool(), request.person_id).await?;
|
let person = Person::read(context.pool(), request.person_id).await?;
|
||||||
let site = SiteOrCommunity::Site(SiteView::read_local(context.pool()).await?.site.into());
|
let site = SiteOrCommunity::Site(SiteView::read_local(context.pool()).await?.site.into());
|
||||||
let expires = request.expires.map(naive_from_unix);
|
let expires = request.expires.map(naive_from_unix);
|
||||||
|
@ -182,8 +181,7 @@ impl SendActivity for BanFromCommunity {
|
||||||
_response: &Self::Response,
|
_response: &Self::Response,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?;
|
|
||||||
let community: ApubCommunity = Community::read(context.pool(), request.community_id)
|
let community: ApubCommunity = Community::read(context.pool(), request.community_id)
|
||||||
.await?
|
.await?
|
||||||
.into();
|
.into();
|
||||||
|
|
|
@ -29,7 +29,7 @@ use lemmy_api_common::{
|
||||||
community::{AddModToCommunity, AddModToCommunityResponse},
|
community::{AddModToCommunity, AddModToCommunityResponse},
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
post::{FeaturePost, PostResponse},
|
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::{
|
use lemmy_db_schema::{
|
||||||
impls::community::CollectionType,
|
impls::community::CollectionType,
|
||||||
|
@ -177,8 +177,7 @@ impl SendActivity for AddModToCommunity {
|
||||||
_response: &Self::Response,
|
_response: &Self::Response,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?;
|
|
||||||
let community: ApubCommunity = Community::read(context.pool(), request.community_id)
|
let community: ApubCommunity = Community::read(context.pool(), request.community_id)
|
||||||
.await?
|
.await?
|
||||||
.into();
|
.into();
|
||||||
|
@ -214,8 +213,7 @@ impl SendActivity for FeaturePost {
|
||||||
response: &Self::Response,
|
response: &Self::Response,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?;
|
|
||||||
// Deprecated, for backwards compatibility with 0.17
|
// Deprecated, for backwards compatibility with 0.17
|
||||||
CreateOrUpdatePage::send(
|
CreateOrUpdatePage::send(
|
||||||
&response.post_view.post,
|
&response.post_view.post,
|
||||||
|
|
|
@ -27,7 +27,7 @@ use activitypub_federation::{
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
post::{LockPost, PostResponse},
|
post::{LockPost, PostResponse},
|
||||||
utils::get_local_user_view_from_jwt,
|
utils::local_user_view_from_jwt,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
|
@ -115,8 +115,7 @@ impl SendActivity for LockPost {
|
||||||
response: &Self::Response,
|
response: &Self::Response,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?;
|
|
||||||
// For backwards compat with 0.17
|
// For backwards compat with 0.17
|
||||||
CreateOrUpdatePage::send(
|
CreateOrUpdatePage::send(
|
||||||
&response.post_view.post,
|
&response.post_view.post,
|
||||||
|
|
|
@ -16,7 +16,7 @@ use lemmy_api_common::{
|
||||||
comment::{CommentReportResponse, CreateCommentReport},
|
comment::{CommentReportResponse, CreateCommentReport},
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
post::{CreatePostReport, PostReportResponse},
|
post::{CreatePostReport, PostReportResponse},
|
||||||
utils::get_local_user_view_from_jwt,
|
utils::local_user_view_from_jwt,
|
||||||
websocket::UserOperation,
|
websocket::UserOperation,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
|
@ -39,8 +39,7 @@ impl SendActivity for CreatePostReport {
|
||||||
response: &Self::Response,
|
response: &Self::Response,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?;
|
|
||||||
Report::send(
|
Report::send(
|
||||||
ObjectId::from(response.post_report_view.post.ap_id.clone()),
|
ObjectId::from(response.post_report_view.post.ap_id.clone()),
|
||||||
&local_user_view.person.into(),
|
&local_user_view.person.into(),
|
||||||
|
@ -61,8 +60,7 @@ impl SendActivity for CreateCommentReport {
|
||||||
response: &Self::Response,
|
response: &Self::Response,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?;
|
|
||||||
Report::send(
|
Report::send(
|
||||||
ObjectId::from(response.comment_report_view.comment.ap_id.clone()),
|
ObjectId::from(response.comment_report_view.comment.ap_id.clone()),
|
||||||
&local_user_view.person.into(),
|
&local_user_view.person.into(),
|
||||||
|
|
|
@ -20,7 +20,7 @@ use activitypub_federation::{
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
community::{CommunityResponse, EditCommunity, HideCommunity},
|
community::{CommunityResponse, EditCommunity, HideCommunity},
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
utils::get_local_user_view_from_jwt,
|
utils::local_user_view_from_jwt,
|
||||||
websocket::UserOperationCrud,
|
websocket::UserOperationCrud,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{source::community::Community, traits::Crud};
|
use lemmy_db_schema::{source::community::Community, traits::Crud};
|
||||||
|
@ -36,8 +36,7 @@ impl SendActivity for EditCommunity {
|
||||||
_response: &Self::Response,
|
_response: &Self::Response,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?;
|
|
||||||
let community = Community::read(context.pool(), request.community_id).await?;
|
let community = Community::read(context.pool(), request.community_id).await?;
|
||||||
UpdateCommunity::send(community.into(), &local_user_view.person.into(), context).await
|
UpdateCommunity::send(community.into(), &local_user_view.person.into(), context).await
|
||||||
}
|
}
|
||||||
|
@ -123,8 +122,7 @@ impl SendActivity for HideCommunity {
|
||||||
_response: &Self::Response,
|
_response: &Self::Response,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?;
|
|
||||||
let community = Community::read(context.pool(), request.community_id).await?;
|
let community = Community::read(context.pool(), request.community_id).await?;
|
||||||
UpdateCommunity::send(community.into(), &local_user_view.person.into(), context).await
|
UpdateCommunity::send(community.into(), &local_user_view.person.into(), context).await
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ use activitypub_federation::{
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
person::{DeleteAccount, DeleteAccountResponse},
|
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 lemmy_utils::error::LemmyError;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
@ -28,8 +28,7 @@ impl SendActivity for DeleteAccount {
|
||||||
_response: &Self::Response,
|
_response: &Self::Response,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?;
|
|
||||||
let actor: ApubPerson = local_user_view.person.into();
|
let actor: ApubPerson = local_user_view.person.into();
|
||||||
delete_user_account(
|
delete_user_account(
|
||||||
actor.id,
|
actor.id,
|
||||||
|
|
|
@ -34,7 +34,7 @@ use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
post::{DeletePost, PostResponse, RemovePost},
|
post::{DeletePost, PostResponse, RemovePost},
|
||||||
private_message::{DeletePrivateMessage, PrivateMessageResponse},
|
private_message::{DeletePrivateMessage, PrivateMessageResponse},
|
||||||
utils::get_local_user_view_from_jwt,
|
utils::local_user_view_from_jwt,
|
||||||
websocket::UserOperationCrud,
|
websocket::UserOperationCrud,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
|
@ -64,8 +64,7 @@ impl SendActivity for DeletePost {
|
||||||
response: &Self::Response,
|
response: &Self::Response,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?;
|
|
||||||
let community = Community::read(context.pool(), response.post_view.community.id).await?;
|
let community = Community::read(context.pool(), response.post_view.community.id).await?;
|
||||||
let deletable = DeletableObjects::Post(response.post_view.post.clone().into());
|
let deletable = DeletableObjects::Post(response.post_view.post.clone().into());
|
||||||
send_apub_delete_in_community(
|
send_apub_delete_in_community(
|
||||||
|
@ -89,8 +88,7 @@ impl SendActivity for RemovePost {
|
||||||
response: &Self::Response,
|
response: &Self::Response,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?;
|
|
||||||
let community = Community::read(context.pool(), response.post_view.community.id).await?;
|
let community = Community::read(context.pool(), response.post_view.community.id).await?;
|
||||||
let deletable = DeletableObjects::Post(response.post_view.post.clone().into());
|
let deletable = DeletableObjects::Post(response.post_view.post.clone().into());
|
||||||
send_apub_delete_in_community(
|
send_apub_delete_in_community(
|
||||||
|
@ -132,8 +130,7 @@ impl SendActivity for RemoveComment {
|
||||||
response: &Self::Response,
|
response: &Self::Response,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?;
|
|
||||||
let comment = Comment::read(context.pool(), request.comment_id).await?;
|
let comment = Comment::read(context.pool(), request.comment_id).await?;
|
||||||
let community = Community::read(context.pool(), response.comment_view.community.id).await?;
|
let community = Community::read(context.pool(), response.comment_view.community.id).await?;
|
||||||
let deletable = DeletableObjects::Comment(comment.into());
|
let deletable = DeletableObjects::Comment(comment.into());
|
||||||
|
@ -158,8 +155,7 @@ impl SendActivity for DeletePrivateMessage {
|
||||||
response: &Self::Response,
|
response: &Self::Response,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?;
|
|
||||||
send_apub_delete_private_message(
|
send_apub_delete_private_message(
|
||||||
&local_user_view.person.into(),
|
&local_user_view.person.into(),
|
||||||
response.private_message_view.private_message.clone(),
|
response.private_message_view.private_message.clone(),
|
||||||
|
@ -179,8 +175,7 @@ impl SendActivity for DeleteCommunity {
|
||||||
_response: &Self::Response,
|
_response: &Self::Response,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?;
|
|
||||||
let community = Community::read(context.pool(), request.community_id).await?;
|
let community = Community::read(context.pool(), request.community_id).await?;
|
||||||
let deletable = DeletableObjects::Community(community.clone().into());
|
let deletable = DeletableObjects::Community(community.clone().into());
|
||||||
send_apub_delete_in_community(
|
send_apub_delete_in_community(
|
||||||
|
@ -204,8 +199,7 @@ impl SendActivity for RemoveCommunity {
|
||||||
_response: &Self::Response,
|
_response: &Self::Response,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?;
|
|
||||||
let community = Community::read(context.pool(), request.community_id).await?;
|
let community = Community::read(context.pool(), request.community_id).await?;
|
||||||
let deletable = DeletableObjects::Community(community.clone().into());
|
let deletable = DeletableObjects::Community(community.clone().into());
|
||||||
send_apub_delete_in_community(
|
send_apub_delete_in_community(
|
||||||
|
|
|
@ -24,7 +24,7 @@ use activitypub_federation::{
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
community::{BlockCommunity, BlockCommunityResponse},
|
community::{BlockCommunity, BlockCommunityResponse},
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
utils::get_local_user_view_from_jwt,
|
utils::local_user_view_from_jwt,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
|
@ -138,8 +138,7 @@ impl SendActivity for BlockCommunity {
|
||||||
_response: &Self::Response,
|
_response: &Self::Response,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?;
|
|
||||||
let community = Community::read(context.pool(), request.community_id).await?;
|
let community = Community::read(context.pool(), request.community_id).await?;
|
||||||
UndoFollow::send(&local_user_view.person.into(), &community.into(), context).await
|
UndoFollow::send(&local_user_view.person.into(), &community.into(), context).await
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ use activitypub_federation::config::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
community::{CommunityResponse, FollowCommunity},
|
community::{CommunityResponse, FollowCommunity},
|
||||||
context::LemmyContext,
|
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_db_schema::{source::community::Community, traits::Crud};
|
||||||
use lemmy_utils::error::LemmyError;
|
use lemmy_utils::error::LemmyError;
|
||||||
|
@ -25,8 +25,7 @@ impl SendActivity for FollowCommunity {
|
||||||
_response: &Self::Response,
|
_response: &Self::Response,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?;
|
|
||||||
let person = local_user_view.person.clone().into();
|
let person = local_user_view.person.clone().into();
|
||||||
let community: ApubCommunity = Community::read(context.pool(), request.community_id)
|
let community: ApubCommunity = Community::read(context.pool(), request.community_id)
|
||||||
.await?
|
.await?
|
||||||
|
|
|
@ -15,7 +15,7 @@ use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
post::{CreatePostLike, PostResponse},
|
post::{CreatePostLike, PostResponse},
|
||||||
sensitive::Sensitive,
|
sensitive::Sensitive,
|
||||||
utils::get_local_user_view_from_jwt,
|
utils::local_user_view_from_jwt,
|
||||||
websocket::UserOperation,
|
websocket::UserOperation,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
|
@ -85,7 +85,7 @@ async fn send_activity(
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let community = Community::read(context.pool(), community_id).await?.into();
|
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)
|
let actor = Person::read(context.pool(), local_user_view.person.id)
|
||||||
.await?
|
.await?
|
||||||
.into();
|
.into();
|
||||||
|
|
|
@ -7,7 +7,7 @@ use activitypub_federation::config::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
comment::{GetComments, GetCommentsResponse},
|
comment::{GetComments, GetCommentsResponse},
|
||||||
context::LemmyContext,
|
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::{
|
use lemmy_db_schema::{
|
||||||
source::{comment::Comment, community::Community, local_site::LocalSite},
|
source::{comment::Comment, community::Community, local_site::LocalSite},
|
||||||
|
@ -27,9 +27,7 @@ impl PerformApub for GetComments {
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<GetCommentsResponse, LemmyError> {
|
) -> Result<GetCommentsResponse, LemmyError> {
|
||||||
let data: &GetComments = self;
|
let data: &GetComments = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await;
|
||||||
get_local_user_view_from_jwt_opt(data.auth.as_ref(), context.pool(), context.secret())
|
|
||||||
.await?;
|
|
||||||
let local_site = LocalSite::read(context.pool()).await?;
|
let local_site = LocalSite::read(context.pool()).await?;
|
||||||
check_private_instance(&local_user_view, &local_site)?;
|
check_private_instance(&local_user_view, &local_site)?;
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ use activitypub_federation::config::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
post::{GetPosts, GetPostsResponse},
|
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_schema::source::{community::Community, local_site::LocalSite};
|
||||||
use lemmy_db_views::post_view::PostQuery;
|
use lemmy_db_views::post_view::PostQuery;
|
||||||
|
@ -24,9 +24,7 @@ impl PerformApub for GetPosts {
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<GetPostsResponse, LemmyError> {
|
) -> Result<GetPostsResponse, LemmyError> {
|
||||||
let data: &GetPosts = self;
|
let data: &GetPosts = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await;
|
||||||
get_local_user_view_from_jwt_opt(data.auth.as_ref(), context.pool(), context.secret())
|
|
||||||
.await?;
|
|
||||||
let local_site = LocalSite::read(context.pool()).await?;
|
let local_site = LocalSite::read(context.pool()).await?;
|
||||||
|
|
||||||
check_private_instance(&local_user_view, &local_site)?;
|
check_private_instance(&local_user_view, &local_site)?;
|
||||||
|
|
|
@ -7,7 +7,7 @@ use activitypub_federation::config::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
community::{GetCommunity, GetCommunityResponse},
|
community::{GetCommunity, GetCommunityResponse},
|
||||||
context::LemmyContext,
|
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,
|
websocket::handlers::online_users::GetCommunityUsersOnline,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::source::{
|
use lemmy_db_schema::source::{
|
||||||
|
@ -30,9 +30,7 @@ impl PerformApub for GetCommunity {
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<GetCommunityResponse, LemmyError> {
|
) -> Result<GetCommunityResponse, LemmyError> {
|
||||||
let data: &GetCommunity = self;
|
let data: &GetCommunity = self;
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await;
|
||||||
get_local_user_view_from_jwt_opt(data.auth.as_ref(), context.pool(), context.secret())
|
|
||||||
.await?;
|
|
||||||
let local_site = LocalSite::read(context.pool()).await?;
|
let local_site = LocalSite::read(context.pool()).await?;
|
||||||
|
|
||||||
if data.name.is_none() && data.id.is_none() {
|
if data.name.is_none() && data.id.is_none() {
|
||||||
|
|
|
@ -3,7 +3,7 @@ use activitypub_federation::config::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
person::{GetPersonDetails, GetPersonDetailsResponse},
|
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::{
|
use lemmy_db_schema::{
|
||||||
source::{local_site::LocalSite, person::Person},
|
source::{local_site::LocalSite, person::Person},
|
||||||
|
@ -30,9 +30,7 @@ impl PerformApub for GetPersonDetails {
|
||||||
return Err(LemmyError::from_message("no_id_given"));
|
return Err(LemmyError::from_message("no_id_given"));
|
||||||
}
|
}
|
||||||
|
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await;
|
||||||
get_local_user_view_from_jwt_opt(data.auth.as_ref(), context.pool(), context.secret())
|
|
||||||
.await?;
|
|
||||||
let local_site = LocalSite::read(context.pool()).await?;
|
let local_site = LocalSite::read(context.pool()).await?;
|
||||||
let is_admin = local_user_view.as_ref().map(|luv| is_admin(luv).is_ok());
|
let is_admin = local_user_view.as_ref().map(|luv| is_admin(luv).is_ok());
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ use diesel::NotFound;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
site::{ResolveObject, ResolveObjectResponse},
|
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_schema::{newtypes::PersonId, source::local_site::LocalSite, utils::DbPool};
|
||||||
use lemmy_db_views::structs::{CommentView, PostView};
|
use lemmy_db_views::structs::{CommentView, PostView};
|
||||||
|
@ -24,8 +24,7 @@ impl PerformApub for ResolveObject {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<ResolveObjectResponse, LemmyError> {
|
) -> Result<ResolveObjectResponse, LemmyError> {
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt(&self.auth, context).await?;
|
||||||
get_local_user_view_from_jwt(&self.auth, context.pool(), context.secret()).await?;
|
|
||||||
let local_site = LocalSite::read(context.pool()).await?;
|
let local_site = LocalSite::read(context.pool()).await?;
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
check_private_instance(&Some(local_user_view), &local_site)?;
|
check_private_instance(&Some(local_user_view), &local_site)?;
|
||||||
|
|
|
@ -7,7 +7,7 @@ use activitypub_federation::config::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
site::{Search, SearchResponse},
|
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::{
|
use lemmy_db_schema::{
|
||||||
source::{community::Community, local_site::LocalSite},
|
source::{community::Community, local_site::LocalSite},
|
||||||
|
@ -30,9 +30,7 @@ impl PerformApub for Search {
|
||||||
) -> Result<SearchResponse, LemmyError> {
|
) -> Result<SearchResponse, LemmyError> {
|
||||||
let data: &Search = self;
|
let data: &Search = self;
|
||||||
|
|
||||||
let local_user_view =
|
let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await;
|
||||||
get_local_user_view_from_jwt_opt(data.auth.as_ref(), context.pool(), context.secret())
|
|
||||||
.await?;
|
|
||||||
let local_site = LocalSite::read(context.pool()).await?;
|
let local_site = LocalSite::read(context.pool()).await?;
|
||||||
|
|
||||||
check_private_instance(&local_user_view, &local_site)?;
|
check_private_instance(&local_user_view, &local_site)?;
|
||||||
|
|
|
@ -11,7 +11,7 @@ use actix_web::{
|
||||||
HttpResponse,
|
HttpResponse,
|
||||||
};
|
};
|
||||||
use futures::stream::{Stream, StreamExt};
|
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_db_schema::source::local_site::LocalSite;
|
||||||
use lemmy_utils::{claims::Claims, rate_limit::RateLimitCell, REQWEST_TIMEOUT};
|
use lemmy_utils::{claims::Claims, rate_limit::RateLimitCell, REQWEST_TIMEOUT};
|
||||||
use reqwest::Body;
|
use reqwest::Body;
|
||||||
|
@ -136,7 +136,7 @@ async fn full_res(
|
||||||
let jwt = req
|
let jwt = req
|
||||||
.cookie("jwt")
|
.cookie("jwt")
|
||||||
.expect("No auth header for picture access");
|
.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
|
.await
|
||||||
.is_err()
|
.is_err()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue