Admin purge (#35)

* Adding admin purge to API.

* v0.13.4-rc.2

* v0.17.0-rc.10

* v0.17.0-rc.12

* Fixing a few purge issues.

* v0.17.0-rc.33
This commit is contained in:
Dessalines 2022-06-23 14:50:20 -04:00 committed by GitHub
parent adf324df19
commit e7f5a5d05f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 244 additions and 1 deletions

View file

@ -1,7 +1,7 @@
{
"name": "lemmy-js-client",
"description": "A javascript / typescript client for Lemmy",
"version": "0.17.0-rc.32",
"version": "0.17.0-rc.33",
"author": "Dessalines <tyhou13@gmx.com>",
"license": "AGPL-3.0",
"main": "./dist/index.js",

View file

@ -115,6 +115,11 @@ import {
LeaveAdmin,
ListRegistrationApplications,
ListRegistrationApplicationsResponse,
PurgeComment,
PurgeCommunity,
PurgeItemResponse,
PurgePerson,
PurgePost,
RegistrationApplicationResponse,
ResolveObject,
ResolveObjectResponse,
@ -1025,6 +1030,62 @@ export class LemmyHttp {
);
}
/**
* Purge / Delete a person from the database.
*
* `HTTP.POST /admin/purge/person`
*/
async purgePerson(form: PurgePerson) {
return this.wrapper(
HttpType.Post,
"/admin/purge/person",
form,
PurgeItemResponse
);
}
/**
* Purge / Delete a community from the database.
*
* `HTTP.POST /admin/purge/community`
*/
async purgeCommunity(form: PurgeCommunity) {
return this.wrapper(
HttpType.Post,
"/admin/purge/community",
form,
PurgeItemResponse
);
}
/**
* Purge / Delete a post from the database.
*
* `HTTP.POST /admin/purge/post`
*/
async purgePost(form: PurgePost) {
return this.wrapper(
HttpType.Post,
"/admin/purge/post",
form,
PurgeItemResponse
);
}
/**
* Purge / Delete a comment from the database.
*
* `HTTP.POST /admin/purge/comment`
*/
async purgeComment(form: PurgeComment) {
return this.wrapper(
HttpType.Post,
"/admin/purge/comment",
form,
PurgeItemResponse
);
}
private buildFullUrl(endpoint: string): string {
return `${this.apiUrl}${endpoint}`;
}

View file

@ -4,6 +4,10 @@ import "reflect-metadata";
import { toOption, toUndefined } from "../../utils";
import { ListingType, SearchType, SortType } from "../others";
import {
AdminPurgeCommentView,
AdminPurgeCommunityView,
AdminPurgePersonView,
AdminPurgePostView,
CommentView,
CommunityBlockView,
CommunityFollowerView,
@ -140,6 +144,14 @@ export class GetModlogResponse {
transferred_to_community: ModTransferCommunityView[];
@Type(() => ModAddView)
added: ModAddView[];
@Type(() => AdminPurgePersonView)
admin_purged_persons: AdminPurgePersonView[];
@Type(() => AdminPurgeCommunityView)
admin_purged_communities: AdminPurgeCommunityView[];
@Type(() => AdminPurgePostView)
admin_purged_posts: AdminPurgePostView[];
@Type(() => AdminPurgeCommentView)
admin_purged_comments: AdminPurgeCommentView[];
}
export class CreateSite {
@ -398,6 +410,62 @@ export class ResolveObjectResponse {
person: Option<PersonViewSafe>;
}
export class PurgePerson {
person_id: number;
@Transform(({ value }) => toOption(value), { toClassOnly: true })
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
@Expose()
reason: Option<string>;
auth: string;
constructor(init: PurgePerson) {
Object.assign(this, init);
}
}
export class PurgeCommunity {
community_id: number;
@Transform(({ value }) => toOption(value), { toClassOnly: true })
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
@Expose()
reason: Option<string>;
auth: string;
constructor(init: PurgeCommunity) {
Object.assign(this, init);
}
}
export class PurgePost {
post_id: number;
@Transform(({ value }) => toOption(value), { toClassOnly: true })
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
@Expose()
reason: Option<string>;
auth: string;
constructor(init: PurgePost) {
Object.assign(this, init);
}
}
export class PurgeComment {
comment_id: number;
@Transform(({ value }) => toOption(value), { toClassOnly: true })
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
@Expose()
reason: Option<string>;
auth: string;
constructor(init: PurgeComment) {
Object.assign(this, init);
}
}
export class PurgeItemResponse {
success: boolean;
}
export class ListRegistrationApplications {
/**
* Only shows the unread applications (IE those without an admin actor)

View file

@ -73,6 +73,10 @@ export enum UserOperation {
GetSiteMetadata,
BlockCommunity,
BlockPerson,
PurgePerson,
PurgeCommunity,
PurgePost,
PurgeComment,
CreateCommentReport,
ResolveCommentReport,
ListCommentReports,

View file

@ -350,6 +350,48 @@ export class ModAdd {
when_: string;
}
export class AdminPurgePerson {
id: number;
admin_person_id: number;
@Transform(({ value }) => toOption(value), { toClassOnly: true })
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
@Expose()
reason: Option<string>;
when_: string;
}
export class AdminPurgeCommunity {
id: number;
admin_person_id: number;
@Transform(({ value }) => toOption(value), { toClassOnly: true })
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
@Expose()
reason: Option<string>;
when_: string;
}
export class AdminPurgePost {
id: number;
admin_person_id: number;
community_id: number;
@Transform(({ value }) => toOption(value), { toClassOnly: true })
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
@Expose()
reason: Option<string>;
when_: string;
}
export class AdminPurgeComment {
id: number;
admin_person_id: number;
post_id: number;
@Transform(({ value }) => toOption(value), { toClassOnly: true })
@Transform(({ value }) => toUndefined(value), { toPlainOnly: true })
@Expose()
reason: Option<string>;
when_: string;
}
export class CommunitySafe {
id: number;
name: string;

View file

@ -11,6 +11,10 @@ import {
} from "./aggregates";
import { SubscribedType } from "./others";
import {
AdminPurgeComment,
AdminPurgeCommunity,
AdminPurgePerson,
AdminPurgePost,
Comment,
CommentReport,
CommunitySafe,
@ -289,6 +293,38 @@ export class ModStickyPostView {
community: CommunitySafe;
}
export class AdminPurgeCommunityView {
@Type(() => AdminPurgeCommunity)
admin_purge_community: AdminPurgeCommunity;
@Type(() => PersonSafe)
admin: PersonSafe;
}
export class AdminPurgePersonView {
@Type(() => AdminPurgePerson)
admin_purge_person: AdminPurgePerson;
@Type(() => PersonSafe)
admin: PersonSafe;
}
export class AdminPurgePostView {
@Type(() => AdminPurgePost)
admin_purge_post: AdminPurgePost;
@Type(() => PersonSafe)
admin: PersonSafe;
@Type(() => CommunitySafe)
community: CommunitySafe;
}
export class AdminPurgeCommentView {
@Type(() => AdminPurgeComment)
admin_purge_comment: AdminPurgeComment;
@Type(() => PersonSafe)
admin: PersonSafe;
@Type(() => Post)
post: Post;
}
export class CommunityFollowerView {
@Type(() => CommunitySafe)
community: CommunitySafe;

View file

@ -77,6 +77,10 @@ import {
GetUnreadRegistrationApplicationCount,
LeaveAdmin,
ListRegistrationApplications,
PurgeComment,
PurgeCommunity,
PurgePerson,
PurgePost,
ResolveObject,
Search,
} from "./interfaces/api/site";
@ -627,6 +631,34 @@ export class LemmyWebsocket {
blockCommunity(form: BlockCommunity) {
return wrapper(UserOperation.BlockCommunity, form);
}
/**
* Purge / Delete a person from the database.
*/
purgePerson(form: PurgePerson) {
return wrapper(UserOperation.PurgePerson, form);
}
/**
* Purge / Delete a community from the database.
*/
purgeCommunity(form: PurgeCommunity) {
return wrapper(UserOperation.PurgeCommunity, form);
}
/**
* Purge / Delete a post from the database.
*/
purgePost(form: PurgePost) {
return wrapper(UserOperation.PurgePost, form);
}
/**
* Purge / Delete a comment from the database.
*/
purgeComment(form: PurgeComment) {
return wrapper(UserOperation.PurgeComment, form);
}
}
function wrapper<MessageType>(op: UserOperation, data: MessageType) {