aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/account/user.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-04-15 10:49:46 +0200
committerChocobozzz <me@florianbigard.com>2019-04-15 14:39:52 +0200
commit1eddc9a74f9a80fa5d0cb25fceb3fc47a1a3c14a (patch)
tree91a10310cdf924779527525d39f8eb7e09e4ba49 /server/models/account/user.ts
parent31b48aad478506d4214586f02792816efa968e4b (diff)
downloadPeerTube-1eddc9a74f9a80fa5d0cb25fceb3fc47a1a3c14a.tar.gz
PeerTube-1eddc9a74f9a80fa5d0cb25fceb3fc47a1a3c14a.tar.zst
PeerTube-1eddc9a74f9a80fa5d0cb25fceb3fc47a1a3c14a.zip
Add user adminFlags
Diffstat (limited to 'server/models/account/user.ts')
-rw-r--r--server/models/account/user.ts18
1 files changed, 17 insertions, 1 deletions
diff --git a/server/models/account/user.ts b/server/models/account/user.ts
index 38585c016..b66458351 100644
--- a/server/models/account/user.ts
+++ b/server/models/account/user.ts
@@ -22,6 +22,7 @@ import {
22import { hasUserRight, USER_ROLE_LABELS, UserRight } from '../../../shared' 22import { hasUserRight, USER_ROLE_LABELS, UserRight } from '../../../shared'
23import { User, UserRole } from '../../../shared/models/users' 23import { User, UserRole } from '../../../shared/models/users'
24import { 24import {
25 isUserAdminFlagsValid,
25 isUserAutoPlayVideoValid, 26 isUserAutoPlayVideoValid,
26 isUserBlockedReasonValid, 27 isUserBlockedReasonValid,
27 isUserBlockedValid, 28 isUserBlockedValid,
@@ -49,6 +50,7 @@ import { VideoModel } from '../video/video'
49import { ActorModel } from '../activitypub/actor' 50import { ActorModel } from '../activitypub/actor'
50import { ActorFollowModel } from '../activitypub/actor-follow' 51import { ActorFollowModel } from '../activitypub/actor-follow'
51import { VideoImportModel } from '../video/video-import' 52import { VideoImportModel } from '../video/video-import'
53import { UserAdminFlag } from '../../../shared/models/users/user-flag.model'
52 54
53enum ScopeNames { 55enum ScopeNames {
54 WITH_VIDEO_CHANNEL = 'WITH_VIDEO_CHANNEL' 56 WITH_VIDEO_CHANNEL = 'WITH_VIDEO_CHANNEL'
@@ -141,6 +143,12 @@ export class UserModel extends Model<UserModel> {
141 autoPlayVideo: boolean 143 autoPlayVideo: boolean
142 144
143 @AllowNull(false) 145 @AllowNull(false)
146 @Default(UserAdminFlag.NONE)
147 @Is('UserAdminFlags', value => throwIfNotValid(value, isUserAdminFlagsValid, 'user admin flags'))
148 @Column
149 adminFlags?: UserAdminFlag
150
151 @AllowNull(false)
144 @Default(false) 152 @Default(false)
145 @Is('UserBlocked', value => throwIfNotValid(value, isUserBlockedValid, 'blocked boolean')) 153 @Is('UserBlocked', value => throwIfNotValid(value, isUserBlockedValid, 'blocked boolean'))
146 @Column 154 @Column
@@ -516,11 +524,15 @@ export class UserModel extends Model<UserModel> {
516 return hasUserRight(this.role, right) 524 return hasUserRight(this.role, right)
517 } 525 }
518 526
527 hasAdminFlag (flag: UserAdminFlag) {
528 return this.adminFlags & flag
529 }
530
519 isPasswordMatch (password: string) { 531 isPasswordMatch (password: string) {
520 return comparePassword(password, this.password) 532 return comparePassword(password, this.password)
521 } 533 }
522 534
523 toFormattedJSON (): User { 535 toFormattedJSON (parameters: { withAdminFlags?: boolean } = {}): User {
524 const videoQuotaUsed = this.get('videoQuotaUsed') 536 const videoQuotaUsed = this.get('videoQuotaUsed')
525 const videoQuotaUsedDaily = this.get('videoQuotaUsedDaily') 537 const videoQuotaUsedDaily = this.get('videoQuotaUsedDaily')
526 538
@@ -551,6 +563,10 @@ export class UserModel extends Model<UserModel> {
551 : undefined 563 : undefined
552 } 564 }
553 565
566 if (parameters.withAdminFlags) {
567 Object.assign(json, { adminFlags: this.adminFlags })
568 }
569
554 if (Array.isArray(this.Account.VideoChannels) === true) { 570 if (Array.isArray(this.Account.VideoChannels) === true) {
555 json.videoChannels = this.Account.VideoChannels 571 json.videoChannels = this.Account.VideoChannels
556 .map(c => c.toFormattedJSON()) 572 .map(c => c.toFormattedJSON())