]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/core/auth/auth-user.model.ts
Remove empty sass files
[github/Chocobozzz/PeerTube.git] / client / src / app / core / auth / auth-user.model.ts
CommitLineData
dfe3f7b7
K
1import { Observable, of } from 'rxjs'
2import { map } from 'rxjs/operators'
67ed6552 3import { User } from '@app/core/users/user.model'
3545e72c 4import { OAuthUserTokens } from '@root-helpers/users'
bd45d503 5import { hasUserRight } from '@shared/core-utils/users'
67ed6552 6import {
67ed6552
C
7 MyUser as ServerMyUserModel,
8 MyUserSpecialPlaylist,
67ed6552
C
9 User as ServerUserModel,
10 UserRight,
dfe3f7b7
K
11 UserRole,
12 UserVideoQuota
67ed6552 13} from '@shared/models'
7da18e44 14
b7819090 15export class AuthUser extends User implements ServerMyUserModel {
3545e72c 16 oauthTokens: OAuthUserTokens
b7819090 17 specialPlaylists: MyUserSpecialPlaylist[]
bd5c83a8 18
dfe3f7b7
K
19 canSeeVideosLink = true
20
3545e72c 21 constructor (userHash: Partial<ServerMyUserModel>, hashTokens: Partial<OAuthUserTokens>) {
df98563e 22 super(userHash)
b7819090 23
3545e72c 24 this.oauthTokens = new OAuthUserTokens(hashTokens)
b7819090 25 this.specialPlaylists = userHash.specialPlaylists
bd5c83a8
C
26 }
27
df98563e 28 getAccessToken () {
3545e72c 29 return this.oauthTokens.accessToken
bd5c83a8 30 }
bd5c83a8 31
df98563e 32 getRefreshToken () {
3545e72c 33 return this.oauthTokens.refreshToken
bd5c83a8
C
34 }
35
df98563e 36 getTokenType () {
3545e72c 37 return this.oauthTokens.tokenType
bd5c83a8
C
38 }
39
df98563e 40 refreshTokens (accessToken: string, refreshToken: string) {
3545e72c
C
41 this.oauthTokens.accessToken = accessToken
42 this.oauthTokens.refreshToken = refreshToken
bd5c83a8
C
43 }
44
757f0da3 45 hasRight (right: UserRight) {
9e5cf66b 46 return hasUserRight(this.role.id, right)
954605a8
C
47 }
48
a6051ba7 49 canManage (user: ServerUserModel) {
9e5cf66b 50 const myRole = this.role.id
a95a4cc8
C
51
52 if (myRole === UserRole.ADMINISTRATOR) return true
53
54 // I'm a moderator: I can only manage users
9e5cf66b 55 return user.role.id === UserRole.USER
a95a4cc8
C
56 }
57
dfe3f7b7
K
58 computeCanSeeVideosLink (quotaObservable: Observable<UserVideoQuota>): Observable<boolean> {
59 if (!this.isUploadDisabled()) {
60 this.canSeeVideosLink = true
61 return of(this.canSeeVideosLink)
62 }
63
64 // Check if the user has videos
65 return quotaObservable.pipe(
66 map(({ videoQuotaUsed }) => {
67 if (videoQuotaUsed !== 0) {
68 // User already uploaded videos, so it can see the link
69 this.canSeeVideosLink = true
70 } else {
71 // No videos, no upload so the user don't need to see the videos link
72 this.canSeeVideosLink = false
73 }
74
75 return this.canSeeVideosLink
76 })
77 )
78 }
bd5c83a8 79}