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
23 nsfwPolicy: NSFWPolicyType
25 adminFlags?: UserAdminFlag
27 autoPlayVideo: boolean
28 autoPlayNextVideo: boolean
29 autoPlayNextVideoPlaylist: boolean
32 // FIXME: deprecated in 4.1
33 webTorrentEnabled: never
35 videosHistoryEnabled: boolean
36 videoLanguages: string[]
44 videoQuotaDaily: number
45 videoQuotaUsed?: number
46 videoQuotaUsedDaily?: number
49 videoCommentsCount?: number
52 abusesAcceptedCount?: number
53 abusesCreatedCount?: number
58 notificationSettings?: UserNotificationSetting
59 videoChannels?: VideoChannel[]
62 blockedReason?: string
64 noInstanceConfigWarningModal: boolean
65 noWelcomeModal: boolean
66 noAccountSetupWarningModal: boolean
68 pluginAuth: string | null
70 lastLoginDate: Date | null
72 twoFactorEnabled: boolean
76 constructor (hash: Partial<UserServerModel>) {
78 this.username = hash.username
79 this.email = hash.email
83 this.videoChannels = hash.videoChannels
85 this.videoQuota = hash.videoQuota
86 this.videoQuotaDaily = hash.videoQuotaDaily
87 this.videoQuotaUsed = hash.videoQuotaUsed
88 this.videoQuotaUsedDaily = hash.videoQuotaUsedDaily
89 this.videosCount = hash.videosCount
90 this.abusesCount = hash.abusesCount
91 this.abusesAcceptedCount = hash.abusesAcceptedCount
92 this.abusesCreatedCount = hash.abusesCreatedCount
93 this.videoCommentsCount = hash.videoCommentsCount
95 this.nsfwPolicy = hash.nsfwPolicy
96 this.p2pEnabled = hash.p2pEnabled
97 this.autoPlayVideo = hash.autoPlayVideo
98 this.autoPlayNextVideo = hash.autoPlayNextVideo
99 this.autoPlayNextVideoPlaylist = hash.autoPlayNextVideoPlaylist
100 this.videosHistoryEnabled = hash.videosHistoryEnabled
101 this.videoLanguages = hash.videoLanguages
103 this.theme = hash.theme
105 this.adminFlags = hash.adminFlags
107 this.blocked = hash.blocked
108 this.blockedReason = hash.blockedReason
110 this.noInstanceConfigWarningModal = hash.noInstanceConfigWarningModal
111 this.noWelcomeModal = hash.noWelcomeModal
112 this.noAccountSetupWarningModal = hash.noAccountSetupWarningModal
114 this.notificationSettings = hash.notificationSettings
116 this.twoFactorEnabled = hash.twoFactorEnabled
118 this.createdAt = hash.createdAt
120 this.pluginAuth = hash.pluginAuth
121 this.lastLoginDate = hash.lastLoginDate
123 if (hash.account !== undefined) {
124 this.account = new Account(hash.account)
128 hasRight (right: UserRight) {
129 return hasUserRight(this.role.id, right)
132 patch (obj: UserServerModel) {
133 for (const key of Object.keys(obj)) {
137 if (obj.account !== undefined) {
138 this.account = new Account(obj.account)
142 updateAccountAvatar (newAccountAvatars?: ActorImage[]) {
143 if (newAccountAvatars) this.account.updateAvatar(newAccountAvatars)
144 else this.account.resetAvatar()
147 isUploadDisabled () {
148 return this.videoQuota === 0 || this.videoQuotaDaily === 0
151 isAutoBlocked (serverConfig: HTMLServerConfig) {
152 if (serverConfig.autoBlacklist.videos.ofUsers.enabled !== true) return false
154 return this.role.id === UserRole.USER && this.adminFlags !== UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST