Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Add bulk accept/reject registration requests

Chocobozzz0f2f54dce95a
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
index 507dbc55bc..3d0ee2de75 100644
--- 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
@@ -1,11 +1,7 @@
<ng-template #modal>
<div class="modal-header">
- <h4 i18n class="modal-title">
- @if (isAccept()) {
- Accept {{ registration.username }} registration
- } @else if (isReject()) {
- Reject {{ registration.username }} registration
- }
+ <h4 class="modal-title">
+ {{ getModalTitle() }}
</h4>
<button class="border-0 p-0" title="Close this modal" i18n-title (click)="hide()">
@@ -18,36 +14,47 @@
<div class="description">
@if (isAccept()) {
<p i18n>
- <strong>Accepting</strong>&nbsp;<em>{{ registration.username }}</em> registration will create the account and channel.
+ @if (hasMultipleRegistrations()) {
+ <strong>Accepting</strong>&nbsp;<em>{{ registrations.length }}</em> registrations will create the accounts and channels.
+ } @else {
+ <strong>Accepting</strong>&nbsp;<em>{{ registration.username }}</em> registration will create the account and channel.
+ }
</p>
@if (isEmailEnabled()) {
- @if (!registration.emailVerified) {
+ @if (hasUnverifiedEmails()) {
<my-alert i18n type="warning">
- Registration email has not been verified. Email delivery has been disabled by default.
+ At least one registration email has not been verified. Email delivery has been disabled by default.
</my-alert>
} @else {
<p i18n [ngClass]="{ 'text-decoration-line-through': isPreventEmailDeliveryChecked() }">
- An email will be sent to <em>{{ registration.email }}</em> explaining its account has been created with the moderation response you'll write
- below.
+ @if (hasMultipleRegistrations()) {
+ An email will be sent to each user explaining its account has been created with the moderation response you'll write below.
+ } @else {
+ An email will be sent to <em>{{ registration.email }}</em> explaining its account has been created with the moderation response you'll write
+ below.
+ }
</p>
}
} @else {
<my-alert type="warning" i18n>
- 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.
+ Emails are not enabled on this instance so PeerTube won't be able to send an email explaining accounts have been created.
</my-alert>
}
} @else if (isReject()) {
<p i18n [ngClass]="{ 'text-decoration-line-through': isPreventEmailDeliveryChecked() }">
- 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.
+ @if (hasMultipleRegistrations()) {
+ An email will be sent to each user explaining its registration request has been <strong>rejected</strong> with the moderation response you'll write
+ below.
+ } @else {
+ 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.
+ }
</p>
@if (!isEmailEnabled()) {
<my-alert type="warning" i18n>
- 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.
+ Emails are not enabled on this instance so PeerTube won't be able to send an email explaining registration requests have been rejected.
</my-alert>
}
}
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
index b3fbedc7cf..47195dfdf2 100644
--- 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
@@ -2,11 +2,15 @@ import { CommonModule } from '@angular/common'
import { Component, OnInit, inject, output, viewChild } from '@angular/core'
import { FormsModule, ReactiveFormsModule } from '@angular/forms'
import { Notifier, ServerService } from '@app/core'
+import { formatICU } from '@app/helpers'
import { FormReactive } from '@app/shared/shared-forms/form-reactive'
import { FormReactiveService } from '@app/shared/shared-forms/form-reactive.service'
import { AlertComponent } from '@app/shared/shared-main/common/alert.component'
import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'
+import { arrayify } from '@peertube/peertube-core-utils'
import { UserRegistration } from '@peertube/peertube-models'
+import { from } from 'rxjs'
+import { concatMap, toArray } from 'rxjs/operators'
import { PeertubeCheckboxComponent } from '../../../shared/shared-forms/peertube-checkbox.component'
import { GlobalIconComponent } from '../../../shared/shared-icons/global-icon.component'
import { AdminRegistrationService } from './admin-registration.service'
@@ -28,7 +32,7 @@ export class ProcessRegistrationModalComponent extends FormReactive implements O
readonly registrationProcessed = output()
- registration: UserRegistration
+ registrations: UserRegistration[] = []
private openedModal: NgbModalRef
private processMode: 'accept' | 'reject'
@@ -48,18 +52,18 @@ export class ProcessRegistrationModalComponent extends FormReactive implements O
return this.processMode === 'reject'
}
- openModal (registration: UserRegistration, mode: 'accept' | 'reject') {
+ openModal (registrationsArg: UserRegistration | UserRegistration[], mode: 'accept' | 'reject') {
this.processMode = mode
- this.registration = registration
+ this.registrations = arrayify(registrationsArg)
- if (this.registration.emailVerified !== true || !this.isEmailEnabled()) {
+ if (this.shouldDisableEmailDelivery()) {
this.form.get('preventEmailDelivery').disable()
} else {
this.form.get('preventEmailDelivery').enable()
}
this.form.patchValue({
- preventEmailDelivery: !this.isEmailEnabled() || registration.emailVerified !== true
+ preventEmailDelivery: this.shouldDisableEmailDelivery()
})
this.openedModal = this.modalService.open(this.modal(), { centered: true })
@@ -67,16 +71,35 @@ export class ProcessRegistrationModalComponent extends FormReactive implements O
hide () {
this.form.reset()
+ this.registrations = []
this.openedModal.close()
}
getSubmitValue () {
- if (this.isAccept()) {
- return $localize`Accept registration`
- }
+ const count = this.registrations.length
+ const label = this.isAccept()
+ ? $localize`{count, plural, =1 {Accept registration} other {Accept registrations}}`
+ : $localize`{count, plural, =1 {Reject registration} other {Reject registrations}}`
+
+ return formatICU(label, { count })
+ }
+
+ getModalTitle () {
+ const count = this.registrations.length
+ const label = this.isAccept()
+ ? $localize`{count, plural, =1 {Accept registration} other {Accept {count} registrations}}`
+ : $localize`{count, plural, =1 {Reject registration} other {Reject {count} registrations}}`
+
+ return formatICU(label, { count })
+ }
+
+ hasMultipleRegistrations () {
+ return this.registrations.length > 1
+ }
- return $localize`Reject registration`
+ get registration () {
+ return this.registrations[0]
}
processRegistration () {
@@ -93,37 +116,75 @@ export class ProcessRegistrationModalComponent extends FormReactive implements O
return this.form.value.preventEmailDelivery
}
+ hasUnverifiedEmails () {
+ return this.registrations.some(registration => registration.emailVerified !== true)
+ }
+
+ shouldDisableEmailDelivery () {
+ return !this.isEmailEnabled() || this.hasUnverifiedEmails()
+ }
+
private acceptRegistration () {
- this.registrationService.acceptRegistration({
- registration: this.registration,
- moderationResponse: this.form.value.moderationResponse,
- preventEmailDelivery: this.form.value.preventEmailDelivery
- }).subscribe({
- next: () => {
- this.notifier.success($localize`${this.registration.username} account created`)
-
- this.registrationProcessed.emit()
- this.hide()
- },
-
- error: err => this.notifier.handleError(err)
- })
+ const moderationResponse = this.form.value.moderationResponse
+ const preventEmailDelivery = this.form.value.preventEmailDelivery
+
+ from(this.registrations)
+ .pipe(
+ concatMap(registration =>
+ this.registrationService.acceptRegistration({
+ registration,
+ moderationResponse,
+ preventEmailDelivery
+ })
+ ),
+ toArray()
+ )
+ .subscribe({
+ next: () => {
+ const count = this.registrations.length
+ const message = formatICU(
+ $localize`{count, plural, =1 {{username} account created} other {{count} accounts created}}`,
+ { count, username: this.registration?.username }
+ )
+
+ this.notifier.success(message)
+ this.registrationProcessed.emit()
+ this.hide()
+ },
+
+ error: err => this.notifier.handleError(err)
+ })
}
private rejectRegistration () {
- this.registrationService.rejectRegistration({
- registration: this.registration,
- moderationResponse: this.form.value.moderationResponse,
- preventEmailDelivery: this.form.value.preventEmailDelivery
- }).subscribe({
- next: () => {
- this.notifier.success($localize`${this.registration.username} registration rejected`)
-
- this.registrationProcessed.emit()
- this.hide()
- },
-
- error: err => this.notifier.handleError(err)
- })
+ const moderationResponse = this.form.value.moderationResponse
+ const preventEmailDelivery = this.form.value.preventEmailDelivery
+
+ from(this.registrations)
+ .pipe(
+ concatMap(registration =>
+ this.registrationService.rejectRegistration({
+ registration,
+ moderationResponse,
+ preventEmailDelivery
+ })
+ ),
+ toArray()
+ )
+ .subscribe({
+ next: () => {
+ const count = this.registrations.length
+ const message = formatICU(
+ $localize`{count, plural, =1 {{username} registration rejected} other {{count} registrations rejected}}`,
+ { count, username: this.registration?.username }
+ )
+
+ this.notifier.success(message)
+ this.registrationProcessed.emit()
+ this.hide()
+ },
+
+ error: err => this.notifier.handleError(err)
+ })
}
}
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
index b876af733e..51a8c1b23b 100644
--- a/client/src/app/+admin/moderation/registration-list/registration-list.component.ts
+++ b/client/src/app/+admin/moderation/registration-list/registration-list.component.ts
@@ -1,5 +1,4 @@
import { Component, OnInit, inject, viewChild } from '@angular/core'
-import { ActivatedRoute, Router } from '@angular/router'
import { ConfirmService, MarkdownService, Notifier, ServerService } from '@app/core'
import { formatICU } from '@app/helpers'
import { PTDatePipe } from '@app/shared/shared-main/common/date.pipe'
@@ -33,8 +32,6 @@ type ColumnName = 'account' | 'email' | 'channel' | 'registrationReason' | 'stat
]
})
export class RegistrationListComponent implements OnInit {
- protected route = inject(ActivatedRoute)
- protected router = inject(Router)
private server = inject(ServerService)
private notifier = inject(Notifier)
private markdownRenderer = inject(MarkdownService)
@@ -45,7 +42,7 @@ export class RegistrationListComponent implements OnInit {
readonly table = viewChild<TableComponent<UserRegistration, DataLoaderOptionsBase, ColumnName>>('table')
registrationActions: DropdownAction<UserRegistration>[][] = []
- bulkActions: DropdownAction<UserRegistration[]>[] = []
+ bulkActions: DropdownAction<UserRegistration[]>[][] = []
requiresEmailVerification: boolean
@@ -85,10 +82,24 @@ export class RegistrationListComponent implements OnInit {
]
this.bulkActions = [
- {
- label: $localize`Delete`,
- handler: registrations => this.removeRegistrations(registrations)
- }
+ [
+ {
+ label: $localize`Accept`,
+ handler: registrations => this.openRegistrationRequestProcessModal(registrations, 'accept'),
+ isDisplayed: registrations => registrations.every(registration => registration.state.id === UserRegistrationState.PENDING)
+ },
+ {
+ label: $localize`Reject`,
+ handler: registrations => this.openRegistrationRequestProcessModal(registrations, 'reject'),
+ isDisplayed: registrations => registrations.every(registration => registration.state.id === UserRegistrationState.PENDING)
+ }
+ ],
+ [
+ {
+ label: $localize`Delete`,
+ handler: registrations => this.removeRegistrations(registrations)
+ }
+ ]
]
}
@@ -125,8 +136,8 @@ export class RegistrationListComponent implements OnInit {
)
}
- private openRegistrationRequestProcessModal (registration: UserRegistration, mode: 'accept' | 'reject') {
- this.processRegistrationModal().openModal(registration, mode)
+ private openRegistrationRequestProcessModal (registrations: UserRegistration | UserRegistration[], mode: 'accept' | 'reject') {
+ this.processRegistrationModal().openModal(registrations, mode)
}
private async removeRegistrations (registrations: UserRegistration[]) {
diff --git a/client/src/app/shared/shared-moderation/generic-account-blocklist.component.ts b/client/src/app/shared/shared-moderation/generic-account-blocklist.component.ts
index 87468d47c2..d58ec71af5 100644
--- a/client/src/app/shared/shared-moderation/generic-account-blocklist.component.ts
+++ b/client/src/app/shared/shared-moderation/generic-account-blocklist.component.ts
@@ -1,7 +1,6 @@
import { Component, inject, input, viewChild } from '@angular/core'
import { Notifier } from '@app/core'
import { ActorAvatarComponent } from '../shared-actor-image/actor-avatar.component'
-import { SearchInputComponent } from '../shared-forms/search-input.component'
import { PTDatePipe } from '../shared-main/common/date.pipe'
import { NumberFormatterPipe } from '../shared-main/common/number-formatter.pipe'
import { DataLoaderOptionsBase, TableColumnInfo, TableComponent } from '../shared-tables/table.component'
@@ -14,7 +13,6 @@ import { BlocklistComponentType, BlocklistService } from './blocklist.service'
imports: [
TableComponent,
NumberFormatterPipe,
- SearchInputComponent,
ActorAvatarComponent,
PTDatePipe
]
diff --git a/client/src/app/shared/shared-moderation/generic-server-blocklist.component.ts b/client/src/app/shared/shared-moderation/generic-server-blocklist.component.ts
index b153115411..8382407c58 100644
--- a/client/src/app/shared/shared-moderation/generic-server-blocklist.component.ts
+++ b/client/src/app/shared/shared-moderation/generic-server-blocklist.component.ts
@@ -2,7 +2,6 @@ import { Component, inject, input, viewChild } from '@angular/core'
import { Notifier } from '@app/core'
import { BatchDomainsModalComponent } from '@app/shared/shared-moderation/batch-domains-modal.component'
import { ServerBlock } from '@peertube/peertube-models'
-import { SearchInputComponent } from '../shared-forms/search-input.component'
import { GlobalIconComponent } from '../shared-icons/global-icon.component'
import { PTDatePipe } from '../shared-main/common/date.pipe'
import { NumberFormatterPipe } from '../shared-main/common/number-formatter.pipe'
@@ -15,7 +14,6 @@ import { BlocklistComponentType, BlocklistService } from './blocklist.service'
imports: [
TableComponent,
NumberFormatterPipe,
- SearchInputComponent,
PTDatePipe,
GlobalIconComponent,
BatchDomainsModalComponent