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'
8 templateUrl: './admin.component.html',
9 styleUrls: [ './admin.component.scss' ]
11 export class AdminComponent implements OnInit {
12 items: ListOverflowItem[] = []
13 menuEntries: TopMenuDropdownParam[] = []
16 private auth: AuthService,
17 private screen: ScreenService,
18 private server: ServerService
21 get isBroadcastMessageDisplayed () {
22 return this.screen.isBroadcastMessageDisplayed
26 this.server.configReloaded.subscribe(() => this.buildMenu())
31 private buildMenu () {
34 this.buildOverviewItems()
35 this.buildFederationItems()
36 this.buildModerationItems()
37 this.buildConfigurationItems()
38 this.buildPluginItems()
39 this.buildSystemItems()
42 private buildOverviewItems () {
43 const overviewItems: TopMenuDropdownParam = {
44 label: $localize`Overview`,
48 if (this.hasUsersRight()) {
49 overviewItems.children.push({
50 label: $localize`Users`,
51 routerLink: '/admin/users',
56 if (this.hasVideosRight()) {
57 overviewItems.children.push({
58 label: $localize`Videos`,
59 routerLink: '/admin/videos',
64 if (this.hasVideoCommentsRight()) {
65 overviewItems.children.push({
66 label: $localize`Comments`,
67 routerLink: '/admin/comments',
68 iconName: 'message-circle'
72 if (overviewItems.children.length !== 0) {
73 this.menuEntries.push(overviewItems)
77 private buildFederationItems () {
78 if (!this.hasServerFollowRight()) return
80 this.menuEntries.push({
81 label: $localize`Federation`,
84 label: $localize`Following`,
85 routerLink: '/admin/follows/following-list',
89 label: $localize`Followers`,
90 routerLink: '/admin/follows/followers-list',
94 label: $localize`Video redundancies`,
95 routerLink: '/admin/follows/video-redundancies-list',
102 private buildModerationItems () {
103 const moderationItems: TopMenuDropdownParam = {
104 label: $localize`Moderation`,
108 if (this.hasRegistrationsRight()) {
109 moderationItems.children.push({
110 label: $localize`Registrations`,
111 routerLink: '/admin/moderation/registrations/list',
116 if (this.hasAbusesRight()) {
117 moderationItems.children.push({
118 label: $localize`Reports`,
119 routerLink: '/admin/moderation/abuses/list',
124 if (this.hasVideoBlocklistRight()) {
125 moderationItems.children.push({
126 label: $localize`Video blocks`,
127 routerLink: '/admin/moderation/video-blocks/list',
132 if (this.hasAccountsBlocklistRight()) {
133 moderationItems.children.push({
134 label: $localize`Muted accounts`,
135 routerLink: '/admin/moderation/blocklist/accounts',
140 if (this.hasServersBlocklistRight()) {
141 moderationItems.children.push({
142 label: $localize`Muted servers`,
143 routerLink: '/admin/moderation/blocklist/servers',
144 iconName: 'peertube-x'
148 if (moderationItems.children.length !== 0) this.menuEntries.push(moderationItems)
151 private buildConfigurationItems () {
152 if (this.hasConfigRight()) {
153 this.menuEntries.push({ label: $localize`Configuration`, routerLink: '/admin/config' })
157 private buildPluginItems () {
158 if (this.hasPluginsRight()) {
159 this.menuEntries.push({ label: $localize`Plugins/Themes`, routerLink: '/admin/plugins' })
163 private buildSystemItems () {
164 const systemItems: TopMenuDropdownParam = {
165 label: $localize`System`,
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'
176 systemItems.children.push({
177 label: $localize`Runner jobs`,
179 routerLink: '/admin/system/runners/jobs-list'
183 if (this.hasJobsRight()) {
184 systemItems.children.push({
185 label: $localize`Local jobs`,
186 iconName: 'circle-tick',
187 routerLink: '/admin/system/jobs'
191 if (this.hasLogsRight()) {
192 systemItems.children.push({
193 label: $localize`Logs`,
194 iconName: 'playlists',
195 routerLink: '/admin/system/logs'
199 if (this.hasDebugRight()) {
200 systemItems.children.push({
201 label: $localize`Debug`,
203 routerLink: '/admin/system/debug'
207 if (systemItems.children.length !== 0) {
208 this.menuEntries.push(systemItems)
212 private hasUsersRight () {
213 return this.auth.getUser().hasRight(UserRight.MANAGE_USERS)
216 private hasServerFollowRight () {
217 return this.auth.getUser().hasRight(UserRight.MANAGE_SERVER_FOLLOW)
220 private hasAbusesRight () {
221 return this.auth.getUser().hasRight(UserRight.MANAGE_ABUSES)
224 private hasVideoBlocklistRight () {
225 return this.auth.getUser().hasRight(UserRight.MANAGE_VIDEO_BLACKLIST)
228 private hasAccountsBlocklistRight () {
229 return this.auth.getUser().hasRight(UserRight.MANAGE_ACCOUNTS_BLOCKLIST)
232 private hasServersBlocklistRight () {
233 return this.auth.getUser().hasRight(UserRight.MANAGE_SERVERS_BLOCKLIST)
236 private hasConfigRight () {
237 return this.auth.getUser().hasRight(UserRight.MANAGE_CONFIGURATION)
240 private hasPluginsRight () {
241 return this.auth.getUser().hasRight(UserRight.MANAGE_PLUGINS)
244 private hasLogsRight () {
245 return this.auth.getUser().hasRight(UserRight.MANAGE_LOGS)
248 private hasJobsRight () {
249 return this.auth.getUser().hasRight(UserRight.MANAGE_JOBS)
252 private hasRunnersRight () {
253 return this.auth.getUser().hasRight(UserRight.MANAGE_RUNNERS)
256 private hasDebugRight () {
257 return this.auth.getUser().hasRight(UserRight.MANAGE_DEBUG)
260 private hasVideoCommentsRight () {
261 return this.auth.getUser().hasRight(UserRight.SEE_ALL_COMMENTS)
264 private hasVideosRight () {
265 return this.auth.getUser().hasRight(UserRight.SEE_ALL_VIDEOS)
268 private hasRegistrationsRight () {
269 return this.auth.getUser().hasRight(UserRight.MANAGE_REGISTRATIONS)
272 private isRemoteRunnersEnabled () {
273 const config = this.server.getHTMLConfig()
275 return config.transcoding.remoteRunners.enabled ||
276 config.live.transcoding.remoteRunners.enabled ||
277 config.videoStudio.remoteRunners.enabled