]>
Commit | Line | Data |
---|---|---|
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' | |
6 | ||
7 | @Component({ | |
8 | templateUrl: './admin.component.html', | |
9 | styleUrls: [ './admin.component.scss' ] | |
10 | }) | |
11 | export class AdminComponent implements OnInit { | |
12 | items: ListOverflowItem[] = [] | |
13 | menuEntries: TopMenuDropdownParam[] = [] | |
14 | ||
15 | constructor ( | |
16 | private auth: AuthService, | |
17 | private screen: ScreenService | |
18 | ) { } | |
19 | ||
20 | get isBroadcastMessageDisplayed () { | |
21 | return this.screen.isBroadcastMessageDisplayed | |
22 | } | |
23 | ||
24 | ngOnInit () { | |
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({ | |
43 | label: $localize`Federation`, | |
44 | children: [ | |
45 | { | |
46 | label: $localize`Following`, | |
47 | routerLink: '/admin/follows/following-list', | |
48 | iconName: 'following' | |
49 | }, | |
50 | { | |
51 | label: $localize`Followers`, | |
52 | routerLink: '/admin/follows/followers-list', | |
53 | iconName: 'follower' | |
54 | }, | |
55 | { | |
56 | label: $localize`Video redundancies`, | |
57 | routerLink: '/admin/follows/video-redundancies-list', | |
58 | iconName: 'videos' | |
59 | } | |
60 | ] | |
61 | }) | |
62 | } | |
63 | ||
64 | private buildModerationItems () { | |
65 | const moderationItems: TopMenuDropdownParam = { | |
66 | label: $localize`Moderation`, | |
67 | children: [] | |
68 | } | |
69 | ||
70 | if (this.hasAbusesRight()) { | |
71 | moderationItems.children.push({ | |
72 | label: $localize`Reports`, | |
73 | routerLink: '/admin/moderation/abuses/list', | |
74 | iconName: 'flag' | |
75 | }) | |
76 | } | |
77 | ||
78 | if (this.hasVideoBlocklistRight()) { | |
79 | moderationItems.children.push({ | |
80 | label: $localize`Video blocks`, | |
81 | routerLink: '/admin/moderation/video-blocks/list', | |
82 | iconName: 'cross' | |
83 | }) | |
84 | } | |
85 | ||
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 | } | |
93 | ||
94 | if (this.hasAccountsBlocklistRight()) { | |
95 | moderationItems.children.push({ | |
96 | label: $localize`Muted accounts`, | |
97 | routerLink: '/admin/moderation/blocklist/accounts', | |
98 | iconName: 'user-x' | |
99 | }) | |
100 | } | |
101 | ||
102 | if (this.hasServersBlocklistRight()) { | |
103 | moderationItems.children.push({ | |
104 | label: $localize`Muted servers`, | |
105 | routerLink: '/admin/moderation/blocklist/servers', | |
106 | iconName: 'peertube-x' | |
107 | }) | |
108 | } | |
109 | ||
110 | if (moderationItems.children.length !== 0) this.menuEntries.push(moderationItems) | |
111 | } | |
112 | ||
113 | private buildConfigurationItems () { | |
114 | if (this.hasConfigRight()) { | |
115 | this.menuEntries.push({ label: $localize`Configuration`, routerLink: '/admin/config' }) | |
116 | } | |
117 | } | |
118 | ||
119 | private buildPluginItems () { | |
120 | if (this.hasPluginsRight()) { | |
121 | this.menuEntries.push({ label: $localize`Plugins/Themes`, routerLink: '/admin/plugins' }) | |
122 | } | |
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 | } | |
154 | ||
155 | if (systemItems.children.length !== 0) { | |
156 | this.menuEntries.push(systemItems) | |
157 | } | |
158 | } | |
159 | ||
160 | private hasUsersRight () { | |
161 | return this.auth.getUser().hasRight(UserRight.MANAGE_USERS) | |
162 | } | |
163 | ||
164 | private hasServerFollowRight () { | |
165 | return this.auth.getUser().hasRight(UserRight.MANAGE_SERVER_FOLLOW) | |
166 | } | |
167 | ||
168 | private hasAbusesRight () { | |
169 | return this.auth.getUser().hasRight(UserRight.MANAGE_ABUSES) | |
170 | } | |
171 | ||
172 | private hasVideoBlocklistRight () { | |
173 | return this.auth.getUser().hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) | |
174 | } | |
175 | ||
176 | private hasAccountsBlocklistRight () { | |
177 | return this.auth.getUser().hasRight(UserRight.MANAGE_ACCOUNTS_BLOCKLIST) | |
178 | } | |
179 | ||
180 | private hasServersBlocklistRight () { | |
181 | return this.auth.getUser().hasRight(UserRight.MANAGE_SERVERS_BLOCKLIST) | |
182 | } | |
183 | ||
184 | private hasConfigRight () { | |
185 | return this.auth.getUser().hasRight(UserRight.MANAGE_CONFIGURATION) | |
186 | } | |
187 | ||
188 | private hasPluginsRight () { | |
189 | return this.auth.getUser().hasRight(UserRight.MANAGE_PLUGINS) | |
190 | } | |
191 | ||
192 | private hasLogsRight () { | |
193 | return this.auth.getUser().hasRight(UserRight.MANAGE_LOGS) | |
194 | } | |
195 | ||
196 | private hasJobsRight () { | |
197 | return this.auth.getUser().hasRight(UserRight.MANAGE_JOBS) | |
198 | } | |
199 | ||
200 | private hasDebugRight () { | |
201 | return this.auth.getUser().hasRight(UserRight.MANAGE_DEBUG) | |
202 | } | |
203 | ||
204 | private hasVideoCommentsRight () { | |
205 | return this.auth.getUser().hasRight(UserRight.SEE_ALL_COMMENTS) | |
206 | } | |
207 | } |