1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-06 03:50:26 +02:00

Add user adminFlags

This commit is contained in:
Chocobozzz 2019-04-15 10:49:46 +02:00
parent 31b48aad47
commit 1eddc9a74f
No known key found for this signature in database
GPG key ID: 583A612D890159BE
65 changed files with 982 additions and 591 deletions

View file

@ -22,6 +22,7 @@ import {
import { hasUserRight, USER_ROLE_LABELS, UserRight } from '../../../shared'
import { User, UserRole } from '../../../shared/models/users'
import {
isUserAdminFlagsValid,
isUserAutoPlayVideoValid,
isUserBlockedReasonValid,
isUserBlockedValid,
@ -49,6 +50,7 @@ import { VideoModel } from '../video/video'
import { ActorModel } from '../activitypub/actor'
import { ActorFollowModel } from '../activitypub/actor-follow'
import { VideoImportModel } from '../video/video-import'
import { UserAdminFlag } from '../../../shared/models/users/user-flag.model'
enum ScopeNames {
WITH_VIDEO_CHANNEL = 'WITH_VIDEO_CHANNEL'
@ -140,6 +142,12 @@ export class UserModel extends Model<UserModel> {
@Column
autoPlayVideo: boolean
@AllowNull(false)
@Default(UserAdminFlag.NONE)
@Is('UserAdminFlags', value => throwIfNotValid(value, isUserAdminFlagsValid, 'user admin flags'))
@Column
adminFlags?: UserAdminFlag
@AllowNull(false)
@Default(false)
@Is('UserBlocked', value => throwIfNotValid(value, isUserBlockedValid, 'blocked boolean'))
@ -516,11 +524,15 @@ export class UserModel extends Model<UserModel> {
return hasUserRight(this.role, right)
}
hasAdminFlag (flag: UserAdminFlag) {
return this.adminFlags & flag
}
isPasswordMatch (password: string) {
return comparePassword(password, this.password)
}
toFormattedJSON (): User {
toFormattedJSON (parameters: { withAdminFlags?: boolean } = {}): User {
const videoQuotaUsed = this.get('videoQuotaUsed')
const videoQuotaUsedDaily = this.get('videoQuotaUsedDaily')
@ -551,6 +563,10 @@ export class UserModel extends Model<UserModel> {
: undefined
}
if (parameters.withAdminFlags) {
Object.assign(json, { adminFlags: this.adminFlags })
}
if (Array.isArray(this.Account.VideoChannels) === true) {
json.videoChannels = this.Account.VideoChannels
.map(c => c.toFormattedJSON())