X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Faccount%2Fuser.ts;h=c1f22b76aaad87c4195416c0096d6e1ffacd80fe;hb=3fbc6974334ca58c068f0f9def0b0a40db2a6de1;hp=e850d1e6df311c4a45b1a054b73e33faa4cbe920;hpb=fb7194043d0486ce0a6a40b2ffbdf32878c33a6f;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/account/user.ts b/server/models/account/user.ts index e850d1e6d..c1f22b76a 100644 --- a/server/models/account/user.ts +++ b/server/models/account/user.ts @@ -1,4 +1,3 @@ -import * as Bluebird from 'bluebird' import { values } from 'lodash' import { col, FindOptions, fn, literal, Op, QueryTypes, where, WhereOptions } from 'sequelize' import { @@ -16,6 +15,7 @@ import { HasOne, Is, IsEmail, + IsUUID, Model, Scopes, Table, @@ -26,10 +26,9 @@ import { MUser, MUserDefault, MUserFormattable, - MUserId, MUserNotifSettingChannelDefault, MUserWithNotificationSetting, - MVideoFullLight + MVideoWithRights } from '@server/types/models' import { hasUserRight, USER_ROLE_LABELS } from '../../../shared/core-utils/users' import { AbuseState, MyUser, UserRight, VideoPlaylistType, VideoPrivacy } from '../../../shared/models' @@ -68,10 +67,10 @@ import { getSort, throwIfNotValid } from '../utils' import { VideoModel } from '../video/video' import { VideoChannelModel } from '../video/video-channel' import { VideoImportModel } from '../video/video-import' +import { VideoLiveModel } from '../video/video-live' import { VideoPlaylistModel } from '../video/video-playlist' import { AccountModel } from './account' import { UserNotificationSettingModel } from './user-notification-setting' -import { VideoLiveModel } from '../video/video-live' enum ScopeNames { FOR_ME_API = 'FOR_ME_API', @@ -220,7 +219,7 @@ enum ScopeNames { } ] }) -export class UserModel extends Model { +export class UserModel extends Model { @AllowNull(true) @Is('UserPassword', value => throwIfNotValid(value, isUserPasswordValid, 'user password', true)) @@ -354,6 +353,12 @@ export class UserModel extends Model { @Column pluginAuth: string + @AllowNull(false) + @Default(DataType.UUIDV4) + @IsUUID(4) + @Column(DataType.UUID) + feedToken: string + @AllowNull(true) @Default(null) @Column @@ -477,7 +482,7 @@ export class UserModel extends Model { }) } - static listWithRight (right: UserRight): Bluebird { + static listWithRight (right: UserRight): Promise { const roles = Object.keys(USER_ROLE_LABELS) .map(k => parseInt(k, 10) as UserRole) .filter(role => hasUserRight(role, right)) @@ -493,7 +498,7 @@ export class UserModel extends Model { return UserModel.findAll(query) } - static listUserSubscribersOf (actorId: number): Bluebird { + static listUserSubscribersOf (actorId: number): Promise { const query = { include: [ { @@ -532,7 +537,7 @@ export class UserModel extends Model { return UserModel.unscoped().findAll(query) } - static listByUsernames (usernames: string[]): Bluebird { + static listByUsernames (usernames: string[]): Promise { const query = { where: { username: usernames @@ -542,11 +547,11 @@ export class UserModel extends Model { return UserModel.findAll(query) } - static loadById (id: number): Bluebird { + static loadById (id: number): Promise { return UserModel.unscoped().findByPk(id) } - static loadByIdWithChannels (id: number, withStats = false): Bluebird { + static loadByIdWithChannels (id: number, withStats = false): Promise { const scopes = [ ScopeNames.WITH_VIDEOCHANNELS ] @@ -556,27 +561,27 @@ export class UserModel extends Model { return UserModel.scope(scopes).findByPk(id) } - static loadByUsername (username: string): Bluebird { + static loadByUsername (username: string): Promise { const query = { where: { - username: { [Op.iLike]: username } + username } } return UserModel.findOne(query) } - static loadForMeAPI (username: string): Bluebird { + static loadForMeAPI (id: number): Promise { const query = { where: { - username: { [Op.iLike]: username } + id } } return UserModel.scope(ScopeNames.FOR_ME_API).findOne(query) } - static loadByEmail (email: string): Bluebird { + static loadByEmail (email: string): Promise { const query = { where: { email @@ -586,7 +591,7 @@ export class UserModel extends Model { return UserModel.findOne(query) } - static loadByUsernameOrEmail (username: string, email?: string): Bluebird { + static loadByUsernameOrEmail (username: string, email?: string): Promise { if (!email) email = username const query = { @@ -602,7 +607,7 @@ export class UserModel extends Model { return UserModel.findOne(query) } - static loadByVideoId (videoId: number): Bluebird { + static loadByVideoId (videoId: number): Promise { const query = { include: [ { @@ -633,7 +638,7 @@ export class UserModel extends Model { return UserModel.findOne(query) } - static loadByVideoImportId (videoImportId: number): Bluebird { + static loadByVideoImportId (videoImportId: number): Promise { const query = { include: [ { @@ -650,7 +655,7 @@ export class UserModel extends Model { return UserModel.findOne(query) } - static loadByChannelActorId (videoChannelActorId: number): Bluebird { + static loadByChannelActorId (videoChannelActorId: number): Promise { const query = { include: [ { @@ -674,7 +679,7 @@ export class UserModel extends Model { return UserModel.findOne(query) } - static loadByAccountActorId (accountActorId: number): Bluebird { + static loadByAccountActorId (accountActorId: number): Promise { const query = { include: [ { @@ -691,7 +696,7 @@ export class UserModel extends Model { return UserModel.findOne(query) } - static loadByLiveId (liveId: number): Bluebird { + static loadByLiveId (liveId: number): Promise { const query = { include: [ { @@ -710,7 +715,7 @@ export class UserModel extends Model { required: true, include: [ { - attributes: [ 'id', 'videoId' ], + attributes: [], model: VideoLiveModel.unscoped(), required: true, where: { @@ -726,7 +731,7 @@ export class UserModel extends Model { ] } - return UserModel.findOne(query) + return UserModel.unscoped().findOne(query) } static generateUserQuotaBaseSQL (options: { @@ -789,12 +794,14 @@ export class UserModel extends Model { const totalDailyActiveUsers = await getActiveUsers(1) const totalWeeklyActiveUsers = await getActiveUsers(7) const totalMonthlyActiveUsers = await getActiveUsers(30) + const totalHalfYearActiveUsers = await getActiveUsers(180) return { totalUsers, totalDailyActiveUsers, totalWeeklyActiveUsers, - totalMonthlyActiveUsers + totalMonthlyActiveUsers, + totalHalfYearActiveUsers } } @@ -812,7 +819,7 @@ export class UserModel extends Model { .then(u => u.map(u => u.username)) } - canGetVideo (video: MVideoFullLight) { + canGetVideo (video: MVideoWithRights) { const videoUserId = video.VideoChannel.Account.userId if (video.isBlacklisted()) {