]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/account/user.ts
Create a dedicated table to track video thumbnails
[github/Chocobozzz/PeerTube.git] / server / models / account / user.ts
index 017a96657b0a0c6289b13cca65860000848e735a..b66458351a6eb6dc0871947c5ac4da1ebad20b78 100644 (file)
@@ -22,6 +22,7 @@ import {
 import { hasUserRight, USER_ROLE_LABELS, UserRight } from '../../../shared'
 import { User, UserRole } from '../../../shared/models/users'
 import {
+  isUserAdminFlagsValid,
   isUserAutoPlayVideoValid,
   isUserBlockedReasonValid,
   isUserBlockedValid,
@@ -42,13 +43,14 @@ import { VideoChannelModel } from '../video/video-channel'
 import { AccountModel } from './account'
 import { NSFWPolicyType } from '../../../shared/models/videos/nsfw-policy.type'
 import { values } from 'lodash'
-import { NSFW_POLICY_TYPES } from '../../initializers'
+import { NSFW_POLICY_TYPES } from '../../initializers/constants'
 import { clearCacheByUserId } from '../../lib/oauth-model'
 import { UserNotificationSettingModel } from './user-notification-setting'
 import { VideoModel } from '../video/video'
 import { ActorModel } from '../activitypub/actor'
 import { ActorFollowModel } from '../activitypub/actor-follow'
 import { VideoImportModel } from '../video/video-import'
+import { UserAdminFlag } from '../../../shared/models/users/user-flag.model'
 
 enum ScopeNames {
   WITH_VIDEO_CHANNEL = 'WITH_VIDEO_CHANNEL'
@@ -140,6 +142,12 @@ export class UserModel extends Model<UserModel> {
   @Column
   autoPlayVideo: boolean
 
+  @AllowNull(false)
+  @Default(UserAdminFlag.NONE)
+  @Is('UserAdminFlags', value => throwIfNotValid(value, isUserAdminFlagsValid, 'user admin flags'))
+  @Column
+  adminFlags?: UserAdminFlag
+
   @AllowNull(false)
   @Default(false)
   @Is('UserBlocked', value => throwIfNotValid(value, isUserBlockedValid, 'blocked boolean'))
@@ -341,7 +349,7 @@ export class UserModel extends Model<UserModel> {
   }
 
   static loadById (id: number) {
-    return UserModel.findById(id)
+    return UserModel.findByPk(id)
   }
 
   static loadByUsername (username: string) {
@@ -516,11 +524,15 @@ export class UserModel extends Model<UserModel> {
     return hasUserRight(this.role, right)
   }
 
+  hasAdminFlag (flag: UserAdminFlag) {
+    return this.adminFlags & flag
+  }
+
   isPasswordMatch (password: string) {
     return comparePassword(password, this.password)
   }
 
-  toFormattedJSON (): User {
+  toFormattedJSON (parameters: { withAdminFlags?: boolean } = {}): User {
     const videoQuotaUsed = this.get('videoQuotaUsed')
     const videoQuotaUsedDaily = this.get('videoQuotaUsedDaily')
 
@@ -551,6 +563,10 @@ export class UserModel extends Model<UserModel> {
             : undefined
     }
 
+    if (parameters.withAdminFlags) {
+      Object.assign(json, { adminFlags: this.adminFlags })
+    }
+
     if (Array.isArray(this.Account.VideoChannels) === true) {
       json.videoChannels = this.Account.VideoChannels
         .map(c => c.toFormattedJSON())