]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/admin.component.ts
Refactor - improve offset content handling with fixed sub-menu and broadcast-message
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / admin.component.ts
1 import { Component, OnInit } from '@angular/core'
2 import { AuthService, ScreenService } 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 screen: ScreenService,
19 private i18n: I18n
20 ) { }
21
22 get isBroadcastMessageDisplayed () {
23 return this.screen.isBroadcastMessageDisplayed
24 }
25
26 ngOnInit () {
27 const federationItems: TopMenuDropdownParam = {
28 label: this.i18n('Federation'),
29 children: [
30 {
31 label: this.i18n('Instances you follow'),
32 routerLink: '/admin/follows/following-list',
33 iconName: 'following'
34 },
35 {
36 label: this.i18n('Instances following you'),
37 routerLink: '/admin/follows/followers-list',
38 iconName: 'follower'
39 },
40 {
41 label: this.i18n('Video redundancies'),
42 routerLink: '/admin/follows/video-redundancies-list',
43 iconName: 'videos'
44 }
45 ]
46 }
47
48 const moderationItems: TopMenuDropdownParam = {
49 label: this.i18n('Moderation'),
50 children: []
51 }
52
53 if (this.hasAbusesRight()) {
54 moderationItems.children.push({
55 label: this.i18n('Reports'),
56 routerLink: '/admin/moderation/abuses/list',
57 iconName: 'flag'
58 })
59 }
60 if (this.hasVideoBlocklistRight()) {
61 moderationItems.children.push({
62 label: this.i18n('Video blocks'),
63 routerLink: '/admin/moderation/video-blocks/list',
64 iconName: 'cross'
65 })
66 }
67 if (this.hasAccountsBlocklistRight()) {
68 moderationItems.children.push({
69 label: this.i18n('Muted accounts'),
70 routerLink: '/admin/moderation/blocklist/accounts',
71 iconName: 'user-x'
72 })
73 }
74 if (this.hasServersBlocklistRight()) {
75 moderationItems.children.push({
76 label: this.i18n('Muted servers'),
77 routerLink: '/admin/moderation/blocklist/servers',
78 iconName: 'peertube-x'
79 })
80 }
81
82 if (this.hasUsersRight()) {
83 this.menuEntries.push({ label: this.i18n('Users'), routerLink: '/admin/users' })
84 }
85
86 if (this.hasServerFollowRight()) this.menuEntries.push(federationItems)
87 if (this.hasAbusesRight() || this.hasVideoBlocklistRight()) this.menuEntries.push(moderationItems)
88
89 if (this.hasConfigRight()) {
90 this.menuEntries.push({ label: this.i18n('Configuration'), routerLink: '/admin/config' })
91 }
92
93 if (this.hasPluginsRight()) {
94 this.menuEntries.push({ label: this.i18n('Plugins/Themes'), routerLink: '/admin/plugins' })
95 }
96
97 if (this.hasJobsRight() || this.hasLogsRight() || this.hasDebugRight()) {
98 this.menuEntries.push({ label: this.i18n('System'), routerLink: '/admin/system' })
99 }
100 }
101
102 hasUsersRight () {
103 return this.auth.getUser().hasRight(UserRight.MANAGE_USERS)
104 }
105
106 hasServerFollowRight () {
107 return this.auth.getUser().hasRight(UserRight.MANAGE_SERVER_FOLLOW)
108 }
109
110 hasAbusesRight () {
111 return this.auth.getUser().hasRight(UserRight.MANAGE_ABUSES)
112 }
113
114 hasVideoBlocklistRight () {
115 return this.auth.getUser().hasRight(UserRight.MANAGE_VIDEO_BLACKLIST)
116 }
117
118 hasAccountsBlocklistRight () {
119 return this.auth.getUser().hasRight(UserRight.MANAGE_ACCOUNTS_BLOCKLIST)
120 }
121
122 hasServersBlocklistRight () {
123 return this.auth.getUser().hasRight(UserRight.MANAGE_SERVERS_BLOCKLIST)
124 }
125
126 hasConfigRight () {
127 return this.auth.getUser().hasRight(UserRight.MANAGE_CONFIGURATION)
128 }
129
130 hasPluginsRight () {
131 return this.auth.getUser().hasRight(UserRight.MANAGE_PLUGINS)
132 }
133
134 hasLogsRight () {
135 return this.auth.getUser().hasRight(UserRight.MANAGE_LOGS)
136 }
137
138 hasJobsRight () {
139 return this.auth.getUser().hasRight(UserRight.MANAGE_JOBS)
140 }
141
142 hasDebugRight () {
143 return this.auth.getUser().hasRight(UserRight.MANAGE_DEBUG)
144 }
145 }