aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/menu/menu.component.ts
diff options
context:
space:
mode:
authorKim <1877318+kimsible@users.noreply.github.com>2020-07-28 15:18:38 +0200
committerGitHub <noreply@github.com>2020-07-28 15:18:38 +0200
commitdfe3f7b72ef46401206f6f461077a7984a0c72f0 (patch)
tree775a747f2dd4bc098afc2ec254792e2e8e8cbbb4 /client/src/app/menu/menu.component.ts
parent0579dee3b29e301838387f53b91b58bff2ffb19a (diff)
downloadPeerTube-dfe3f7b72ef46401206f6f461077a7984a0c72f0.tar.gz
PeerTube-dfe3f7b72ef46401206f6f461077a7984a0c72f0.tar.zst
PeerTube-dfe3f7b72ef46401206f6f461077a7984a0c72f0.zip
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 <kimsible@users.noreply.github.com> Co-authored-by: Chocobozzz <me@florianbigard.com>
Diffstat (limited to 'client/src/app/menu/menu.component.ts')
-rw-r--r--client/src/app/menu/menu.component.ts67
1 files changed, 45 insertions, 22 deletions
diff --git a/client/src/app/menu/menu.component.ts b/client/src/app/menu/menu.component.ts
index 0ea251f1c..2c55b9a84 100644
--- a/client/src/app/menu/menu.component.ts
+++ b/client/src/app/menu/menu.component.ts
@@ -1,21 +1,25 @@
1import { HotkeysService } from 'angular2-hotkeys' 1import { HotkeysService } from 'angular2-hotkeys'
2import * as debug from 'debug'
3import { switchMap } from 'rxjs/operators'
2import { Component, OnInit, ViewChild } from '@angular/core' 4import { Component, OnInit, ViewChild } from '@angular/core'
3import { AuthService, AuthStatus, RedirectService, ScreenService, ServerService, User, UserService } from '@app/core' 5import { AuthService, AuthStatus, AuthUser, RedirectService, ScreenService, ServerService, UserService } from '@app/core'
4import { LanguageChooserComponent } from '@app/menu/language-chooser.component' 6import { LanguageChooserComponent } from '@app/menu/language-chooser.component'
5import { QuickSettingsModalComponent } from '@app/modal/quick-settings-modal.component' 7import { QuickSettingsModalComponent } from '@app/modal/quick-settings-modal.component'
6import { I18n } from '@ngx-translate/i18n-polyfill' 8import { I18n } from '@ngx-translate/i18n-polyfill'
7import { ServerConfig, UserRight, VideoConstant } from '@shared/models' 9import { ServerConfig, UserRight, VideoConstant } from '@shared/models'
8 10
11const logger = debug('peertube:menu:MenuComponent')
12
9@Component({ 13@Component({
10 selector: 'my-menu', 14 selector: 'my-menu',
11 templateUrl: './menu.component.html', 15 templateUrl: './menu.component.html',
12 styleUrls: [ './menu.component.scss' ] 16 styleUrls: ['./menu.component.scss']
13}) 17})
14export class MenuComponent implements OnInit { 18export class MenuComponent implements OnInit {
15 @ViewChild('languageChooserModal', { static: true }) languageChooserModal: LanguageChooserComponent 19 @ViewChild('languageChooserModal', { static: true }) languageChooserModal: LanguageChooserComponent
16 @ViewChild('quickSettingsModal', { static: true }) quickSettingsModal: QuickSettingsModalComponent 20 @ViewChild('quickSettingsModal', { static: true }) quickSettingsModal: QuickSettingsModalComponent
17 21
18 user: User 22 user: AuthUser
19 isLoggedIn: boolean 23 isLoggedIn: boolean
20 24
21 userHasAdminAccess = false 25 userHasAdminAccess = false
@@ -25,7 +29,7 @@ export class MenuComponent implements OnInit {
25 29
26 private languages: VideoConstant<string>[] = [] 30 private languages: VideoConstant<string>[] = []
27 private serverConfig: ServerConfig 31 private serverConfig: ServerConfig
28 private routesPerRight: { [ role in UserRight ]?: string } = { 32 private routesPerRight: { [role in UserRight]?: string } = {
29 [UserRight.MANAGE_USERS]: '/admin/users', 33 [UserRight.MANAGE_USERS]: '/admin/users',
30 [UserRight.MANAGE_SERVER_FOLLOW]: '/admin/friends', 34 [UserRight.MANAGE_SERVER_FOLLOW]: '/admin/friends',
31 [UserRight.MANAGE_ABUSES]: '/admin/moderation/abuses', 35 [UserRight.MANAGE_ABUSES]: '/admin/moderation/abuses',
@@ -62,21 +66,30 @@ export class MenuComponent implements OnInit {
62 .subscribe(config => this.serverConfig = config) 66 .subscribe(config => this.serverConfig = config)
63 67
64 this.isLoggedIn = this.authService.isLoggedIn() 68 this.isLoggedIn = this.authService.isLoggedIn()
65 if (this.isLoggedIn === true) this.user = this.authService.getUser() 69 if (this.isLoggedIn === true) {
66 this.computeIsUserHasAdminAccess() 70 this.user = this.authService.getUser()
71 this.computeVideosLink()
72 }
73
74 this.computeAdminAccess()
67 75
68 this.authService.loginChangedSource.subscribe( 76 this.authService.loginChangedSource.subscribe(
69 status => { 77 status => {
70 if (status === AuthStatus.LoggedIn) { 78 if (status === AuthStatus.LoggedIn) {
71 this.isLoggedIn = true 79 this.isLoggedIn = true
72 this.user = this.authService.getUser() 80 this.user = this.authService.getUser()
73 this.computeIsUserHasAdminAccess() 81
74 console.log('Logged in.') 82 this.computeAdminAccess()
83 this.computeVideosLink()
84
85 logger('Logged in.')
75 } else if (status === AuthStatus.LoggedOut) { 86 } else if (status === AuthStatus.LoggedOut) {
76 this.isLoggedIn = false 87 this.isLoggedIn = false
77 this.user = undefined 88 this.user = undefined
78 this.computeIsUserHasAdminAccess() 89
79 console.log('Logged out.') 90 this.computeAdminAccess()
91
92 logger('Logged out.')
80 } else { 93 } else {
81 console.error('Unknown auth status: ' + status) 94 console.error('Unknown auth status: ' + status)
82 } 95 }
@@ -84,15 +97,15 @@ export class MenuComponent implements OnInit {
84 ) 97 )
85 98
86 this.hotkeysService.cheatSheetToggle 99 this.hotkeysService.cheatSheetToggle
87 .subscribe(isOpen => this.helpVisible = isOpen) 100 .subscribe(isOpen => this.helpVisible = isOpen)
88 101
89 this.serverService.getVideoLanguages() 102 this.serverService.getVideoLanguages()
90 .subscribe(languages => { 103 .subscribe(languages => {
91 this.languages = languages 104 this.languages = languages
92 105
93 this.authService.userInformationLoaded 106 this.authService.userInformationLoaded
94 .subscribe(() => this.buildUserLanguages()) 107 .subscribe(() => this.buildUserLanguages())
95 }) 108 })
96 } 109 }
97 110
98 get language () { 111 get language () {
@@ -116,7 +129,7 @@ export class MenuComponent implements OnInit {
116 129
117 isRegistrationAllowed () { 130 isRegistrationAllowed () {
118 return this.serverConfig.signup.allowed && 131 return this.serverConfig.signup.allowed &&
119 this.serverConfig.signup.allowedForCurrentIP 132 this.serverConfig.signup.allowedForCurrentIP
120 } 133 }
121 134
122 getFirstAdminRightAvailable () { 135 getFirstAdminRightAvailable () {
@@ -172,7 +185,7 @@ export class MenuComponent implements OnInit {
172 this.user.webTorrentEnabled = !this.user.webTorrentEnabled 185 this.user.webTorrentEnabled = !this.user.webTorrentEnabled
173 186
174 this.userService.updateMyProfile({ webTorrentEnabled: this.user.webTorrentEnabled }) 187 this.userService.updateMyProfile({ webTorrentEnabled: this.user.webTorrentEnabled })
175 .subscribe(() => this.authService.refreshUserInformation()) 188 .subscribe(() => this.authService.refreshUserInformation())
176 } 189 }
177 190
178 langForLocale (localeId: string) { 191 langForLocale (localeId: string) {
@@ -188,18 +201,28 @@ export class MenuComponent implements OnInit {
188 } 201 }
189 202
190 if (!this.user.videoLanguages) { 203 if (!this.user.videoLanguages) {
191 this.videoLanguages = [ this.i18n('any language') ] 204 this.videoLanguages = [this.i18n('any language')]
192 return 205 return
193 } 206 }
194 207
195 this.videoLanguages = this.user.videoLanguages 208 this.videoLanguages = this.user.videoLanguages
196 .map(locale => this.langForLocale(locale)) 209 .map(locale => this.langForLocale(locale))
197 .map(value => value === undefined ? '?' : value) 210 .map(value => value === undefined ? '?' : value)
198 } 211 }
199 212
200 private computeIsUserHasAdminAccess () { 213 private computeAdminAccess () {
201 const right = this.getFirstAdminRightAvailable() 214 const right = this.getFirstAdminRightAvailable()
202 215
203 this.userHasAdminAccess = right !== undefined 216 this.userHasAdminAccess = right !== undefined
204 } 217 }
218
219 private computeVideosLink () {
220 this.authService.userInformationLoaded
221 .pipe(
222 switchMap(() => this.user.computeCanSeeVideosLink(this.userService.getMyVideoQuotaUsed()))
223 ).subscribe(res => {
224 if (res === true) logger('User can see videos link.')
225 else logger('User cannot see videos link.')
226 })
227 }
205} 228}