diff options
Diffstat (limited to 'client/src/app/+admin/moderation')
12 files changed, 616 insertions, 15 deletions
diff --git a/client/src/app/+admin/moderation/index.ts b/client/src/app/+admin/moderation/index.ts index 9dab270cc..135b4b408 100644 --- a/client/src/app/+admin/moderation/index.ts +++ b/client/src/app/+admin/moderation/index.ts | |||
@@ -1,4 +1,5 @@ | |||
1 | export * from './abuse-list' | 1 | export * from './abuse-list' |
2 | export * from './instance-blocklist' | 2 | export * from './instance-blocklist' |
3 | export * from './video-block-list' | 3 | export * from './video-block-list' |
4 | export * from './registration-list' | ||
4 | export * from './moderation.routes' | 5 | export * from './moderation.routes' |
diff --git a/client/src/app/+admin/moderation/moderation.routes.ts b/client/src/app/+admin/moderation/moderation.routes.ts index 1ad301039..378d2bed7 100644 --- a/client/src/app/+admin/moderation/moderation.routes.ts +++ b/client/src/app/+admin/moderation/moderation.routes.ts | |||
@@ -4,6 +4,7 @@ import { InstanceAccountBlocklistComponent, InstanceServerBlocklistComponent } f | |||
4 | import { VideoBlockListComponent } from '@app/+admin/moderation/video-block-list' | 4 | import { VideoBlockListComponent } from '@app/+admin/moderation/video-block-list' |
5 | import { UserRightGuard } from '@app/core' | 5 | import { UserRightGuard } from '@app/core' |
6 | import { UserRight } from '@shared/models' | 6 | import { UserRight } from '@shared/models' |
7 | import { RegistrationListComponent } from './registration-list' | ||
7 | 8 | ||
8 | export const ModerationRoutes: Routes = [ | 9 | export const ModerationRoutes: Routes = [ |
9 | { | 10 | { |
@@ -68,7 +69,19 @@ export const ModerationRoutes: Routes = [ | |||
68 | } | 69 | } |
69 | }, | 70 | }, |
70 | 71 | ||
71 | // We move this component in admin overview pages | 72 | { |
73 | path: 'registrations/list', | ||
74 | component: RegistrationListComponent, | ||
75 | canActivate: [ UserRightGuard ], | ||
76 | data: { | ||
77 | userRight: UserRight.MANAGE_REGISTRATIONS, | ||
78 | meta: { | ||
79 | title: $localize`User registrations` | ||
80 | } | ||
81 | } | ||
82 | }, | ||
83 | |||
84 | // We moved this component in admin overview pages | ||
72 | { | 85 | { |
73 | path: 'video-comments', | 86 | path: 'video-comments', |
74 | redirectTo: 'video-comments/list', | 87 | redirectTo: 'video-comments/list', |
diff --git a/client/src/app/+admin/moderation/registration-list/admin-registration.service.ts b/client/src/app/+admin/moderation/registration-list/admin-registration.service.ts new file mode 100644 index 000000000..a9f13cf2f --- /dev/null +++ b/client/src/app/+admin/moderation/registration-list/admin-registration.service.ts | |||
@@ -0,0 +1,81 @@ | |||
1 | import { SortMeta } from 'primeng/api' | ||
2 | import { from } from 'rxjs' | ||
3 | import { catchError, concatMap, toArray } from 'rxjs/operators' | ||
4 | import { HttpClient, HttpParams } from '@angular/common/http' | ||
5 | import { Injectable } from '@angular/core' | ||
6 | import { RestExtractor, RestPagination, RestService } from '@app/core' | ||
7 | import { arrayify } from '@shared/core-utils' | ||
8 | import { ResultList, UserRegistration, UserRegistrationUpdateState } from '@shared/models' | ||
9 | import { environment } from '../../../../environments/environment' | ||
10 | |||
11 | @Injectable() | ||
12 | export class AdminRegistrationService { | ||
13 | private static BASE_REGISTRATION_URL = environment.apiUrl + '/api/v1/users/registrations' | ||
14 | |||
15 | constructor ( | ||
16 | private authHttp: HttpClient, | ||
17 | private restExtractor: RestExtractor, | ||
18 | private restService: RestService | ||
19 | ) { } | ||
20 | |||
21 | listRegistrations (options: { | ||
22 | pagination: RestPagination | ||
23 | sort: SortMeta | ||
24 | search?: string | ||
25 | }) { | ||
26 | const { pagination, sort, search } = options | ||
27 | |||
28 | const url = AdminRegistrationService.BASE_REGISTRATION_URL | ||
29 | |||
30 | let params = new HttpParams() | ||
31 | params = this.restService.addRestGetParams(params, pagination, sort) | ||
32 | |||
33 | if (search) { | ||
34 | params = params.append('search', search) | ||
35 | } | ||
36 | |||
37 | return this.authHttp.get<ResultList<UserRegistration>>(url, { params }) | ||
38 | .pipe( | ||
39 | catchError(res => this.restExtractor.handleError(res)) | ||
40 | ) | ||
41 | } | ||
42 | |||
43 | acceptRegistration (options: { | ||
44 | registration: UserRegistration | ||
45 | moderationResponse: string | ||
46 | preventEmailDelivery: boolean | ||
47 | }) { | ||
48 | const { registration, moderationResponse, preventEmailDelivery } = options | ||
49 | |||
50 | const url = AdminRegistrationService.BASE_REGISTRATION_URL + '/' + registration.id + '/accept' | ||
51 | const body: UserRegistrationUpdateState = { moderationResponse, preventEmailDelivery } | ||
52 | |||
53 | return this.authHttp.post(url, body) | ||
54 | .pipe(catchError(res => this.restExtractor.handleError(res))) | ||
55 | } | ||
56 | |||
57 | rejectRegistration (options: { | ||
58 | registration: UserRegistration | ||
59 | moderationResponse: string | ||
60 | preventEmailDelivery: boolean | ||
61 | }) { | ||
62 | const { registration, moderationResponse, preventEmailDelivery } = options | ||
63 | |||
64 | const url = AdminRegistrationService.BASE_REGISTRATION_URL + '/' + registration.id + '/reject' | ||
65 | const body: UserRegistrationUpdateState = { moderationResponse, preventEmailDelivery } | ||
66 | |||
67 | return this.authHttp.post(url, body) | ||
68 | .pipe(catchError(res => this.restExtractor.handleError(res))) | ||
69 | } | ||
70 | |||
71 | removeRegistrations (registrationsArg: UserRegistration | UserRegistration[]) { | ||
72 | const registrations = arrayify(registrationsArg) | ||
73 | |||
74 | return from(registrations) | ||
75 | .pipe( | ||
76 | concatMap(r => this.authHttp.delete(AdminRegistrationService.BASE_REGISTRATION_URL + '/' + r.id)), | ||
77 | toArray(), | ||
78 | catchError(err => this.restExtractor.handleError(err)) | ||
79 | ) | ||
80 | } | ||
81 | } | ||
diff --git a/client/src/app/+admin/moderation/registration-list/index.ts b/client/src/app/+admin/moderation/registration-list/index.ts new file mode 100644 index 000000000..060b676a4 --- /dev/null +++ b/client/src/app/+admin/moderation/registration-list/index.ts | |||
@@ -0,0 +1,4 @@ | |||
1 | export * from './admin-registration.service' | ||
2 | export * from './process-registration-modal.component' | ||
3 | export * from './process-registration-validators' | ||
4 | export * from './registration-list.component' | ||
diff --git a/client/src/app/+admin/moderation/registration-list/process-registration-modal.component.html b/client/src/app/+admin/moderation/registration-list/process-registration-modal.component.html new file mode 100644 index 000000000..8e46b0cf9 --- /dev/null +++ b/client/src/app/+admin/moderation/registration-list/process-registration-modal.component.html | |||
@@ -0,0 +1,74 @@ | |||
1 | <ng-template #modal> | ||
2 | <div class="modal-header"> | ||
3 | <h4 i18n class="modal-title"> | ||
4 | <ng-container *ngIf="isAccept()">Accept {{ registration.username }} registration</ng-container> | ||
5 | <ng-container *ngIf="isReject()">Reject {{ registration.username }} registration</ng-container> | ||
6 | </h4> | ||
7 | |||
8 | <my-global-icon iconName="cross" aria-label="Close" role="button" (click)="hide()"></my-global-icon> | ||
9 | </div> | ||
10 | |||
11 | <form novalidate [formGroup]="form" (ngSubmit)="processRegistration()"> | ||
12 | <div class="modal-body mb-3"> | ||
13 | |||
14 | <div i18n *ngIf="!registration.emailVerified" class="alert alert-warning"> | ||
15 | Registration email has not been verified. Email delivery has been disabled by default. | ||
16 | </div> | ||
17 | |||
18 | <div class="description"> | ||
19 | <ng-container *ngIf="isAccept()"> | ||
20 | <p i18n> | ||
21 | <strong>Accepting</strong> <em>{{ registration.username }}</em> registration will create the account and channel. | ||
22 | </p> | ||
23 | |||
24 | <p *ngIf="isEmailEnabled()" i18n [ngClass]="{ 'text-decoration-line-through': isPreventEmailDeliveryChecked() }"> | ||
25 | An email will be sent to <em>{{ registration.email }}</em> explaining its account has been created with the moderation response you'll write below. | ||
26 | </p> | ||
27 | |||
28 | <div *ngIf="!isEmailEnabled()" class="alert alert-warning" i18n> | ||
29 | Emails are not enabled on this instance so PeerTube won't be able to send an email to <em>{{ registration.email }}</em> explaining its account has been created. | ||
30 | </div> | ||
31 | </ng-container> | ||
32 | |||
33 | <ng-container *ngIf="isReject()"> | ||
34 | <p i18n [ngClass]="{ 'text-decoration-line-through': isPreventEmailDeliveryChecked() }"> | ||
35 | An email will be sent to <em>{{ registration.email }}</em> explaining its registration request has been <strong>rejected</strong> with the moderation response you'll write below. | ||
36 | </p> | ||
37 | |||
38 | <div *ngIf="!isEmailEnabled()" class="alert alert-warning" i18n> | ||
39 | Emails are not enabled on this instance so PeerTube won't be able to send an email to <em>{{ registration.email }}</em> explaining its registration request has been rejected. | ||
40 | </div> | ||
41 | </ng-container> | ||
42 | </div> | ||
43 | |||
44 | <div class="form-group"> | ||
45 | <label for="moderationResponse" i18n>Send a message to the user</label> | ||
46 | |||
47 | <textarea | ||
48 | formControlName="moderationResponse" ngbAutofocus name="moderationResponse" id="moderationResponse" | ||
49 | [ngClass]="{ 'input-error': formErrors['moderationResponse'] }" class="form-control" | ||
50 | ></textarea> | ||
51 | |||
52 | <div *ngIf="formErrors.moderationResponse" class="form-error"> | ||
53 | {{ formErrors.moderationResponse }} | ||
54 | </div> | ||
55 | </div> | ||
56 | |||
57 | <div class="form-group"> | ||
58 | <my-peertube-checkbox | ||
59 | inputName="preventEmailDelivery" formControlName="preventEmailDelivery" [disabled]="!isEmailEnabled()" | ||
60 | i18n-labelText labelText="Prevent email from being sent to the user" | ||
61 | ></my-peertube-checkbox> | ||
62 | </div> | ||
63 | </div> | ||
64 | |||
65 | <div class="modal-footer inputs"> | ||
66 | <input | ||
67 | type="button" role="button" i18n-value value="Cancel" class="peertube-button grey-button" | ||
68 | (click)="hide()" (key.enter)="hide()" | ||
69 | > | ||
70 | |||
71 | <input type="submit" [value]="getSubmitValue()" class="peertube-button orange-button" [disabled]="!form.valid"> | ||
72 | </div> | ||
73 | </form> | ||
74 | </ng-template> | ||
diff --git a/client/src/app/+admin/moderation/registration-list/process-registration-modal.component.scss b/client/src/app/+admin/moderation/registration-list/process-registration-modal.component.scss new file mode 100644 index 000000000..3e03bed89 --- /dev/null +++ b/client/src/app/+admin/moderation/registration-list/process-registration-modal.component.scss | |||
@@ -0,0 +1,3 @@ | |||
1 | @use '_variables' as *; | ||
2 | @use '_mixins' as *; | ||
3 | |||
diff --git a/client/src/app/+admin/moderation/registration-list/process-registration-modal.component.ts b/client/src/app/+admin/moderation/registration-list/process-registration-modal.component.ts new file mode 100644 index 000000000..3a7e5dea1 --- /dev/null +++ b/client/src/app/+admin/moderation/registration-list/process-registration-modal.component.ts | |||
@@ -0,0 +1,122 @@ | |||
1 | import { Component, EventEmitter, OnInit, Output, ViewChild } from '@angular/core' | ||
2 | import { Notifier, ServerService } from '@app/core' | ||
3 | import { FormReactive, FormReactiveService } from '@app/shared/shared-forms' | ||
4 | import { NgbModal } from '@ng-bootstrap/ng-bootstrap' | ||
5 | import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref' | ||
6 | import { UserRegistration } from '@shared/models' | ||
7 | import { AdminRegistrationService } from './admin-registration.service' | ||
8 | import { REGISTRATION_MODERATION_RESPONSE_VALIDATOR } from './process-registration-validators' | ||
9 | |||
10 | @Component({ | ||
11 | selector: 'my-process-registration-modal', | ||
12 | templateUrl: './process-registration-modal.component.html', | ||
13 | styleUrls: [ './process-registration-modal.component.scss' ] | ||
14 | }) | ||
15 | export class ProcessRegistrationModalComponent extends FormReactive implements OnInit { | ||
16 | @ViewChild('modal', { static: true }) modal: NgbModal | ||
17 | |||
18 | @Output() registrationProcessed = new EventEmitter() | ||
19 | |||
20 | registration: UserRegistration | ||
21 | |||
22 | private openedModal: NgbModalRef | ||
23 | private processMode: 'accept' | 'reject' | ||
24 | |||
25 | constructor ( | ||
26 | protected formReactiveService: FormReactiveService, | ||
27 | private server: ServerService, | ||
28 | private modalService: NgbModal, | ||
29 | private notifier: Notifier, | ||
30 | private registrationService: AdminRegistrationService | ||
31 | ) { | ||
32 | super() | ||
33 | } | ||
34 | |||
35 | ngOnInit () { | ||
36 | this.buildForm({ | ||
37 | moderationResponse: REGISTRATION_MODERATION_RESPONSE_VALIDATOR, | ||
38 | preventEmailDelivery: null | ||
39 | }) | ||
40 | } | ||
41 | |||
42 | isAccept () { | ||
43 | return this.processMode === 'accept' | ||
44 | } | ||
45 | |||
46 | isReject () { | ||
47 | return this.processMode === 'reject' | ||
48 | } | ||
49 | |||
50 | openModal (registration: UserRegistration, mode: 'accept' | 'reject') { | ||
51 | this.processMode = mode | ||
52 | this.registration = registration | ||
53 | |||
54 | this.form.patchValue({ | ||
55 | preventEmailDelivery: !this.isEmailEnabled() || registration.emailVerified !== true | ||
56 | }) | ||
57 | |||
58 | this.openedModal = this.modalService.open(this.modal, { centered: true }) | ||
59 | } | ||
60 | |||
61 | hide () { | ||
62 | this.form.reset() | ||
63 | |||
64 | this.openedModal.close() | ||
65 | } | ||
66 | |||
67 | getSubmitValue () { | ||
68 | if (this.isAccept()) { | ||
69 | return $localize`Accept registration` | ||
70 | } | ||
71 | |||
72 | return $localize`Reject registration` | ||
73 | } | ||
74 | |||
75 | processRegistration () { | ||
76 | if (this.isAccept()) return this.acceptRegistration() | ||
77 | |||
78 | return this.rejectRegistration() | ||
79 | } | ||
80 | |||
81 | isEmailEnabled () { | ||
82 | return this.server.getHTMLConfig().email.enabled | ||
83 | } | ||
84 | |||
85 | isPreventEmailDeliveryChecked () { | ||
86 | return this.form.value.preventEmailDelivery | ||
87 | } | ||
88 | |||
89 | private acceptRegistration () { | ||
90 | this.registrationService.acceptRegistration({ | ||
91 | registration: this.registration, | ||
92 | moderationResponse: this.form.value.moderationResponse, | ||
93 | preventEmailDelivery: this.form.value.preventEmailDelivery | ||
94 | }).subscribe({ | ||
95 | next: () => { | ||
96 | this.notifier.success($localize`${this.registration.username} account created`) | ||
97 | |||
98 | this.registrationProcessed.emit() | ||
99 | this.hide() | ||
100 | }, | ||
101 | |||
102 | error: err => this.notifier.error(err.message) | ||
103 | }) | ||
104 | } | ||
105 | |||
106 | private rejectRegistration () { | ||
107 | this.registrationService.rejectRegistration({ | ||
108 | registration: this.registration, | ||
109 | moderationResponse: this.form.value.moderationResponse, | ||
110 | preventEmailDelivery: this.form.value.preventEmailDelivery | ||
111 | }).subscribe({ | ||
112 | next: () => { | ||
113 | this.notifier.success($localize`${this.registration.username} registration rejected`) | ||
114 | |||
115 | this.registrationProcessed.emit() | ||
116 | this.hide() | ||
117 | }, | ||
118 | |||
119 | error: err => this.notifier.error(err.message) | ||
120 | }) | ||
121 | } | ||
122 | } | ||
diff --git a/client/src/app/+admin/moderation/registration-list/process-registration-validators.ts b/client/src/app/+admin/moderation/registration-list/process-registration-validators.ts new file mode 100644 index 000000000..e01a07d9d --- /dev/null +++ b/client/src/app/+admin/moderation/registration-list/process-registration-validators.ts | |||
@@ -0,0 +1,11 @@ | |||
1 | import { Validators } from '@angular/forms' | ||
2 | import { BuildFormValidator } from '@app/shared/form-validators' | ||
3 | |||
4 | export const REGISTRATION_MODERATION_RESPONSE_VALIDATOR: BuildFormValidator = { | ||
5 | VALIDATORS: [ Validators.required, Validators.minLength(2), Validators.maxLength(3000) ], | ||
6 | MESSAGES: { | ||
7 | required: $localize`Moderation response is required.`, | ||
8 | minlength: $localize`Moderation response must be at least 2 characters long.`, | ||
9 | maxlength: $localize`Moderation response cannot be more than 3000 characters long.` | ||
10 | } | ||
11 | } | ||
diff --git a/client/src/app/+admin/moderation/registration-list/registration-list.component.html b/client/src/app/+admin/moderation/registration-list/registration-list.component.html new file mode 100644 index 000000000..a2b888101 --- /dev/null +++ b/client/src/app/+admin/moderation/registration-list/registration-list.component.html | |||
@@ -0,0 +1,135 @@ | |||
1 | <h1> | ||
2 | <my-global-icon iconName="user" aria-hidden="true"></my-global-icon> | ||
3 | <ng-container i18n>Registration requests</ng-container> | ||
4 | </h1> | ||
5 | |||
6 | <p-table | ||
7 | [value]="registrations" [paginator]="totalRecords > 0" [totalRecords]="totalRecords" [rows]="rowsPerPage" [first]="pagination.start" | ||
8 | [rowsPerPageOptions]="rowsPerPageOptions" [sortField]="sort.field" [sortOrder]="sort.order" dataKey="id" | ||
9 | [lazy]="true" (onLazyLoad)="loadLazy($event)" [lazyLoadOnInit]="false" | ||
10 | [(selection)]="selectedRows" [showCurrentPageReport]="true" i18n-currentPageReportTemplate | ||
11 | currentPageReportTemplate="Showing {{'{first}'}} to {{'{last}'}} of {{'{totalRecords}'}} registrations" | ||
12 | [expandedRowKeys]="expandedRows" | ||
13 | > | ||
14 | <ng-template pTemplate="caption"> | ||
15 | <div class="caption"> | ||
16 | <div class="left-buttons"> | ||
17 | <my-action-dropdown | ||
18 | *ngIf="isInSelectionMode()" i18n-label label="Batch actions" theme="orange" | ||
19 | [actions]="bulkActions" [entry]="selectedRows" | ||
20 | > | ||
21 | </my-action-dropdown> | ||
22 | </div> | ||
23 | |||
24 | <div class="ms-auto"> | ||
25 | <my-advanced-input-filter (search)="onSearch($event)"></my-advanced-input-filter> | ||
26 | </div> | ||
27 | </div> | ||
28 | </ng-template> | ||
29 | |||
30 | <ng-template pTemplate="header"> | ||
31 | <tr> <!-- header --> | ||
32 | <th style="width: 40px"> | ||
33 | <p-tableHeaderCheckbox ariaLabel="Select all rows" i18n-ariaLabel></p-tableHeaderCheckbox> | ||
34 | </th> | ||
35 | <th style="width: 40px;"></th> | ||
36 | <th style="width: 150px;"></th> | ||
37 | <th i18n>Account</th> | ||
38 | <th i18n>Email</th> | ||
39 | <th i18n>Channel</th> | ||
40 | <th i18n>Registration reason</th> | ||
41 | <th i18n pSortableColumn="state" style="width: 80px;">State <p-sortIcon field="state"></p-sortIcon></th> | ||
42 | <th i18n>Moderation response</th> | ||
43 | <th style="width: 150px;" i18n pSortableColumn="createdAt">Requested on <p-sortIcon field="createdAt"></p-sortIcon></th> | ||
44 | </tr> | ||
45 | </ng-template> | ||
46 | |||
47 | <ng-template pTemplate="body" let-expanded="expanded" let-registration> | ||
48 | <tr [pSelectableRow]="registration"> | ||
49 | <td class="checkbox-cell"> | ||
50 | <p-tableCheckbox [value]="registration" ariaLabel="Select this row" i18n-ariaLabel></p-tableCheckbox> | ||
51 | </td> | ||
52 | |||
53 | <td class="expand-cell" [pRowToggler]="registration"> | ||
54 | <my-table-expander-icon [expanded]="expanded"></my-table-expander-icon> | ||
55 | </td> | ||
56 | |||
57 | <td class="action-cell"> | ||
58 | <my-action-dropdown | ||
59 | [ngClass]="{ 'show': expanded }" placement="bottom-right top-right left auto" container="body" | ||
60 | i18n-label label="Actions" [actions]="registrationActions" [entry]="registration" | ||
61 | ></my-action-dropdown> | ||
62 | </td> | ||
63 | |||
64 | <td> | ||
65 | <div class="chip two-lines"> | ||
66 | <div> | ||
67 | <span>{{ registration.username }}</span> | ||
68 | <span class="muted">{{ registration.accountDisplayName }}</span> | ||
69 | </div> | ||
70 | </div> | ||
71 | </td> | ||
72 | |||
73 | <td> | ||
74 | <my-user-email-info [entry]="registration" [requiresEmailVerification]="requiresEmailVerification"></my-user-email-info> | ||
75 | </td> | ||
76 | |||
77 | <td> | ||
78 | <div class="chip two-lines"> | ||
79 | <div> | ||
80 | <span>{{ registration.channelHandle }}</span> | ||
81 | <span class="muted">{{ registration.channelDisplayName }}</span> | ||
82 | </div> | ||
83 | </div> | ||
84 | </td> | ||
85 | |||
86 | <td container="body" placement="left auto" [ngbTooltip]="registration.registrationReason"> | ||
87 | {{ registration.registrationReason }} | ||
88 | </td> | ||
89 | |||
90 | <td class="c-hand abuse-states" [pRowToggler]="registration"> | ||
91 | <my-global-icon *ngIf="isRegistrationAccepted(registration)" [title]="registration.state.label" iconName="tick"></my-global-icon> | ||
92 | <my-global-icon *ngIf="isRegistrationRejected(registration)" [title]="registration.state.label" iconName="cross"></my-global-icon> | ||
93 | </td> | ||
94 | |||
95 | <td container="body" placement="left auto" [ngbTooltip]="registration.moderationResponse"> | ||
96 | {{ registration.moderationResponse }} | ||
97 | </td> | ||
98 | |||
99 | <td class="c-hand" [pRowToggler]="registration">{{ registration.createdAt | date: 'short' }}</td> | ||
100 | </tr> | ||
101 | </ng-template> | ||
102 | |||
103 | <ng-template pTemplate="rowexpansion" let-registration> | ||
104 | <tr> | ||
105 | <td colspan="9"> | ||
106 | <div class="moderation-expanded"> | ||
107 | <div class="left"> | ||
108 | <div class="d-flex"> | ||
109 | <span class="moderation-expanded-label" i18n>Registration reason:</span> | ||
110 | <span class="moderation-expanded-text" [innerHTML]="registration.registrationReasonHTML"></span> | ||
111 | </div> | ||
112 | |||
113 | <div *ngIf="registration.moderationResponse"> | ||
114 | <span class="moderation-expanded-label" i18n>Moderation response:</span> | ||
115 | <span class="moderation-expanded-text" [innerHTML]="registration.moderationResponseHTML"></span> | ||
116 | </div> | ||
117 | </div> | ||
118 | </div> | ||
119 | </td> | ||
120 | </tr> | ||
121 | </ng-template> | ||
122 | |||
123 | <ng-template pTemplate="emptymessage"> | ||
124 | <tr> | ||
125 | <td colspan="9"> | ||
126 | <div class="no-results"> | ||
127 | <ng-container *ngIf="search" i18n>No registrations found matching current filters.</ng-container> | ||
128 | <ng-container *ngIf="!search" i18n>No registrations found.</ng-container> | ||
129 | </div> | ||
130 | </td> | ||
131 | </tr> | ||
132 | </ng-template> | ||
133 | </p-table> | ||
134 | |||
135 | <my-process-registration-modal #processRegistrationModal (registrationProcessed)="onRegistrationProcessed()"></my-process-registration-modal> | ||
diff --git a/client/src/app/+admin/moderation/registration-list/registration-list.component.scss b/client/src/app/+admin/moderation/registration-list/registration-list.component.scss new file mode 100644 index 000000000..9cae08e85 --- /dev/null +++ b/client/src/app/+admin/moderation/registration-list/registration-list.component.scss | |||
@@ -0,0 +1,7 @@ | |||
1 | @use '_mixins' as *; | ||
2 | @use '_variables' as *; | ||
3 | |||
4 | my-global-icon { | ||
5 | width: 24px; | ||
6 | height: 24px; | ||
7 | } | ||
diff --git a/client/src/app/+admin/moderation/registration-list/registration-list.component.ts b/client/src/app/+admin/moderation/registration-list/registration-list.component.ts new file mode 100644 index 000000000..ed8fbec51 --- /dev/null +++ b/client/src/app/+admin/moderation/registration-list/registration-list.component.ts | |||
@@ -0,0 +1,151 @@ | |||
1 | import { SortMeta } from 'primeng/api' | ||
2 | import { Component, OnInit, ViewChild } from '@angular/core' | ||
3 | import { ActivatedRoute, Router } from '@angular/router' | ||
4 | import { ConfirmService, MarkdownService, Notifier, RestPagination, RestTable, ServerService } from '@app/core' | ||
5 | import { prepareIcu } from '@app/helpers' | ||
6 | import { AdvancedInputFilter } from '@app/shared/shared-forms' | ||
7 | import { DropdownAction } from '@app/shared/shared-main' | ||
8 | import { UserRegistration, UserRegistrationState } from '@shared/models' | ||
9 | import { AdminRegistrationService } from './admin-registration.service' | ||
10 | import { ProcessRegistrationModalComponent } from './process-registration-modal.component' | ||
11 | |||
12 | @Component({ | ||
13 | selector: 'my-registration-list', | ||
14 | templateUrl: './registration-list.component.html', | ||
15 | styleUrls: [ '../../../shared/shared-moderation/moderation.scss', './registration-list.component.scss' ] | ||
16 | }) | ||
17 | export class RegistrationListComponent extends RestTable <UserRegistration> implements OnInit { | ||
18 | @ViewChild('processRegistrationModal', { static: true }) processRegistrationModal: ProcessRegistrationModalComponent | ||
19 | |||
20 | registrations: (UserRegistration & { registrationReasonHTML?: string, moderationResponseHTML?: string })[] = [] | ||
21 | totalRecords = 0 | ||
22 | sort: SortMeta = { field: 'createdAt', order: -1 } | ||
23 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } | ||
24 | |||
25 | registrationActions: DropdownAction<UserRegistration>[][] = [] | ||
26 | bulkActions: DropdownAction<UserRegistration[]>[] = [] | ||
27 | |||
28 | inputFilters: AdvancedInputFilter[] = [] | ||
29 | |||
30 | requiresEmailVerification: boolean | ||
31 | |||
32 | constructor ( | ||
33 | protected route: ActivatedRoute, | ||
34 | protected router: Router, | ||
35 | private server: ServerService, | ||
36 | private notifier: Notifier, | ||
37 | private markdownRenderer: MarkdownService, | ||
38 | private confirmService: ConfirmService, | ||
39 | private adminRegistrationService: AdminRegistrationService | ||
40 | ) { | ||
41 | super() | ||
42 | |||
43 | this.registrationActions = [ | ||
44 | [ | ||
45 | { | ||
46 | label: $localize`Accept this request`, | ||
47 | handler: registration => this.openRegistrationRequestProcessModal(registration, 'accept'), | ||
48 | isDisplayed: registration => registration.state.id === UserRegistrationState.PENDING | ||
49 | }, | ||
50 | { | ||
51 | label: $localize`Reject this request`, | ||
52 | handler: registration => this.openRegistrationRequestProcessModal(registration, 'reject'), | ||
53 | isDisplayed: registration => registration.state.id === UserRegistrationState.PENDING | ||
54 | }, | ||
55 | { | ||
56 | label: $localize`Remove this request`, | ||
57 | handler: registration => this.removeRegistrations([ registration ]) | ||
58 | } | ||
59 | ] | ||
60 | ] | ||
61 | |||
62 | this.bulkActions = [ | ||
63 | { | ||
64 | label: $localize`Delete`, | ||
65 | handler: registrations => this.removeRegistrations(registrations) | ||
66 | } | ||
67 | ] | ||
68 | } | ||
69 | |||
70 | ngOnInit () { | ||
71 | this.initialize() | ||
72 | |||
73 | this.server.getConfig() | ||
74 | .subscribe(config => { | ||
75 | this.requiresEmailVerification = config.signup.requiresEmailVerification | ||
76 | }) | ||
77 | } | ||
78 | |||
79 | getIdentifier () { | ||
80 | return 'RegistrationListComponent' | ||
81 | } | ||
82 | |||
83 | isRegistrationAccepted (registration: UserRegistration) { | ||
84 | return registration.state.id === UserRegistrationState.ACCEPTED | ||
85 | } | ||
86 | |||
87 | isRegistrationRejected (registration: UserRegistration) { | ||
88 | return registration.state.id === UserRegistrationState.REJECTED | ||
89 | } | ||
90 | |||
91 | onRegistrationProcessed () { | ||
92 | this.reloadData() | ||
93 | } | ||
94 | |||
95 | protected reloadDataInternal () { | ||
96 | this.adminRegistrationService.listRegistrations({ | ||
97 | pagination: this.pagination, | ||
98 | sort: this.sort, | ||
99 | search: this.search | ||
100 | }).subscribe({ | ||
101 | next: async resultList => { | ||
102 | this.totalRecords = resultList.total | ||
103 | this.registrations = resultList.data | ||
104 | |||
105 | for (const registration of this.registrations) { | ||
106 | registration.registrationReasonHTML = await this.toHtml(registration.registrationReason) | ||
107 | registration.moderationResponseHTML = await this.toHtml(registration.moderationResponse) | ||
108 | } | ||
109 | }, | ||
110 | |||
111 | error: err => this.notifier.error(err.message) | ||
112 | }) | ||
113 | } | ||
114 | |||
115 | private openRegistrationRequestProcessModal (registration: UserRegistration, mode: 'accept' | 'reject') { | ||
116 | this.processRegistrationModal.openModal(registration, mode) | ||
117 | } | ||
118 | |||
119 | private async removeRegistrations (registrations: UserRegistration[]) { | ||
120 | const icuParams = { count: registrations.length, username: registrations[0].username } | ||
121 | |||
122 | // eslint-disable-next-line max-len | ||
123 | const message = prepareIcu($localize`Do you really want to delete {count, plural, =1 {{username} registration request?} other {{count} registration requests?}}`)( | ||
124 | icuParams, | ||
125 | $localize`Do you really want to delete these registration requests?` | ||
126 | ) | ||
127 | |||
128 | const res = await this.confirmService.confirm(message, $localize`Delete`) | ||
129 | if (res === false) return | ||
130 | |||
131 | this.adminRegistrationService.removeRegistrations(registrations) | ||
132 | .subscribe({ | ||
133 | next: () => { | ||
134 | // eslint-disable-next-line max-len | ||
135 | const message = prepareIcu($localize`Removed {count, plural, =1 {{username} registration request} other {{count} registration requests}}`)( | ||
136 | icuParams, | ||
137 | $localize`Registration requests removed` | ||
138 | ) | ||
139 | |||
140 | this.notifier.success(message) | ||
141 | this.reloadData() | ||
142 | }, | ||
143 | |||
144 | error: err => this.notifier.error(err.message) | ||
145 | }) | ||
146 | } | ||
147 | |||
148 | private toHtml (text: string) { | ||
149 | return this.markdownRenderer.textMarkdownToHTML({ markdown: text }) | ||
150 | } | ||
151 | } | ||
diff --git a/client/src/app/+admin/moderation/video-block-list/video-block-list.component.ts b/client/src/app/+admin/moderation/video-block-list/video-block-list.component.ts index efd99e52b..f365a2500 100644 --- a/client/src/app/+admin/moderation/video-block-list/video-block-list.component.ts +++ b/client/src/app/+admin/moderation/video-block-list/video-block-list.component.ts | |||
@@ -159,26 +159,25 @@ export class VideoBlockListComponent extends RestTable implements OnInit { | |||
159 | }) | 159 | }) |
160 | } | 160 | } |
161 | 161 | ||
162 | protected reloadData () { | 162 | protected reloadDataInternal () { |
163 | this.videoBlocklistService.listBlocks({ | 163 | this.videoBlocklistService.listBlocks({ |
164 | pagination: this.pagination, | 164 | pagination: this.pagination, |
165 | sort: this.sort, | 165 | sort: this.sort, |
166 | search: this.search | 166 | search: this.search |
167 | }) | 167 | }).subscribe({ |
168 | .subscribe({ | 168 | next: async resultList => { |
169 | next: async resultList => { | 169 | this.totalRecords = resultList.total |
170 | this.totalRecords = resultList.total | ||
171 | 170 | ||
172 | this.blocklist = resultList.data | 171 | this.blocklist = resultList.data |
173 | 172 | ||
174 | for (const element of this.blocklist) { | 173 | for (const element of this.blocklist) { |
175 | Object.assign(element, { | 174 | Object.assign(element, { |
176 | reasonHtml: await this.toHtml(element.reason) | 175 | reasonHtml: await this.toHtml(element.reason) |
177 | }) | 176 | }) |
178 | } | 177 | } |
179 | }, | 178 | }, |
180 | 179 | ||
181 | error: err => this.notifier.error(err.message) | 180 | error: err => this.notifier.error(err.message) |
182 | }) | 181 | }) |
183 | } | 182 | } |
184 | } | 183 | } |