-import {
- User as UserServerModel,
- UserRole,
- VideoChannel
-} from '../../../../../shared'
+import { hasUserRight, User as UserServerModel, UserRight, UserRole, VideoChannel } from '../../../../../shared'
+import { Account } from '../account/account.model'
+import { NSFWPolicyType } from '../../../../../shared/models/videos/nsfw-policy.type'
export type UserConstructorHash = {
id: number,
email: string,
role: UserRole,
videoQuota?: number,
- displayNSFW?: boolean,
+ nsfwPolicy?: NSFWPolicyType,
+ autoPlayVideo?: boolean,
createdAt?: Date,
- author?: {
- id: number
- uuid: string
- },
+ account?: Account,
videoChannels?: VideoChannel[]
}
export class User implements UserServerModel {
username: string
email: string
role: UserRole
- displayNSFW: boolean
+ nsfwPolicy: NSFWPolicyType
+ autoPlayVideo: boolean
videoQuota: number
- author: {
- id: number
- uuid: string
- }
+ account: Account
videoChannels: VideoChannel[]
createdAt: Date
this.username = hash.username
this.email = hash.email
this.role = hash.role
- this.author = hash.author
+ this.account = hash.account
if (hash.videoChannels !== undefined) {
this.videoChannels = hash.videoChannels
this.videoQuota = hash.videoQuota
}
- if (hash.displayNSFW !== undefined) {
- this.displayNSFW = hash.displayNSFW
+ if (hash.nsfwPolicy !== undefined) {
+ this.nsfwPolicy = hash.nsfwPolicy
+ }
+
+ if (hash.autoPlayVideo !== undefined) {
+ this.autoPlayVideo = hash.autoPlayVideo
}
if (hash.createdAt !== undefined) {
}
}
- isAdmin () {
- return this.role === 'admin'
+ hasRight (right: UserRight) {
+ return hasUserRight(this.role, right)
+ }
+
+ getAvatarUrl () {
+ return Account.GET_ACCOUNT_AVATAR_URL(this.account)
+ }
+
+ patch (obj: UserServerModel) {
+ for (const key of Object.keys(obj)) {
+ this[key] = obj[key]
+ }
}
}