]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/admin.component.ts
Admin menu header consistency for system entries
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / admin.component.ts
CommitLineData
24e7916c 1import { Component, OnInit } from '@angular/core'
7034b3c9 2import { AuthService, ScreenService } from '@app/core'
67ed6552 3import { ListOverflowItem } from '@app/shared/shared-main'
0a4cb95c 4import { TopMenuDropdownParam } from '@app/shared/shared-main/misc/top-menu-dropdown.component'
66357162 5import { UserRight } from '@shared/models'
7da18e44
C
6
7@Component({
0a4cb95c
RK
8 templateUrl: './admin.component.html',
9 styleUrls: [ './admin.component.scss' ]
7da18e44 10})
24e7916c
RK
11export class AdminComponent implements OnInit {
12 items: ListOverflowItem[] = []
0a4cb95c 13 menuEntries: TopMenuDropdownParam[] = []
24e7916c
RK
14
15 constructor (
16 private auth: AuthService,
66357162 17 private screen: ScreenService
7034b3c9 18 ) { }
19
20 get isBroadcastMessageDisplayed () {
21 return this.screen.isBroadcastMessageDisplayed
22 }
24e7916c
RK
23
24 ngOnInit () {
dbb76162
C
25 this.buildOverviewItems()
26 this.buildFederationItems()
27 this.buildModerationItems()
28 this.buildConfigurationItems()
29 this.buildPluginItems()
30 this.buildSystemItems()
31 }
32
33 private buildOverviewItems () {
34 if (this.hasUsersRight()) {
35 this.menuEntries.push({ label: $localize`Users`, routerLink: '/admin/users' })
36 }
37 }
38
39 private buildFederationItems () {
40 if (!this.hasServerFollowRight()) return
41
42 this.menuEntries.push({
66357162 43 label: $localize`Federation`,
0a4cb95c
RK
44 children: [
45 {
4d029ef8 46 label: $localize`Following`,
57e56eb2 47 routerLink: '/admin/follows/following-list',
ea7337cf 48 iconName: 'following'
0a4cb95c
RK
49 },
50 {
4d029ef8 51 label: $localize`Followers`,
57e56eb2 52 routerLink: '/admin/follows/followers-list',
ea7337cf 53 iconName: 'follower'
0a4cb95c
RK
54 },
55 {
66357162 56 label: $localize`Video redundancies`,
57e56eb2 57 routerLink: '/admin/follows/video-redundancies-list',
0a4cb95c
RK
58 iconName: 'videos'
59 }
60 ]
dbb76162
C
61 })
62 }
0a4cb95c 63
dbb76162 64 private buildModerationItems () {
0a4cb95c 65 const moderationItems: TopMenuDropdownParam = {
66357162 66 label: $localize`Moderation`,
0a4cb95c
RK
67 children: []
68 }
57e56eb2 69
4f32032f 70 if (this.hasAbusesRight()) {
57e56eb2 71 moderationItems.children.push({
66357162 72 label: $localize`Reports`,
8ca56654 73 routerLink: '/admin/moderation/abuses/list',
57e56eb2
C
74 iconName: 'flag'
75 })
76 }
dbb76162 77
57e56eb2
C
78 if (this.hasVideoBlocklistRight()) {
79 moderationItems.children.push({
66357162 80 label: $localize`Video blocks`,
57e56eb2
C
81 routerLink: '/admin/moderation/video-blocks/list',
82 iconName: 'cross'
83 })
84 }
dbb76162 85
0f8d00e3
C
86 if (this.hasVideoCommentsRight()) {
87 moderationItems.children.push({
88 label: $localize`Video comments`,
89 routerLink: '/admin/moderation/video-comments/list',
90 iconName: 'message-circle'
91 })
92 }
dbb76162 93
57e56eb2
C
94 if (this.hasAccountsBlocklistRight()) {
95 moderationItems.children.push({
66357162 96 label: $localize`Muted accounts`,
57e56eb2 97 routerLink: '/admin/moderation/blocklist/accounts',
345b4a22 98 iconName: 'user-x'
57e56eb2
C
99 })
100 }
dbb76162 101
57e56eb2
C
102 if (this.hasServersBlocklistRight()) {
103 moderationItems.children.push({
66357162 104 label: $localize`Muted servers`,
57e56eb2 105 routerLink: '/admin/moderation/blocklist/servers',
345b4a22 106 iconName: 'peertube-x'
57e56eb2
C
107 })
108 }
0a4cb95c 109
dbb76162
C
110 if (moderationItems.children.length !== 0) this.menuEntries.push(moderationItems)
111 }
dfe3f7b7 112
dbb76162 113 private buildConfigurationItems () {
dfe3f7b7 114 if (this.hasConfigRight()) {
66357162 115 this.menuEntries.push({ label: $localize`Configuration`, routerLink: '/admin/config' })
dfe3f7b7 116 }
dbb76162 117 }
dfe3f7b7 118
dbb76162 119 private buildPluginItems () {
dfe3f7b7 120 if (this.hasPluginsRight()) {
66357162 121 this.menuEntries.push({ label: $localize`Plugins/Themes`, routerLink: '/admin/plugins' })
dfe3f7b7 122 }
dbb76162
C
123 }
124
125 private buildSystemItems () {
126 const systemItems: TopMenuDropdownParam = {
127 label: $localize`System`,
128 children: []
129 }
130
131 if (this.hasJobsRight()) {
132 systemItems.children.push({
133 label: $localize`Jobs`,
134 iconName: 'circle-tick',
135 routerLink: '/admin/system/jobs'
136 })
137 }
138
139 if (this.hasLogsRight()) {
140 systemItems.children.push({
141 label: $localize`Logs`,
142 iconName: 'playlists',
143 routerLink: '/admin/system/logs'
144 })
145 }
146
147 if (this.hasDebugRight()) {
148 systemItems.children.push({
149 label: $localize`Debug`,
150 iconName: 'cog',
151 routerLink: '/admin/system/debug'
152 })
153 }
dfe3f7b7 154
dbb76162
C
155 if (systemItems.children.length !== 0) {
156 this.menuEntries.push(systemItems)
dfe3f7b7 157 }
24e7916c 158 }
04e0fc48 159
dbb76162 160 private hasUsersRight () {
04e0fc48
C
161 return this.auth.getUser().hasRight(UserRight.MANAGE_USERS)
162 }
163
dbb76162 164 private hasServerFollowRight () {
04e0fc48
C
165 return this.auth.getUser().hasRight(UserRight.MANAGE_SERVER_FOLLOW)
166 }
167
dbb76162 168 private hasAbusesRight () {
d95d1559 169 return this.auth.getUser().hasRight(UserRight.MANAGE_ABUSES)
04e0fc48
C
170 }
171
dbb76162 172 private hasVideoBlocklistRight () {
3487330d 173 return this.auth.getUser().hasRight(UserRight.MANAGE_VIDEO_BLACKLIST)
04e0fc48
C
174 }
175
dbb76162 176 private hasAccountsBlocklistRight () {
0a4cb95c
RK
177 return this.auth.getUser().hasRight(UserRight.MANAGE_ACCOUNTS_BLOCKLIST)
178 }
179
dbb76162 180 private hasServersBlocklistRight () {
0a4cb95c
RK
181 return this.auth.getUser().hasRight(UserRight.MANAGE_SERVERS_BLOCKLIST)
182 }
183
dbb76162 184 private hasConfigRight () {
5d79474c 185 return this.auth.getUser().hasRight(UserRight.MANAGE_CONFIGURATION)
04e0fc48 186 }
fd206f0b 187
dbb76162 188 private hasPluginsRight () {
d00dc28d
C
189 return this.auth.getUser().hasRight(UserRight.MANAGE_PLUGINS)
190 }
191
dbb76162 192 private hasLogsRight () {
2c22613c
C
193 return this.auth.getUser().hasRight(UserRight.MANAGE_LOGS)
194 }
195
dbb76162 196 private hasJobsRight () {
5d79474c
C
197 return this.auth.getUser().hasRight(UserRight.MANAGE_JOBS)
198 }
199
dbb76162 200 private hasDebugRight () {
5d79474c 201 return this.auth.getUser().hasRight(UserRight.MANAGE_DEBUG)
fd206f0b 202 }
0f8d00e3 203
dbb76162 204 private hasVideoCommentsRight () {
0f8d00e3
C
205 return this.auth.getUser().hasRight(UserRight.SEE_ALL_COMMENTS)
206 }
7da18e44 207}