mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-26 06:11:26 +00:00
Fix up convert more responses to SuccessResponse (#4066)
* Revert "Convert more responses to SuccessResponse. Fixes #2860 (#4058)"
This reverts commit 8deb4e5752
.
* Removing purgeitem and deletecustomemoji response.
* Adding back in utils building.
This commit is contained in:
parent
8deb4e5752
commit
c1db65c6e5
16 changed files with 159 additions and 44 deletions
|
@ -19,7 +19,7 @@
|
||||||
"eslint": "^8.51.0",
|
"eslint": "^8.51.0",
|
||||||
"eslint-plugin-prettier": "^5.0.1",
|
"eslint-plugin-prettier": "^5.0.1",
|
||||||
"jest": "^29.5.0",
|
"jest": "^29.5.0",
|
||||||
"lemmy-js-client": "0.19.0-alpha.12",
|
"lemmy-js-client": "0.19.0-rc.12",
|
||||||
"prettier": "^3.0.0",
|
"prettier": "^3.0.0",
|
||||||
"ts-jest": "^29.1.0",
|
"ts-jest": "^29.1.0",
|
||||||
"typescript": "^5.0.4"
|
"typescript": "^5.0.4"
|
||||||
|
|
|
@ -25,6 +25,7 @@ import {
|
||||||
getCommunityByName,
|
getCommunityByName,
|
||||||
blockInstance,
|
blockInstance,
|
||||||
waitUntil,
|
waitUntil,
|
||||||
|
delay,
|
||||||
alphaUrl,
|
alphaUrl,
|
||||||
delta,
|
delta,
|
||||||
betaAllowedInstances,
|
betaAllowedInstances,
|
||||||
|
@ -240,7 +241,7 @@ test("Admin actions in remote community are not federated to origin", async () =
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
expect(banRes.success).toBe(true);
|
expect(banRes.banned).toBe(true);
|
||||||
|
|
||||||
// ban doesnt federate to community's origin instance alpha
|
// ban doesnt federate to community's origin instance alpha
|
||||||
let alphaPost = (await resolvePost(alpha, gammaPost.post)).post;
|
let alphaPost = (await resolvePost(alpha, gammaPost.post)).post;
|
||||||
|
|
|
@ -415,7 +415,7 @@ test("Enforce site ban for federated user", async () => {
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
expect(banAlpha.success).toBe(true);
|
expect(banAlpha.banned).toBe(true);
|
||||||
|
|
||||||
// alpha ban should be federated to beta
|
// alpha ban should be federated to beta
|
||||||
let alphaUserOnBeta1 = await waitUntil(
|
let alphaUserOnBeta1 = await waitUntil(
|
||||||
|
@ -437,7 +437,7 @@ test("Enforce site ban for federated user", async () => {
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
expect(unBanAlpha.success).toBe(true);
|
expect(unBanAlpha.banned).toBe(false);
|
||||||
|
|
||||||
// Login gets invalidated by ban, need to login again
|
// Login gets invalidated by ban, need to login again
|
||||||
if (!alphaUserPerson) {
|
if (!alphaUserPerson) {
|
||||||
|
@ -479,7 +479,7 @@ test.skip("Enforce community ban for federated user", async () => {
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
expect(banAlpha.success).toBe(true);
|
expect(banAlpha.banned).toBe(true);
|
||||||
|
|
||||||
// ensure that the post by alpha got removed
|
// ensure that the post by alpha got removed
|
||||||
await expect(getPost(alpha, searchBeta1.posts[0].post.id)).rejects.toBe(
|
await expect(getPost(alpha, searchBeta1.posts[0].post.id)).rejects.toBe(
|
||||||
|
@ -499,7 +499,7 @@ test.skip("Enforce community ban for federated user", async () => {
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
expect(unBanAlpha.success).toBe(true);
|
expect(unBanAlpha.banned).toBe(false);
|
||||||
let postRes3 = await createPost(alpha, betaCommunity.community.id);
|
let postRes3 = await createPost(alpha, betaCommunity.community.id);
|
||||||
expect(postRes3.post_view.post).toBeDefined();
|
expect(postRes3.post_view.post).toBeDefined();
|
||||||
expect(postRes3.post_view.community.local).toBe(false);
|
expect(postRes3.post_view.community.local).toBe(false);
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import {
|
import {
|
||||||
BlockInstance,
|
BlockInstance,
|
||||||
|
BlockInstanceResponse,
|
||||||
GetReplies,
|
GetReplies,
|
||||||
GetRepliesResponse,
|
GetRepliesResponse,
|
||||||
GetUnreadCountResponse,
|
GetUnreadCountResponse,
|
||||||
InstanceId,
|
InstanceId,
|
||||||
LemmyHttp,
|
LemmyHttp,
|
||||||
PostView,
|
PostView,
|
||||||
SuccessResponse,
|
|
||||||
} from "lemmy-js-client";
|
} from "lemmy-js-client";
|
||||||
import { CreatePost } from "lemmy-js-client/dist/types/CreatePost";
|
import { CreatePost } from "lemmy-js-client/dist/types/CreatePost";
|
||||||
import { DeletePost } from "lemmy-js-client/dist/types/DeletePost";
|
import { DeletePost } from "lemmy-js-client/dist/types/DeletePost";
|
||||||
|
@ -27,7 +27,9 @@ import { ResolveObjectResponse } from "lemmy-js-client/dist/types/ResolveObjectR
|
||||||
import { Search } from "lemmy-js-client/dist/types/Search";
|
import { Search } from "lemmy-js-client/dist/types/Search";
|
||||||
import { SearchResponse } from "lemmy-js-client/dist/types/SearchResponse";
|
import { SearchResponse } from "lemmy-js-client/dist/types/SearchResponse";
|
||||||
import { Comment } from "lemmy-js-client/dist/types/Comment";
|
import { Comment } from "lemmy-js-client/dist/types/Comment";
|
||||||
|
import { BanPersonResponse } from "lemmy-js-client/dist/types/BanPersonResponse";
|
||||||
import { BanPerson } from "lemmy-js-client/dist/types/BanPerson";
|
import { BanPerson } from "lemmy-js-client/dist/types/BanPerson";
|
||||||
|
import { BanFromCommunityResponse } from "lemmy-js-client/dist/types/BanFromCommunityResponse";
|
||||||
import { BanFromCommunity } from "lemmy-js-client/dist/types/BanFromCommunity";
|
import { BanFromCommunity } from "lemmy-js-client/dist/types/BanFromCommunity";
|
||||||
import { CommunityResponse } from "lemmy-js-client/dist/types/CommunityResponse";
|
import { CommunityResponse } from "lemmy-js-client/dist/types/CommunityResponse";
|
||||||
import { FollowCommunity } from "lemmy-js-client/dist/types/FollowCommunity";
|
import { FollowCommunity } from "lemmy-js-client/dist/types/FollowCommunity";
|
||||||
|
@ -53,6 +55,7 @@ import { Register } from "lemmy-js-client/dist/types/Register";
|
||||||
import { SaveUserSettings } from "lemmy-js-client/dist/types/SaveUserSettings";
|
import { SaveUserSettings } from "lemmy-js-client/dist/types/SaveUserSettings";
|
||||||
import { DeleteAccount } from "lemmy-js-client/dist/types/DeleteAccount";
|
import { DeleteAccount } from "lemmy-js-client/dist/types/DeleteAccount";
|
||||||
import { GetSiteResponse } from "lemmy-js-client/dist/types/GetSiteResponse";
|
import { GetSiteResponse } from "lemmy-js-client/dist/types/GetSiteResponse";
|
||||||
|
import { DeleteAccountResponse } from "lemmy-js-client/dist/types/DeleteAccountResponse";
|
||||||
import { PrivateMessagesResponse } from "lemmy-js-client/dist/types/PrivateMessagesResponse";
|
import { PrivateMessagesResponse } from "lemmy-js-client/dist/types/PrivateMessagesResponse";
|
||||||
import { GetPrivateMessages } from "lemmy-js-client/dist/types/GetPrivateMessages";
|
import { GetPrivateMessages } from "lemmy-js-client/dist/types/GetPrivateMessages";
|
||||||
import { PostReportResponse } from "lemmy-js-client/dist/types/PostReportResponse";
|
import { PostReportResponse } from "lemmy-js-client/dist/types/PostReportResponse";
|
||||||
|
@ -382,7 +385,7 @@ export async function banPersonFromSite(
|
||||||
person_id: number,
|
person_id: number,
|
||||||
ban: boolean,
|
ban: boolean,
|
||||||
remove_data: boolean,
|
remove_data: boolean,
|
||||||
): Promise<SuccessResponse> {
|
): Promise<BanPersonResponse> {
|
||||||
// Make sure lemmy-beta/c/main is cached on lemmy_alpha
|
// Make sure lemmy-beta/c/main is cached on lemmy_alpha
|
||||||
let form: BanPerson = {
|
let form: BanPerson = {
|
||||||
person_id,
|
person_id,
|
||||||
|
@ -398,7 +401,7 @@ export async function banPersonFromCommunity(
|
||||||
community_id: number,
|
community_id: number,
|
||||||
remove_data: boolean,
|
remove_data: boolean,
|
||||||
ban: boolean,
|
ban: boolean,
|
||||||
): Promise<SuccessResponse> {
|
): Promise<BanFromCommunityResponse> {
|
||||||
let form: BanFromCommunity = {
|
let form: BanFromCommunity = {
|
||||||
person_id,
|
person_id,
|
||||||
community_id,
|
community_id,
|
||||||
|
@ -686,7 +689,9 @@ export async function getPersonDetails(
|
||||||
return api.getPersonDetails(form);
|
return api.getPersonDetails(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function deleteUser(api: LemmyHttp): Promise<SuccessResponse> {
|
export async function deleteUser(
|
||||||
|
api: LemmyHttp,
|
||||||
|
): Promise<DeleteAccountResponse> {
|
||||||
let form: DeleteAccount = {
|
let form: DeleteAccount = {
|
||||||
delete_content: true,
|
delete_content: true,
|
||||||
password,
|
password,
|
||||||
|
@ -783,7 +788,7 @@ export function blockInstance(
|
||||||
api: LemmyHttp,
|
api: LemmyHttp,
|
||||||
instance_id: InstanceId,
|
instance_id: InstanceId,
|
||||||
block: boolean,
|
block: boolean,
|
||||||
): Promise<SuccessResponse> {
|
): Promise<BlockInstanceResponse> {
|
||||||
let form: BlockInstance = {
|
let form: BlockInstance = {
|
||||||
instance_id,
|
instance_id,
|
||||||
block,
|
block,
|
||||||
|
|
|
@ -2275,10 +2275,10 @@ kleur@^3.0.3:
|
||||||
resolved "https://registry.yarnpkg.com/kleur/-/kleur-3.0.3.tgz#a79c9ecc86ee1ce3fa6206d1216c501f147fc07e"
|
resolved "https://registry.yarnpkg.com/kleur/-/kleur-3.0.3.tgz#a79c9ecc86ee1ce3fa6206d1216c501f147fc07e"
|
||||||
integrity sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==
|
integrity sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==
|
||||||
|
|
||||||
lemmy-js-client@0.19.0-alpha.12:
|
lemmy-js-client@0.19.0-rc.12:
|
||||||
version "0.19.0-alpha.12"
|
version "0.19.0-rc.12"
|
||||||
resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.19.0-alpha.12.tgz#0f98743483b3859414e7accce905105a7fc6df78"
|
resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.19.0-rc.12.tgz#e3bd4e21b1966d583ab790ef70ece8394b012b48"
|
||||||
integrity sha512-4SicZRNxZpLAxrjP54eRJmFHJ2AjNbWJv3PuTp2g6tkLQPUukDr8RsEOoDXDoIoqadgR3B5z1ujnuTtQrVrFKg==
|
integrity sha512-1iu2fW9vlb3TrI+QR/ODP3+5pWZB0rUqL1wH09IzomDXohCqoQvfmXpwArmgF4Eq8GZgjkcfeMDC2gMrfw/i7Q==
|
||||||
dependencies:
|
dependencies:
|
||||||
cross-fetch "^3.1.5"
|
cross-fetch "^3.1.5"
|
||||||
form-data "^4.0.0"
|
form-data "^4.0.0"
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
use activitypub_federation::config::Data;
|
use activitypub_federation::config::Data;
|
||||||
use actix_web::web::Json;
|
use actix_web::web::Json;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
community::AddModToCommunity,
|
community::{AddModToCommunity, AddModToCommunityResponse},
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
send_activity::{ActivityChannel, SendActivityData},
|
send_activity::{ActivityChannel, SendActivityData},
|
||||||
utils::check_community_mod_action,
|
utils::check_community_mod_action,
|
||||||
SuccessResponse,
|
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
|
@ -15,6 +14,7 @@ use lemmy_db_schema::{
|
||||||
traits::{Crud, Joinable},
|
traits::{Crud, Joinable},
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::LocalUserView;
|
use lemmy_db_views::structs::LocalUserView;
|
||||||
|
use lemmy_db_views_actor::structs::CommunityModeratorView;
|
||||||
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
||||||
|
|
||||||
#[tracing::instrument(skip(context))]
|
#[tracing::instrument(skip(context))]
|
||||||
|
@ -22,7 +22,7 @@ pub async fn add_mod_to_community(
|
||||||
data: Json<AddModToCommunity>,
|
data: Json<AddModToCommunity>,
|
||||||
context: Data<LemmyContext>,
|
context: Data<LemmyContext>,
|
||||||
local_user_view: LocalUserView,
|
local_user_view: LocalUserView,
|
||||||
) -> Result<Json<SuccessResponse>, LemmyError> {
|
) -> Result<Json<AddModToCommunityResponse>, LemmyError> {
|
||||||
let community_id = data.community_id;
|
let community_id = data.community_id;
|
||||||
|
|
||||||
// Verify that only mods or admins can add mod
|
// Verify that only mods or admins can add mod
|
||||||
|
@ -63,6 +63,11 @@ pub async fn add_mod_to_community(
|
||||||
|
|
||||||
ModAddCommunity::create(&mut context.pool(), &form).await?;
|
ModAddCommunity::create(&mut context.pool(), &form).await?;
|
||||||
|
|
||||||
|
// Note: in case a remote mod is added, this returns the old moderators list, it will only get
|
||||||
|
// updated once we receive an activity from the community (like `Announce/Add/Moderator`)
|
||||||
|
let community_id = data.community_id;
|
||||||
|
let moderators = CommunityModeratorView::for_community(&mut context.pool(), community_id).await?;
|
||||||
|
|
||||||
ActivityChannel::submit_activity(
|
ActivityChannel::submit_activity(
|
||||||
SendActivityData::AddModToCommunity(
|
SendActivityData::AddModToCommunity(
|
||||||
local_user_view.person,
|
local_user_view.person,
|
||||||
|
@ -74,5 +79,5 @@ pub async fn add_mod_to_community(
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(Json(SuccessResponse::default()))
|
Ok(Json(AddModToCommunityResponse { moderators }))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
use activitypub_federation::config::Data;
|
use activitypub_federation::config::Data;
|
||||||
use actix_web::web::Json;
|
use actix_web::web::Json;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
community::BanFromCommunity,
|
community::{BanFromCommunity, BanFromCommunityResponse},
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
send_activity::{ActivityChannel, SendActivityData},
|
send_activity::{ActivityChannel, SendActivityData},
|
||||||
utils::{check_community_mod_action, check_expire_time, remove_user_data_in_community},
|
utils::{check_community_mod_action, check_expire_time, remove_user_data_in_community},
|
||||||
SuccessResponse,
|
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
|
@ -31,7 +30,7 @@ pub async fn ban_from_community(
|
||||||
data: Json<BanFromCommunity>,
|
data: Json<BanFromCommunity>,
|
||||||
context: Data<LemmyContext>,
|
context: Data<LemmyContext>,
|
||||||
local_user_view: LocalUserView,
|
local_user_view: LocalUserView,
|
||||||
) -> Result<Json<SuccessResponse>, LemmyError> {
|
) -> Result<Json<BanFromCommunityResponse>, LemmyError> {
|
||||||
let banned_person_id = data.person_id;
|
let banned_person_id = data.person_id;
|
||||||
let remove_data = data.remove_data.unwrap_or(false);
|
let remove_data = data.remove_data.unwrap_or(false);
|
||||||
let expires = check_expire_time(data.expires)?;
|
let expires = check_expire_time(data.expires)?;
|
||||||
|
@ -103,5 +102,8 @@ pub async fn ban_from_community(
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(Json(SuccessResponse::default()))
|
Ok(Json(BanFromCommunityResponse {
|
||||||
|
person_view,
|
||||||
|
banned: data.ban,
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
use activitypub_federation::config::Data;
|
use activitypub_federation::config::Data;
|
||||||
use actix_web::web::Json;
|
use actix_web::web::Json;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
community::BlockCommunity,
|
community::{BlockCommunity, BlockCommunityResponse},
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
send_activity::{ActivityChannel, SendActivityData},
|
send_activity::{ActivityChannel, SendActivityData},
|
||||||
SuccessResponse,
|
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
|
@ -22,7 +21,7 @@ pub async fn block_community(
|
||||||
data: Json<BlockCommunity>,
|
data: Json<BlockCommunity>,
|
||||||
context: Data<LemmyContext>,
|
context: Data<LemmyContext>,
|
||||||
local_user_view: LocalUserView,
|
local_user_view: LocalUserView,
|
||||||
) -> Result<Json<SuccessResponse>, LemmyError> {
|
) -> Result<Json<BlockCommunityResponse>, LemmyError> {
|
||||||
let community_id = data.community_id;
|
let community_id = data.community_id;
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
let community_block_form = CommunityBlockForm {
|
let community_block_form = CommunityBlockForm {
|
||||||
|
@ -64,5 +63,8 @@ pub async fn block_community(
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(Json(SuccessResponse::default()))
|
Ok(Json(BlockCommunityResponse {
|
||||||
|
blocked: data.block,
|
||||||
|
community_view,
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
use actix_web::web::{Data, Json};
|
use actix_web::web::{Data, Json};
|
||||||
use lemmy_api_common::{context::LemmyContext, person::AddAdmin, utils::is_admin, SuccessResponse};
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
|
person::{AddAdmin, AddAdminResponse},
|
||||||
|
utils::is_admin,
|
||||||
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
local_user::{LocalUser, LocalUserUpdateForm},
|
local_user::{LocalUser, LocalUserUpdateForm},
|
||||||
|
@ -8,6 +12,7 @@ use lemmy_db_schema::{
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::LocalUserView;
|
use lemmy_db_views::structs::LocalUserView;
|
||||||
|
use lemmy_db_views_actor::structs::PersonView;
|
||||||
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
||||||
|
|
||||||
#[tracing::instrument(skip(context))]
|
#[tracing::instrument(skip(context))]
|
||||||
|
@ -15,7 +20,7 @@ pub async fn add_admin(
|
||||||
data: Json<AddAdmin>,
|
data: Json<AddAdmin>,
|
||||||
context: Data<LemmyContext>,
|
context: Data<LemmyContext>,
|
||||||
local_user_view: LocalUserView,
|
local_user_view: LocalUserView,
|
||||||
) -> Result<Json<SuccessResponse>, LemmyError> {
|
) -> Result<Json<AddAdminResponse>, LemmyError> {
|
||||||
// Make sure user is an admin
|
// Make sure user is an admin
|
||||||
is_admin(&local_user_view)?;
|
is_admin(&local_user_view)?;
|
||||||
|
|
||||||
|
@ -44,5 +49,7 @@ pub async fn add_admin(
|
||||||
|
|
||||||
ModAdd::create(&mut context.pool(), &form).await?;
|
ModAdd::create(&mut context.pool(), &form).await?;
|
||||||
|
|
||||||
Ok(Json(SuccessResponse::default()))
|
let admins = PersonView::admins(&mut context.pool()).await?;
|
||||||
|
|
||||||
|
Ok(Json(AddAdminResponse { admins }))
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,10 +2,9 @@ use activitypub_federation::config::Data;
|
||||||
use actix_web::web::Json;
|
use actix_web::web::Json;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
person::BanPerson,
|
person::{BanPerson, BanPersonResponse},
|
||||||
send_activity::{ActivityChannel, SendActivityData},
|
send_activity::{ActivityChannel, SendActivityData},
|
||||||
utils::{check_expire_time, is_admin, remove_user_data},
|
utils::{check_expire_time, is_admin, remove_user_data},
|
||||||
SuccessResponse,
|
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
|
@ -27,7 +26,7 @@ pub async fn ban_from_site(
|
||||||
data: Json<BanPerson>,
|
data: Json<BanPerson>,
|
||||||
context: Data<LemmyContext>,
|
context: Data<LemmyContext>,
|
||||||
local_user_view: LocalUserView,
|
local_user_view: LocalUserView,
|
||||||
) -> Result<Json<SuccessResponse>, LemmyError> {
|
) -> Result<Json<BanPersonResponse>, LemmyError> {
|
||||||
// Make sure user is an admin
|
// Make sure user is an admin
|
||||||
is_admin(&local_user_view)?;
|
is_admin(&local_user_view)?;
|
||||||
|
|
||||||
|
@ -82,5 +81,8 @@ pub async fn ban_from_site(
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(Json(SuccessResponse::default()))
|
Ok(Json(BanPersonResponse {
|
||||||
|
person_view,
|
||||||
|
banned: data.ban,
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
use actix_web::web::{Data, Json};
|
use actix_web::web::{Data, Json};
|
||||||
use lemmy_api_common::{context::LemmyContext, person::BlockPerson, SuccessResponse};
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
|
person::{BlockPerson, BlockPersonResponse},
|
||||||
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::person_block::{PersonBlock, PersonBlockForm},
|
source::person_block::{PersonBlock, PersonBlockForm},
|
||||||
traits::Blockable,
|
traits::Blockable,
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::LocalUserView;
|
use lemmy_db_views::structs::LocalUserView;
|
||||||
|
use lemmy_db_views_actor::structs::PersonView;
|
||||||
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
||||||
|
|
||||||
#[tracing::instrument(skip(context))]
|
#[tracing::instrument(skip(context))]
|
||||||
|
@ -12,7 +16,7 @@ pub async fn block_person(
|
||||||
data: Json<BlockPerson>,
|
data: Json<BlockPerson>,
|
||||||
context: Data<LemmyContext>,
|
context: Data<LemmyContext>,
|
||||||
local_user_view: LocalUserView,
|
local_user_view: LocalUserView,
|
||||||
) -> Result<Json<SuccessResponse>, LemmyError> {
|
) -> Result<Json<BlockPersonResponse>, LemmyError> {
|
||||||
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;
|
||||||
|
|
||||||
|
@ -41,5 +45,9 @@ pub async fn block_person(
|
||||||
.with_lemmy_type(LemmyErrorType::PersonBlockAlreadyExists)?;
|
.with_lemmy_type(LemmyErrorType::PersonBlockAlreadyExists)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Json(SuccessResponse::default()))
|
let person_view = PersonView::read(&mut context.pool(), target_id).await?;
|
||||||
|
Ok(Json(BlockPersonResponse {
|
||||||
|
person_view,
|
||||||
|
blocked: data.block,
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
use actix_web::web::{Data, Json};
|
use actix_web::web::{Data, Json};
|
||||||
use lemmy_api_common::{context::LemmyContext, person::MarkCommentReplyAsRead, SuccessResponse};
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
|
person::{CommentReplyResponse, MarkCommentReplyAsRead},
|
||||||
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::comment_reply::{CommentReply, CommentReplyUpdateForm},
|
source::comment_reply::{CommentReply, CommentReplyUpdateForm},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::LocalUserView;
|
use lemmy_db_views::structs::LocalUserView;
|
||||||
|
use lemmy_db_views_actor::structs::CommentReplyView;
|
||||||
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
||||||
|
|
||||||
#[tracing::instrument(skip(context))]
|
#[tracing::instrument(skip(context))]
|
||||||
|
@ -12,7 +16,7 @@ pub async fn mark_reply_as_read(
|
||||||
data: Json<MarkCommentReplyAsRead>,
|
data: Json<MarkCommentReplyAsRead>,
|
||||||
context: Data<LemmyContext>,
|
context: Data<LemmyContext>,
|
||||||
local_user_view: LocalUserView,
|
local_user_view: LocalUserView,
|
||||||
) -> Result<Json<SuccessResponse>, LemmyError> {
|
) -> Result<Json<CommentReplyResponse>, LemmyError> {
|
||||||
let comment_reply_id = data.comment_reply_id;
|
let comment_reply_id = data.comment_reply_id;
|
||||||
let read_comment_reply = CommentReply::read(&mut context.pool(), comment_reply_id).await?;
|
let read_comment_reply = CommentReply::read(&mut context.pool(), comment_reply_id).await?;
|
||||||
|
|
||||||
|
@ -31,5 +35,10 @@ pub async fn mark_reply_as_read(
|
||||||
.await
|
.await
|
||||||
.with_lemmy_type(LemmyErrorType::CouldntUpdateComment)?;
|
.with_lemmy_type(LemmyErrorType::CouldntUpdateComment)?;
|
||||||
|
|
||||||
Ok(Json(SuccessResponse::default()))
|
let comment_reply_id = read_comment_reply.id;
|
||||||
|
let person_id = local_user_view.person.id;
|
||||||
|
let comment_reply_view =
|
||||||
|
CommentReplyView::read(&mut context.pool(), comment_reply_id, Some(person_id)).await?;
|
||||||
|
|
||||||
|
Ok(Json(CommentReplyResponse { comment_reply_view }))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
use activitypub_federation::config::Data;
|
use activitypub_federation::config::Data;
|
||||||
use actix_web::web::Json;
|
use actix_web::web::Json;
|
||||||
use lemmy_api_common::{context::LemmyContext, site::BlockInstance, SuccessResponse};
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
|
site::{BlockInstance, BlockInstanceResponse},
|
||||||
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::instance_block::{InstanceBlock, InstanceBlockForm},
|
source::instance_block::{InstanceBlock, InstanceBlockForm},
|
||||||
traits::Blockable,
|
traits::Blockable,
|
||||||
|
@ -13,7 +16,7 @@ pub async fn block_instance(
|
||||||
data: Json<BlockInstance>,
|
data: Json<BlockInstance>,
|
||||||
local_user_view: LocalUserView,
|
local_user_view: LocalUserView,
|
||||||
context: Data<LemmyContext>,
|
context: Data<LemmyContext>,
|
||||||
) -> Result<Json<SuccessResponse>, LemmyError> {
|
) -> Result<Json<BlockInstanceResponse>, LemmyError> {
|
||||||
let instance_id = data.instance_id;
|
let instance_id = data.instance_id;
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
let instance_block_form = InstanceBlockForm {
|
let instance_block_form = InstanceBlockForm {
|
||||||
|
@ -31,5 +34,7 @@ pub async fn block_instance(
|
||||||
.with_lemmy_type(LemmyErrorType::InstanceBlockAlreadyExists)?;
|
.with_lemmy_type(LemmyErrorType::InstanceBlockAlreadyExists)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Json(SuccessResponse::default()))
|
Ok(Json(BlockInstanceResponse {
|
||||||
|
blocked: data.block,
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ use lemmy_db_schema::{
|
||||||
ListingType,
|
ListingType,
|
||||||
SortType,
|
SortType,
|
||||||
};
|
};
|
||||||
use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView};
|
use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView, PersonView};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_with::skip_serializing_none;
|
use serde_with::skip_serializing_none;
|
||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
|
@ -100,6 +100,15 @@ pub struct BanFromCommunity {
|
||||||
pub expires: Option<i64>,
|
pub expires: Option<i64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
|
#[cfg_attr(feature = "full", derive(TS))]
|
||||||
|
#[cfg_attr(feature = "full", ts(export))]
|
||||||
|
/// The response for banning a user from a community.
|
||||||
|
pub struct BanFromCommunityResponse {
|
||||||
|
pub person_view: PersonView,
|
||||||
|
pub banned: bool,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
||||||
#[cfg_attr(feature = "full", derive(TS))]
|
#[cfg_attr(feature = "full", derive(TS))]
|
||||||
#[cfg_attr(feature = "full", ts(export))]
|
#[cfg_attr(feature = "full", ts(export))]
|
||||||
|
@ -110,6 +119,14 @@ pub struct AddModToCommunity {
|
||||||
pub added: bool,
|
pub added: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
|
#[cfg_attr(feature = "full", derive(TS))]
|
||||||
|
#[cfg_attr(feature = "full", ts(export))]
|
||||||
|
/// The response of adding a moderator to a community.
|
||||||
|
pub struct AddModToCommunityResponse {
|
||||||
|
pub moderators: Vec<CommunityModeratorView>,
|
||||||
|
}
|
||||||
|
|
||||||
#[skip_serializing_none]
|
#[skip_serializing_none]
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
||||||
#[cfg_attr(feature = "full", derive(TS))]
|
#[cfg_attr(feature = "full", derive(TS))]
|
||||||
|
@ -183,6 +200,16 @@ pub struct BlockCommunity {
|
||||||
pub block: bool,
|
pub block: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[skip_serializing_none]
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
|
#[cfg_attr(feature = "full", derive(TS))]
|
||||||
|
#[cfg_attr(feature = "full", ts(export))]
|
||||||
|
/// The block community response.
|
||||||
|
pub struct BlockCommunityResponse {
|
||||||
|
pub community_view: CommunityView,
|
||||||
|
pub blocked: bool,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
||||||
#[cfg_attr(feature = "full", derive(TS))]
|
#[cfg_attr(feature = "full", derive(TS))]
|
||||||
#[cfg_attr(feature = "full", ts(export))]
|
#[cfg_attr(feature = "full", ts(export))]
|
||||||
|
|
|
@ -193,6 +193,14 @@ pub struct AddAdmin {
|
||||||
pub added: bool,
|
pub added: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
|
#[cfg_attr(feature = "full", derive(TS))]
|
||||||
|
#[cfg_attr(feature = "full", ts(export))]
|
||||||
|
/// The response of current admins.
|
||||||
|
pub struct AddAdminResponse {
|
||||||
|
pub admins: Vec<PersonView>,
|
||||||
|
}
|
||||||
|
|
||||||
#[skip_serializing_none]
|
#[skip_serializing_none]
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
||||||
#[cfg_attr(feature = "full", derive(TS))]
|
#[cfg_attr(feature = "full", derive(TS))]
|
||||||
|
@ -216,6 +224,15 @@ pub struct BannedPersonsResponse {
|
||||||
pub banned: Vec<PersonView>,
|
pub banned: Vec<PersonView>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
|
#[cfg_attr(feature = "full", derive(TS))]
|
||||||
|
#[cfg_attr(feature = "full", ts(export))]
|
||||||
|
/// A response for a banned person.
|
||||||
|
pub struct BanPersonResponse {
|
||||||
|
pub person_view: PersonView,
|
||||||
|
pub banned: bool,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
||||||
#[cfg_attr(feature = "full", derive(TS))]
|
#[cfg_attr(feature = "full", derive(TS))]
|
||||||
#[cfg_attr(feature = "full", ts(export))]
|
#[cfg_attr(feature = "full", ts(export))]
|
||||||
|
@ -225,6 +242,15 @@ pub struct BlockPerson {
|
||||||
pub block: bool,
|
pub block: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
|
#[cfg_attr(feature = "full", derive(TS))]
|
||||||
|
#[cfg_attr(feature = "full", ts(export))]
|
||||||
|
/// The response for a person block.
|
||||||
|
pub struct BlockPersonResponse {
|
||||||
|
pub person_view: PersonView,
|
||||||
|
pub blocked: bool,
|
||||||
|
}
|
||||||
|
|
||||||
#[skip_serializing_none]
|
#[skip_serializing_none]
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
||||||
#[cfg_attr(feature = "full", derive(TS))]
|
#[cfg_attr(feature = "full", derive(TS))]
|
||||||
|
@ -292,6 +318,14 @@ pub struct MarkCommentReplyAsRead {
|
||||||
pub read: bool,
|
pub read: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
|
#[cfg_attr(feature = "full", derive(TS))]
|
||||||
|
#[cfg_attr(feature = "full", ts(export))]
|
||||||
|
/// The response for a comment reply action.
|
||||||
|
pub struct CommentReplyResponse {
|
||||||
|
pub comment_reply_view: CommentReplyView,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
||||||
#[cfg_attr(feature = "full", derive(TS))]
|
#[cfg_attr(feature = "full", derive(TS))]
|
||||||
#[cfg_attr(feature = "full", ts(export))]
|
#[cfg_attr(feature = "full", ts(export))]
|
||||||
|
|
|
@ -416,3 +416,11 @@ pub struct BlockInstance {
|
||||||
pub instance_id: InstanceId,
|
pub instance_id: InstanceId,
|
||||||
pub block: bool,
|
pub block: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[skip_serializing_none]
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
|
#[cfg_attr(feature = "full", derive(TS))]
|
||||||
|
#[cfg_attr(feature = "full", ts(export))]
|
||||||
|
pub struct BlockInstanceResponse {
|
||||||
|
pub blocked: bool,
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue