From dfe3f7b72ef46401206f6f461077a7984a0c72f0 Mon Sep 17 00:00:00 2001 From: Kim <1877318+kimsible@users.noreply.github.com> Date: Tue, 28 Jul 2020 15:18:38 +0200 Subject: Add alert and hide upload view when no upload is possible (#2966) * Add alert and hide upload view when no upload is possible * Add about instance link to alert * Hide videos and imports links when no upload is possible * Correct curly spacing lint * Put logic canUpload to User model + add isHidden param to to-menu-dropdown * Use canSeeVideoLinks from user model * Rename and change logic canUpload to isUploadDisabled * Use isDisplayed() method intead of isHidden value * Refactor client and check videos count using quota Co-authored-by: kimsible Co-authored-by: Chocobozzz --- client/src/app/core/auth/auth-user.model.ts | 29 ++++++++++++++++++++++++++++- client/src/app/core/users/user.model.ts | 4 ++++ 2 files changed, 32 insertions(+), 1 deletion(-) (limited to 'client/src/app/core') diff --git a/client/src/app/core/auth/auth-user.model.ts b/client/src/app/core/auth/auth-user.model.ts index 4e7801550..88b730938 100644 --- a/client/src/app/core/auth/auth-user.model.ts +++ b/client/src/app/core/auth/auth-user.model.ts @@ -1,3 +1,5 @@ +import { Observable, of } from 'rxjs' +import { map } from 'rxjs/operators' import { User } from '@app/core/users/user.model' import { peertubeLocalStorage } from '@app/helpers/peertube-web-storage' import { @@ -7,7 +9,8 @@ import { NSFWPolicyType, User as ServerUserModel, UserRight, - UserRole + UserRole, + UserVideoQuota } from '@shared/models' export type TokenOptions = { @@ -74,6 +77,8 @@ export class AuthUser extends User implements ServerMyUserModel { tokens: Tokens specialPlaylists: MyUserSpecialPlaylist[] + canSeeVideosLink = true + static load () { const usernameLocalStorage = peertubeLocalStorage.getItem(this.KEYS.USERNAME) if (usernameLocalStorage) { @@ -150,4 +155,26 @@ export class AuthUser extends User implements ServerMyUserModel { peertubeLocalStorage.setItem(AuthUser.KEYS.AUTO_PLAY_VIDEO, JSON.stringify(this.autoPlayVideo)) this.tokens.save() } + + computeCanSeeVideosLink (quotaObservable: Observable): Observable { + if (!this.isUploadDisabled()) { + this.canSeeVideosLink = true + return of(this.canSeeVideosLink) + } + + // Check if the user has videos + return quotaObservable.pipe( + map(({ videoQuotaUsed }) => { + if (videoQuotaUsed !== 0) { + // User already uploaded videos, so it can see the link + this.canSeeVideosLink = true + } else { + // No videos, no upload so the user don't need to see the videos link + this.canSeeVideosLink = false + } + + return this.canSeeVideosLink + }) + ) + } } diff --git a/client/src/app/core/users/user.model.ts b/client/src/app/core/users/user.model.ts index 31b9c2152..6a56786d9 100644 --- a/client/src/app/core/users/user.model.ts +++ b/client/src/app/core/users/user.model.ts @@ -149,4 +149,8 @@ export class User implements UserServerModel { updateAccountAvatar (newAccountAvatar: Avatar) { this.account.updateAvatar(newAccountAvatar) } + + isUploadDisabled () { + return this.videoQuota === 0 || this.videoQuotaDaily === 0 + } } -- cgit v1.2.3