]> 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 31b9c21525a462a74276bde53bb2ea256e68cac0..d57608f1c66310b04debe4cc738b95e3f570ee8a 100644 (file)
@@ -1,7 +1,9 @@
 import { Account } from '@app/shared/shared-main/account/account.model'
+import { objectKeysTyped } from '@shared/core-utils'
+import { hasUserRight } from '@shared/core-utils/users'
 import {
-  Avatar,
-  hasUserRight,
+  ActorImage,
+  HTMLServerConfig,
   NSFWPolicyType,
   User as UserServerModel,
   UserAdminFlag,
@@ -12,27 +14,13 @@ import {
 } from '@shared/models'
 
 export class User implements UserServerModel {
-  static KEYS = {
-    ID: 'id',
-    ROLE: 'role',
-    EMAIL: 'email',
-    VIDEOS_HISTORY_ENABLED: 'videos-history-enabled',
-    USERNAME: 'username',
-    NSFW_POLICY: 'nsfw_policy',
-    WEBTORRENT_ENABLED: 'peertube-videojs-' + 'webtorrent_enabled',
-    AUTO_PLAY_VIDEO: 'auto_play_video',
-    SESSION_STORAGE_AUTO_PLAY_NEXT_VIDEO: 'auto_play_next_video',
-    AUTO_PLAY_VIDEO_PLAYLIST: 'auto_play_video_playlist',
-    THEME: 'last_active_theme',
-    VIDEO_LANGUAGES: 'video_languages'
-  }
-
   id: number
   username: string
   email: string
   pendingEmail: string | null
 
   emailVerified: boolean
+  emailPublic: boolean
   nsfwPolicy: NSFWPolicyType
 
   adminFlags?: UserAdminFlag
@@ -40,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
@@ -70,11 +64,14 @@ export class User implements UserServerModel {
 
   noInstanceConfigWarningModal: boolean
   noWelcomeModal: boolean
+  noAccountSetupWarningModal: boolean
 
   pluginAuth: string | null
 
   lastLoginDate: Date | null
 
+  twoFactorEnabled: boolean
+
   createdAt: Date
 
   constructor (hash: Partial<UserServerModel>) {
@@ -97,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
@@ -113,9 +110,12 @@ export class User implements UserServerModel {
 
     this.noInstanceConfigWarningModal = hash.noInstanceConfigWarningModal
     this.noWelcomeModal = hash.noWelcomeModal
+    this.noAccountSetupWarningModal = hash.noAccountSetupWarningModal
 
     this.notificationSettings = hash.notificationSettings
 
+    this.twoFactorEnabled = hash.twoFactorEnabled
+
     this.createdAt = hash.createdAt
 
     this.pluginAuth = hash.pluginAuth
@@ -126,19 +126,14 @@ export class User implements UserServerModel {
     }
   }
 
-  get accountAvatarUrl () {
-    if (!this.account) return ''
-
-    return this.account.avatarUrl
-  }
-
   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) {
@@ -146,7 +141,18 @@ export class User implements UserServerModel {
     }
   }
 
-  updateAccountAvatar (newAccountAvatar: Avatar) {
-    this.account.updateAvatar(newAccountAvatar)
+  updateAccountAvatar (newAccountAvatars?: ActorImage[]) {
+    if (newAccountAvatars) this.account.updateAvatar(newAccountAvatars)
+    else this.account.resetAvatar()
+  }
+
+  isUploadDisabled () {
+    return this.videoQuota === 0 || this.videoQuotaDaily === 0
+  }
+
+  isAutoBlocked (serverConfig: HTMLServerConfig) {
+    if (serverConfig.autoBlacklist.videos.ofUsers.enabled !== true) return false
+
+    return this.role.id === UserRole.USER && this.adminFlags !== UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST
   }
 }