aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/account/user.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/account/user.ts')
-rw-r--r--server/models/account/user.ts30
1 files changed, 16 insertions, 14 deletions
diff --git a/server/models/account/user.ts b/server/models/account/user.ts
index 0041bf577..24b1626e7 100644
--- a/server/models/account/user.ts
+++ b/server/models/account/user.ts
@@ -54,6 +54,8 @@ import { VideoImportModel } from '../video/video-import'
54import { UserAdminFlag } from '../../../shared/models/users/user-flag.model' 54import { UserAdminFlag } from '../../../shared/models/users/user-flag.model'
55import { isThemeNameValid } from '../../helpers/custom-validators/plugins' 55import { isThemeNameValid } from '../../helpers/custom-validators/plugins'
56import { getThemeOrDefault } from '../../lib/plugins/theme-utils' 56import { getThemeOrDefault } from '../../lib/plugins/theme-utils'
57import * as Bluebird from 'bluebird'
58import { MUserChannel, MUserDefault, MUserId, MUserWithNotificationSetting } from '@server/typings/models'
57 59
58enum ScopeNames { 60enum ScopeNames {
59 WITH_VIDEO_CHANNEL = 'WITH_VIDEO_CHANNEL' 61 WITH_VIDEO_CHANNEL = 'WITH_VIDEO_CHANNEL'
@@ -303,7 +305,7 @@ export class UserModel extends Model<UserModel> {
303 }) 305 })
304 } 306 }
305 307
306 static listWithRight (right: UserRight) { 308 static listWithRight (right: UserRight): Bluebird<MUserDefault[]> {
307 const roles = Object.keys(USER_ROLE_LABELS) 309 const roles = Object.keys(USER_ROLE_LABELS)
308 .map(k => parseInt(k, 10) as UserRole) 310 .map(k => parseInt(k, 10) as UserRole)
309 .filter(role => hasUserRight(role, right)) 311 .filter(role => hasUserRight(role, right))
@@ -319,7 +321,7 @@ export class UserModel extends Model<UserModel> {
319 return UserModel.findAll(query) 321 return UserModel.findAll(query)
320 } 322 }
321 323
322 static listUserSubscribersOf (actorId: number) { 324 static listUserSubscribersOf (actorId: number): Bluebird<MUserWithNotificationSetting[]> {
323 const query = { 325 const query = {
324 include: [ 326 include: [
325 { 327 {
@@ -358,7 +360,7 @@ export class UserModel extends Model<UserModel> {
358 return UserModel.unscoped().findAll(query) 360 return UserModel.unscoped().findAll(query)
359 } 361 }
360 362
361 static listByUsernames (usernames: string[]) { 363 static listByUsernames (usernames: string[]): Bluebird<MUserDefault[]> {
362 const query = { 364 const query = {
363 where: { 365 where: {
364 username: usernames 366 username: usernames
@@ -368,11 +370,11 @@ export class UserModel extends Model<UserModel> {
368 return UserModel.findAll(query) 370 return UserModel.findAll(query)
369 } 371 }
370 372
371 static loadById (id: number) { 373 static loadById (id: number): Bluebird<MUserDefault> {
372 return UserModel.findByPk(id) 374 return UserModel.findByPk(id)
373 } 375 }
374 376
375 static loadByUsername (username: string) { 377 static loadByUsername (username: string): Bluebird<MUserDefault> {
376 const query = { 378 const query = {
377 where: { 379 where: {
378 username: { [ Op.iLike ]: username } 380 username: { [ Op.iLike ]: username }
@@ -382,7 +384,7 @@ export class UserModel extends Model<UserModel> {
382 return UserModel.findOne(query) 384 return UserModel.findOne(query)
383 } 385 }
384 386
385 static loadByUsernameAndPopulateChannels (username: string) { 387 static loadByUsernameAndPopulateChannels (username: string): Bluebird<MUserChannel> {
386 const query = { 388 const query = {
387 where: { 389 where: {
388 username: { [ Op.iLike ]: username } 390 username: { [ Op.iLike ]: username }
@@ -392,7 +394,7 @@ export class UserModel extends Model<UserModel> {
392 return UserModel.scope(ScopeNames.WITH_VIDEO_CHANNEL).findOne(query) 394 return UserModel.scope(ScopeNames.WITH_VIDEO_CHANNEL).findOne(query)
393 } 395 }
394 396
395 static loadByEmail (email: string) { 397 static loadByEmail (email: string): Bluebird<MUserDefault> {
396 const query = { 398 const query = {
397 where: { 399 where: {
398 email 400 email
@@ -402,7 +404,7 @@ export class UserModel extends Model<UserModel> {
402 return UserModel.findOne(query) 404 return UserModel.findOne(query)
403 } 405 }
404 406
405 static loadByUsernameOrEmail (username: string, email?: string) { 407 static loadByUsernameOrEmail (username: string, email?: string): Bluebird<MUserDefault> {
406 if (!email) email = username 408 if (!email) email = username
407 409
408 const query = { 410 const query = {
@@ -414,7 +416,7 @@ export class UserModel extends Model<UserModel> {
414 return UserModel.findOne(query) 416 return UserModel.findOne(query)
415 } 417 }
416 418
417 static loadByVideoId (videoId: number) { 419 static loadByVideoId (videoId: number): Bluebird<MUserDefault> {
418 const query = { 420 const query = {
419 include: [ 421 include: [
420 { 422 {
@@ -445,7 +447,7 @@ export class UserModel extends Model<UserModel> {
445 return UserModel.findOne(query) 447 return UserModel.findOne(query)
446 } 448 }
447 449
448 static loadByVideoImportId (videoImportId: number) { 450 static loadByVideoImportId (videoImportId: number): Bluebird<MUserDefault> {
449 const query = { 451 const query = {
450 include: [ 452 include: [
451 { 453 {
@@ -462,7 +464,7 @@ export class UserModel extends Model<UserModel> {
462 return UserModel.findOne(query) 464 return UserModel.findOne(query)
463 } 465 }
464 466
465 static loadByChannelActorId (videoChannelActorId: number) { 467 static loadByChannelActorId (videoChannelActorId: number): Bluebird<MUserDefault> {
466 const query = { 468 const query = {
467 include: [ 469 include: [
468 { 470 {
@@ -486,7 +488,7 @@ export class UserModel extends Model<UserModel> {
486 return UserModel.findOne(query) 488 return UserModel.findOne(query)
487 } 489 }
488 490
489 static loadByAccountActorId (accountActorId: number) { 491 static loadByAccountActorId (accountActorId: number): Bluebird<MUserDefault> {
490 const query = { 492 const query = {
491 include: [ 493 include: [
492 { 494 {
@@ -503,7 +505,7 @@ export class UserModel extends Model<UserModel> {
503 return UserModel.findOne(query) 505 return UserModel.findOne(query)
504 } 506 }
505 507
506 static getOriginalVideoFileTotalFromUser (user: UserModel) { 508 static getOriginalVideoFileTotalFromUser (user: MUserId) {
507 // Don't use sequelize because we need to use a sub query 509 // Don't use sequelize because we need to use a sub query
508 const query = UserModel.generateUserQuotaBaseSQL() 510 const query = UserModel.generateUserQuotaBaseSQL()
509 511
@@ -511,7 +513,7 @@ export class UserModel extends Model<UserModel> {
511 } 513 }
512 514
513 // Returns cumulative size of all video files uploaded in the last 24 hours. 515 // Returns cumulative size of all video files uploaded in the last 24 hours.
514 static getOriginalVideoFileTotalDailyFromUser (user: UserModel) { 516 static getOriginalVideoFileTotalDailyFromUser (user: MUserId) {
515 // Don't use sequelize because we need to use a sub query 517 // Don't use sequelize because we need to use a sub query
516 const query = UserModel.generateUserQuotaBaseSQL('"video"."createdAt" > now() - interval \'24 hours\'') 518 const query = UserModel.generateUserQuotaBaseSQL('"video"."createdAt" > now() - interval \'24 hours\'')
517 519