]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/shared/moderation/user-moderation-dropdown.component.ts
Add bulk comment actions on account dropdown
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / moderation / user-moderation-dropdown.component.ts
index 9197556b037a70f165a3e7abfa6c29f013cb1f7d..82f39050e691b2d96d207b046dcafd80dfd36b6a 100644 (file)
@@ -7,7 +7,8 @@ import { AuthService, ConfirmService, Notifier, ServerService } from '@app/core'
 import { User, UserRight } from '../../../../../shared/models/users'
 import { Account } from '@app/shared/account/account.model'
 import { BlocklistService } from '@app/shared/blocklist'
-import { ServerConfig } from '@shared/models'
+import { ServerConfig, BulkRemoveCommentsOfBody } from '@shared/models'
+import { BulkService } from '../bulk/bulk.service'
 
 @Component({
   selector: 'my-user-moderation-dropdown',
@@ -20,8 +21,9 @@ export class UserModerationDropdownComponent implements OnInit, OnChanges {
   @Input() account: Account
 
   @Input() buttonSize: 'normal' | 'small' = 'normal'
-  @Input() placement = 'left'
+  @Input() placement = 'left-top left-bottom auto'
   @Input() label: string
+  @Input() container: 'body' | undefined = undefined
 
   @Output() userChanged = new EventEmitter()
   @Output() userDeleted = new EventEmitter()
@@ -37,6 +39,7 @@ export class UserModerationDropdownComponent implements OnInit, OnChanges {
     private serverService: ServerService,
     private userService: UserService,
     private blocklistService: BlocklistService,
+    private bulkService: BulkService,
     private i18n: I18n
   ) { }
 
@@ -228,6 +231,21 @@ export class UserModerationDropdownComponent implements OnInit, OnChanges {
         )
   }
 
+  async bulkRemoveCommentsOf (body: BulkRemoveCommentsOfBody) {
+    const message = this.i18n('Are you sure you want to remove all the comments of this account?')
+    const res = await this.confirmService.confirm(message, this.i18n('Delete account comments'))
+    if (res === false) return
+
+    this.bulkService.removeCommentsOf(body)
+        .subscribe(
+          () => {
+            this.notifier.success(this.i18n('Will remove comments of this account (may take several minutes).'))
+          },
+
+          err => this.notifier.error(err.message)
+        )
+  }
+
   getRouterUserEditLink (user: User) {
     return [ '/admin', 'users', 'update', user.id ]
   }
@@ -299,12 +317,17 @@ export class UserModerationDropdownComponent implements OnInit, OnChanges {
             description: this.i18n('Show back content from that instance for you.'),
             isDisplayed: ({ account }) => !account.userId && account.mutedServerByInstance === true,
             handler: ({ account }) => this.unblockServerByUser(account.host)
+          },
+          {
+            label: this.i18n('Remove comments from your videos'),
+            description: this.i18n('Remove comments of this account from your videos.'),
+            handler: ({ account }) => this.bulkRemoveCommentsOf({ accountName: account.nameWithHost, scope: 'my-videos' })
           }
         ])
 
         let instanceActions: DropdownAction<{ user: User, account: Account }>[] = []
 
-        // Instance actions
+        // Instance actions on account blocklists
         if (authUser.hasRight(UserRight.MANAGE_ACCOUNTS_BLOCKLIST)) {
           instanceActions = instanceActions.concat([
             {
@@ -322,7 +345,7 @@ export class UserModerationDropdownComponent implements OnInit, OnChanges {
           ])
         }
 
-        // Instance actions
+        // Instance actions on server blocklists
         if (authUser.hasRight(UserRight.MANAGE_SERVERS_BLOCKLIST)) {
           instanceActions = instanceActions.concat([
             {
@@ -340,6 +363,16 @@ export class UserModerationDropdownComponent implements OnInit, OnChanges {
           ])
         }
 
+        if (authUser.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT)) {
+          instanceActions = instanceActions.concat([
+            {
+              label: this.i18n('Remove comments from your instance'),
+              description: this.i18n('Remove comments of this account from your instance.'),
+              handler: ({ account }) => this.bulkRemoveCommentsOf({ accountName: account.nameWithHost, scope: 'instance' })
+            }
+          ])
+        }
+
         if (instanceActions.length !== 0) {
           this.userActions.push(instanceActions)
         }