From 64cc5e8575fda47b281ae20abf0020e27fc8ce7c Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Fri, 5 Oct 2018 15:17:34 +0200 Subject: add webtorrent opt-out settings - add a key in localstorage to remember the opt-out - add a user setting --- server/models/account/user.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'server/models') diff --git a/server/models/account/user.ts b/server/models/account/user.ts index 39654cfcf..5fe7d7e7d 100644 --- a/server/models/account/user.ts +++ b/server/models/account/user.ts @@ -31,7 +31,8 @@ import { isUserRoleValid, isUserUsernameValid, isUserVideoQuotaDailyValid, - isUserVideoQuotaValid + isUserVideoQuotaValid, + isUserWebTorrentPolicyValid } from '../../helpers/custom-validators/users' import { comparePassword, cryptPassword } from '../../helpers/peertube-crypto' import { OAuthTokenModel } from '../oauth/oauth-token' @@ -39,8 +40,9 @@ import { getSort, throwIfNotValid } from '../utils' import { VideoChannelModel } from '../video/video-channel' import { AccountModel } from './account' import { NSFWPolicyType } from '../../../shared/models/videos/nsfw-policy.type' +import { WebTorrentPolicyType } from '../../../shared/models/users/user-webtorrent-policy.type' import { values } from 'lodash' -import { NSFW_POLICY_TYPES } from '../../initializers' +import { NSFW_POLICY_TYPES, WEBTORRENT_POLICY_TYPES } from '../../initializers' import { clearCacheByUserId } from '../../lib/oauth-model' enum ScopeNames { @@ -107,6 +109,11 @@ export class UserModel extends Model { @Column(DataType.ENUM(values(NSFW_POLICY_TYPES))) nsfwPolicy: NSFWPolicyType + @AllowNull(false) + @Is('UserWebTorrentPolicy', value => throwIfNotValid(value, isUserWebTorrentPolicyValid, 'WebTorrent policy')) + @Column(DataType.ENUM(values(WEBTORRENT_POLICY_TYPES))) + webTorrentPolicy: WebTorrentPolicyType + @AllowNull(false) @Default(true) @Is('UserAutoPlayVideo', value => throwIfNotValid(value, isUserAutoPlayVideoValid, 'auto play video boolean')) @@ -355,6 +362,7 @@ export class UserModel extends Model { email: this.email, emailVerified: this.emailVerified, nsfwPolicy: this.nsfwPolicy, + webTorrentPolicy: this.webTorrentPolicy, autoPlayVideo: this.autoPlayVideo, role: this.role, roleLabel: USER_ROLE_LABELS[ this.role ], -- cgit v1.2.3 From ed638e5325096ef580da20f370ac61c59cd48cf7 Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Fri, 12 Oct 2018 18:12:39 +0200 Subject: move to boolean switch --- server/models/account/user.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'server/models') 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 { isUserUsernameValid, isUserVideoQuotaDailyValid, isUserVideoQuotaValid, - isUserWebTorrentPolicyValid + isUserWebTorrentEnabledValid } from '../../helpers/custom-validators/users' import { comparePassword, cryptPassword } from '../../helpers/peertube-crypto' import { OAuthTokenModel } from '../oauth/oauth-token' @@ -40,9 +40,8 @@ import { getSort, throwIfNotValid } from '../utils' import { VideoChannelModel } from '../video/video-channel' import { AccountModel } from './account' import { NSFWPolicyType } from '../../../shared/models/videos/nsfw-policy.type' -import { WebTorrentPolicyType } from '../../../shared/models/users/user-webtorrent-policy.type' import { values } from 'lodash' -import { NSFW_POLICY_TYPES, WEBTORRENT_POLICY_TYPES } from '../../initializers' +import { NSFW_POLICY_TYPES } from '../../initializers' import { clearCacheByUserId } from '../../lib/oauth-model' enum ScopeNames { @@ -110,9 +109,9 @@ export class UserModel extends Model { nsfwPolicy: NSFWPolicyType @AllowNull(false) - @Is('UserWebTorrentPolicy', value => throwIfNotValid(value, isUserWebTorrentPolicyValid, 'WebTorrent policy')) - @Column(DataType.ENUM(values(WEBTORRENT_POLICY_TYPES))) - webTorrentPolicy: WebTorrentPolicyType + @Is('UserWebTorrentEnabled', value => throwIfNotValid(value, isUserWebTorrentEnabledValid, 'WebTorrent enabled')) + @Column + webTorrentEnabled: boolean @AllowNull(false) @Default(true) @@ -362,7 +361,7 @@ export class UserModel extends Model { email: this.email, emailVerified: this.emailVerified, nsfwPolicy: this.nsfwPolicy, - webTorrentPolicy: this.webTorrentPolicy, + webTorrentEnabled: this.webTorrentEnabled, autoPlayVideo: this.autoPlayVideo, role: this.role, roleLabel: USER_ROLE_LABELS[ this.role ], -- cgit v1.2.3