From bd45d503e5d007e730f4e81dccd7e7864c9a85cc Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 6 Aug 2020 14:58:01 +0200 Subject: Reorganize shared models --- server/models/abuse/abuse.ts | 8 +++++--- server/models/account/user.ts | 45 ++++++++++++++++++++++--------------------- 2 files changed, 28 insertions(+), 25 deletions(-) (limited to 'server/models') diff --git a/server/models/abuse/abuse.ts b/server/models/abuse/abuse.ts index 1b599db62..2a407c3d2 100644 --- a/server/models/abuse/abuse.ts +++ b/server/models/abuse/abuse.ts @@ -17,11 +17,11 @@ import { UpdatedAt } from 'sequelize-typescript' import { isAbuseModerationCommentValid, isAbuseReasonValid, isAbuseStateValid } from '@server/helpers/custom-validators/abuses' +import { abusePredefinedReasonsMap } from '@shared/core-utils/abuse' import { AbuseFilter, AbuseObject, AbusePredefinedReasons, - abusePredefinedReasonsMap, AbusePredefinedReasonsString, AbuseState, AbuseVideoIs, @@ -646,8 +646,10 @@ export class AbuseModel extends Model { } private static getPredefinedReasonsStrings (predefinedReasons: AbusePredefinedReasons[]): AbusePredefinedReasonsString[] { + const invertedPredefinedReasons = invert(abusePredefinedReasonsMap) + return (predefinedReasons || []) - .filter(r => r in AbusePredefinedReasons) - .map(r => invert(abusePredefinedReasonsMap)[r] as AbusePredefinedReasonsString) + .map(r => invertedPredefinedReasons[r] as AbusePredefinedReasonsString) + .filter(v => !!v) } } diff --git a/server/models/account/user.ts b/server/models/account/user.ts index 5f45f8e7c..22e6715b4 100644 --- a/server/models/account/user.ts +++ b/server/models/account/user.ts @@ -1,3 +1,5 @@ +import * as Bluebird from 'bluebird' +import { values } from 'lodash' import { col, FindOptions, fn, literal, Op, QueryTypes, where, WhereOptions } from 'sequelize' import { AfterDestroy, @@ -19,8 +21,21 @@ import { Table, UpdatedAt } from 'sequelize-typescript' -import { hasUserRight, MyUser, USER_ROLE_LABELS, UserRight, AbuseState, VideoPlaylistType, VideoPrivacy } from '../../../shared' +import { + MMyUserFormattable, + MUserDefault, + MUserFormattable, + MUserId, + MUserNotifSettingChannelDefault, + MUserWithNotificationSetting, + MVideoFullLight +} from '@server/types/models' +import { hasUserRight, USER_ROLE_LABELS } from '../../../shared/core-utils/users' +import { AbuseState, MyUser, UserRight, VideoPlaylistType, VideoPrivacy } from '../../../shared/models' import { User, UserRole } from '../../../shared/models/users' +import { UserAdminFlag } from '../../../shared/models/users/user-flag.model' +import { NSFWPolicyType } from '../../../shared/models/videos/nsfw-policy.type' +import { isThemeNameValid } from '../../helpers/custom-validators/plugins' import { isNoInstanceConfigWarningModal, isNoWelcomeModal, @@ -42,33 +57,19 @@ import { isUserWebTorrentEnabledValid } from '../../helpers/custom-validators/users' import { comparePassword, cryptPassword } from '../../helpers/peertube-crypto' +import { DEFAULT_USER_THEME_NAME, NSFW_POLICY_TYPES } from '../../initializers/constants' +import { clearCacheByUserId } from '../../lib/oauth-model' +import { getThemeOrDefault } from '../../lib/plugins/theme-utils' +import { ActorModel } from '../activitypub/actor' +import { ActorFollowModel } from '../activitypub/actor-follow' import { OAuthTokenModel } from '../oauth/oauth-token' import { getSort, throwIfNotValid } from '../utils' +import { VideoModel } from '../video/video' import { VideoChannelModel } from '../video/video-channel' +import { VideoImportModel } from '../video/video-import' import { VideoPlaylistModel } from '../video/video-playlist' import { AccountModel } from './account' -import { NSFWPolicyType } from '../../../shared/models/videos/nsfw-policy.type' -import { values } from 'lodash' -import { DEFAULT_USER_THEME_NAME, NSFW_POLICY_TYPES } from '../../initializers/constants' -import { clearCacheByUserId } from '../../lib/oauth-model' import { UserNotificationSettingModel } from './user-notification-setting' -import { VideoModel } from '../video/video' -import { ActorModel } from '../activitypub/actor' -import { ActorFollowModel } from '../activitypub/actor-follow' -import { VideoImportModel } from '../video/video-import' -import { UserAdminFlag } from '../../../shared/models/users/user-flag.model' -import { isThemeNameValid } from '../../helpers/custom-validators/plugins' -import { getThemeOrDefault } from '../../lib/plugins/theme-utils' -import * as Bluebird from 'bluebird' -import { - MMyUserFormattable, - MUserDefault, - MUserFormattable, - MUserId, - MUserNotifSettingChannelDefault, - MUserWithNotificationSetting, - MVideoFullLight -} from '@server/types/models' enum ScopeNames { FOR_ME_API = 'FOR_ME_API', -- cgit v1.2.3