]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/shared/shared-moderation/user-moderation-dropdown.component.ts
Implement two factor in client
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-moderation / user-moderation-dropdown.component.ts
index 0d19565efb6db6096c9b67d79faf75bea088aa9d..c69a45c2581fc064c54ae613aebc1aac6453dde0 100644 (file)
@@ -7,6 +7,16 @@ import { BlocklistService } from './blocklist.service'
 import { BulkService } from './bulk.service'
 import { UserBanModalComponent } from './user-ban-modal.component'
 
+export type AccountMutedStatus =
+  Pick<Account, 'id' | 'nameWithHost' | 'host' | 'userId' |
+  'mutedByInstance' | 'mutedByUser' | 'mutedServerByInstance' | 'mutedServerByUser'>
+
+export type UserModerationDisplayType = {
+  myAccount?: boolean
+  instanceAccount?: boolean
+  instanceUser?: boolean
+}
+
 @Component({
   selector: 'my-user-moderation-dropdown',
   templateUrl: './user-moderation-dropdown.component.html'
@@ -15,8 +25,8 @@ export class UserModerationDropdownComponent implements OnInit, OnChanges {
   @ViewChild('userBanModal') userBanModal: UserBanModalComponent
 
   @Input() user: User
-  @Input() account: Account
-  @Input() prependActions: DropdownAction<{ user: User, account: Account }>[]
+  @Input() account: AccountMutedStatus
+  @Input() prependActions: DropdownAction<{ user: User, account: AccountMutedStatus }>[]
 
   @Input() buttonSize: 'normal' | 'small' = 'normal'
   @Input() buttonStyled = true
@@ -24,10 +34,16 @@ export class UserModerationDropdownComponent implements OnInit, OnChanges {
   @Input() label: string
   @Input() container: 'body' | undefined = undefined
 
+  @Input() displayOptions: UserModerationDisplayType = {
+    myAccount: true,
+    instanceAccount: true,
+    instanceUser: true
+  }
+
   @Output() userChanged = new EventEmitter()
   @Output() userDeleted = new EventEmitter()
 
-  userActions: DropdownAction<{ user: User, account: Account }>[][] = []
+  userActions: DropdownAction<{ user: User, account: AccountMutedStatus }>[][] = []
 
   requiresEmailVerification = false
 
@@ -84,7 +100,8 @@ export class UserModerationDropdownComponent implements OnInit, OnChanges {
       return
     }
 
-    const message = $localize`If you remove user ${user.username}, you won't be able to create another with the same username!`
+    // eslint-disable-next-line max-len
+    const message = $localize`If you remove this user, you won't be able to create another user or channel with <strong>${user.username}</strong> username!`
     const res = await this.confirmService.confirm(message, $localize`Delete ${user.username}`)
     if (res === false) return
 
@@ -111,7 +128,7 @@ export class UserModerationDropdownComponent implements OnInit, OnChanges {
       })
   }
 
-  blockAccountByUser (account: Account) {
+  blockAccountByUser (account: AccountMutedStatus) {
     this.blocklistService.blockAccountByUser(account)
         .subscribe({
           next: () => {
@@ -125,7 +142,7 @@ export class UserModerationDropdownComponent implements OnInit, OnChanges {
         })
   }
 
-  unblockAccountByUser (account: Account) {
+  unblockAccountByUser (account: AccountMutedStatus) {
     this.blocklistService.unblockAccountByUser(account)
         .subscribe({
           next: () => {
@@ -167,7 +184,7 @@ export class UserModerationDropdownComponent implements OnInit, OnChanges {
         })
   }
 
-  blockAccountByInstance (account: Account) {
+  blockAccountByInstance (account: AccountMutedStatus) {
     this.blocklistService.blockAccountByInstance(account)
         .subscribe({
           next: () => {
@@ -181,7 +198,7 @@ export class UserModerationDropdownComponent implements OnInit, OnChanges {
         })
   }
 
-  unblockAccountByInstance (account: Account) {
+  unblockAccountByInstance (account: AccountMutedStatus) {
     this.blocklistService.unblockAccountByInstance(account)
         .subscribe({
           next: () => {
@@ -246,7 +263,7 @@ export class UserModerationDropdownComponent implements OnInit, OnChanges {
     return user && this.authService.getUser().id === user.id
   }
 
-  private isMyAccount (account: Account) {
+  private isMyAccount (account: AccountMutedStatus) {
     return account && this.authService.getUser().account.id === account.id
   }
 
@@ -267,9 +284,9 @@ export class UserModerationDropdownComponent implements OnInit, OnChanges {
   }
 
   private buildMyAccountModerationActions () {
-    if (!this.account || !this.authService.isLoggedIn()) return []
+    if (!this.account || !this.displayOptions.myAccount || !this.authService.isLoggedIn()) return []
 
-    const myAccountActions: DropdownAction<{ user: User, account: Account }>[] = [
+    const myAccountActions: DropdownAction<{ user: User, account: AccountMutedStatus }>[] = [
       {
         label: $localize`My account moderation`,
         class: [ 'red' ],
@@ -315,9 +332,9 @@ export class UserModerationDropdownComponent implements OnInit, OnChanges {
 
     const authUser = this.authService.getUser()
 
-    let instanceActions: DropdownAction<{ user: User, account: Account }>[] = []
+    let instanceActions: DropdownAction<{ user: User, account: AccountMutedStatus }>[] = []
 
-    if (this.user && authUser.hasRight(UserRight.MANAGE_USERS) && authUser.canManage(this.user)) {
+    if (this.user && this.displayOptions.instanceUser && authUser.hasRight(UserRight.MANAGE_USERS) && authUser.canManage(this.user)) {
       instanceActions = instanceActions.concat([
         {
           label: $localize`Edit user`,
@@ -351,7 +368,7 @@ export class UserModerationDropdownComponent implements OnInit, OnChanges {
     }
 
     // Instance actions on account blocklists
-    if (this.account && authUser.hasRight(UserRight.MANAGE_ACCOUNTS_BLOCKLIST)) {
+    if (this.account && this.displayOptions.instanceAccount && authUser.hasRight(UserRight.MANAGE_ACCOUNTS_BLOCKLIST)) {
       instanceActions = instanceActions.concat([
         {
           label: $localize`Mute this account`,
@@ -369,7 +386,7 @@ export class UserModerationDropdownComponent implements OnInit, OnChanges {
     }
 
     // Instance actions on server blocklists
-    if (this.account && authUser.hasRight(UserRight.MANAGE_SERVERS_BLOCKLIST)) {
+    if (this.account && this.displayOptions.instanceAccount && authUser.hasRight(UserRight.MANAGE_SERVERS_BLOCKLIST)) {
       instanceActions = instanceActions.concat([
         {
           label: $localize`Mute the instance`,
@@ -386,7 +403,7 @@ export class UserModerationDropdownComponent implements OnInit, OnChanges {
       ])
     }
 
-    if (this.account && authUser.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT)) {
+    if (this.account && this.displayOptions.instanceAccount && authUser.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT)) {
       instanceActions = instanceActions.concat([
         {
           label: $localize`Remove comments from your instance`,