diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2020-06-15 13:18:22 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-15 13:18:22 +0200 |
commit | 228393302d98136d4dc35c5f197edc8cebd5d64f (patch) | |
tree | f92b3ad80bcc9c89088ff1d4de5ebff76a3f46ed /client/src/app/+admin/moderation/instance-blocklist/instance-server-blocklist.component.ts | |
parent | 7dfe35288613967f5ac69cd46901ec60c5050b93 (diff) | |
download | PeerTube-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/+admin/moderation/instance-blocklist/instance-server-blocklist.component.ts')
-rw-r--r-- | client/src/app/+admin/moderation/instance-blocklist/instance-server-blocklist.component.ts | 81 |
1 files changed, 6 insertions, 75 deletions
diff --git a/client/src/app/+admin/moderation/instance-blocklist/instance-server-blocklist.component.ts b/client/src/app/+admin/moderation/instance-blocklist/instance-server-blocklist.component.ts index 559c9c0b0..9d4ec174a 100644 --- a/client/src/app/+admin/moderation/instance-blocklist/instance-server-blocklist.component.ts +++ b/client/src/app/+admin/moderation/instance-blocklist/instance-server-blocklist.component.ts | |||
@@ -1,84 +1,15 @@ | |||
1 | import { Component, OnInit, ViewChild } from '@angular/core' | 1 | import { Component } from '@angular/core' |
2 | import { Notifier } from '@app/core' | 2 | import { GenericServerBlocklistComponent, BlocklistComponentType } from '@app/shared/blocklist' |
3 | import { I18n } from '@ngx-translate/i18n-polyfill' | ||
4 | import { RestPagination, RestTable } from '@app/shared' | ||
5 | import { SortMeta } from 'primeng/api' | ||
6 | import { BlocklistService } from '@app/shared/blocklist' | ||
7 | import { ServerBlock } from '../../../../../../shared' | ||
8 | import { BatchDomainsModalComponent } from '@app/+admin/config/shared/batch-domains-modal.component' | ||
9 | 3 | ||
10 | @Component({ | 4 | @Component({ |
11 | selector: 'my-instance-server-blocklist', | 5 | selector: 'my-instance-server-blocklist', |
12 | styleUrls: [ '../moderation.component.scss', './instance-server-blocklist.component.scss' ], | 6 | styleUrls: [ '../../../shared/blocklist/server-blocklist.component.scss' ], |
13 | templateUrl: './instance-server-blocklist.component.html' | 7 | templateUrl: '../../../shared/blocklist/server-blocklist.component.html' |
14 | }) | 8 | }) |
15 | export class InstanceServerBlocklistComponent extends RestTable implements OnInit { | 9 | export class InstanceServerBlocklistComponent extends GenericServerBlocklistComponent { |
16 | @ViewChild('batchDomainsModal') batchDomainsModal: BatchDomainsModalComponent | 10 | mode = BlocklistComponentType.Instance |
17 | |||
18 | blockedServers: ServerBlock[] = [] | ||
19 | totalRecords = 0 | ||
20 | sort: SortMeta = { field: 'createdAt', order: -1 } | ||
21 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } | ||
22 | |||
23 | constructor ( | ||
24 | private notifier: Notifier, | ||
25 | private blocklistService: BlocklistService, | ||
26 | private i18n: I18n | ||
27 | ) { | ||
28 | super() | ||
29 | } | ||
30 | |||
31 | ngOnInit () { | ||
32 | this.initialize() | ||
33 | } | ||
34 | 11 | ||
35 | getIdentifier () { | 12 | getIdentifier () { |
36 | return 'InstanceServerBlocklistComponent' | 13 | return 'InstanceServerBlocklistComponent' |
37 | } | 14 | } |
38 | |||
39 | unblockServer (serverBlock: ServerBlock) { | ||
40 | const host = serverBlock.blockedServer.host | ||
41 | |||
42 | this.blocklistService.unblockServerByInstance(host) | ||
43 | .subscribe( | ||
44 | () => { | ||
45 | this.notifier.success(this.i18n('Instance {{host}} unmuted by your instance.', { host })) | ||
46 | |||
47 | this.loadData() | ||
48 | } | ||
49 | ) | ||
50 | } | ||
51 | |||
52 | addServersToBlock () { | ||
53 | this.batchDomainsModal.openModal() | ||
54 | } | ||
55 | |||
56 | onDomainsToBlock (domains: string[]) { | ||
57 | domains.forEach(domain => { | ||
58 | this.blocklistService.blockServerByInstance(domain) | ||
59 | .subscribe( | ||
60 | () => { | ||
61 | this.notifier.success(this.i18n('Instance {{domain}} muted by your instance.', { domain })) | ||
62 | |||
63 | this.loadData() | ||
64 | } | ||
65 | ) | ||
66 | }) | ||
67 | } | ||
68 | |||
69 | protected loadData () { | ||
70 | return this.blocklistService.getInstanceServerBlocklist({ | ||
71 | pagination: this.pagination, | ||
72 | sort: this.sort, | ||
73 | search: this.search | ||
74 | }) | ||
75 | .subscribe( | ||
76 | resultList => { | ||
77 | this.blockedServers = resultList.data | ||
78 | this.totalRecords = resultList.total | ||
79 | }, | ||
80 | |||
81 | err => this.notifier.error(err.message) | ||
82 | ) | ||
83 | } | ||
84 | } | 15 | } |