aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
Diffstat (limited to 'server/models')
-rw-r--r--server/models/account/user.ts58
1 files changed, 45 insertions, 13 deletions
diff --git a/server/models/account/user.ts b/server/models/account/user.ts
index 616dd603c..451e1fd6b 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 isNoInstanceConfigWarningModal,
25 isUserAdminFlagsValid, 26 isUserAdminFlagsValid,
26 isUserAutoPlayVideoValid, 27 isUserAutoPlayVideoValid,
27 isUserBlockedReasonValid, 28 isUserBlockedReasonValid,
@@ -35,7 +36,8 @@ import {
35 isUserVideoQuotaDailyValid, 36 isUserVideoQuotaDailyValid,
36 isUserVideoQuotaValid, 37 isUserVideoQuotaValid,
37 isUserVideosHistoryEnabledValid, 38 isUserVideosHistoryEnabledValid,
38 isUserWebTorrentEnabledValid 39 isUserWebTorrentEnabledValid,
40 isNoWelcomeModal
39} from '../../helpers/custom-validators/users' 41} from '../../helpers/custom-validators/users'
40import { comparePassword, cryptPassword } from '../../helpers/peertube-crypto' 42import { comparePassword, cryptPassword } from '../../helpers/peertube-crypto'
41import { OAuthTokenModel } from '../oauth/oauth-token' 43import { OAuthTokenModel } from '../oauth/oauth-token'
@@ -203,6 +205,24 @@ export class UserModel extends Model<UserModel> {
203 @Column 205 @Column
204 theme: string 206 theme: string
205 207
208 @AllowNull(false)
209 @Default(false)
210 @Is(
211 'UserNoInstanceConfigWarningModal',
212 value => throwIfNotValid(value, isNoInstanceConfigWarningModal, 'no instance config warning modal')
213 )
214 @Column
215 noInstanceConfigWarningModal: boolean
216
217 @AllowNull(false)
218 @Default(false)
219 @Is(
220 'UserNoInstanceConfigWarningModal',
221 value => throwIfNotValid(value, isNoWelcomeModal, 'no welcome modal')
222 )
223 @Column
224 noWelcomeModal: boolean
225
206 @CreatedAt 226 @CreatedAt
207 createdAt: Date 227 createdAt: Date
208 228
@@ -560,40 +580,52 @@ export class UserModel extends Model<UserModel> {
560 return comparePassword(password, this.password) 580 return comparePassword(password, this.password)
561 } 581 }
562 582
563 toSummaryJSON
564
565 toFormattedJSON (this: MUserFormattable, parameters: { withAdminFlags?: boolean } = {}): User { 583 toFormattedJSON (this: MUserFormattable, parameters: { withAdminFlags?: boolean } = {}): User {
566 const videoQuotaUsed = this.get('videoQuotaUsed') 584 const videoQuotaUsed = this.get('videoQuotaUsed')
567 const videoQuotaUsedDaily = this.get('videoQuotaUsedDaily') 585 const videoQuotaUsedDaily = this.get('videoQuotaUsedDaily')
568 586
569 const json = { 587 const json: User = {
570 id: this.id, 588 id: this.id,
571 username: this.username, 589 username: this.username,
572 email: this.email, 590 email: this.email,
591 theme: getThemeOrDefault(this.theme, DEFAULT_USER_THEME_NAME),
592
573 pendingEmail: this.pendingEmail, 593 pendingEmail: this.pendingEmail,
574 emailVerified: this.emailVerified, 594 emailVerified: this.emailVerified,
595
575 nsfwPolicy: this.nsfwPolicy, 596 nsfwPolicy: this.nsfwPolicy,
576 webTorrentEnabled: this.webTorrentEnabled, 597 webTorrentEnabled: this.webTorrentEnabled,
577 videosHistoryEnabled: this.videosHistoryEnabled, 598 videosHistoryEnabled: this.videosHistoryEnabled,
578 autoPlayVideo: this.autoPlayVideo, 599 autoPlayVideo: this.autoPlayVideo,
579 videoLanguages: this.videoLanguages, 600 videoLanguages: this.videoLanguages,
601
580 role: this.role, 602 role: this.role,
581 theme: getThemeOrDefault(this.theme, DEFAULT_USER_THEME_NAME),
582 roleLabel: USER_ROLE_LABELS[ this.role ], 603 roleLabel: USER_ROLE_LABELS[ this.role ],
604
583 videoQuota: this.videoQuota, 605 videoQuota: this.videoQuota,
584 videoQuotaDaily: this.videoQuotaDaily, 606 videoQuotaDaily: this.videoQuotaDaily,
585 createdAt: this.createdAt, 607 videoQuotaUsed: videoQuotaUsed !== undefined
608 ? parseInt(videoQuotaUsed + '', 10)
609 : undefined,
610 videoQuotaUsedDaily: videoQuotaUsedDaily !== undefined
611 ? parseInt(videoQuotaUsedDaily + '', 10)
612 : undefined,
613
614 noInstanceConfigWarningModal: this.noInstanceConfigWarningModal,
615 noWelcomeModal: this.noWelcomeModal,
616
586 blocked: this.blocked, 617 blocked: this.blocked,
587 blockedReason: this.blockedReason, 618 blockedReason: this.blockedReason,
619
588 account: this.Account.toFormattedJSON(), 620 account: this.Account.toFormattedJSON(),
589 notificationSettings: this.NotificationSetting ? this.NotificationSetting.toFormattedJSON() : undefined, 621
622 notificationSettings: this.NotificationSetting
623 ? this.NotificationSetting.toFormattedJSON()
624 : undefined,
625
590 videoChannels: [], 626 videoChannels: [],
591 videoQuotaUsed: videoQuotaUsed !== undefined 627
592 ? parseInt(videoQuotaUsed + '', 10) 628 createdAt: this.createdAt
593 : undefined,
594 videoQuotaUsedDaily: videoQuotaUsedDaily !== undefined
595 ? parseInt(videoQuotaUsedDaily + '', 10)
596 : undefined
597 } 629 }
598 630
599 if (parameters.withAdminFlags) { 631 if (parameters.withAdminFlags) {