]>
Commit | Line | Data |
---|---|---|
1 | import { Component, OnInit } from '@angular/core' | |
2 | import { AuthService } from '@app/core' | |
3 | import { ListOverflowItem } from '@app/shared/shared-main' | |
4 | import { I18n } from '@ngx-translate/i18n-polyfill' | |
5 | import { UserRight } from '@shared/models' | |
6 | import { TopMenuDropdownParam } from '@app/shared/shared-main/misc/top-menu-dropdown.component' | |
7 | ||
8 | @Component({ | |
9 | templateUrl: './admin.component.html', | |
10 | styleUrls: [ './admin.component.scss' ] | |
11 | }) | |
12 | export class AdminComponent implements OnInit { | |
13 | items: ListOverflowItem[] = [] | |
14 | menuEntries: TopMenuDropdownParam[] = [] | |
15 | ||
16 | constructor ( | |
17 | private auth: AuthService, | |
18 | private i18n: I18n | |
19 | ) {} | |
20 | ||
21 | ngOnInit () { | |
22 | const federationItems: TopMenuDropdownParam = { | |
23 | label: this.i18n('Federation'), | |
24 | children: [ | |
25 | { | |
26 | label: this.i18n('Instances you follow'), | |
27 | routerLink: '/admin/follows/following-list', | |
28 | iconName: 'sign-out' | |
29 | }, | |
30 | { | |
31 | label: this.i18n('Instances following you'), | |
32 | routerLink: '/admin/follows/followers-list', | |
33 | iconName: 'sign-in' | |
34 | }, | |
35 | { | |
36 | label: this.i18n('Video redundancies'), | |
37 | routerLink: '/admin/follows/video-redundancies-list', | |
38 | iconName: 'videos' | |
39 | } | |
40 | ] | |
41 | } | |
42 | ||
43 | const moderationItems: TopMenuDropdownParam = { | |
44 | label: this.i18n('Moderation'), | |
45 | children: [] | |
46 | } | |
47 | if (this.hasVideoAbusesRight()) moderationItems.children.push({ | |
48 | label: this.i18n('Video reports'), | |
49 | routerLink: '/admin/moderation/video-abuses/list', | |
50 | iconName: 'flag' | |
51 | }) | |
52 | if (this.hasVideoBlocklistRight()) moderationItems.children.push({ | |
53 | label: this.i18n('Video blocks'), | |
54 | routerLink: '/admin/moderation/video-blocks/list', | |
55 | iconName: 'cross' | |
56 | }) | |
57 | if (this.hasAccountsBlocklistRight()) moderationItems.children.push({ | |
58 | label: this.i18n('Muted accounts'), | |
59 | routerLink: '/admin/moderation/blocklist/accounts', | |
60 | iconName: 'user' | |
61 | }) | |
62 | if (this.hasServersBlocklistRight()) moderationItems.children.push({ | |
63 | label: this.i18n('Muted servers'), | |
64 | routerLink: '/admin/moderation/blocklist/servers', | |
65 | iconName: 'server' | |
66 | }) | |
67 | ||
68 | if (this.hasUsersRight()) this.menuEntries.push({ label: this.i18n('Users'), routerLink: '/admin/users' }) | |
69 | if (this.hasServerFollowRight()) this.menuEntries.push(federationItems) | |
70 | if (this.hasVideoAbusesRight() || this.hasVideoBlocklistRight()) this.menuEntries.push(moderationItems) | |
71 | if (this.hasConfigRight()) this.menuEntries.push({ label: this.i18n('Configuration'), routerLink: '/admin/config' }) | |
72 | if (this.hasPluginsRight()) this.menuEntries.push({ label: this.i18n('Plugins/Themes'), routerLink: '/admin/plugins' }) | |
73 | if (this.hasJobsRight() || this.hasLogsRight() || this.hasDebugRight()) this.menuEntries.push({ label: this.i18n('System'), routerLink: '/admin/system' }) | |
74 | } | |
75 | ||
76 | hasUsersRight () { | |
77 | return this.auth.getUser().hasRight(UserRight.MANAGE_USERS) | |
78 | } | |
79 | ||
80 | hasServerFollowRight () { | |
81 | return this.auth.getUser().hasRight(UserRight.MANAGE_SERVER_FOLLOW) | |
82 | } | |
83 | ||
84 | hasVideoAbusesRight () { | |
85 | return this.auth.getUser().hasRight(UserRight.MANAGE_VIDEO_ABUSES) | |
86 | } | |
87 | ||
88 | hasVideoBlocklistRight () { | |
89 | return this.auth.getUser().hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) | |
90 | } | |
91 | ||
92 | hasAccountsBlocklistRight () { | |
93 | return this.auth.getUser().hasRight(UserRight.MANAGE_ACCOUNTS_BLOCKLIST) | |
94 | } | |
95 | ||
96 | hasServersBlocklistRight () { | |
97 | return this.auth.getUser().hasRight(UserRight.MANAGE_SERVERS_BLOCKLIST) | |
98 | } | |
99 | ||
100 | hasConfigRight () { | |
101 | return this.auth.getUser().hasRight(UserRight.MANAGE_CONFIGURATION) | |
102 | } | |
103 | ||
104 | hasPluginsRight () { | |
105 | return this.auth.getUser().hasRight(UserRight.MANAGE_PLUGINS) | |
106 | } | |
107 | ||
108 | hasLogsRight () { | |
109 | return this.auth.getUser().hasRight(UserRight.MANAGE_LOGS) | |
110 | } | |
111 | ||
112 | hasJobsRight () { | |
113 | return this.auth.getUser().hasRight(UserRight.MANAGE_JOBS) | |
114 | } | |
115 | ||
116 | hasDebugRight () { | |
117 | return this.auth.getUser().hasRight(UserRight.MANAGE_DEBUG) | |
118 | } | |
119 | } |