Reorganize shared models
This commit is contained in:
parent
583eb04b54
commit
bd45d503e5
59 changed files with 155 additions and 144 deletions
|
|
@ -1,9 +1,12 @@
|
|||
import * as express from 'express'
|
||||
import { logger } from '@server/helpers/logger'
|
||||
import { createAccountAbuse, createVideoAbuse, createVideoCommentAbuse } from '@server/lib/moderation'
|
||||
import { Notifier } from '@server/lib/notifier'
|
||||
import { AbuseModel } from '@server/models/abuse/abuse'
|
||||
import { AbuseMessageModel } from '@server/models/abuse/abuse-message'
|
||||
import { getServerActor } from '@server/models/application/application'
|
||||
import { AbuseCreate, abusePredefinedReasonsMap, AbuseState, UserRight } from '../../../shared'
|
||||
import { abusePredefinedReasonsMap } from '@shared/core-utils/abuse'
|
||||
import { AbuseCreate, AbuseState, UserRight } from '../../../shared'
|
||||
import { getFormattedObjects } from '../../helpers/utils'
|
||||
import { sequelizeTypescript } from '../../initializers/database'
|
||||
import {
|
||||
|
|
@ -25,8 +28,6 @@ import {
|
|||
setDefaultSort
|
||||
} from '../../middlewares'
|
||||
import { AccountModel } from '../../models/account/account'
|
||||
import { Notifier } from '@server/lib/notifier'
|
||||
import { logger } from '@server/helpers/logger'
|
||||
|
||||
const abuseRouter = express.Router()
|
||||
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
import { constants, promises as fs } from 'fs'
|
||||
import * as express from 'express'
|
||||
import { constants, promises as fs } from 'fs'
|
||||
import { join } from 'path'
|
||||
import { root } from '../helpers/core-utils'
|
||||
import { ACCEPT_HEADERS, STATIC_MAX_AGE } from '../initializers/constants'
|
||||
import { asyncMiddleware, embedCSP } from '../middlewares'
|
||||
import { buildFileLocale, getCompleteLocale, is18nLocale, LOCALE_FILES } from '../../shared/models/i18n/i18n'
|
||||
import { ClientHtml } from '../lib/client-html'
|
||||
import { logger } from '../helpers/logger'
|
||||
import { CONFIG } from '@server/initializers/config'
|
||||
import { buildFileLocale, getCompleteLocale, is18nLocale, LOCALE_FILES } from '@shared/core-utils/i18n'
|
||||
import { root } from '../helpers/core-utils'
|
||||
import { logger } from '../helpers/logger'
|
||||
import { ACCEPT_HEADERS, STATIC_MAX_AGE } from '../initializers/constants'
|
||||
import { ClientHtml } from '../lib/client-html'
|
||||
import { asyncMiddleware, embedCSP } from '../middlewares'
|
||||
|
||||
const clientsRouter = express.Router()
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import { getPluginValidator, pluginStaticDirectoryValidator, getExternalAuthVali
|
|||
import { serveThemeCSSValidator } from '../middlewares/validators/themes'
|
||||
import { PluginType } from '../../shared/models/plugins/plugin.type'
|
||||
import { isTestInstance } from '../helpers/core-utils'
|
||||
import { getCompleteLocale, is18nLocale } from '../../shared/models/i18n'
|
||||
import { getCompleteLocale, is18nLocale } from '../../shared/core-utils/i18n'
|
||||
import { logger } from '@server/helpers/logger'
|
||||
|
||||
const sendFileOptions = {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import validator from 'validator'
|
||||
import { AbuseFilter, abusePredefinedReasonsMap, AbusePredefinedReasonsString, AbuseVideoIs, AbuseCreate } from '@shared/models'
|
||||
import { abusePredefinedReasonsMap } from '@shared/core-utils/abuse'
|
||||
import { AbuseCreate, AbuseFilter, AbusePredefinedReasonsString, AbuseVideoIs } from '@shared/models'
|
||||
import { ABUSE_STATES, CONSTRAINTS_FIELDS } from '../../initializers/constants'
|
||||
import { exists, isArray } from './misc'
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,8 @@ import { isUrlValid } from './activitypub/misc'
|
|||
const PLUGINS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.PLUGINS
|
||||
|
||||
function isPluginTypeValid (value: any) {
|
||||
return exists(value) && validator.isInt('' + value) && PluginType[value] !== undefined
|
||||
return exists(value) &&
|
||||
(value === PluginType.PLUGIN || value === PluginType.THEME)
|
||||
}
|
||||
|
||||
function isPluginNameValid (value: string) {
|
||||
|
|
|
|||
|
|
@ -10,7 +10,8 @@ function isVideoBlacklistReasonValid (value: string) {
|
|||
}
|
||||
|
||||
function isVideoBlacklistTypeValid (value: any) {
|
||||
return exists(value) && validator.isInt('' + value) && VideoBlacklistType[value] !== undefined
|
||||
return exists(value) &&
|
||||
(value === VideoBlacklistType.AUTO_BEFORE_PUBLISHED || value === VideoBlacklistType.MANUAL)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@ import { createAccountAbuse, createVideoAbuse, createVideoCommentAbuse } from '@
|
|||
import { AccountModel } from '@server/models/account/account'
|
||||
import { VideoModel } from '@server/models/video/video'
|
||||
import { VideoCommentModel } from '@server/models/video/video-comment'
|
||||
import { AbuseObject, abusePredefinedReasonsMap, AbuseState, ActivityCreate, ActivityFlag } from '../../../../shared'
|
||||
import { abusePredefinedReasonsMap } from '@shared/core-utils/abuse'
|
||||
import { AbuseObject, AbuseState, ActivityCreate, ActivityFlag } from '../../../../shared'
|
||||
import { getAPId } from '../../../helpers/activitypub'
|
||||
import { retryTransactionWrapper } from '../../../helpers/database-utils'
|
||||
import { logger } from '../../../helpers/logger'
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import * as express from 'express'
|
||||
import { buildFileLocale, getDefaultLocale, is18nLocale, POSSIBLE_LOCALES } from '../../shared/models/i18n/i18n'
|
||||
import { buildFileLocale, getDefaultLocale, is18nLocale, POSSIBLE_LOCALES } from '../../shared/core-utils/i18n/i18n'
|
||||
import {
|
||||
AVATARS_SIZE,
|
||||
CUSTOM_HTML_TAG_COMMENTS,
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ function ensureUserHasRight (userRight: UserRight) {
|
|||
return function (req: express.Request, res: express.Response, next: express.NextFunction) {
|
||||
const user = res.locals.oauth.token.user
|
||||
if (user.hasRight(userRight) === false) {
|
||||
const message = `User ${user.username} does not have right ${UserRight[userRight]} to access to ${req.path}.`
|
||||
const message = `User ${user.username} does not have right ${userRight} to access to ${req.path}.`
|
||||
logger.info(message)
|
||||
|
||||
return res.status(403).json({ error: message })
|
||||
|
|
|
|||
|
|
@ -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<AbuseModel> {
|
|||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 { OAuthTokenModel } from '../oauth/oauth-token'
|
||||
import { getSort, throwIfNotValid } from '../utils'
|
||||
import { VideoChannelModel } from '../video/video-channel'
|
||||
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 { 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 { 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'
|
||||
import { VideoPlaylistModel } from '../video/video-playlist'
|
||||
import { AccountModel } from './account'
|
||||
import { UserNotificationSettingModel } from './user-notification-setting'
|
||||
|
||||
enum ScopeNames {
|
||||
FOR_ME_API = 'FOR_ME_API',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue