]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/core/users/user.model.ts
More robust quota check
[github/Chocobozzz/PeerTube.git] / client / src / app / core / users / user.model.ts
CommitLineData
67ed6552 1import { Account } from '@app/shared/shared-main/account/account.model'
bd45d503 2import { hasUserRight } from '@shared/core-utils/users'
d3217560 3import {
f4796856 4 ActorImage,
e0b1231b 5 HTMLServerConfig,
67ed6552 6 NSFWPolicyType,
d3217560 7 User as UserServerModel,
67ed6552 8 UserAdminFlag,
d3217560
RK
9 UserNotificationSetting,
10 UserRight,
67ed6552
C
11 UserRole,
12 VideoChannel
13} from '@shared/models'
69f616ab
C
14
15export class User implements UserServerModel {
df98563e
C
16 id: number
17 username: string
18 email: string
0ba5f5ba 19 pendingEmail: string | null
43d0ea7f 20
fc2ec87a 21 emailVerified: boolean
0883b324 22 nsfwPolicy: NSFWPolicyType
276d9652 23
43d0ea7f 24 adminFlags?: UserAdminFlag
1eddc9a7 25
7efe153b 26 autoPlayVideo: boolean
6aa54148 27 autoPlayNextVideo: boolean
bee29df8 28 autoPlayNextVideoPlaylist: boolean
a9bfa85d
C
29
30 p2pEnabled: boolean
31 // FIXME: deprecated in 4.1
32 webTorrentEnabled: never
33
276d9652 34 videosHistoryEnabled: boolean
3caf77d3 35 videoLanguages: string[]
276d9652 36
9e5cf66b
C
37 role: {
38 id: UserRole
39 label: string
40 }
43d0ea7f 41
b0f9f39e 42 videoQuota: number
bee0abff 43 videoQuotaDaily: number
43d0ea7f
C
44 videoQuotaUsed?: number
45 videoQuotaUsedDaily?: number
4f32032f 46
76314386 47 videosCount?: number
76314386 48 videoCommentsCount?: number
7da18e44 49
4f32032f
C
50 abusesCount?: number
51 abusesAcceptedCount?: number
52 abusesCreatedCount?: number
53
7cd4d2ba
C
54 theme: string
55
43d0ea7f
C
56 account: Account
57 notificationSettings?: UserNotificationSetting
58 videoChannels?: VideoChannel[]
1eddc9a7 59
eacb25c4
C
60 blocked: boolean
61 blockedReason?: string
62
43d0ea7f
C
63 noInstanceConfigWarningModal: boolean
64 noWelcomeModal: boolean
8f581725 65 noAccountSetupWarningModal: boolean
43d0ea7f 66
8bb71f2e
C
67 pluginAuth: string | null
68
3cc665f4
C
69 lastLoginDate: Date | null
70
d12b40fb
C
71 twoFactorEnabled: boolean
72
43d0ea7f 73 createdAt: Date
2f1548fd 74
276d9652 75 constructor (hash: Partial<UserServerModel>) {
df98563e
C
76 this.id = hash.id
77 this.username = hash.username
78 this.email = hash.email
1eddc9a7 79
df98563e 80 this.role = hash.role
ad9e39fb 81
eacb25c4 82 this.videoChannels = hash.videoChannels
43d0ea7f 83
eacb25c4 84 this.videoQuota = hash.videoQuota
bee0abff 85 this.videoQuotaDaily = hash.videoQuotaDaily
43d0ea7f
C
86 this.videoQuotaUsed = hash.videoQuotaUsed
87 this.videoQuotaUsedDaily = hash.videoQuotaUsedDaily
76314386 88 this.videosCount = hash.videosCount
4f32032f
C
89 this.abusesCount = hash.abusesCount
90 this.abusesAcceptedCount = hash.abusesAcceptedCount
91 this.abusesCreatedCount = hash.abusesCreatedCount
76314386 92 this.videoCommentsCount = hash.videoCommentsCount
43d0ea7f 93
eacb25c4 94 this.nsfwPolicy = hash.nsfwPolicy
a9bfa85d 95 this.p2pEnabled = hash.p2pEnabled
eacb25c4 96 this.autoPlayVideo = hash.autoPlayVideo
d3217560
RK
97 this.autoPlayNextVideo = hash.autoPlayNextVideo
98 this.autoPlayNextVideoPlaylist = hash.autoPlayNextVideoPlaylist
99 this.videosHistoryEnabled = hash.videosHistoryEnabled
100 this.videoLanguages = hash.videoLanguages
1eddc9a7 101
7cd4d2ba
C
102 this.theme = hash.theme
103
1eddc9a7
C
104 this.adminFlags = hash.adminFlags
105
eacb25c4
C
106 this.blocked = hash.blocked
107 this.blockedReason = hash.blockedReason
108
43d0ea7f
C
109 this.noInstanceConfigWarningModal = hash.noInstanceConfigWarningModal
110 this.noWelcomeModal = hash.noWelcomeModal
8f581725 111 this.noAccountSetupWarningModal = hash.noAccountSetupWarningModal
43d0ea7f 112
2f1548fd
C
113 this.notificationSettings = hash.notificationSettings
114
d12b40fb
C
115 this.twoFactorEnabled = hash.twoFactorEnabled
116
43d0ea7f
C
117 this.createdAt = hash.createdAt
118
8bb71f2e 119 this.pluginAuth = hash.pluginAuth
3cc665f4 120 this.lastLoginDate = hash.lastLoginDate
8bb71f2e 121
ad9e39fb
C
122 if (hash.account !== undefined) {
123 this.account = new Account(hash.account)
124 }
52d9f792
C
125 }
126
954605a8 127 hasRight (right: UserRight) {
9e5cf66b 128 return hasUserRight(this.role.id, right)
7da18e44 129 }
2295ce6c 130
ce5496d6
C
131 patch (obj: UserServerModel) {
132 for (const key of Object.keys(obj)) {
133 this[key] = obj[key]
134 }
d3e91a5f 135
ad9e39fb
C
136 if (obj.account !== undefined) {
137 this.account = new Account(obj.account)
138 }
d3e91a5f
C
139 }
140
d0800f76 141 updateAccountAvatar (newAccountAvatars?: ActorImage[]) {
142 if (newAccountAvatars) this.account.updateAvatar(newAccountAvatars)
1ea7da81 143 else this.account.resetAvatar()
ce5496d6 144 }
dfe3f7b7
K
145
146 isUploadDisabled () {
147 return this.videoQuota === 0 || this.videoQuotaDaily === 0
148 }
4e1592da 149
e0b1231b
C
150 isAutoBlocked (serverConfig: HTMLServerConfig) {
151 if (serverConfig.autoBlacklist.videos.ofUsers.enabled !== true) return false
152
9e5cf66b 153 return this.role.id === UserRole.USER && this.adminFlags !== UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST
4e1592da 154 }
7da18e44 155}