mirror of
https://github.com/wassname/talk.git
synced 2026-09-13 13:10:43 +08:00
[CORL-155] User Suspending and Banning (#2247)
* feat: suspending, banning, now propogation * feat: adapting to `now` * feat: support auth for suspension/banned * feat: added trace-id to requests * feat: new mutation api with hooks support * feat: added user status filtering, current field * feat: Implement filter by status, adapt to new USER_STATUS type, add lookup helper <3 * fix: typo * fix: tests * chore: rename banned status to ban status * test: feature test + lots of test helper improvements e.g. types * fix: add translation to ban user modal * fix: translation * fix: test
This commit is contained in:
@@ -7,6 +7,7 @@ import { VError } from "verror";
|
||||
import { ERROR_CODES, ERROR_TYPES } from "talk-common/errors";
|
||||
import { translate } from "talk-server/services/i18n";
|
||||
|
||||
import { GQLUSER_AUTH_CONDITIONS } from "talk-server/graph/tenant/schema/__generated__/types";
|
||||
import { ERROR_TRANSLATIONS } from "./translations";
|
||||
|
||||
/**
|
||||
@@ -345,10 +346,19 @@ export class TokenInvalidError extends TalkError {
|
||||
}
|
||||
|
||||
export class UserForbiddenError extends TalkError {
|
||||
constructor(reason: string, resource: string, userID: string | null) {
|
||||
constructor(
|
||||
reason: string,
|
||||
resource: string,
|
||||
operation: string,
|
||||
userID?: string,
|
||||
permit?: GQLUSER_AUTH_CONDITIONS[],
|
||||
conditions?: GQLUSER_AUTH_CONDITIONS[]
|
||||
) {
|
||||
super({
|
||||
code: ERROR_CODES.USER_NOT_ENTITLED,
|
||||
context: { pvt: { reason, userID, resource } },
|
||||
context: {
|
||||
pvt: { reason, userID, resource, operation, conditions, permit },
|
||||
},
|
||||
status: 403,
|
||||
});
|
||||
}
|
||||
@@ -451,3 +461,47 @@ export class SpamCommentError extends TalkError {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export class UserAlreadySuspendedError extends TalkError {
|
||||
constructor(until: Date) {
|
||||
super({
|
||||
code: ERROR_CODES.USER_ALREADY_SUSPENDED,
|
||||
context: {
|
||||
pub: {
|
||||
until: until.toISOString(),
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export class UserAlreadyBannedError extends TalkError {
|
||||
constructor() {
|
||||
super({
|
||||
code: ERROR_CODES.USER_ALREADY_BANNED,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export class UserBanned extends TalkError {
|
||||
constructor(userID: string, resource?: string, operation?: string) {
|
||||
super({
|
||||
code: ERROR_CODES.USER_BANNED,
|
||||
context: { pvt: { resource, operation, userID } },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export class UserSuspended extends TalkError {
|
||||
constructor(
|
||||
userID: string,
|
||||
until: Date,
|
||||
resource?: string,
|
||||
operation?: string
|
||||
) {
|
||||
super({
|
||||
code: ERROR_CODES.USER_SUSPENDED,
|
||||
context: { pvt: { resource, operation, userID }, pub: { until } },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,10 @@ export const ERROR_TRANSLATIONS: Record<ERROR_CODES, string> = {
|
||||
USERNAME_TOO_SHORT: "error-usernameTooShort",
|
||||
AUTHENTICATION_ERROR: "error-authenticationError",
|
||||
INVALID_CREDENTIALS: "error-invalidCredentials",
|
||||
TOXIC_COMMENT: "error-toxicCommentError",
|
||||
SPAM_COMMENT: "error-spamCommentError",
|
||||
TOXIC_COMMENT: "error-toxicComment",
|
||||
SPAM_COMMENT: "error-spamComment",
|
||||
USER_ALREADY_SUSPENDED: "error-userAlreadySuspended",
|
||||
USER_ALREADY_BANNED: "error-userAlreadyBanned",
|
||||
USER_BANNED: "error-userBanned",
|
||||
USER_SUSPENDED: "error-userSuspended",
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user