1 import { Component, OnInit } from '@angular/core'
2 import { AuthService, ScreenService } 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
20 get isBroadcastMessageDisplayed () {
21 return this.screen.isBroadcastMessageDisplayed
25 this.buildOverviewItems()
26 this.buildFederationItems()
27 this.buildModerationItems()
28 this.buildConfigurationItems()
29 this.buildPluginItems()
30 this.buildSystemItems()
33 private buildOverviewItems () {
34 if (this.hasUsersRight()) {
35 this.menuEntries.push({ label: $localize`Users`, routerLink: '/admin/users' })
39 private buildFederationItems () {
40 if (!this.hasServerFollowRight()) return
42 this.menuEntries.push({
43 label: $localize`Federation`,
46 label: $localize`Following`,
47 routerLink: '/admin/follows/following-list',
51 label: $localize`Followers`,
52 routerLink: '/admin/follows/followers-list',
56 label: $localize`Video redundancies`,
57 routerLink: '/admin/follows/video-redundancies-list',
64 private buildModerationItems () {
65 const moderationItems: TopMenuDropdownParam = {
66 label: $localize`Moderation`,
70 if (this.hasAbusesRight()) {
71 moderationItems.children.push({
72 label: $localize`Reports`,
73 routerLink: '/admin/moderation/abuses/list',
78 if (this.hasVideoBlocklistRight()) {
79 moderationItems.children.push({
80 label: $localize`Video blocks`,
81 routerLink: '/admin/moderation/video-blocks/list',
86 if (this.hasVideoCommentsRight()) {
87 moderationItems.children.push({
88 label: $localize`Video comments`,
89 routerLink: '/admin/moderation/video-comments/list',
90 iconName: 'message-circle'
94 if (this.hasAccountsBlocklistRight()) {
95 moderationItems.children.push({
96 label: $localize`Muted accounts`,
97 routerLink: '/admin/moderation/blocklist/accounts',
102 if (this.hasServersBlocklistRight()) {
103 moderationItems.children.push({
104 label: $localize`Muted servers`,
105 routerLink: '/admin/moderation/blocklist/servers',
106 iconName: 'peertube-x'
110 if (moderationItems.children.length !== 0) this.menuEntries.push(moderationItems)
113 private buildConfigurationItems () {
114 if (this.hasConfigRight()) {
115 this.menuEntries.push({ label: $localize`Configuration`, routerLink: '/admin/config' })
119 private buildPluginItems () {
120 if (this.hasPluginsRight()) {
121 this.menuEntries.push({ label: $localize`Plugins/Themes`, routerLink: '/admin/plugins' })
125 private buildSystemItems () {
126 const systemItems: TopMenuDropdownParam = {
127 label: $localize`System`,
131 if (this.hasJobsRight()) {
132 systemItems.children.push({
133 label: $localize`Jobs`,
134 iconName: 'circle-tick',
135 routerLink: '/admin/system/jobs'
139 if (this.hasLogsRight()) {
140 systemItems.children.push({
141 label: $localize`Logs`,
142 iconName: 'playlists',
143 routerLink: '/admin/system/logs'
147 if (this.hasDebugRight()) {
148 systemItems.children.push({
149 label: $localize`Debug`,
151 routerLink: '/admin/system/debug'
155 if (systemItems.children.length !== 0) {
156 this.menuEntries.push(systemItems)
160 private hasUsersRight () {
161 return this.auth.getUser().hasRight(UserRight.MANAGE_USERS)
164 private hasServerFollowRight () {
165 return this.auth.getUser().hasRight(UserRight.MANAGE_SERVER_FOLLOW)
168 private hasAbusesRight () {
169 return this.auth.getUser().hasRight(UserRight.MANAGE_ABUSES)
172 private hasVideoBlocklistRight () {
173 return this.auth.getUser().hasRight(UserRight.MANAGE_VIDEO_BLACKLIST)
176 private hasAccountsBlocklistRight () {
177 return this.auth.getUser().hasRight(UserRight.MANAGE_ACCOUNTS_BLOCKLIST)
180 private hasServersBlocklistRight () {
181 return this.auth.getUser().hasRight(UserRight.MANAGE_SERVERS_BLOCKLIST)
184 private hasConfigRight () {
185 return this.auth.getUser().hasRight(UserRight.MANAGE_CONFIGURATION)
188 private hasPluginsRight () {
189 return this.auth.getUser().hasRight(UserRight.MANAGE_PLUGINS)
192 private hasLogsRight () {
193 return this.auth.getUser().hasRight(UserRight.MANAGE_LOGS)
196 private hasJobsRight () {
197 return this.auth.getUser().hasRight(UserRight.MANAGE_JOBS)
200 private hasDebugRight () {
201 return this.auth.getUser().hasRight(UserRight.MANAGE_DEBUG)
204 private hasVideoCommentsRight () {
205 return this.auth.getUser().hasRight(UserRight.SEE_ALL_COMMENTS)