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