]>
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 | const federationItems: TopMenuDropdownParam = { | |
26 | label: $localize`Federation`, | |
27 | children: [ | |
28 | { | |
29 | label: $localize`Instances you follow`, | |
30 | routerLink: '/admin/follows/following-list', | |
31 | iconName: 'following' | |
32 | }, | |
33 | { | |
34 | label: $localize`Instances following you`, | |
35 | routerLink: '/admin/follows/followers-list', | |
36 | iconName: 'follower' | |
37 | }, | |
38 | { | |
39 | label: $localize`Video redundancies`, | |
40 | routerLink: '/admin/follows/video-redundancies-list', | |
41 | iconName: 'videos' | |
42 | } | |
43 | ] | |
44 | } | |
45 | ||
46 | const moderationItems: TopMenuDropdownParam = { | |
47 | label: $localize`Moderation`, | |
48 | children: [] | |
49 | } | |
50 | ||
51 | if (this.hasAbusesRight()) { | |
52 | moderationItems.children.push({ | |
53 | label: $localize`Reports`, | |
54 | routerLink: '/admin/moderation/abuses/list', | |
55 | iconName: 'flag' | |
56 | }) | |
57 | } | |
58 | if (this.hasVideoBlocklistRight()) { | |
59 | moderationItems.children.push({ | |
60 | label: $localize`Video blocks`, | |
61 | routerLink: '/admin/moderation/video-blocks/list', | |
62 | iconName: 'cross' | |
63 | }) | |
64 | } | |
65 | if (this.hasVideoCommentsRight()) { | |
66 | moderationItems.children.push({ | |
67 | label: $localize`Video comments`, | |
68 | routerLink: '/admin/moderation/video-comments/list', | |
69 | iconName: 'message-circle' | |
70 | }) | |
71 | } | |
72 | if (this.hasAccountsBlocklistRight()) { | |
73 | moderationItems.children.push({ | |
74 | label: $localize`Muted accounts`, | |
75 | routerLink: '/admin/moderation/blocklist/accounts', | |
76 | iconName: 'user-x' | |
77 | }) | |
78 | } | |
79 | if (this.hasServersBlocklistRight()) { | |
80 | moderationItems.children.push({ | |
81 | label: $localize`Muted servers`, | |
82 | routerLink: '/admin/moderation/blocklist/servers', | |
83 | iconName: 'peertube-x' | |
84 | }) | |
85 | } | |
86 | ||
87 | if (this.hasUsersRight()) { | |
88 | this.menuEntries.push({ label: $localize`Users`, routerLink: '/admin/users' }) | |
89 | } | |
90 | ||
91 | if (this.hasServerFollowRight()) this.menuEntries.push(federationItems) | |
92 | if (this.hasAbusesRight() || this.hasVideoBlocklistRight()) this.menuEntries.push(moderationItems) | |
93 | ||
94 | if (this.hasConfigRight()) { | |
95 | this.menuEntries.push({ label: $localize`Configuration`, routerLink: '/admin/config' }) | |
96 | } | |
97 | ||
98 | if (this.hasPluginsRight()) { | |
99 | this.menuEntries.push({ label: $localize`Plugins/Themes`, routerLink: '/admin/plugins' }) | |
100 | } | |
101 | ||
102 | if (this.hasJobsRight() || this.hasLogsRight() || this.hasDebugRight()) { | |
103 | this.menuEntries.push({ label: $localize`System`, routerLink: '/admin/system' }) | |
104 | } | |
105 | } | |
106 | ||
107 | hasUsersRight () { | |
108 | return this.auth.getUser().hasRight(UserRight.MANAGE_USERS) | |
109 | } | |
110 | ||
111 | hasServerFollowRight () { | |
112 | return this.auth.getUser().hasRight(UserRight.MANAGE_SERVER_FOLLOW) | |
113 | } | |
114 | ||
115 | hasAbusesRight () { | |
116 | return this.auth.getUser().hasRight(UserRight.MANAGE_ABUSES) | |
117 | } | |
118 | ||
119 | hasVideoBlocklistRight () { | |
120 | return this.auth.getUser().hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) | |
121 | } | |
122 | ||
123 | hasAccountsBlocklistRight () { | |
124 | return this.auth.getUser().hasRight(UserRight.MANAGE_ACCOUNTS_BLOCKLIST) | |
125 | } | |
126 | ||
127 | hasServersBlocklistRight () { | |
128 | return this.auth.getUser().hasRight(UserRight.MANAGE_SERVERS_BLOCKLIST) | |
129 | } | |
130 | ||
131 | hasConfigRight () { | |
132 | return this.auth.getUser().hasRight(UserRight.MANAGE_CONFIGURATION) | |
133 | } | |
134 | ||
135 | hasPluginsRight () { | |
136 | return this.auth.getUser().hasRight(UserRight.MANAGE_PLUGINS) | |
137 | } | |
138 | ||
139 | hasLogsRight () { | |
140 | return this.auth.getUser().hasRight(UserRight.MANAGE_LOGS) | |
141 | } | |
142 | ||
143 | hasJobsRight () { | |
144 | return this.auth.getUser().hasRight(UserRight.MANAGE_JOBS) | |
145 | } | |
146 | ||
147 | hasDebugRight () { | |
148 | return this.auth.getUser().hasRight(UserRight.MANAGE_DEBUG) | |
149 | } | |
150 | ||
151 | hasVideoCommentsRight () { | |
152 | return this.auth.getUser().hasRight(UserRight.SEE_ALL_COMMENTS) | |
153 | } | |
154 | } |