diff options
author | Chocobozzz <me@florianbigard.com> | 2021-12-15 15:58:10 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-12-16 10:08:55 +0100 |
commit | a9bfa85d2cdf13670aaced740da5b493fbeddfce (patch) | |
tree | 3781c9218d4cc7786b6589365c0efbed2151703d /client/src/app/core/auth/auth-user.model.ts | |
parent | c77fdc605b3ccc1ab6890f889d8200fbe9372949 (diff) | |
download | PeerTube-a9bfa85d2cdf13670aaced740da5b493fbeddfce.tar.gz PeerTube-a9bfa85d2cdf13670aaced740da5b493fbeddfce.tar.zst PeerTube-a9bfa85d2cdf13670aaced740da5b493fbeddfce.zip |
Add ability for admins to set default p2p policy
Diffstat (limited to 'client/src/app/core/auth/auth-user.model.ts')
-rw-r--r-- | client/src/app/core/auth/auth-user.model.ts | 44 |
1 files changed, 4 insertions, 40 deletions
diff --git a/client/src/app/core/auth/auth-user.model.ts b/client/src/app/core/auth/auth-user.model.ts index f10b37e5a..cd9665e37 100644 --- a/client/src/app/core/auth/auth-user.model.ts +++ b/client/src/app/core/auth/auth-user.model.ts | |||
@@ -1,13 +1,7 @@ | |||
1 | import { Observable, of } from 'rxjs' | 1 | import { Observable, of } from 'rxjs' |
2 | import { map } from 'rxjs/operators' | 2 | import { map } from 'rxjs/operators' |
3 | import { User } from '@app/core/users/user.model' | 3 | import { User } from '@app/core/users/user.model' |
4 | import { | 4 | import { UserTokens } from '@root-helpers/users' |
5 | flushUserInfoFromLocalStorage, | ||
6 | getUserInfoFromLocalStorage, | ||
7 | saveUserInfoIntoLocalStorage, | ||
8 | TokenOptions, | ||
9 | Tokens | ||
10 | } from '@root-helpers/users' | ||
11 | import { hasUserRight } from '@shared/core-utils/users' | 5 | import { hasUserRight } from '@shared/core-utils/users' |
12 | import { | 6 | import { |
13 | MyUser as ServerMyUserModel, | 7 | MyUser as ServerMyUserModel, |
@@ -19,31 +13,15 @@ import { | |||
19 | } from '@shared/models' | 13 | } from '@shared/models' |
20 | 14 | ||
21 | export class AuthUser extends User implements ServerMyUserModel { | 15 | export class AuthUser extends User implements ServerMyUserModel { |
22 | tokens: Tokens | 16 | tokens: UserTokens |
23 | specialPlaylists: MyUserSpecialPlaylist[] | 17 | specialPlaylists: MyUserSpecialPlaylist[] |
24 | 18 | ||
25 | canSeeVideosLink = true | 19 | canSeeVideosLink = true |
26 | 20 | ||
27 | static load () { | 21 | constructor (userHash: Partial<ServerMyUserModel>, hashTokens: Partial<UserTokens>) { |
28 | const tokens = Tokens.load() | ||
29 | if (!tokens) return null | ||
30 | |||
31 | const userInfo = getUserInfoFromLocalStorage() | ||
32 | if (!userInfo) return null | ||
33 | |||
34 | return new AuthUser(userInfo, tokens) | ||
35 | } | ||
36 | |||
37 | static flush () { | ||
38 | flushUserInfoFromLocalStorage() | ||
39 | |||
40 | Tokens.flush() | ||
41 | } | ||
42 | |||
43 | constructor (userHash: Partial<ServerMyUserModel>, hashTokens: TokenOptions) { | ||
44 | super(userHash) | 22 | super(userHash) |
45 | 23 | ||
46 | this.tokens = new Tokens(hashTokens) | 24 | this.tokens = new UserTokens(hashTokens) |
47 | this.specialPlaylists = userHash.specialPlaylists | 25 | this.specialPlaylists = userHash.specialPlaylists |
48 | } | 26 | } |
49 | 27 | ||
@@ -77,20 +55,6 @@ export class AuthUser extends User implements ServerMyUserModel { | |||
77 | return user.role === UserRole.USER | 55 | return user.role === UserRole.USER |
78 | } | 56 | } |
79 | 57 | ||
80 | save () { | ||
81 | saveUserInfoIntoLocalStorage({ | ||
82 | id: this.id, | ||
83 | username: this.username, | ||
84 | email: this.email, | ||
85 | role: this.role, | ||
86 | nsfwPolicy: this.nsfwPolicy, | ||
87 | webTorrentEnabled: this.webTorrentEnabled, | ||
88 | autoPlayVideo: this.autoPlayVideo | ||
89 | }) | ||
90 | |||
91 | this.tokens.save() | ||
92 | } | ||
93 | |||
94 | computeCanSeeVideosLink (quotaObservable: Observable<UserVideoQuota>): Observable<boolean> { | 58 | computeCanSeeVideosLink (quotaObservable: Observable<UserVideoQuota>): Observable<boolean> { |
95 | if (!this.isUploadDisabled()) { | 59 | if (!this.isUploadDisabled()) { |
96 | this.canSeeVideosLink = true | 60 | this.canSeeVideosLink = true |