]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/core/users/user.model.ts
Bumped to version v5.2.1
[github/Chocobozzz/PeerTube.git] / client / src / app / core / users / user.model.ts
index c0e5d31698622c1b6f3f597946659094de30e7a4..d57608f1c66310b04debe4cc738b95e3f570ee8a 100644 (file)
@@ -1,4 +1,5 @@
 import { Account } from '@app/shared/shared-main/account/account.model'
+import { objectKeysTyped } from '@shared/core-utils'
 import { hasUserRight } from '@shared/core-utils/users'
 import {
   ActorImage,
@@ -19,6 +20,7 @@ export class User implements UserServerModel {
   pendingEmail: string | null
 
   emailVerified: boolean
+  emailPublic: boolean
   nsfwPolicy: NSFWPolicyType
 
   adminFlags?: UserAdminFlag
@@ -26,12 +28,18 @@ export class User implements UserServerModel {
   autoPlayVideo: boolean
   autoPlayNextVideo: boolean
   autoPlayNextVideoPlaylist: boolean
-  webTorrentEnabled: boolean
+
+  p2pEnabled: boolean
+  // FIXME: deprecated in 4.1
+  webTorrentEnabled: never
+
   videosHistoryEnabled: boolean
   videoLanguages: string[]
 
-  role: UserRole
-  roleLabel: string
+  role: {
+    id: UserRole
+    label: string
+  }
 
   videoQuota: number
   videoQuotaDaily: number
@@ -62,6 +70,8 @@ export class User implements UserServerModel {
 
   lastLoginDate: Date | null
 
+  twoFactorEnabled: boolean
+
   createdAt: Date
 
   constructor (hash: Partial<UserServerModel>) {
@@ -84,7 +94,7 @@ export class User implements UserServerModel {
     this.videoCommentsCount = hash.videoCommentsCount
 
     this.nsfwPolicy = hash.nsfwPolicy
-    this.webTorrentEnabled = hash.webTorrentEnabled
+    this.p2pEnabled = hash.p2pEnabled
     this.autoPlayVideo = hash.autoPlayVideo
     this.autoPlayNextVideo = hash.autoPlayNextVideo
     this.autoPlayNextVideoPlaylist = hash.autoPlayNextVideoPlaylist
@@ -104,6 +114,8 @@ export class User implements UserServerModel {
 
     this.notificationSettings = hash.notificationSettings
 
+    this.twoFactorEnabled = hash.twoFactorEnabled
+
     this.createdAt = hash.createdAt
 
     this.pluginAuth = hash.pluginAuth
@@ -115,12 +127,13 @@ export class User implements UserServerModel {
   }
 
   hasRight (right: UserRight) {
-    return hasUserRight(this.role, right)
+    return hasUserRight(this.role.id, right)
   }
 
   patch (obj: UserServerModel) {
-    for (const key of Object.keys(obj)) {
-      this[key] = obj[key]
+    for (const key of objectKeysTyped(obj)) {
+      // FIXME: typings
+      (this as any)[key] = obj[key]
     }
 
     if (obj.account !== undefined) {
@@ -128,8 +141,8 @@ export class User implements UserServerModel {
     }
   }
 
-  updateAccountAvatar (newAccountAvatar?: ActorImage) {
-    if (newAccountAvatar) this.account.updateAvatar(newAccountAvatar)
+  updateAccountAvatar (newAccountAvatars?: ActorImage[]) {
+    if (newAccountAvatars) this.account.updateAvatar(newAccountAvatars)
     else this.account.resetAvatar()
   }
 
@@ -140,6 +153,6 @@ export class User implements UserServerModel {
   isAutoBlocked (serverConfig: HTMLServerConfig) {
     if (serverConfig.autoBlacklist.videos.ofUsers.enabled !== true) return false
 
-    return this.role === UserRole.USER && this.adminFlags !== UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST
+    return this.role.id === UserRole.USER && this.adminFlags !== UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST
   }
 }