X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Faccount%2Fuser.ts;h=ea017c338fbdd4f6d73b0bac60677028d0f62490;hb=8b9a525a180cc9f3a98c334cc052dcfc8f36dcd4;hp=680b1d52d9debb806818162f9de09ebf5972ec38;hpb=5cf84858d49f4231cc4efec5e3132f17f65f6cf6;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/account/user.ts b/server/models/account/user.ts index 680b1d52d..ea017c338 100644 --- a/server/models/account/user.ts +++ b/server/models/account/user.ts @@ -1,5 +1,7 @@ import * as Sequelize from 'sequelize' import { + AfterDestroy, + AfterUpdate, AllowNull, BeforeCreate, BeforeUpdate, @@ -29,7 +31,9 @@ import { isUserRoleValid, isUserUsernameValid, isUserVideoQuotaDailyValid, - isUserVideoQuotaValid + isUserVideoQuotaValid, + isUserWebTorrentEnabledValid, + isUserVideosHistoryEnabledValid } from '../../helpers/custom-validators/users' import { comparePassword, cryptPassword } from '../../helpers/peertube-crypto' import { OAuthTokenModel } from '../oauth/oauth-token' @@ -39,6 +43,7 @@ import { AccountModel } from './account' import { NSFWPolicyType } from '../../../shared/models/videos/nsfw-policy.type' import { values } from 'lodash' import { NSFW_POLICY_TYPES } from '../../initializers' +import { clearCacheByUserId } from '../../lib/oauth-model' enum ScopeNames { WITH_VIDEO_CHANNEL = 'WITH_VIDEO_CHANNEL' @@ -104,6 +109,18 @@ export class UserModel extends Model { @Column(DataType.ENUM(values(NSFW_POLICY_TYPES))) nsfwPolicy: NSFWPolicyType + @AllowNull(false) + @Default(true) + @Is('UserWebTorrentEnabled', value => throwIfNotValid(value, isUserWebTorrentEnabledValid, 'WebTorrent enabled')) + @Column + webTorrentEnabled: boolean + + @AllowNull(false) + @Default(true) + @Is('UserVideosHistoryEnabled', value => throwIfNotValid(value, isUserVideosHistoryEnabledValid, 'Videos history enabled')) + @Column + videosHistoryEnabled: boolean + @AllowNull(false) @Default(true) @Is('UserAutoPlayVideo', value => throwIfNotValid(value, isUserAutoPlayVideoValid, 'auto play video boolean')) @@ -168,11 +185,35 @@ export class UserModel extends Model { } } + @AfterUpdate + @AfterDestroy + static removeTokenCache (instance: UserModel) { + return clearCacheByUserId(instance.id) + } + static countTotal () { return this.count() } - static listForApi (start: number, count: number, sort: string) { + static listForApi (start: number, count: number, sort: string, search?: string) { + let where = undefined + if (search) { + where = { + [Sequelize.Op.or]: [ + { + email: { + [Sequelize.Op.iLike]: '%' + search + '%' + } + }, + { + username: { + [ Sequelize.Op.iLike ]: '%' + search + '%' + } + } + ] + } + } + const query = { attributes: { include: [ @@ -195,7 +236,8 @@ export class UserModel extends Model { }, offset: start, limit: count, - order: getSort(sort) + order: getSort(sort), + where } return UserModel.findAndCountAll(query) @@ -327,6 +369,7 @@ export class UserModel extends Model { email: this.email, emailVerified: this.emailVerified, nsfwPolicy: this.nsfwPolicy, + webTorrentEnabled: this.webTorrentEnabled, autoPlayVideo: this.autoPlayVideo, role: this.role, roleLabel: USER_ROLE_LABELS[ this.role ],