]>
Commit | Line | Data |
---|---|---|
1 | import { Account } from '@app/shared/shared-main/account/account.model' | |
2 | import { hasUserRight } from '@shared/core-utils/users' | |
3 | import { | |
4 | ActorImage, | |
5 | HTMLServerConfig, | |
6 | NSFWPolicyType, | |
7 | User as UserServerModel, | |
8 | UserAdminFlag, | |
9 | UserNotificationSetting, | |
10 | UserRight, | |
11 | UserRole, | |
12 | VideoChannel | |
13 | } from '@shared/models' | |
14 | ||
15 | export class User implements UserServerModel { | |
16 | id: number | |
17 | username: string | |
18 | email: string | |
19 | pendingEmail: string | null | |
20 | ||
21 | emailVerified: boolean | |
22 | emailPublic: boolean | |
23 | nsfwPolicy: NSFWPolicyType | |
24 | ||
25 | adminFlags?: UserAdminFlag | |
26 | ||
27 | autoPlayVideo: boolean | |
28 | autoPlayNextVideo: boolean | |
29 | autoPlayNextVideoPlaylist: boolean | |
30 | ||
31 | p2pEnabled: boolean | |
32 | // FIXME: deprecated in 4.1 | |
33 | webTorrentEnabled: never | |
34 | ||
35 | videosHistoryEnabled: boolean | |
36 | videoLanguages: string[] | |
37 | ||
38 | role: { | |
39 | id: UserRole | |
40 | label: string | |
41 | } | |
42 | ||
43 | videoQuota: number | |
44 | videoQuotaDaily: number | |
45 | videoQuotaUsed?: number | |
46 | videoQuotaUsedDaily?: number | |
47 | ||
48 | videosCount?: number | |
49 | videoCommentsCount?: number | |
50 | ||
51 | abusesCount?: number | |
52 | abusesAcceptedCount?: number | |
53 | abusesCreatedCount?: number | |
54 | ||
55 | theme: string | |
56 | ||
57 | account: Account | |
58 | notificationSettings?: UserNotificationSetting | |
59 | videoChannels?: VideoChannel[] | |
60 | ||
61 | blocked: boolean | |
62 | blockedReason?: string | |
63 | ||
64 | noInstanceConfigWarningModal: boolean | |
65 | noWelcomeModal: boolean | |
66 | noAccountSetupWarningModal: boolean | |
67 | ||
68 | pluginAuth: string | null | |
69 | ||
70 | lastLoginDate: Date | null | |
71 | ||
72 | twoFactorEnabled: boolean | |
73 | ||
74 | createdAt: Date | |
75 | ||
76 | constructor (hash: Partial<UserServerModel>) { | |
77 | this.id = hash.id | |
78 | this.username = hash.username | |
79 | this.email = hash.email | |
80 | ||
81 | this.role = hash.role | |
82 | ||
83 | this.videoChannels = hash.videoChannels | |
84 | ||
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 | |
94 | ||
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 | |
102 | ||
103 | this.theme = hash.theme | |
104 | ||
105 | this.adminFlags = hash.adminFlags | |
106 | ||
107 | this.blocked = hash.blocked | |
108 | this.blockedReason = hash.blockedReason | |
109 | ||
110 | this.noInstanceConfigWarningModal = hash.noInstanceConfigWarningModal | |
111 | this.noWelcomeModal = hash.noWelcomeModal | |
112 | this.noAccountSetupWarningModal = hash.noAccountSetupWarningModal | |
113 | ||
114 | this.notificationSettings = hash.notificationSettings | |
115 | ||
116 | this.twoFactorEnabled = hash.twoFactorEnabled | |
117 | ||
118 | this.createdAt = hash.createdAt | |
119 | ||
120 | this.pluginAuth = hash.pluginAuth | |
121 | this.lastLoginDate = hash.lastLoginDate | |
122 | ||
123 | if (hash.account !== undefined) { | |
124 | this.account = new Account(hash.account) | |
125 | } | |
126 | } | |
127 | ||
128 | hasRight (right: UserRight) { | |
129 | return hasUserRight(this.role.id, right) | |
130 | } | |
131 | ||
132 | patch (obj: UserServerModel) { | |
133 | for (const key of Object.keys(obj)) { | |
134 | this[key] = obj[key] | |
135 | } | |
136 | ||
137 | if (obj.account !== undefined) { | |
138 | this.account = new Account(obj.account) | |
139 | } | |
140 | } | |
141 | ||
142 | updateAccountAvatar (newAccountAvatars?: ActorImage[]) { | |
143 | if (newAccountAvatars) this.account.updateAvatar(newAccountAvatars) | |
144 | else this.account.resetAvatar() | |
145 | } | |
146 | ||
147 | isUploadDisabled () { | |
148 | return this.videoQuota === 0 || this.videoQuotaDaily === 0 | |
149 | } | |
150 | ||
151 | isAutoBlocked (serverConfig: HTMLServerConfig) { | |
152 | if (serverConfig.autoBlacklist.videos.ofUsers.enabled !== true) return false | |
153 | ||
154 | return this.role.id === UserRole.USER && this.adminFlags !== UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST | |
155 | } | |
156 | } |