]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/users/user.model.ts
Add tests to user roles
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / users / user.model.ts
1 import {
2 User as UserServerModel,
3 UserRole,
4 VideoChannel,
5 UserRight,
6 hasUserRight
7 } from '../../../../../shared'
8
9 export type UserConstructorHash = {
10 id: number,
11 username: string,
12 email: string,
13 role: UserRole,
14 videoQuota?: number,
15 displayNSFW?: boolean,
16 createdAt?: Date,
17 author?: {
18 id: number
19 uuid: string
20 },
21 videoChannels?: VideoChannel[]
22 }
23 export class User implements UserServerModel {
24 id: number
25 username: string
26 email: string
27 role: UserRole
28 displayNSFW: boolean
29 videoQuota: number
30 author: {
31 id: number
32 uuid: string
33 }
34 videoChannels: VideoChannel[]
35 createdAt: Date
36
37 constructor (hash: UserConstructorHash) {
38 this.id = hash.id
39 this.username = hash.username
40 this.email = hash.email
41 this.role = hash.role
42 this.author = hash.author
43
44 if (hash.videoChannels !== undefined) {
45 this.videoChannels = hash.videoChannels
46 }
47
48 if (hash.videoQuota !== undefined) {
49 this.videoQuota = hash.videoQuota
50 }
51
52 if (hash.displayNSFW !== undefined) {
53 this.displayNSFW = hash.displayNSFW
54 }
55
56 if (hash.createdAt !== undefined) {
57 this.createdAt = hash.createdAt
58 }
59 }
60
61 hasRight (right: UserRight) {
62 return hasUserRight(this.role, right)
63 }
64 }