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 const overviewItems: TopMenuDropdownParam = {
35 label: $localize`Overview`,
39 if (this.hasUsersRight()) {
40 overviewItems.children.push({
41 label: $localize`Users`,
42 routerLink: '/admin/users',
47 if (this.hasVideosRight()) {
48 overviewItems.children.push({
49 label: $localize`Videos`,
50 routerLink: '/admin/videos',
55 if (this.hasVideoCommentsRight()) {
56 overviewItems.children.push({
57 label: $localize`Comments`,
58 routerLink: '/admin/comments',
59 iconName: 'message-circle'
63 if (overviewItems.children.length !== 0) {
64 this.menuEntries.push(overviewItems)
68 private buildFederationItems () {
69 if (!this.hasServerFollowRight()) return
71 this.menuEntries.push({
72 label: $localize`Federation`,
75 label: $localize`Following`,
76 routerLink: '/admin/follows/following-list',
80 label: $localize`Followers`,
81 routerLink: '/admin/follows/followers-list',
85 label: $localize`Video redundancies`,
86 routerLink: '/admin/follows/video-redundancies-list',
93 private buildModerationItems () {
94 const moderationItems: TopMenuDropdownParam = {
95 label: $localize`Moderation`,
99 if (this.hasRegistrationsRight()) {
100 moderationItems.children.push({
101 label: $localize`Registrations`,
102 routerLink: '/admin/moderation/registrations/list',
107 if (this.hasAbusesRight()) {
108 moderationItems.children.push({
109 label: $localize`Reports`,
110 routerLink: '/admin/moderation/abuses/list',
115 if (this.hasVideoBlocklistRight()) {
116 moderationItems.children.push({
117 label: $localize`Video blocks`,
118 routerLink: '/admin/moderation/video-blocks/list',
123 if (this.hasAccountsBlocklistRight()) {
124 moderationItems.children.push({
125 label: $localize`Muted accounts`,
126 routerLink: '/admin/moderation/blocklist/accounts',
131 if (this.hasServersBlocklistRight()) {
132 moderationItems.children.push({
133 label: $localize`Muted servers`,
134 routerLink: '/admin/moderation/blocklist/servers',
135 iconName: 'peertube-x'
139 if (moderationItems.children.length !== 0) this.menuEntries.push(moderationItems)
142 private buildConfigurationItems () {
143 if (this.hasConfigRight()) {
144 this.menuEntries.push({ label: $localize`Configuration`, routerLink: '/admin/config' })
148 private buildPluginItems () {
149 if (this.hasPluginsRight()) {
150 this.menuEntries.push({ label: $localize`Plugins/Themes`, routerLink: '/admin/plugins' })
154 private buildSystemItems () {
155 const systemItems: TopMenuDropdownParam = {
156 label: $localize`System`,
160 if (this.hasJobsRight()) {
161 systemItems.children.push({
162 label: $localize`Jobs`,
163 iconName: 'circle-tick',
164 routerLink: '/admin/system/jobs'
168 if (this.hasLogsRight()) {
169 systemItems.children.push({
170 label: $localize`Logs`,
171 iconName: 'playlists',
172 routerLink: '/admin/system/logs'
176 if (this.hasDebugRight()) {
177 systemItems.children.push({
178 label: $localize`Debug`,
180 routerLink: '/admin/system/debug'
184 if (systemItems.children.length !== 0) {
185 this.menuEntries.push(systemItems)
189 private hasUsersRight () {
190 return this.auth.getUser().hasRight(UserRight.MANAGE_USERS)
193 private hasServerFollowRight () {
194 return this.auth.getUser().hasRight(UserRight.MANAGE_SERVER_FOLLOW)
197 private hasAbusesRight () {
198 return this.auth.getUser().hasRight(UserRight.MANAGE_ABUSES)
201 private hasVideoBlocklistRight () {
202 return this.auth.getUser().hasRight(UserRight.MANAGE_VIDEO_BLACKLIST)
205 private hasAccountsBlocklistRight () {
206 return this.auth.getUser().hasRight(UserRight.MANAGE_ACCOUNTS_BLOCKLIST)
209 private hasServersBlocklistRight () {
210 return this.auth.getUser().hasRight(UserRight.MANAGE_SERVERS_BLOCKLIST)
213 private hasConfigRight () {
214 return this.auth.getUser().hasRight(UserRight.MANAGE_CONFIGURATION)
217 private hasPluginsRight () {
218 return this.auth.getUser().hasRight(UserRight.MANAGE_PLUGINS)
221 private hasLogsRight () {
222 return this.auth.getUser().hasRight(UserRight.MANAGE_LOGS)
225 private hasJobsRight () {
226 return this.auth.getUser().hasRight(UserRight.MANAGE_JOBS)
229 private hasDebugRight () {
230 return this.auth.getUser().hasRight(UserRight.MANAGE_DEBUG)
233 private hasVideoCommentsRight () {
234 return this.auth.getUser().hasRight(UserRight.SEE_ALL_COMMENTS)
237 private hasVideosRight () {
238 return this.auth.getUser().hasRight(UserRight.SEE_ALL_VIDEOS)
241 private hasRegistrationsRight () {
242 return this.auth.getUser().hasRight(UserRight.MANAGE_REGISTRATIONS)