]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/core/users/user.model.ts
Fix NSFW filter and add tests
[github/Chocobozzz/PeerTube.git] / client / src / app / core / users / user.model.ts
1 import { Account } from '@app/shared/shared-main/account/account.model'
2 import { hasUserRight } from '@shared/core-utils/users'
3 import {
4 ActorImage,
5 NSFWPolicyType,
6 User as UserServerModel,
7 UserAdminFlag,
8 UserNotificationSetting,
9 UserRight,
10 UserRole,
11 VideoChannel
12 } from '@shared/models'
13
14 export class User implements UserServerModel {
15 id: number
16 username: string
17 email: string
18 pendingEmail: string | null
19
20 emailVerified: boolean
21 nsfwPolicy: NSFWPolicyType
22
23 adminFlags?: UserAdminFlag
24
25 autoPlayVideo: boolean
26 autoPlayNextVideo: boolean
27 autoPlayNextVideoPlaylist: boolean
28 webTorrentEnabled: boolean
29 videosHistoryEnabled: boolean
30 videoLanguages: string[]
31
32 role: UserRole
33 roleLabel: string
34
35 videoQuota: number
36 videoQuotaDaily: number
37 videoQuotaUsed?: number
38 videoQuotaUsedDaily?: number
39
40 videosCount?: number
41 videoCommentsCount?: number
42
43 abusesCount?: number
44 abusesAcceptedCount?: number
45 abusesCreatedCount?: number
46
47 theme: string
48
49 account: Account
50 notificationSettings?: UserNotificationSetting
51 videoChannels?: VideoChannel[]
52
53 blocked: boolean
54 blockedReason?: string
55
56 noInstanceConfigWarningModal: boolean
57 noWelcomeModal: boolean
58 noAccountSetupWarningModal: boolean
59
60 pluginAuth: string | null
61
62 lastLoginDate: Date | null
63
64 createdAt: Date
65
66 constructor (hash: Partial<UserServerModel>) {
67 this.id = hash.id
68 this.username = hash.username
69 this.email = hash.email
70
71 this.role = hash.role
72
73 this.videoChannels = hash.videoChannels
74
75 this.videoQuota = hash.videoQuota
76 this.videoQuotaDaily = hash.videoQuotaDaily
77 this.videoQuotaUsed = hash.videoQuotaUsed
78 this.videoQuotaUsedDaily = hash.videoQuotaUsedDaily
79 this.videosCount = hash.videosCount
80 this.abusesCount = hash.abusesCount
81 this.abusesAcceptedCount = hash.abusesAcceptedCount
82 this.abusesCreatedCount = hash.abusesCreatedCount
83 this.videoCommentsCount = hash.videoCommentsCount
84
85 this.nsfwPolicy = hash.nsfwPolicy
86 this.webTorrentEnabled = hash.webTorrentEnabled
87 this.autoPlayVideo = hash.autoPlayVideo
88 this.autoPlayNextVideo = hash.autoPlayNextVideo
89 this.autoPlayNextVideoPlaylist = hash.autoPlayNextVideoPlaylist
90 this.videosHistoryEnabled = hash.videosHistoryEnabled
91 this.videoLanguages = hash.videoLanguages
92
93 this.theme = hash.theme
94
95 this.adminFlags = hash.adminFlags
96
97 this.blocked = hash.blocked
98 this.blockedReason = hash.blockedReason
99
100 this.noInstanceConfigWarningModal = hash.noInstanceConfigWarningModal
101 this.noWelcomeModal = hash.noWelcomeModal
102 this.noAccountSetupWarningModal = hash.noAccountSetupWarningModal
103
104 this.notificationSettings = hash.notificationSettings
105
106 this.createdAt = hash.createdAt
107
108 this.pluginAuth = hash.pluginAuth
109 this.lastLoginDate = hash.lastLoginDate
110
111 if (hash.account !== undefined) {
112 this.account = new Account(hash.account)
113 }
114 }
115
116 hasRight (right: UserRight) {
117 return hasUserRight(this.role, right)
118 }
119
120 patch (obj: UserServerModel) {
121 for (const key of Object.keys(obj)) {
122 this[key] = obj[key]
123 }
124
125 if (obj.account !== undefined) {
126 this.account = new Account(obj.account)
127 }
128 }
129
130 updateAccountAvatar (newAccountAvatar?: ActorImage) {
131 if (newAccountAvatar) this.account.updateAvatar(newAccountAvatar)
132 else this.account.resetAvatar()
133 }
134
135 isUploadDisabled () {
136 return this.videoQuota === 0 || this.videoQuotaDaily === 0
137 }
138
139 isAutoBlocked () {
140 return this.role === UserRole.USER && this.adminFlags !== UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST
141 }
142 }