X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Faccount%2Fuser.ts;h=c1f22b76aaad87c4195416c0096d6e1ffacd80fe;hb=3fbc6974334ca58c068f0f9def0b0a40db2a6de1;hp=2aa6469fb0f884bff9fc6a185656552f701f00a3;hpb=97969c4edf51b37eee691adba43368bb0fbb729b;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/account/user.ts b/server/models/account/user.ts index 2aa6469fb..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, @@ -28,7 +28,7 @@ import { MUserFormattable, 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' @@ -219,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)) @@ -353,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 @@ -476,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)) @@ -492,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: [ { @@ -531,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 @@ -541,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 ] @@ -555,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 @@ -585,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 = { @@ -601,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: [ { @@ -632,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: [ { @@ -649,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: [ { @@ -673,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: [ { @@ -690,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: [ { @@ -788,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 } } @@ -811,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()) {