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[]
41 videoQuotaDaily: number
42 videoQuotaUsed?: number
43 videoQuotaUsedDaily?: number
46 videoCommentsCount?: number
49 abusesAcceptedCount?: number
50 abusesCreatedCount?: number
55 notificationSettings?: UserNotificationSetting
56 videoChannels?: VideoChannel[]
59 blockedReason?: string
61 noInstanceConfigWarningModal: boolean
62 noWelcomeModal: boolean
63 noAccountSetupWarningModal: boolean
65 pluginAuth: string | null
67 lastLoginDate: Date | null
69 twoFactorEnabled: boolean
73 constructor (hash: Partial<UserServerModel>) {
75 this.username = hash.username
76 this.email = hash.email
80 this.videoChannels = hash.videoChannels
82 this.videoQuota = hash.videoQuota
83 this.videoQuotaDaily = hash.videoQuotaDaily
84 this.videoQuotaUsed = hash.videoQuotaUsed
85 this.videoQuotaUsedDaily = hash.videoQuotaUsedDaily
86 this.videosCount = hash.videosCount
87 this.abusesCount = hash.abusesCount
88 this.abusesAcceptedCount = hash.abusesAcceptedCount
89 this.abusesCreatedCount = hash.abusesCreatedCount
90 this.videoCommentsCount = hash.videoCommentsCount
92 this.nsfwPolicy = hash.nsfwPolicy
93 this.p2pEnabled = hash.p2pEnabled
94 this.autoPlayVideo = hash.autoPlayVideo
95 this.autoPlayNextVideo = hash.autoPlayNextVideo
96 this.autoPlayNextVideoPlaylist = hash.autoPlayNextVideoPlaylist
97 this.videosHistoryEnabled = hash.videosHistoryEnabled
98 this.videoLanguages = hash.videoLanguages
100 this.theme = hash.theme
102 this.adminFlags = hash.adminFlags
104 this.blocked = hash.blocked
105 this.blockedReason = hash.blockedReason
107 this.noInstanceConfigWarningModal = hash.noInstanceConfigWarningModal
108 this.noWelcomeModal = hash.noWelcomeModal
109 this.noAccountSetupWarningModal = hash.noAccountSetupWarningModal
111 this.notificationSettings = hash.notificationSettings
113 this.twoFactorEnabled = hash.twoFactorEnabled
115 this.createdAt = hash.createdAt
117 this.pluginAuth = hash.pluginAuth
118 this.lastLoginDate = hash.lastLoginDate
120 if (hash.account !== undefined) {
121 this.account = new Account(hash.account)
125 hasRight (right: UserRight) {
126 return hasUserRight(this.role, right)
129 patch (obj: UserServerModel) {
130 for (const key of Object.keys(obj)) {
134 if (obj.account !== undefined) {
135 this.account = new Account(obj.account)
139 updateAccountAvatar (newAccountAvatars?: ActorImage[]) {
140 if (newAccountAvatars) this.account.updateAvatar(newAccountAvatars)
141 else this.account.resetAvatar()
144 isUploadDisabled () {
145 return this.videoQuota === 0 || this.videoQuotaDaily === 0
148 isAutoBlocked (serverConfig: HTMLServerConfig) {
149 if (serverConfig.autoBlacklist.videos.ofUsers.enabled !== true) return false
151 return this.role === UserRole.USER && this.adminFlags !== UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST