X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fuser%2Fuser.ts;h=bcf56dfa12d10dc09f6fa8ac89588d3c7cedda65;hb=40fa53ac9900fb140027bd2ed03f3e90dde1b4bd;hp=ddce455a1dda464bd9a17a51c401e7b46da8027d;hpb=8f581725651c4b2c213d75fc028e306bbf239d3e;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/user/user.ts b/server/models/user/user.ts index ddce455a1..bcf56dfa1 100644 --- a/server/models/user/user.ts +++ b/server/models/user/user.ts @@ -31,7 +31,7 @@ import { MUserWithNotificationSetting, MVideoWithRights } from '@server/types/models' -import { AttributesOnly } from '@shared/core-utils' +import { AttributesOnly } from '@shared/typescript-utils' 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' @@ -48,14 +48,14 @@ import { isUserEmailVerifiedValid, isUserNoModal, isUserNSFWPolicyValid, + isUserP2PEnabledValid, isUserPasswordValid, isUserRoleValid, isUserUsernameValid, isUserVideoLanguages, isUserVideoQuotaDailyValid, isUserVideoQuotaValid, - isUserVideosHistoryEnabledValid, - isUserWebTorrentEnabledValid + isUserVideosHistoryEnabledValid } from '../../helpers/custom-validators/users' import { comparePassword, cryptPassword } from '../../helpers/peertube-crypto' import { DEFAULT_USER_THEME_NAME, NSFW_POLICY_TYPES } from '../../initializers/constants' @@ -106,7 +106,7 @@ enum ScopeNames { include: [ { model: ActorImageModel, - as: 'Banner', + as: 'Banners', required: false } ] @@ -267,10 +267,9 @@ export class UserModel extends Model>> { nsfwPolicy: NSFWPolicyType @AllowNull(false) - @Default(true) - @Is('UserWebTorrentEnabled', value => throwIfNotValid(value, isUserWebTorrentEnabledValid, 'WebTorrent enabled')) + @Is('p2pEnabled', value => throwIfNotValid(value, isUserP2PEnabledValid, 'P2P enabled')) @Column - webTorrentEnabled: boolean + p2pEnabled: boolean @AllowNull(false) @Default(true) @@ -487,7 +486,7 @@ export class UserModel extends Model>> { ')' ), 'videoQuotaUsed' - ] as any // FIXME: typings + ] ] }, offset: start, @@ -496,13 +495,10 @@ export class UserModel extends Model>> { where } - return UserModel.findAndCountAll(query) - .then(({ rows, count }) => { - return { - data: rows, - total: count - } - }) + return Promise.all([ + UserModel.unscoped().count(query), + UserModel.findAll(query) + ]).then(([ total, data ]) => ({ total, data })) } static listWithRight (right: UserRight): Promise { @@ -624,7 +620,7 @@ export class UserModel extends Model>> { const query = { where: { [Op.or]: [ - where(fn('lower', col('username')), fn('lower', username)), + where(fn('lower', col('username')), fn('lower', username) as any), { email } ] @@ -892,7 +888,11 @@ export class UserModel extends Model>> { emailVerified: this.emailVerified, nsfwPolicy: this.nsfwPolicy, - webTorrentEnabled: this.webTorrentEnabled, + + // FIXME: deprecated in 4.1 + webTorrentEnabled: this.p2pEnabled, + p2pEnabled: this.p2pEnabled, + videosHistoryEnabled: this.videosHistoryEnabled, autoPlayVideo: this.autoPlayVideo, autoPlayNextVideo: this.autoPlayNextVideo,