]>
Commit | Line | Data |
---|---|---|
24e7916c | 1 | import { Component, OnInit } from '@angular/core' |
7034b3c9 | 2 | import { AuthService, ScreenService } from '@app/core' |
67ed6552 | 3 | import { ListOverflowItem } from '@app/shared/shared-main' |
0a4cb95c | 4 | import { TopMenuDropdownParam } from '@app/shared/shared-main/misc/top-menu-dropdown.component' |
66357162 | 5 | import { 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 |
11 | export 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 () { | |
00004f7f C |
34 | const overviewItems: TopMenuDropdownParam = { |
35 | label: $localize`Overview`, | |
36 | children: [] | |
37 | } | |
38 | ||
dbb76162 | 39 | if (this.hasUsersRight()) { |
00004f7f C |
40 | overviewItems.children.push({ |
41 | label: $localize`Users`, | |
42 | routerLink: '/admin/users', | |
43 | iconName: 'user' | |
44 | }) | |
45 | } | |
46 | ||
33f6dce1 C |
47 | if (this.hasVideosRight()) { |
48 | overviewItems.children.push({ | |
49 | label: $localize`Videos`, | |
50 | routerLink: '/admin/videos', | |
51 | iconName: 'videos' | |
52 | }) | |
53 | } | |
54 | ||
5a51ecc2 C |
55 | if (this.hasVideoCommentsRight()) { |
56 | overviewItems.children.push({ | |
57 | label: $localize`Comments`, | |
58 | routerLink: '/admin/comments', | |
59 | iconName: 'message-circle' | |
60 | }) | |
61 | } | |
62 | ||
00004f7f C |
63 | if (overviewItems.children.length !== 0) { |
64 | this.menuEntries.push(overviewItems) | |
dbb76162 C |
65 | } |
66 | } | |
67 | ||
68 | private buildFederationItems () { | |
69 | if (!this.hasServerFollowRight()) return | |
70 | ||
71 | this.menuEntries.push({ | |
66357162 | 72 | label: $localize`Federation`, |
0a4cb95c RK |
73 | children: [ |
74 | { | |
4d029ef8 | 75 | label: $localize`Following`, |
57e56eb2 | 76 | routerLink: '/admin/follows/following-list', |
ea7337cf | 77 | iconName: 'following' |
0a4cb95c RK |
78 | }, |
79 | { | |
4d029ef8 | 80 | label: $localize`Followers`, |
57e56eb2 | 81 | routerLink: '/admin/follows/followers-list', |
ea7337cf | 82 | iconName: 'follower' |
0a4cb95c RK |
83 | }, |
84 | { | |
66357162 | 85 | label: $localize`Video redundancies`, |
57e56eb2 | 86 | routerLink: '/admin/follows/video-redundancies-list', |
0a4cb95c RK |
87 | iconName: 'videos' |
88 | } | |
89 | ] | |
dbb76162 C |
90 | }) |
91 | } | |
0a4cb95c | 92 | |
dbb76162 | 93 | private buildModerationItems () { |
0a4cb95c | 94 | const moderationItems: TopMenuDropdownParam = { |
66357162 | 95 | label: $localize`Moderation`, |
0a4cb95c RK |
96 | children: [] |
97 | } | |
57e56eb2 | 98 | |
4f32032f | 99 | if (this.hasAbusesRight()) { |
57e56eb2 | 100 | moderationItems.children.push({ |
66357162 | 101 | label: $localize`Reports`, |
8ca56654 | 102 | routerLink: '/admin/moderation/abuses/list', |
57e56eb2 C |
103 | iconName: 'flag' |
104 | }) | |
105 | } | |
dbb76162 | 106 | |
57e56eb2 C |
107 | if (this.hasVideoBlocklistRight()) { |
108 | moderationItems.children.push({ | |
66357162 | 109 | label: $localize`Video blocks`, |
57e56eb2 C |
110 | routerLink: '/admin/moderation/video-blocks/list', |
111 | iconName: 'cross' | |
112 | }) | |
113 | } | |
dbb76162 | 114 | |
57e56eb2 C |
115 | if (this.hasAccountsBlocklistRight()) { |
116 | moderationItems.children.push({ | |
66357162 | 117 | label: $localize`Muted accounts`, |
57e56eb2 | 118 | routerLink: '/admin/moderation/blocklist/accounts', |
345b4a22 | 119 | iconName: 'user-x' |
57e56eb2 C |
120 | }) |
121 | } | |
dbb76162 | 122 | |
57e56eb2 C |
123 | if (this.hasServersBlocklistRight()) { |
124 | moderationItems.children.push({ | |
66357162 | 125 | label: $localize`Muted servers`, |
57e56eb2 | 126 | routerLink: '/admin/moderation/blocklist/servers', |
345b4a22 | 127 | iconName: 'peertube-x' |
57e56eb2 C |
128 | }) |
129 | } | |
0a4cb95c | 130 | |
dbb76162 C |
131 | if (moderationItems.children.length !== 0) this.menuEntries.push(moderationItems) |
132 | } | |
dfe3f7b7 | 133 | |
dbb76162 | 134 | private buildConfigurationItems () { |
dfe3f7b7 | 135 | if (this.hasConfigRight()) { |
66357162 | 136 | this.menuEntries.push({ label: $localize`Configuration`, routerLink: '/admin/config' }) |
dfe3f7b7 | 137 | } |
dbb76162 | 138 | } |
dfe3f7b7 | 139 | |
dbb76162 | 140 | private buildPluginItems () { |
dfe3f7b7 | 141 | if (this.hasPluginsRight()) { |
66357162 | 142 | this.menuEntries.push({ label: $localize`Plugins/Themes`, routerLink: '/admin/plugins' }) |
dfe3f7b7 | 143 | } |
dbb76162 C |
144 | } |
145 | ||
146 | private buildSystemItems () { | |
147 | const systemItems: TopMenuDropdownParam = { | |
148 | label: $localize`System`, | |
149 | children: [] | |
150 | } | |
151 | ||
152 | if (this.hasJobsRight()) { | |
153 | systemItems.children.push({ | |
154 | label: $localize`Jobs`, | |
155 | iconName: 'circle-tick', | |
156 | routerLink: '/admin/system/jobs' | |
157 | }) | |
158 | } | |
159 | ||
160 | if (this.hasLogsRight()) { | |
161 | systemItems.children.push({ | |
162 | label: $localize`Logs`, | |
163 | iconName: 'playlists', | |
164 | routerLink: '/admin/system/logs' | |
165 | }) | |
166 | } | |
167 | ||
168 | if (this.hasDebugRight()) { | |
169 | systemItems.children.push({ | |
170 | label: $localize`Debug`, | |
171 | iconName: 'cog', | |
172 | routerLink: '/admin/system/debug' | |
173 | }) | |
174 | } | |
dfe3f7b7 | 175 | |
dbb76162 C |
176 | if (systemItems.children.length !== 0) { |
177 | this.menuEntries.push(systemItems) | |
dfe3f7b7 | 178 | } |
24e7916c | 179 | } |
04e0fc48 | 180 | |
dbb76162 | 181 | private hasUsersRight () { |
04e0fc48 C |
182 | return this.auth.getUser().hasRight(UserRight.MANAGE_USERS) |
183 | } | |
184 | ||
dbb76162 | 185 | private hasServerFollowRight () { |
04e0fc48 C |
186 | return this.auth.getUser().hasRight(UserRight.MANAGE_SERVER_FOLLOW) |
187 | } | |
188 | ||
dbb76162 | 189 | private hasAbusesRight () { |
d95d1559 | 190 | return this.auth.getUser().hasRight(UserRight.MANAGE_ABUSES) |
04e0fc48 C |
191 | } |
192 | ||
dbb76162 | 193 | private hasVideoBlocklistRight () { |
3487330d | 194 | return this.auth.getUser().hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) |
04e0fc48 C |
195 | } |
196 | ||
dbb76162 | 197 | private hasAccountsBlocklistRight () { |
0a4cb95c RK |
198 | return this.auth.getUser().hasRight(UserRight.MANAGE_ACCOUNTS_BLOCKLIST) |
199 | } | |
200 | ||
dbb76162 | 201 | private hasServersBlocklistRight () { |
0a4cb95c RK |
202 | return this.auth.getUser().hasRight(UserRight.MANAGE_SERVERS_BLOCKLIST) |
203 | } | |
204 | ||
dbb76162 | 205 | private hasConfigRight () { |
5d79474c | 206 | return this.auth.getUser().hasRight(UserRight.MANAGE_CONFIGURATION) |
04e0fc48 | 207 | } |
fd206f0b | 208 | |
dbb76162 | 209 | private hasPluginsRight () { |
d00dc28d C |
210 | return this.auth.getUser().hasRight(UserRight.MANAGE_PLUGINS) |
211 | } | |
212 | ||
dbb76162 | 213 | private hasLogsRight () { |
2c22613c C |
214 | return this.auth.getUser().hasRight(UserRight.MANAGE_LOGS) |
215 | } | |
216 | ||
dbb76162 | 217 | private hasJobsRight () { |
5d79474c C |
218 | return this.auth.getUser().hasRight(UserRight.MANAGE_JOBS) |
219 | } | |
220 | ||
dbb76162 | 221 | private hasDebugRight () { |
5d79474c | 222 | return this.auth.getUser().hasRight(UserRight.MANAGE_DEBUG) |
fd206f0b | 223 | } |
0f8d00e3 | 224 | |
dbb76162 | 225 | private hasVideoCommentsRight () { |
0f8d00e3 C |
226 | return this.auth.getUser().hasRight(UserRight.SEE_ALL_COMMENTS) |
227 | } | |
33f6dce1 C |
228 | |
229 | private hasVideosRight () { | |
230 | return this.auth.getUser().hasRight(UserRight.SEE_ALL_VIDEOS) | |
231 | } | |
7da18e44 | 232 | } |