aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/blocklist/server-blocklist.component.ts
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2020-06-15 13:18:22 +0200
committerGitHub <noreply@github.com>2020-06-15 13:18:22 +0200
commit228393302d98136d4dc35c5f197edc8cebd5d64f (patch)
treef92b3ad80bcc9c89088ff1d4de5ebff76a3f46ed /client/src/app/shared/blocklist/server-blocklist.component.ts
parent7dfe35288613967f5ac69cd46901ec60c5050b93 (diff)
downloadPeerTube-228393302d98136d4dc35c5f197edc8cebd5d64f.tar.gz
PeerTube-228393302d98136d4dc35c5f197edc8cebd5d64f.tar.zst
PeerTube-228393302d98136d4dc35c5f197edc8cebd5d64f.zip
factorize account/server blocklists for users and instance (#2875)
Diffstat (limited to 'client/src/app/shared/blocklist/server-blocklist.component.ts')
-rw-r--r--client/src/app/shared/blocklist/server-blocklist.component.ts101
1 files changed, 101 insertions, 0 deletions
diff --git a/client/src/app/shared/blocklist/server-blocklist.component.ts b/client/src/app/shared/blocklist/server-blocklist.component.ts
new file mode 100644
index 000000000..f2b36badc
--- /dev/null
+++ b/client/src/app/shared/blocklist/server-blocklist.component.ts
@@ -0,0 +1,101 @@
1import { OnInit, ViewChild } from '@angular/core'
2import { Notifier } from '@app/core'
3import { I18n } from '@ngx-translate/i18n-polyfill'
4import { RestPagination, RestTable } from '@app/shared/rest'
5import { SortMeta } from 'primeng/api'
6import { BlocklistService, BlocklistComponentType } from './blocklist.service'
7import { ServerBlock } from '../../../../../shared/models/blocklist/server-block.model'
8import { BatchDomainsModalComponent } from '@app/+admin/config/shared/batch-domains-modal.component'
9
10export class GenericServerBlocklistComponent extends RestTable implements OnInit {
11 @ViewChild('batchDomainsModal') batchDomainsModal: BatchDomainsModalComponent
12
13 // @ts-ignore: "Abstract methods can only appear within an abstract class"
14 public abstract mode: BlocklistComponentType
15
16 blockedServers: ServerBlock[] = []
17 totalRecords = 0
18 sort: SortMeta = { field: 'createdAt', order: -1 }
19 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
20
21 constructor (
22 protected notifier: Notifier,
23 protected blocklistService: BlocklistService,
24 protected i18n: I18n
25 ) {
26 super()
27 }
28
29 ngOnInit () {
30 this.initialize()
31 }
32
33 // @ts-ignore: "Abstract methods can only appear within an abstract class"
34 public abstract getIdentifier (): string
35
36 unblockServer (serverBlock: ServerBlock) {
37 const operation = (host: string) => this.mode === BlocklistComponentType.Account
38 ? this.blocklistService.unblockServerByUser(host)
39 : this.blocklistService.unblockServerByInstance(host)
40 const host = serverBlock.blockedServer.host
41
42 operation(host).subscribe(
43 () => {
44 this.notifier.success(
45 this.mode === BlocklistComponentType.Account
46 ? this.i18n('Instance {{host}} unmuted.', { host })
47 : this.i18n('Instance {{host}} unmuted by your instance.', { host })
48 )
49
50 this.loadData()
51 }
52 )
53 }
54
55 addServersToBlock () {
56 this.batchDomainsModal.openModal()
57 }
58
59 onDomainsToBlock (domains: string[]) {
60 const operation = (domain: string) => this.mode === BlocklistComponentType.Account
61 ? this.blocklistService.blockServerByUser(domain)
62 : this.blocklistService.blockServerByInstance(domain)
63
64 domains.forEach(domain => {
65 operation(domain).subscribe(
66 () => {
67 this.notifier.success(
68 this.mode === BlocklistComponentType.Account
69 ? this.i18n('Instance {{domain}} muted.', { domain })
70 : this.i18n('Instance {{domain}} muted by your instance.', { domain })
71 )
72
73 this.loadData()
74 }
75 )
76 })
77 }
78
79 protected loadData () {
80 const operation = this.mode === BlocklistComponentType.Account
81 ? this.blocklistService.getUserServerBlocklist({
82 pagination: this.pagination,
83 sort: this.sort,
84 search: this.search
85 })
86 : this.blocklistService.getInstanceServerBlocklist({
87 pagination: this.pagination,
88 sort: this.sort,
89 search: this.search
90 })
91
92 return operation.subscribe(
93 resultList => {
94 this.blockedServers = resultList.data
95 this.totalRecords = resultList.total
96 },
97
98 err => this.notifier.error(err.message)
99 )
100 }
101}