diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/controllers/api/users/me.ts | 2 | ||||
-rw-r--r-- | server/helpers/custom-validators/users.ts | 9 | ||||
-rw-r--r-- | server/initializers/constants.ts | 8 | ||||
-rw-r--r-- | server/initializers/migrations/0280-webtorrent-policy-user.ts | 16 | ||||
-rw-r--r-- | server/models/account/user.ts | 13 |
5 files changed, 20 insertions, 28 deletions
diff --git a/server/controllers/api/users/me.ts b/server/controllers/api/users/me.ts index f78294f17..3c511dc70 100644 --- a/server/controllers/api/users/me.ts +++ b/server/controllers/api/users/me.ts | |||
@@ -327,7 +327,7 @@ async function updateMe (req: express.Request, res: express.Response, next: expr | |||
327 | if (body.password !== undefined) user.password = body.password | 327 | if (body.password !== undefined) user.password = body.password |
328 | if (body.email !== undefined) user.email = body.email | 328 | if (body.email !== undefined) user.email = body.email |
329 | if (body.nsfwPolicy !== undefined) user.nsfwPolicy = body.nsfwPolicy | 329 | if (body.nsfwPolicy !== undefined) user.nsfwPolicy = body.nsfwPolicy |
330 | if (body.webTorrentPolicy !== undefined) user.webTorrentPolicy = body.webTorrentPolicy | 330 | if (body.webTorrentEnabled !== undefined) user.webTorrentEnabled = body.webTorrentEnabled |
331 | if (body.autoPlayVideo !== undefined) user.autoPlayVideo = body.autoPlayVideo | 331 | if (body.autoPlayVideo !== undefined) user.autoPlayVideo = body.autoPlayVideo |
332 | 332 | ||
333 | await sequelizeTypescript.transaction(async t => { | 333 | await sequelizeTypescript.transaction(async t => { |
diff --git a/server/helpers/custom-validators/users.ts b/server/helpers/custom-validators/users.ts index 2024d4a22..1cb5e5b0f 100644 --- a/server/helpers/custom-validators/users.ts +++ b/server/helpers/custom-validators/users.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import 'express-validator' | 1 | import 'express-validator' |
2 | import * as validator from 'validator' | 2 | import * as validator from 'validator' |
3 | import { UserRole } from '../../../shared' | 3 | import { UserRole } from '../../../shared' |
4 | import { CONSTRAINTS_FIELDS, NSFW_POLICY_TYPES, WEBTORRENT_POLICY_TYPES } from '../../initializers' | 4 | import { CONSTRAINTS_FIELDS, NSFW_POLICY_TYPES } from '../../initializers' |
5 | import { exists, isFileValid, isBooleanValid } from './misc' | 5 | import { exists, isFileValid, isBooleanValid } from './misc' |
6 | import { values } from 'lodash' | 6 | import { values } from 'lodash' |
7 | 7 | ||
@@ -42,9 +42,8 @@ function isUserNSFWPolicyValid (value: any) { | |||
42 | return exists(value) && nsfwPolicies.indexOf(value) !== -1 | 42 | return exists(value) && nsfwPolicies.indexOf(value) !== -1 |
43 | } | 43 | } |
44 | 44 | ||
45 | const webTorrentPolicies = values(WEBTORRENT_POLICY_TYPES) | 45 | function isUserWebTorrentEnabledValid (value: any) { |
46 | function isUserWebTorrentPolicyValid (value: any) { | 46 | return isBooleanValid(value) |
47 | return exists(value) && webTorrentPolicies.indexOf(value) !== -1 | ||
48 | } | 47 | } |
49 | 48 | ||
50 | function isUserAutoPlayVideoValid (value: any) { | 49 | function isUserAutoPlayVideoValid (value: any) { |
@@ -83,7 +82,7 @@ export { | |||
83 | isUserUsernameValid, | 82 | isUserUsernameValid, |
84 | isUserEmailVerifiedValid, | 83 | isUserEmailVerifiedValid, |
85 | isUserNSFWPolicyValid, | 84 | isUserNSFWPolicyValid, |
86 | isUserWebTorrentPolicyValid, | 85 | isUserWebTorrentEnabledValid, |
87 | isUserAutoPlayVideoValid, | 86 | isUserAutoPlayVideoValid, |
88 | isUserDisplayNameValid, | 87 | isUserDisplayNameValid, |
89 | isUserDescriptionValid, | 88 | isUserDescriptionValid, |
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index f56763a16..c3e4fcede 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts | |||
@@ -7,7 +7,6 @@ import { VideoAbuseState, VideoImportState, VideoPrivacy, VideoTranscodingFPS } | |||
7 | // Do not use barrels, remain constants as independent as possible | 7 | // Do not use barrels, remain constants as independent as possible |
8 | import { buildPath, isTestInstance, parseDuration, parseBytes, root, sanitizeHost, sanitizeUrl } from '../helpers/core-utils' | 8 | import { buildPath, isTestInstance, parseDuration, parseBytes, root, sanitizeHost, sanitizeUrl } from '../helpers/core-utils' |
9 | import { NSFWPolicyType } from '../../shared/models/videos/nsfw-policy.type' | 9 | import { NSFWPolicyType } from '../../shared/models/videos/nsfw-policy.type' |
10 | import { WebTorrentPolicyType } from '../../shared/models/users/user-webtorrent-policy.type' | ||
11 | import { invert } from 'lodash' | 10 | import { invert } from 'lodash' |
12 | import { CronRepeatOptions, EveryRepeatOptions } from 'bull' | 11 | import { CronRepeatOptions, EveryRepeatOptions } from 'bull' |
13 | import * as bytes from 'bytes' | 12 | import * as bytes from 'bytes' |
@@ -547,12 +546,6 @@ const NSFW_POLICY_TYPES: { [ id: string]: NSFWPolicyType } = { | |||
547 | DISPLAY: 'display' | 546 | DISPLAY: 'display' |
548 | } | 547 | } |
549 | 548 | ||
550 | const WEBTORRENT_POLICY_TYPES: { [ id: string]: WebTorrentPolicyType } = { | ||
551 | ENABLE: 'enable', | ||
552 | DISABLE: 'disable', | ||
553 | DISABLE_ON_MOBILE: 'disable_on_mobile' | ||
554 | } | ||
555 | |||
556 | // --------------------------------------------------------------------------- | 549 | // --------------------------------------------------------------------------- |
557 | 550 | ||
558 | // Express static paths (router) | 551 | // Express static paths (router) |
@@ -705,7 +698,6 @@ export { | |||
705 | FEEDS, | 698 | FEEDS, |
706 | JOB_TTL, | 699 | JOB_TTL, |
707 | NSFW_POLICY_TYPES, | 700 | NSFW_POLICY_TYPES, |
708 | WEBTORRENT_POLICY_TYPES, | ||
709 | TORRENT_MIMETYPE_EXT, | 701 | TORRENT_MIMETYPE_EXT, |
710 | STATIC_MAX_AGE, | 702 | STATIC_MAX_AGE, |
711 | STATIC_PATHS, | 703 | STATIC_PATHS, |
diff --git a/server/initializers/migrations/0280-webtorrent-policy-user.ts b/server/initializers/migrations/0280-webtorrent-policy-user.ts index d24f6709e..e6488356a 100644 --- a/server/initializers/migrations/0280-webtorrent-policy-user.ts +++ b/server/initializers/migrations/0280-webtorrent-policy-user.ts | |||
@@ -1,6 +1,4 @@ | |||
1 | import * as Sequelize from 'sequelize' | 1 | import * as Sequelize from 'sequelize' |
2 | import { values } from 'lodash' | ||
3 | import { WEBTORRENT_POLICY_TYPES } from '../constants' | ||
4 | 2 | ||
5 | async function up (utils: { | 3 | async function up (utils: { |
6 | transaction: Sequelize.Transaction | 4 | transaction: Sequelize.Transaction |
@@ -9,18 +7,22 @@ async function up (utils: { | |||
9 | }): Promise<any> { | 7 | }): Promise<any> { |
10 | { | 8 | { |
11 | const data = { | 9 | const data = { |
12 | type: Sequelize.ENUM(values(WEBTORRENT_POLICY_TYPES)), | 10 | type: Sequelize.BOOLEAN, |
13 | allowNull: false, | 11 | allowNull: false, |
14 | defaultValue: 'enable' | 12 | defaultValue: true |
15 | } | 13 | } |
16 | 14 | ||
17 | await utils.queryInterface.addColumn('user', 'webTorrentPolicy', data) | 15 | await utils.queryInterface.addColumn('user', 'webTorrentEnabled', data) |
18 | } | 16 | } |
19 | 17 | ||
20 | } | 18 | } |
21 | 19 | ||
22 | function down (options) { | 20 | async function down (utils: { |
23 | throw new Error('Not implemented.') | 21 | transaction: Sequelize.Transaction |
22 | queryInterface: Sequelize.QueryInterface | ||
23 | sequelize: Sequelize.Sequelize | ||
24 | }): Promise<any> { | ||
25 | await utils.queryInterface.removeColumn('user', 'webTorrentEnabled') | ||
24 | } | 26 | } |
25 | 27 | ||
26 | export { up, down } | 28 | export { up, down } |
diff --git a/server/models/account/user.ts b/server/models/account/user.ts index 5fe7d7e7d..4b4a562fa 100644 --- a/server/models/account/user.ts +++ b/server/models/account/user.ts | |||
@@ -32,7 +32,7 @@ import { | |||
32 | isUserUsernameValid, | 32 | isUserUsernameValid, |
33 | isUserVideoQuotaDailyValid, | 33 | isUserVideoQuotaDailyValid, |
34 | isUserVideoQuotaValid, | 34 | isUserVideoQuotaValid, |
35 | isUserWebTorrentPolicyValid | 35 | isUserWebTorrentEnabledValid |
36 | } from '../../helpers/custom-validators/users' | 36 | } from '../../helpers/custom-validators/users' |
37 | import { comparePassword, cryptPassword } from '../../helpers/peertube-crypto' | 37 | import { comparePassword, cryptPassword } from '../../helpers/peertube-crypto' |
38 | import { OAuthTokenModel } from '../oauth/oauth-token' | 38 | import { OAuthTokenModel } from '../oauth/oauth-token' |
@@ -40,9 +40,8 @@ import { getSort, throwIfNotValid } from '../utils' | |||
40 | import { VideoChannelModel } from '../video/video-channel' | 40 | import { VideoChannelModel } from '../video/video-channel' |
41 | import { AccountModel } from './account' | 41 | import { AccountModel } from './account' |
42 | import { NSFWPolicyType } from '../../../shared/models/videos/nsfw-policy.type' | 42 | import { NSFWPolicyType } from '../../../shared/models/videos/nsfw-policy.type' |
43 | import { WebTorrentPolicyType } from '../../../shared/models/users/user-webtorrent-policy.type' | ||
44 | import { values } from 'lodash' | 43 | import { values } from 'lodash' |
45 | import { NSFW_POLICY_TYPES, WEBTORRENT_POLICY_TYPES } from '../../initializers' | 44 | import { NSFW_POLICY_TYPES } from '../../initializers' |
46 | import { clearCacheByUserId } from '../../lib/oauth-model' | 45 | import { clearCacheByUserId } from '../../lib/oauth-model' |
47 | 46 | ||
48 | enum ScopeNames { | 47 | enum ScopeNames { |
@@ -110,9 +109,9 @@ export class UserModel extends Model<UserModel> { | |||
110 | nsfwPolicy: NSFWPolicyType | 109 | nsfwPolicy: NSFWPolicyType |
111 | 110 | ||
112 | @AllowNull(false) | 111 | @AllowNull(false) |
113 | @Is('UserWebTorrentPolicy', value => throwIfNotValid(value, isUserWebTorrentPolicyValid, 'WebTorrent policy')) | 112 | @Is('UserWebTorrentEnabled', value => throwIfNotValid(value, isUserWebTorrentEnabledValid, 'WebTorrent enabled')) |
114 | @Column(DataType.ENUM(values(WEBTORRENT_POLICY_TYPES))) | 113 | @Column |
115 | webTorrentPolicy: WebTorrentPolicyType | 114 | webTorrentEnabled: boolean |
116 | 115 | ||
117 | @AllowNull(false) | 116 | @AllowNull(false) |
118 | @Default(true) | 117 | @Default(true) |
@@ -362,7 +361,7 @@ export class UserModel extends Model<UserModel> { | |||
362 | email: this.email, | 361 | email: this.email, |
363 | emailVerified: this.emailVerified, | 362 | emailVerified: this.emailVerified, |
364 | nsfwPolicy: this.nsfwPolicy, | 363 | nsfwPolicy: this.nsfwPolicy, |
365 | webTorrentPolicy: this.webTorrentPolicy, | 364 | webTorrentEnabled: this.webTorrentEnabled, |
366 | autoPlayVideo: this.autoPlayVideo, | 365 | autoPlayVideo: this.autoPlayVideo, |
367 | role: this.role, | 366 | role: this.role, |
368 | roleLabel: USER_ROLE_LABELS[ this.role ], | 367 | roleLabel: USER_ROLE_LABELS[ this.role ], |