diff options
author | Chocobozzz <me@florianbigard.com> | 2020-08-06 14:58:01 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-08-07 08:28:14 +0200 |
commit | bd45d503e5d007e730f4e81dccd7e7864c9a85cc (patch) | |
tree | b78df768b8253ba401232c17da940cea016c9960 /server | |
parent | 583eb04b541175035d6d452ca626a96ebf2b7437 (diff) | |
download | PeerTube-bd45d503e5d007e730f4e81dccd7e7864c9a85cc.tar.gz PeerTube-bd45d503e5d007e730f4e81dccd7e7864c9a85cc.tar.zst PeerTube-bd45d503e5d007e730f4e81dccd7e7864c9a85cc.zip |
Reorganize shared models
Diffstat (limited to 'server')
-rw-r--r-- | server/controllers/api/abuse.ts | 7 | ||||
-rw-r--r-- | server/controllers/client.ts | 10 | ||||
-rw-r--r-- | server/controllers/plugins.ts | 2 | ||||
-rw-r--r-- | server/helpers/custom-validators/abuses.ts | 3 | ||||
-rw-r--r-- | server/helpers/custom-validators/plugins.ts | 3 | ||||
-rw-r--r-- | server/helpers/custom-validators/video-blacklist.ts | 3 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-flag.ts | 3 | ||||
-rw-r--r-- | server/lib/client-html.ts | 2 | ||||
-rw-r--r-- | server/middlewares/user-right.ts | 2 | ||||
-rw-r--r-- | server/models/abuse/abuse.ts | 8 | ||||
-rw-r--r-- | server/models/account/user.ts | 45 |
11 files changed, 48 insertions, 40 deletions
diff --git a/server/controllers/api/abuse.ts b/server/controllers/api/abuse.ts index 03e6be8c8..b97b99f16 100644 --- a/server/controllers/api/abuse.ts +++ b/server/controllers/api/abuse.ts | |||
@@ -1,9 +1,12 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { logger } from '@server/helpers/logger' | ||
2 | import { createAccountAbuse, createVideoAbuse, createVideoCommentAbuse } from '@server/lib/moderation' | 3 | import { createAccountAbuse, createVideoAbuse, createVideoCommentAbuse } from '@server/lib/moderation' |
4 | import { Notifier } from '@server/lib/notifier' | ||
3 | import { AbuseModel } from '@server/models/abuse/abuse' | 5 | import { AbuseModel } from '@server/models/abuse/abuse' |
4 | import { AbuseMessageModel } from '@server/models/abuse/abuse-message' | 6 | import { AbuseMessageModel } from '@server/models/abuse/abuse-message' |
5 | import { getServerActor } from '@server/models/application/application' | 7 | import { getServerActor } from '@server/models/application/application' |
6 | import { AbuseCreate, abusePredefinedReasonsMap, AbuseState, UserRight } from '../../../shared' | 8 | import { abusePredefinedReasonsMap } from '@shared/core-utils/abuse' |
9 | import { AbuseCreate, AbuseState, UserRight } from '../../../shared' | ||
7 | import { getFormattedObjects } from '../../helpers/utils' | 10 | import { getFormattedObjects } from '../../helpers/utils' |
8 | import { sequelizeTypescript } from '../../initializers/database' | 11 | import { sequelizeTypescript } from '../../initializers/database' |
9 | import { | 12 | import { |
@@ -25,8 +28,6 @@ import { | |||
25 | setDefaultSort | 28 | setDefaultSort |
26 | } from '../../middlewares' | 29 | } from '../../middlewares' |
27 | import { AccountModel } from '../../models/account/account' | 30 | import { AccountModel } from '../../models/account/account' |
28 | import { Notifier } from '@server/lib/notifier' | ||
29 | import { logger } from '@server/helpers/logger' | ||
30 | 31 | ||
31 | const abuseRouter = express.Router() | 32 | const abuseRouter = express.Router() |
32 | 33 | ||
diff --git a/server/controllers/client.ts b/server/controllers/client.ts index 8c7f881a9..7c80820f4 100644 --- a/server/controllers/client.ts +++ b/server/controllers/client.ts | |||
@@ -1,13 +1,13 @@ | |||
1 | import { constants, promises as fs } from 'fs' | ||
2 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { constants, promises as fs } from 'fs' | ||
3 | import { join } from 'path' | 3 | import { join } from 'path' |
4 | import { CONFIG } from '@server/initializers/config' | ||
5 | import { buildFileLocale, getCompleteLocale, is18nLocale, LOCALE_FILES } from '@shared/core-utils/i18n' | ||
4 | import { root } from '../helpers/core-utils' | 6 | import { root } from '../helpers/core-utils' |
7 | import { logger } from '../helpers/logger' | ||
5 | import { ACCEPT_HEADERS, STATIC_MAX_AGE } from '../initializers/constants' | 8 | import { ACCEPT_HEADERS, STATIC_MAX_AGE } from '../initializers/constants' |
6 | import { asyncMiddleware, embedCSP } from '../middlewares' | ||
7 | import { buildFileLocale, getCompleteLocale, is18nLocale, LOCALE_FILES } from '../../shared/models/i18n/i18n' | ||
8 | import { ClientHtml } from '../lib/client-html' | 9 | import { ClientHtml } from '../lib/client-html' |
9 | import { logger } from '../helpers/logger' | 10 | import { asyncMiddleware, embedCSP } from '../middlewares' |
10 | import { CONFIG } from '@server/initializers/config' | ||
11 | 11 | ||
12 | const clientsRouter = express.Router() | 12 | const clientsRouter = express.Router() |
13 | 13 | ||
diff --git a/server/controllers/plugins.ts b/server/controllers/plugins.ts index f88a1632d..7b947bb6e 100644 --- a/server/controllers/plugins.ts +++ b/server/controllers/plugins.ts | |||
@@ -6,7 +6,7 @@ import { getPluginValidator, pluginStaticDirectoryValidator, getExternalAuthVali | |||
6 | import { serveThemeCSSValidator } from '../middlewares/validators/themes' | 6 | import { serveThemeCSSValidator } from '../middlewares/validators/themes' |
7 | import { PluginType } from '../../shared/models/plugins/plugin.type' | 7 | import { PluginType } from '../../shared/models/plugins/plugin.type' |
8 | import { isTestInstance } from '../helpers/core-utils' | 8 | import { isTestInstance } from '../helpers/core-utils' |
9 | import { getCompleteLocale, is18nLocale } from '../../shared/models/i18n' | 9 | import { getCompleteLocale, is18nLocale } from '../../shared/core-utils/i18n' |
10 | import { logger } from '@server/helpers/logger' | 10 | import { logger } from '@server/helpers/logger' |
11 | 11 | ||
12 | const sendFileOptions = { | 12 | const sendFileOptions = { |
diff --git a/server/helpers/custom-validators/abuses.ts b/server/helpers/custom-validators/abuses.ts index 0ddde4b06..94719641a 100644 --- a/server/helpers/custom-validators/abuses.ts +++ b/server/helpers/custom-validators/abuses.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | import validator from 'validator' | 1 | import validator from 'validator' |
2 | import { AbuseFilter, abusePredefinedReasonsMap, AbusePredefinedReasonsString, AbuseVideoIs, AbuseCreate } from '@shared/models' | 2 | import { abusePredefinedReasonsMap } from '@shared/core-utils/abuse' |
3 | import { AbuseCreate, AbuseFilter, AbusePredefinedReasonsString, AbuseVideoIs } from '@shared/models' | ||
3 | import { ABUSE_STATES, CONSTRAINTS_FIELDS } from '../../initializers/constants' | 4 | import { ABUSE_STATES, CONSTRAINTS_FIELDS } from '../../initializers/constants' |
4 | import { exists, isArray } from './misc' | 5 | import { exists, isArray } from './misc' |
5 | 6 | ||
diff --git a/server/helpers/custom-validators/plugins.ts b/server/helpers/custom-validators/plugins.ts index d2fc03936..f2d4efb32 100644 --- a/server/helpers/custom-validators/plugins.ts +++ b/server/helpers/custom-validators/plugins.ts | |||
@@ -8,7 +8,8 @@ import { isUrlValid } from './activitypub/misc' | |||
8 | const PLUGINS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.PLUGINS | 8 | const PLUGINS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.PLUGINS |
9 | 9 | ||
10 | function isPluginTypeValid (value: any) { | 10 | function isPluginTypeValid (value: any) { |
11 | return exists(value) && validator.isInt('' + value) && PluginType[value] !== undefined | 11 | return exists(value) && |
12 | (value === PluginType.PLUGIN || value === PluginType.THEME) | ||
12 | } | 13 | } |
13 | 14 | ||
14 | function isPluginNameValid (value: string) { | 15 | function isPluginNameValid (value: string) { |
diff --git a/server/helpers/custom-validators/video-blacklist.ts b/server/helpers/custom-validators/video-blacklist.ts index 17cb3b00b..34fcec38e 100644 --- a/server/helpers/custom-validators/video-blacklist.ts +++ b/server/helpers/custom-validators/video-blacklist.ts | |||
@@ -10,7 +10,8 @@ function isVideoBlacklistReasonValid (value: string) { | |||
10 | } | 10 | } |
11 | 11 | ||
12 | function isVideoBlacklistTypeValid (value: any) { | 12 | function isVideoBlacklistTypeValid (value: any) { |
13 | return exists(value) && validator.isInt('' + value) && VideoBlacklistType[value] !== undefined | 13 | return exists(value) && |
14 | (value === VideoBlacklistType.AUTO_BEFORE_PUBLISHED || value === VideoBlacklistType.MANUAL) | ||
14 | } | 15 | } |
15 | 16 | ||
16 | // --------------------------------------------------------------------------- | 17 | // --------------------------------------------------------------------------- |
diff --git a/server/lib/activitypub/process/process-flag.ts b/server/lib/activitypub/process/process-flag.ts index 6350cee12..40d07558c 100644 --- a/server/lib/activitypub/process/process-flag.ts +++ b/server/lib/activitypub/process/process-flag.ts | |||
@@ -2,7 +2,8 @@ import { createAccountAbuse, createVideoAbuse, createVideoCommentAbuse } from '@ | |||
2 | import { AccountModel } from '@server/models/account/account' | 2 | import { AccountModel } from '@server/models/account/account' |
3 | import { VideoModel } from '@server/models/video/video' | 3 | import { VideoModel } from '@server/models/video/video' |
4 | import { VideoCommentModel } from '@server/models/video/video-comment' | 4 | import { VideoCommentModel } from '@server/models/video/video-comment' |
5 | import { AbuseObject, abusePredefinedReasonsMap, AbuseState, ActivityCreate, ActivityFlag } from '../../../../shared' | 5 | import { abusePredefinedReasonsMap } from '@shared/core-utils/abuse' |
6 | import { AbuseObject, AbuseState, ActivityCreate, ActivityFlag } from '../../../../shared' | ||
6 | import { getAPId } from '../../../helpers/activitypub' | 7 | import { getAPId } from '../../../helpers/activitypub' |
7 | import { retryTransactionWrapper } from '../../../helpers/database-utils' | 8 | import { retryTransactionWrapper } from '../../../helpers/database-utils' |
8 | import { logger } from '../../../helpers/logger' | 9 | import { logger } from '../../../helpers/logger' |
diff --git a/server/lib/client-html.ts b/server/lib/client-html.ts index ffe53d0d5..d8ae73b5d 100644 --- a/server/lib/client-html.ts +++ b/server/lib/client-html.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { buildFileLocale, getDefaultLocale, is18nLocale, POSSIBLE_LOCALES } from '../../shared/models/i18n/i18n' | 2 | import { buildFileLocale, getDefaultLocale, is18nLocale, POSSIBLE_LOCALES } from '../../shared/core-utils/i18n/i18n' |
3 | import { | 3 | import { |
4 | AVATARS_SIZE, | 4 | AVATARS_SIZE, |
5 | CUSTOM_HTML_TAG_COMMENTS, | 5 | CUSTOM_HTML_TAG_COMMENTS, |
diff --git a/server/middlewares/user-right.ts b/server/middlewares/user-right.ts index 4d836485c..aaf0b323a 100644 --- a/server/middlewares/user-right.ts +++ b/server/middlewares/user-right.ts | |||
@@ -6,7 +6,7 @@ function ensureUserHasRight (userRight: UserRight) { | |||
6 | return function (req: express.Request, res: express.Response, next: express.NextFunction) { | 6 | return function (req: express.Request, res: express.Response, next: express.NextFunction) { |
7 | const user = res.locals.oauth.token.user | 7 | const user = res.locals.oauth.token.user |
8 | if (user.hasRight(userRight) === false) { | 8 | if (user.hasRight(userRight) === false) { |
9 | const message = `User ${user.username} does not have right ${UserRight[userRight]} to access to ${req.path}.` | 9 | const message = `User ${user.username} does not have right ${userRight} to access to ${req.path}.` |
10 | logger.info(message) | 10 | logger.info(message) |
11 | 11 | ||
12 | return res.status(403).json({ error: message }) | 12 | return res.status(403).json({ error: message }) |
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 { | |||
17 | UpdatedAt | 17 | UpdatedAt |
18 | } from 'sequelize-typescript' | 18 | } from 'sequelize-typescript' |
19 | import { isAbuseModerationCommentValid, isAbuseReasonValid, isAbuseStateValid } from '@server/helpers/custom-validators/abuses' | 19 | import { isAbuseModerationCommentValid, isAbuseReasonValid, isAbuseStateValid } from '@server/helpers/custom-validators/abuses' |
20 | import { abusePredefinedReasonsMap } from '@shared/core-utils/abuse' | ||
20 | import { | 21 | import { |
21 | AbuseFilter, | 22 | AbuseFilter, |
22 | AbuseObject, | 23 | AbuseObject, |
23 | AbusePredefinedReasons, | 24 | AbusePredefinedReasons, |
24 | abusePredefinedReasonsMap, | ||
25 | AbusePredefinedReasonsString, | 25 | AbusePredefinedReasonsString, |
26 | AbuseState, | 26 | AbuseState, |
27 | AbuseVideoIs, | 27 | AbuseVideoIs, |
@@ -646,8 +646,10 @@ export class AbuseModel extends Model<AbuseModel> { | |||
646 | } | 646 | } |
647 | 647 | ||
648 | private static getPredefinedReasonsStrings (predefinedReasons: AbusePredefinedReasons[]): AbusePredefinedReasonsString[] { | 648 | private static getPredefinedReasonsStrings (predefinedReasons: AbusePredefinedReasons[]): AbusePredefinedReasonsString[] { |
649 | const invertedPredefinedReasons = invert(abusePredefinedReasonsMap) | ||
650 | |||
649 | return (predefinedReasons || []) | 651 | return (predefinedReasons || []) |
650 | .filter(r => r in AbusePredefinedReasons) | 652 | .map(r => invertedPredefinedReasons[r] as AbusePredefinedReasonsString) |
651 | .map(r => invert(abusePredefinedReasonsMap)[r] as AbusePredefinedReasonsString) | 653 | .filter(v => !!v) |
652 | } | 654 | } |
653 | } | 655 | } |
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 @@ | |||
1 | import * as Bluebird from 'bluebird' | ||
2 | import { values } from 'lodash' | ||
1 | import { col, FindOptions, fn, literal, Op, QueryTypes, where, WhereOptions } from 'sequelize' | 3 | import { col, FindOptions, fn, literal, Op, QueryTypes, where, WhereOptions } from 'sequelize' |
2 | import { | 4 | import { |
3 | AfterDestroy, | 5 | AfterDestroy, |
@@ -19,8 +21,21 @@ import { | |||
19 | Table, | 21 | Table, |
20 | UpdatedAt | 22 | UpdatedAt |
21 | } from 'sequelize-typescript' | 23 | } from 'sequelize-typescript' |
22 | import { hasUserRight, MyUser, USER_ROLE_LABELS, UserRight, AbuseState, VideoPlaylistType, VideoPrivacy } from '../../../shared' | 24 | import { |
25 | MMyUserFormattable, | ||
26 | MUserDefault, | ||
27 | MUserFormattable, | ||
28 | MUserId, | ||
29 | MUserNotifSettingChannelDefault, | ||
30 | MUserWithNotificationSetting, | ||
31 | MVideoFullLight | ||
32 | } from '@server/types/models' | ||
33 | import { hasUserRight, USER_ROLE_LABELS } from '../../../shared/core-utils/users' | ||
34 | import { AbuseState, MyUser, UserRight, VideoPlaylistType, VideoPrivacy } from '../../../shared/models' | ||
23 | import { User, UserRole } from '../../../shared/models/users' | 35 | import { User, UserRole } from '../../../shared/models/users' |
36 | import { UserAdminFlag } from '../../../shared/models/users/user-flag.model' | ||
37 | import { NSFWPolicyType } from '../../../shared/models/videos/nsfw-policy.type' | ||
38 | import { isThemeNameValid } from '../../helpers/custom-validators/plugins' | ||
24 | import { | 39 | import { |
25 | isNoInstanceConfigWarningModal, | 40 | isNoInstanceConfigWarningModal, |
26 | isNoWelcomeModal, | 41 | isNoWelcomeModal, |
@@ -42,33 +57,19 @@ import { | |||
42 | isUserWebTorrentEnabledValid | 57 | isUserWebTorrentEnabledValid |
43 | } from '../../helpers/custom-validators/users' | 58 | } from '../../helpers/custom-validators/users' |
44 | import { comparePassword, cryptPassword } from '../../helpers/peertube-crypto' | 59 | import { comparePassword, cryptPassword } from '../../helpers/peertube-crypto' |
60 | import { DEFAULT_USER_THEME_NAME, NSFW_POLICY_TYPES } from '../../initializers/constants' | ||
61 | import { clearCacheByUserId } from '../../lib/oauth-model' | ||
62 | import { getThemeOrDefault } from '../../lib/plugins/theme-utils' | ||
63 | import { ActorModel } from '../activitypub/actor' | ||
64 | import { ActorFollowModel } from '../activitypub/actor-follow' | ||
45 | import { OAuthTokenModel } from '../oauth/oauth-token' | 65 | import { OAuthTokenModel } from '../oauth/oauth-token' |
46 | import { getSort, throwIfNotValid } from '../utils' | 66 | import { getSort, throwIfNotValid } from '../utils' |
67 | import { VideoModel } from '../video/video' | ||
47 | import { VideoChannelModel } from '../video/video-channel' | 68 | import { VideoChannelModel } from '../video/video-channel' |
69 | import { VideoImportModel } from '../video/video-import' | ||
48 | import { VideoPlaylistModel } from '../video/video-playlist' | 70 | import { VideoPlaylistModel } from '../video/video-playlist' |
49 | import { AccountModel } from './account' | 71 | import { AccountModel } from './account' |
50 | import { NSFWPolicyType } from '../../../shared/models/videos/nsfw-policy.type' | ||
51 | import { values } from 'lodash' | ||
52 | import { DEFAULT_USER_THEME_NAME, NSFW_POLICY_TYPES } from '../../initializers/constants' | ||
53 | import { clearCacheByUserId } from '../../lib/oauth-model' | ||
54 | import { UserNotificationSettingModel } from './user-notification-setting' | 72 | import { UserNotificationSettingModel } from './user-notification-setting' |
55 | import { VideoModel } from '../video/video' | ||
56 | import { ActorModel } from '../activitypub/actor' | ||
57 | import { ActorFollowModel } from '../activitypub/actor-follow' | ||
58 | import { VideoImportModel } from '../video/video-import' | ||
59 | import { UserAdminFlag } from '../../../shared/models/users/user-flag.model' | ||
60 | import { isThemeNameValid } from '../../helpers/custom-validators/plugins' | ||
61 | import { getThemeOrDefault } from '../../lib/plugins/theme-utils' | ||
62 | import * as Bluebird from 'bluebird' | ||
63 | import { | ||
64 | MMyUserFormattable, | ||
65 | MUserDefault, | ||
66 | MUserFormattable, | ||
67 | MUserId, | ||
68 | MUserNotifSettingChannelDefault, | ||
69 | MUserWithNotificationSetting, | ||
70 | MVideoFullLight | ||
71 | } from '@server/types/models' | ||
72 | 73 | ||
73 | enum ScopeNames { | 74 | enum ScopeNames { |
74 | FOR_ME_API = 'FOR_ME_API', | 75 | FOR_ME_API = 'FOR_ME_API', |