diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/controllers/api/users/me.ts | 1 | ||||
-rw-r--r-- | server/helpers/custom-validators/users.ts | 5 | ||||
-rw-r--r-- | server/initializers/constants.ts | 2 | ||||
-rw-r--r-- | server/initializers/migrations/0280-webtorrent-policy-user.ts | 28 | ||||
-rw-r--r-- | server/models/account/user.ts | 9 |
5 files changed, 43 insertions, 2 deletions
diff --git a/server/controllers/api/users/me.ts b/server/controllers/api/users/me.ts index ebe668110..82299747d 100644 --- a/server/controllers/api/users/me.ts +++ b/server/controllers/api/users/me.ts | |||
@@ -328,6 +328,7 @@ async function updateMe (req: express.Request, res: express.Response, next: expr | |||
328 | if (body.password !== undefined) user.password = body.password | 328 | if (body.password !== undefined) user.password = body.password |
329 | if (body.email !== undefined) user.email = body.email | 329 | if (body.email !== undefined) user.email = body.email |
330 | if (body.nsfwPolicy !== undefined) user.nsfwPolicy = body.nsfwPolicy | 330 | if (body.nsfwPolicy !== undefined) user.nsfwPolicy = body.nsfwPolicy |
331 | if (body.webTorrentEnabled !== undefined) user.webTorrentEnabled = body.webTorrentEnabled | ||
331 | if (body.autoPlayVideo !== undefined) user.autoPlayVideo = body.autoPlayVideo | 332 | if (body.autoPlayVideo !== undefined) user.autoPlayVideo = body.autoPlayVideo |
332 | 333 | ||
333 | await sequelizeTypescript.transaction(async t => { | 334 | await sequelizeTypescript.transaction(async t => { |
diff --git a/server/helpers/custom-validators/users.ts b/server/helpers/custom-validators/users.ts index 90fc74a48..1cb5e5b0f 100644 --- a/server/helpers/custom-validators/users.ts +++ b/server/helpers/custom-validators/users.ts | |||
@@ -42,6 +42,10 @@ 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 | function isUserWebTorrentEnabledValid (value: any) { | ||
46 | return isBooleanValid(value) | ||
47 | } | ||
48 | |||
45 | function isUserAutoPlayVideoValid (value: any) { | 49 | function isUserAutoPlayVideoValid (value: any) { |
46 | return isBooleanValid(value) | 50 | return isBooleanValid(value) |
47 | } | 51 | } |
@@ -78,6 +82,7 @@ export { | |||
78 | isUserUsernameValid, | 82 | isUserUsernameValid, |
79 | isUserEmailVerifiedValid, | 83 | isUserEmailVerifiedValid, |
80 | isUserNSFWPolicyValid, | 84 | isUserNSFWPolicyValid, |
85 | isUserWebTorrentEnabledValid, | ||
81 | isUserAutoPlayVideoValid, | 86 | isUserAutoPlayVideoValid, |
82 | isUserDisplayNameValid, | 87 | isUserDisplayNameValid, |
83 | isUserDescriptionValid, | 88 | isUserDescriptionValid, |
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index cf00da2c7..03158e356 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts | |||
@@ -16,7 +16,7 @@ let config: IConfig = require('config') | |||
16 | 16 | ||
17 | // --------------------------------------------------------------------------- | 17 | // --------------------------------------------------------------------------- |
18 | 18 | ||
19 | const LAST_MIGRATION_VERSION = 275 | 19 | const LAST_MIGRATION_VERSION = 280 |
20 | 20 | ||
21 | // --------------------------------------------------------------------------- | 21 | // --------------------------------------------------------------------------- |
22 | 22 | ||
diff --git a/server/initializers/migrations/0280-webtorrent-policy-user.ts b/server/initializers/migrations/0280-webtorrent-policy-user.ts new file mode 100644 index 000000000..e6488356a --- /dev/null +++ b/server/initializers/migrations/0280-webtorrent-policy-user.ts | |||
@@ -0,0 +1,28 @@ | |||
1 | import * as Sequelize from 'sequelize' | ||
2 | |||
3 | async function up (utils: { | ||
4 | transaction: Sequelize.Transaction | ||
5 | queryInterface: Sequelize.QueryInterface | ||
6 | sequelize: Sequelize.Sequelize | ||
7 | }): Promise<any> { | ||
8 | { | ||
9 | const data = { | ||
10 | type: Sequelize.BOOLEAN, | ||
11 | allowNull: false, | ||
12 | defaultValue: true | ||
13 | } | ||
14 | |||
15 | await utils.queryInterface.addColumn('user', 'webTorrentEnabled', data) | ||
16 | } | ||
17 | |||
18 | } | ||
19 | |||
20 | async function down (utils: { | ||
21 | transaction: Sequelize.Transaction | ||
22 | queryInterface: Sequelize.QueryInterface | ||
23 | sequelize: Sequelize.Sequelize | ||
24 | }): Promise<any> { | ||
25 | await utils.queryInterface.removeColumn('user', 'webTorrentEnabled') | ||
26 | } | ||
27 | |||
28 | export { up, down } | ||
diff --git a/server/models/account/user.ts b/server/models/account/user.ts index 39654cfcf..4b4a562fa 100644 --- a/server/models/account/user.ts +++ b/server/models/account/user.ts | |||
@@ -31,7 +31,8 @@ import { | |||
31 | isUserRoleValid, | 31 | isUserRoleValid, |
32 | isUserUsernameValid, | 32 | isUserUsernameValid, |
33 | isUserVideoQuotaDailyValid, | 33 | isUserVideoQuotaDailyValid, |
34 | isUserVideoQuotaValid | 34 | isUserVideoQuotaValid, |
35 | isUserWebTorrentEnabledValid | ||
35 | } from '../../helpers/custom-validators/users' | 36 | } from '../../helpers/custom-validators/users' |
36 | import { comparePassword, cryptPassword } from '../../helpers/peertube-crypto' | 37 | import { comparePassword, cryptPassword } from '../../helpers/peertube-crypto' |
37 | import { OAuthTokenModel } from '../oauth/oauth-token' | 38 | import { OAuthTokenModel } from '../oauth/oauth-token' |
@@ -108,6 +109,11 @@ export class UserModel extends Model<UserModel> { | |||
108 | nsfwPolicy: NSFWPolicyType | 109 | nsfwPolicy: NSFWPolicyType |
109 | 110 | ||
110 | @AllowNull(false) | 111 | @AllowNull(false) |
112 | @Is('UserWebTorrentEnabled', value => throwIfNotValid(value, isUserWebTorrentEnabledValid, 'WebTorrent enabled')) | ||
113 | @Column | ||
114 | webTorrentEnabled: boolean | ||
115 | |||
116 | @AllowNull(false) | ||
111 | @Default(true) | 117 | @Default(true) |
112 | @Is('UserAutoPlayVideo', value => throwIfNotValid(value, isUserAutoPlayVideoValid, 'auto play video boolean')) | 118 | @Is('UserAutoPlayVideo', value => throwIfNotValid(value, isUserAutoPlayVideoValid, 'auto play video boolean')) |
113 | @Column | 119 | @Column |
@@ -355,6 +361,7 @@ export class UserModel extends Model<UserModel> { | |||
355 | email: this.email, | 361 | email: this.email, |
356 | emailVerified: this.emailVerified, | 362 | emailVerified: this.emailVerified, |
357 | nsfwPolicy: this.nsfwPolicy, | 363 | nsfwPolicy: this.nsfwPolicy, |
364 | webTorrentEnabled: this.webTorrentEnabled, | ||
358 | autoPlayVideo: this.autoPlayVideo, | 365 | autoPlayVideo: this.autoPlayVideo, |
359 | role: this.role, | 366 | role: this.role, |
360 | roleLabel: USER_ROLE_LABELS[ this.role ], | 367 | roleLabel: USER_ROLE_LABELS[ this.role ], |