Fix is managaeble for channels
authorChocobozzz <me@florianbigard.com>
Wed, 22 Jan 2020 14:01:38 +0000 (15:01 +0100)
committerChocobozzz <me@florianbigard.com>
Wed, 22 Jan 2020 14:01:38 +0000 (15:01 +0100)
client/src/app/+accounts/accounts.component.ts
client/src/app/+video-channels/video-channels.component.html
client/src/app/+video-channels/video-channels.component.ts

index b06ecfe0e49db6fe0c7a03fc28911c0ad4ad6b72..ad611f2211bf5961cf0ab28f948e4ed3716b7749 100644 (file)
@@ -35,34 +35,41 @@ export class AccountsComponent implements OnInit, OnDestroy {
     private redirectService: RedirectService,
     private authService: AuthService,
     private i18n: I18n
-  ) {}
+  ) {
+  }
 
   ngOnInit () {
     this.routeSub = this.route.params
-      .pipe(
-        map(params => params[ 'accountId' ]),
-        distinctUntilChanged(),
-        switchMap(accountId => this.accountService.getAccount(accountId)),
-        tap(account => {
-          this.account = account
-
-          this.isAccountManageable = this.account.userId && this.account.userId === this.authService.getUser().id
-
-          this.accountFollowerTitle = this.i18n(
-            '{{followers}} direct account followers',
-            { followers: this.subscribersDisplayFor(account.followersCount) }
-          )
-
-          this.getUserIfNeeded(account)
-        }),
-        switchMap(account => this.videoChannelService.listAccountVideoChannels(account)),
-        catchError(err => this.restExtractor.redirectTo404IfNotFound(err, [ 400, 404 ]))
-      )
-      .subscribe(
-        videoChannels => this.videoChannels = videoChannels.data,
-
-        err => this.notifier.error(err.message)
-      )
+                        .pipe(
+                          map(params => params[ 'accountId' ]),
+                          distinctUntilChanged(),
+                          switchMap(accountId => this.accountService.getAccount(accountId)),
+                          tap(account => {
+                            this.account = account
+
+                            if (this.authService.isLoggedIn()) {
+                              this.authService.userInformationLoaded.subscribe(
+                                () => {
+                                  this.isAccountManageable = this.account.userId && this.account.userId === this.authService.getUser().id
+
+                                  this.accountFollowerTitle = this.i18n(
+                                    '{{followers}} direct account followers',
+                                    { followers: this.subscribersDisplayFor(account.followersCount) }
+                                  )
+                                }
+                              )
+                            }
+
+                            this.getUserIfNeeded(account)
+                          }),
+                          switchMap(account => this.videoChannelService.listAccountVideoChannels(account)),
+                          catchError(err => this.restExtractor.redirectTo404IfNotFound(err, [ 400, 404 ]))
+                        )
+                        .subscribe(
+                          videoChannels => this.videoChannels = videoChannels.data,
+
+                          err => this.notifier.error(err.message)
+                        )
   }
 
   ngOnDestroy () {
@@ -97,11 +104,8 @@ export class AccountsComponent implements OnInit, OnDestroy {
 
     const user = this.authService.getUser()
     if (user.hasRight(UserRight.MANAGE_USERS)) {
-      forkJoin([
-        this.userService.getUser(account.userId),
-        this.authService.userInformationLoaded.pipe(first())
-      ]).subscribe(
-        ([ accountUser ]) => this.accountUser = accountUser,
+      this.userService.getUser(account.userId).subscribe(
+        accountUser => this.accountUser = accountUser,
 
         err => this.notifier.error(err.message)
       )
index 065fc2c04bdb57dc5272021aeefa284a5f9b5e07..f0bb083ca03de4a96176d5124d86deb77c789743 100644 (file)
@@ -16,7 +16,7 @@
           </div>
 
           <div class="right-buttons">
-            <a *ngIf="isManageable" [routerLink]="[ '/my-account/video-channels/update', videoChannel.nameWithHost ]" class="btn btn-outline-tertiary mr-2" i18n>Manage</a>
+            <a *ngIf="isChannelManageable" [routerLink]="[ '/my-account/video-channels/update', videoChannel.nameWithHost ]" class="btn btn-outline-tertiary mr-2" i18n>Manage</a>
             <my-subscribe-button #subscribeButton [videoChannels]="[videoChannel]"></my-subscribe-button>
           </div>
         </div>
index 493a6d499e6ef245e2b4a70fec075a32b4fdd5ee..7b335b13f5eb9f05b5a9cbca62a13706e244b95d 100644 (file)
@@ -3,7 +3,7 @@ import { ActivatedRoute } from '@angular/router'
 import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
 import { VideoChannelService } from '@app/shared/video-channel/video-channel.service'
 import { RestExtractor } from '@app/shared'
-import { catchError, distinctUntilChanged, map, switchMap } from 'rxjs/operators'
+import { catchError, distinctUntilChanged, map, switchMap, tap } from 'rxjs/operators'
 import { Subscription } from 'rxjs'
 import { AuthService, Notifier } from '@app/core'
 import { Hotkey, HotkeysService } from 'angular2-hotkeys'
@@ -19,6 +19,7 @@ export class VideoChannelsComponent implements OnInit, OnDestroy {
 
   videoChannel: VideoChannel
   hotkeys: Hotkey[]
+  isChannelManageable = false
 
   private routeSub: Subscription
 
@@ -40,7 +41,17 @@ export class VideoChannelsComponent implements OnInit, OnDestroy {
                           switchMap(videoChannelName => this.videoChannelService.getVideoChannel(videoChannelName)),
                           catchError(err => this.restExtractor.redirectTo404IfNotFound(err, [ 400, 404 ]))
                         )
-                        .subscribe(videoChannel => this.videoChannel = videoChannel)
+                        .subscribe(videoChannel => {
+                          this.videoChannel = videoChannel
+
+                          if (this.authService.isLoggedIn()) {
+                            this.authService.userInformationLoaded
+                              .subscribe(() => {
+                                const channelUserId = this.videoChannel.ownerAccount.userId
+                                this.isChannelManageable = channelUserId && channelUserId === this.authService.getUser().id
+                              })
+                          }
+                        })
 
     this.hotkeys = [
       new Hotkey('S', (event: KeyboardEvent): boolean => {