1 import { Account } from '@app/shared/shared-main/account/account.model'
2 import { hasUserRight } from '@shared/core-utils/users'
7 User as UserServerModel,
9 UserNotificationSetting,
13 } from '@shared/models'
15 export class User implements UserServerModel {
19 pendingEmail: string | null
21 emailVerified: boolean
22 nsfwPolicy: NSFWPolicyType
24 adminFlags?: UserAdminFlag
26 autoPlayVideo: boolean
27 autoPlayNextVideo: boolean
28 autoPlayNextVideoPlaylist: boolean
31 // FIXME: deprecated in 4.1
32 webTorrentEnabled: never
34 videosHistoryEnabled: boolean
35 videoLanguages: string[]
43 videoQuotaDaily: number
44 videoQuotaUsed?: number
45 videoQuotaUsedDaily?: number
48 videoCommentsCount?: number
51 abusesAcceptedCount?: number
52 abusesCreatedCount?: number
57 notificationSettings?: UserNotificationSetting
58 videoChannels?: VideoChannel[]
61 blockedReason?: string
63 noInstanceConfigWarningModal: boolean
64 noWelcomeModal: boolean
65 noAccountSetupWarningModal: boolean
67 pluginAuth: string | null
69 lastLoginDate: Date | null
71 twoFactorEnabled: boolean
75 constructor (hash: Partial<UserServerModel>) {
77 this.username = hash.username
78 this.email = hash.email
82 this.videoChannels = hash.videoChannels
84 this.videoQuota = hash.videoQuota
85 this.videoQuotaDaily = hash.videoQuotaDaily
86 this.videoQuotaUsed = hash.videoQuotaUsed
87 this.videoQuotaUsedDaily = hash.videoQuotaUsedDaily
88 this.videosCount = hash.videosCount
89 this.abusesCount = hash.abusesCount
90 this.abusesAcceptedCount = hash.abusesAcceptedCount
91 this.abusesCreatedCount = hash.abusesCreatedCount
92 this.videoCommentsCount = hash.videoCommentsCount
94 this.nsfwPolicy = hash.nsfwPolicy
95 this.p2pEnabled = hash.p2pEnabled
96 this.autoPlayVideo = hash.autoPlayVideo
97 this.autoPlayNextVideo = hash.autoPlayNextVideo
98 this.autoPlayNextVideoPlaylist = hash.autoPlayNextVideoPlaylist
99 this.videosHistoryEnabled = hash.videosHistoryEnabled
100 this.videoLanguages = hash.videoLanguages
102 this.theme = hash.theme
104 this.adminFlags = hash.adminFlags
106 this.blocked = hash.blocked
107 this.blockedReason = hash.blockedReason
109 this.noInstanceConfigWarningModal = hash.noInstanceConfigWarningModal
110 this.noWelcomeModal = hash.noWelcomeModal
111 this.noAccountSetupWarningModal = hash.noAccountSetupWarningModal
113 this.notificationSettings = hash.notificationSettings
115 this.twoFactorEnabled = hash.twoFactorEnabled
117 this.createdAt = hash.createdAt
119 this.pluginAuth = hash.pluginAuth
120 this.lastLoginDate = hash.lastLoginDate
122 if (hash.account !== undefined) {
123 this.account = new Account(hash.account)
127 hasRight (right: UserRight) {
128 return hasUserRight(this.role.id, right)
131 patch (obj: UserServerModel) {
132 for (const key of Object.keys(obj)) {
136 if (obj.account !== undefined) {
137 this.account = new Account(obj.account)
141 updateAccountAvatar (newAccountAvatars?: ActorImage[]) {
142 if (newAccountAvatars) this.account.updateAvatar(newAccountAvatars)
143 else this.account.resetAvatar()
146 isUploadDisabled () {
147 return this.videoQuota === 0 || this.videoQuotaDaily === 0
150 isAutoBlocked (serverConfig: HTMLServerConfig) {
151 if (serverConfig.autoBlacklist.videos.ofUsers.enabled !== true) return false
153 return this.role.id === UserRole.USER && this.adminFlags !== UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST