]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/admin.component.ts
Bumped to version v5.2.1
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / admin.component.ts
1 import { Component, OnInit } from '@angular/core'
2 import { AuthService, ScreenService, ServerService } from '@app/core'
3 import { ListOverflowItem } from '@app/shared/shared-main'
4 import { TopMenuDropdownParam } from '@app/shared/shared-main/misc/top-menu-dropdown.component'
5 import { UserRight } from '@shared/models'
6
7 @Component({
8 templateUrl: './admin.component.html',
9 styleUrls: [ './admin.component.scss' ]
10 })
11 export class AdminComponent implements OnInit {
12 items: ListOverflowItem[] = []
13 menuEntries: TopMenuDropdownParam[] = []
14
15 constructor (
16 private auth: AuthService,
17 private screen: ScreenService,
18 private server: ServerService
19 ) { }
20
21 get isBroadcastMessageDisplayed () {
22 return this.screen.isBroadcastMessageDisplayed
23 }
24
25 ngOnInit () {
26 this.server.configReloaded.subscribe(() => this.buildMenu())
27
28 this.buildMenu()
29 }
30
31 private buildMenu () {
32 this.menuEntries = []
33
34 this.buildOverviewItems()
35 this.buildFederationItems()
36 this.buildModerationItems()
37 this.buildConfigurationItems()
38 this.buildPluginItems()
39 this.buildSystemItems()
40 }
41
42 private buildOverviewItems () {
43 const overviewItems: TopMenuDropdownParam = {
44 label: $localize`Overview`,
45 children: []
46 }
47
48 if (this.hasUsersRight()) {
49 overviewItems.children.push({
50 label: $localize`Users`,
51 routerLink: '/admin/users',
52 iconName: 'user'
53 })
54 }
55
56 if (this.hasVideosRight()) {
57 overviewItems.children.push({
58 label: $localize`Videos`,
59 routerLink: '/admin/videos',
60 iconName: 'videos'
61 })
62 }
63
64 if (this.hasVideoCommentsRight()) {
65 overviewItems.children.push({
66 label: $localize`Comments`,
67 routerLink: '/admin/comments',
68 iconName: 'message-circle'
69 })
70 }
71
72 if (overviewItems.children.length !== 0) {
73 this.menuEntries.push(overviewItems)
74 }
75 }
76
77 private buildFederationItems () {
78 if (!this.hasServerFollowRight()) return
79
80 this.menuEntries.push({
81 label: $localize`Federation`,
82 children: [
83 {
84 label: $localize`Following`,
85 routerLink: '/admin/follows/following-list',
86 iconName: 'following'
87 },
88 {
89 label: $localize`Followers`,
90 routerLink: '/admin/follows/followers-list',
91 iconName: 'follower'
92 },
93 {
94 label: $localize`Video redundancies`,
95 routerLink: '/admin/follows/video-redundancies-list',
96 iconName: 'videos'
97 }
98 ]
99 })
100 }
101
102 private buildModerationItems () {
103 const moderationItems: TopMenuDropdownParam = {
104 label: $localize`Moderation`,
105 children: []
106 }
107
108 if (this.hasRegistrationsRight()) {
109 moderationItems.children.push({
110 label: $localize`Registrations`,
111 routerLink: '/admin/moderation/registrations/list',
112 iconName: 'user'
113 })
114 }
115
116 if (this.hasAbusesRight()) {
117 moderationItems.children.push({
118 label: $localize`Reports`,
119 routerLink: '/admin/moderation/abuses/list',
120 iconName: 'flag'
121 })
122 }
123
124 if (this.hasVideoBlocklistRight()) {
125 moderationItems.children.push({
126 label: $localize`Video blocks`,
127 routerLink: '/admin/moderation/video-blocks/list',
128 iconName: 'cross'
129 })
130 }
131
132 if (this.hasAccountsBlocklistRight()) {
133 moderationItems.children.push({
134 label: $localize`Muted accounts`,
135 routerLink: '/admin/moderation/blocklist/accounts',
136 iconName: 'user-x'
137 })
138 }
139
140 if (this.hasServersBlocklistRight()) {
141 moderationItems.children.push({
142 label: $localize`Muted servers`,
143 routerLink: '/admin/moderation/blocklist/servers',
144 iconName: 'peertube-x'
145 })
146 }
147
148 if (moderationItems.children.length !== 0) this.menuEntries.push(moderationItems)
149 }
150
151 private buildConfigurationItems () {
152 if (this.hasConfigRight()) {
153 this.menuEntries.push({ label: $localize`Configuration`, routerLink: '/admin/config' })
154 }
155 }
156
157 private buildPluginItems () {
158 if (this.hasPluginsRight()) {
159 this.menuEntries.push({ label: $localize`Plugins/Themes`, routerLink: '/admin/plugins' })
160 }
161 }
162
163 private buildSystemItems () {
164 const systemItems: TopMenuDropdownParam = {
165 label: $localize`System`,
166 children: []
167 }
168
169 if (this.isRemoteRunnersEnabled() && this.hasRunnersRight()) {
170 systemItems.children.push({
171 label: $localize`Remote runners`,
172 iconName: 'codesandbox',
173 routerLink: '/admin/system/runners/runners-list'
174 })
175
176 systemItems.children.push({
177 label: $localize`Runner jobs`,
178 iconName: 'globe',
179 routerLink: '/admin/system/runners/jobs-list'
180 })
181 }
182
183 if (this.hasJobsRight()) {
184 systemItems.children.push({
185 label: $localize`Local jobs`,
186 iconName: 'circle-tick',
187 routerLink: '/admin/system/jobs'
188 })
189 }
190
191 if (this.hasLogsRight()) {
192 systemItems.children.push({
193 label: $localize`Logs`,
194 iconName: 'playlists',
195 routerLink: '/admin/system/logs'
196 })
197 }
198
199 if (this.hasDebugRight()) {
200 systemItems.children.push({
201 label: $localize`Debug`,
202 iconName: 'cog',
203 routerLink: '/admin/system/debug'
204 })
205 }
206
207 if (systemItems.children.length !== 0) {
208 this.menuEntries.push(systemItems)
209 }
210 }
211
212 private hasUsersRight () {
213 return this.auth.getUser().hasRight(UserRight.MANAGE_USERS)
214 }
215
216 private hasServerFollowRight () {
217 return this.auth.getUser().hasRight(UserRight.MANAGE_SERVER_FOLLOW)
218 }
219
220 private hasAbusesRight () {
221 return this.auth.getUser().hasRight(UserRight.MANAGE_ABUSES)
222 }
223
224 private hasVideoBlocklistRight () {
225 return this.auth.getUser().hasRight(UserRight.MANAGE_VIDEO_BLACKLIST)
226 }
227
228 private hasAccountsBlocklistRight () {
229 return this.auth.getUser().hasRight(UserRight.MANAGE_ACCOUNTS_BLOCKLIST)
230 }
231
232 private hasServersBlocklistRight () {
233 return this.auth.getUser().hasRight(UserRight.MANAGE_SERVERS_BLOCKLIST)
234 }
235
236 private hasConfigRight () {
237 return this.auth.getUser().hasRight(UserRight.MANAGE_CONFIGURATION)
238 }
239
240 private hasPluginsRight () {
241 return this.auth.getUser().hasRight(UserRight.MANAGE_PLUGINS)
242 }
243
244 private hasLogsRight () {
245 return this.auth.getUser().hasRight(UserRight.MANAGE_LOGS)
246 }
247
248 private hasJobsRight () {
249 return this.auth.getUser().hasRight(UserRight.MANAGE_JOBS)
250 }
251
252 private hasRunnersRight () {
253 return this.auth.getUser().hasRight(UserRight.MANAGE_RUNNERS)
254 }
255
256 private hasDebugRight () {
257 return this.auth.getUser().hasRight(UserRight.MANAGE_DEBUG)
258 }
259
260 private hasVideoCommentsRight () {
261 return this.auth.getUser().hasRight(UserRight.SEE_ALL_COMMENTS)
262 }
263
264 private hasVideosRight () {
265 return this.auth.getUser().hasRight(UserRight.SEE_ALL_VIDEOS)
266 }
267
268 private hasRegistrationsRight () {
269 return this.auth.getUser().hasRight(UserRight.MANAGE_REGISTRATIONS)
270 }
271
272 private isRemoteRunnersEnabled () {
273 const config = this.server.getHTMLConfig()
274
275 return config.transcoding.remoteRunners.enabled ||
276 config.live.transcoding.remoteRunners.enabled ||
277 config.videoStudio.remoteRunners.enabled
278 }
279 }