X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Faccount%2Fuser.ts;h=5fe7d7e7d94aa00864ed6d3a954d02cc623fd8e0;hb=64cc5e8575fda47b281ae20abf0020e27fc8ce7c;hp=e56b0bf40b06bb988e8cf9c04f82ace36cd8ec50;hpb=f201a749929ec8094a7ba6bcab7b196870ca5a5e;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/account/user.ts b/server/models/account/user.ts index e56b0bf40..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')) @@ -181,7 +188,25 @@ export class UserModel extends Model { 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: [ @@ -204,7 +229,8 @@ export class UserModel extends Model { }, offset: start, limit: count, - order: getSort(sort) + order: getSort(sort), + where } return UserModel.findAndCountAll(query) @@ -336,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 ],