aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+admin/admin.component.ts
blob: 66e068c4ccaeb718b6940a16a53559e53be7d8b3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import { Component, OnInit } from '@angular/core'
import { AuthService, ScreenService } from '@app/core'
import { ListOverflowItem } from '@app/shared/shared-main'
import { I18n } from '@ngx-translate/i18n-polyfill'
import { UserRight } from '@shared/models'
import { TopMenuDropdownParam } from '@app/shared/shared-main/misc/top-menu-dropdown.component'

@Component({
  templateUrl: './admin.component.html',
  styleUrls: [ './admin.component.scss' ]
})
export class AdminComponent implements OnInit {
  items: ListOverflowItem[] = []
  menuEntries: TopMenuDropdownParam[] = []

  constructor (
    private auth: AuthService,
    private screen: ScreenService,
    private i18n: I18n
  ) { }

  get isBroadcastMessageDisplayed () {
    return this.screen.isBroadcastMessageDisplayed
  }

  ngOnInit () {
    const federationItems: TopMenuDropdownParam = {
      label: this.i18n('Federation'),
      children: [
        {
          label: this.i18n('Instances you follow'),
          routerLink: '/admin/follows/following-list',
          iconName: 'following'
        },
        {
          label: this.i18n('Instances following you'),
          routerLink: '/admin/follows/followers-list',
          iconName: 'follower'
        },
        {
          label: this.i18n('Video redundancies'),
          routerLink: '/admin/follows/video-redundancies-list',
          iconName: 'videos'
        }
      ]
    }

    const moderationItems: TopMenuDropdownParam = {
      label: this.i18n('Moderation'),
      children: []
    }

    if (this.hasAbusesRight()) {
      moderationItems.children.push({
        label: this.i18n('Reports'),
        routerLink: '/admin/moderation/abuses/list',
        iconName: 'flag'
      })
    }
    if (this.hasVideoBlocklistRight()) {
      moderationItems.children.push({
        label: this.i18n('Video blocks'),
        routerLink: '/admin/moderation/video-blocks/list',
        iconName: 'cross'
      })
    }
    if (this.hasAccountsBlocklistRight()) {
      moderationItems.children.push({
        label: this.i18n('Muted accounts'),
        routerLink: '/admin/moderation/blocklist/accounts',
        iconName: 'user-x'
      })
    }
    if (this.hasServersBlocklistRight()) {
      moderationItems.children.push({
        label: this.i18n('Muted servers'),
        routerLink: '/admin/moderation/blocklist/servers',
        iconName: 'peertube-x'
      })
    }

    if (this.hasUsersRight()) {
      this.menuEntries.push({ label: this.i18n('Users'), routerLink: '/admin/users' })
    }

    if (this.hasServerFollowRight()) this.menuEntries.push(federationItems)
    if (this.hasAbusesRight() || this.hasVideoBlocklistRight()) this.menuEntries.push(moderationItems)

    if (this.hasConfigRight()) {
      this.menuEntries.push({ label: this.i18n('Configuration'), routerLink: '/admin/config' })
    }

    if (this.hasPluginsRight()) {
      this.menuEntries.push({ label: this.i18n('Plugins/Themes'), routerLink: '/admin/plugins' })
    }

    if (this.hasJobsRight() || this.hasLogsRight() || this.hasDebugRight()) {
      this.menuEntries.push({ label: this.i18n('System'), routerLink: '/admin/system' })
    }
  }

  hasUsersRight () {
    return this.auth.getUser().hasRight(UserRight.MANAGE_USERS)
  }

  hasServerFollowRight () {
    return this.auth.getUser().hasRight(UserRight.MANAGE_SERVER_FOLLOW)
  }

  hasAbusesRight () {
    return this.auth.getUser().hasRight(UserRight.MANAGE_ABUSES)
  }

  hasVideoBlocklistRight () {
    return this.auth.getUser().hasRight(UserRight.MANAGE_VIDEO_BLACKLIST)
  }

  hasAccountsBlocklistRight () {
    return this.auth.getUser().hasRight(UserRight.MANAGE_ACCOUNTS_BLOCKLIST)
  }

  hasServersBlocklistRight () {
    return this.auth.getUser().hasRight(UserRight.MANAGE_SERVERS_BLOCKLIST)
  }

  hasConfigRight () {
    return this.auth.getUser().hasRight(UserRight.MANAGE_CONFIGURATION)
  }

  hasPluginsRight () {
    return this.auth.getUser().hasRight(UserRight.MANAGE_PLUGINS)
  }

  hasLogsRight () {
    return this.auth.getUser().hasRight(UserRight.MANAGE_LOGS)
  }

  hasJobsRight () {
    return this.auth.getUser().hasRight(UserRight.MANAGE_JOBS)
  }

  hasDebugRight () {
    return this.auth.getUser().hasRight(UserRight.MANAGE_DEBUG)
  }
}