Improve validation on api/users endpoints (#5752)

This commit is contained in:
Tom Moor
2023-08-31 18:06:18 -04:00
committed by GitHub
parent dec03b9d84
commit 7abb4f9ad6
15 changed files with 395 additions and 309 deletions

View File

@@ -31,6 +31,7 @@ import {
UserPreferences,
NotificationEventType,
NotificationEventDefaults,
UserRole,
} from "@shared/types";
import { stringToColor } from "@shared/utils/color";
import env from "@server/env";
@@ -65,11 +66,6 @@ export enum UserFlag {
MobileWeb = "mobileWeb",
}
export enum UserRole {
Member = "member",
Viewer = "viewer",
}
@Scopes(() => ({
withAuthentications: {
include: [
@@ -532,7 +528,7 @@ class User extends ParanoidModel {
});
if (res.count >= 1) {
if (to === "member") {
if (to === UserRole.Member) {
await this.update(
{
isAdmin: false,
@@ -540,7 +536,7 @@ class User extends ParanoidModel {
},
options
);
} else if (to === "viewer") {
} else if (to === UserRole.Viewer) {
await this.update(
{
isAdmin: false,