1 import { Account } from '@app/shared/shared-main/account/account.model'
2 import { objectKeysTyped } from '@shared/core-utils'
3 import { hasUserRight } from '@shared/core-utils/users'
8 User as UserServerModel,
10 UserNotificationSetting,
14 } from '@shared/models'
16 export class User implements UserServerModel {
20 pendingEmail: string | null
22 emailVerified: boolean
24 nsfwPolicy: NSFWPolicyType
26 adminFlags?: UserAdminFlag
28 autoPlayVideo: boolean
29 autoPlayNextVideo: boolean
30 autoPlayNextVideoPlaylist: boolean
33 // FIXME: deprecated in 4.1
34 webTorrentEnabled: never
36 videosHistoryEnabled: boolean
37 videoLanguages: string[]
45 videoQuotaDaily: number
46 videoQuotaUsed?: number
47 videoQuotaUsedDaily?: number
50 videoCommentsCount?: number
53 abusesAcceptedCount?: number
54 abusesCreatedCount?: number
59 notificationSettings?: UserNotificationSetting
60 videoChannels?: VideoChannel[]
63 blockedReason?: string
65 noInstanceConfigWarningModal: boolean
66 noWelcomeModal: boolean
67 noAccountSetupWarningModal: boolean
69 pluginAuth: string | null
71 lastLoginDate: Date | null
73 twoFactorEnabled: boolean
77 constructor (hash: Partial<UserServerModel>) {
79 this.username = hash.username
80 this.email = hash.email
84 this.videoChannels = hash.videoChannels
86 this.videoQuota = hash.videoQuota
87 this.videoQuotaDaily = hash.videoQuotaDaily
88 this.videoQuotaUsed = hash.videoQuotaUsed
89 this.videoQuotaUsedDaily = hash.videoQuotaUsedDaily
90 this.videosCount = hash.videosCount
91 this.abusesCount = hash.abusesCount
92 this.abusesAcceptedCount = hash.abusesAcceptedCount
93 this.abusesCreatedCount = hash.abusesCreatedCount
94 this.videoCommentsCount = hash.videoCommentsCount
96 this.nsfwPolicy = hash.nsfwPolicy
97 this.p2pEnabled = hash.p2pEnabled
98 this.autoPlayVideo = hash.autoPlayVideo
99 this.autoPlayNextVideo = hash.autoPlayNextVideo
100 this.autoPlayNextVideoPlaylist = hash.autoPlayNextVideoPlaylist
101 this.videosHistoryEnabled = hash.videosHistoryEnabled
102 this.videoLanguages = hash.videoLanguages
104 this.theme = hash.theme
106 this.adminFlags = hash.adminFlags
108 this.blocked = hash.blocked
109 this.blockedReason = hash.blockedReason
111 this.noInstanceConfigWarningModal = hash.noInstanceConfigWarningModal
112 this.noWelcomeModal = hash.noWelcomeModal
113 this.noAccountSetupWarningModal = hash.noAccountSetupWarningModal
115 this.notificationSettings = hash.notificationSettings
117 this.twoFactorEnabled = hash.twoFactorEnabled
119 this.createdAt = hash.createdAt
121 this.pluginAuth = hash.pluginAuth
122 this.lastLoginDate = hash.lastLoginDate
124 if (hash.account !== undefined) {
125 this.account = new Account(hash.account)
129 hasRight (right: UserRight) {
130 return hasUserRight(this.role.id, right)
133 patch (obj: UserServerModel) {
134 for (const key of objectKeysTyped(obj)) {
136 (this as any)[key] = obj[key]
139 if (obj.account !== undefined) {
140 this.account = new Account(obj.account)
144 updateAccountAvatar (newAccountAvatars?: ActorImage[]) {
145 if (newAccountAvatars) this.account.updateAvatar(newAccountAvatars)
146 else this.account.resetAvatar()
149 isUploadDisabled () {
150 return this.videoQuota === 0 || this.videoQuotaDaily === 0
153 isAutoBlocked (serverConfig: HTMLServerConfig) {
154 if (serverConfig.autoBlacklist.videos.ofUsers.enabled !== true) return false
156 return this.role.id === UserRole.USER && this.adminFlags !== UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST