-import { values } from 'lodash'
import { col, FindOptions, fn, literal, Op, QueryTypes, where, WhereOptions } from 'sequelize'
import {
AfterDestroy,
MUserDefault,
MUserFormattable,
MUserNotifSettingChannelDefault,
- MUserWithNotificationSetting,
- MVideoWithRights
+ MUserWithNotificationSetting
} from '@server/types/models'
import { AttributesOnly } from '@shared/typescript-utils'
import { hasUserRight, USER_ROLE_LABELS } from '../../../shared/core-utils/users'
-import { AbuseState, MyUser, UserRight, VideoPlaylistType, VideoPrivacy } from '../../../shared/models'
+import { AbuseState, MyUser, UserRight, VideoPlaylistType } from '../../../shared/models'
import { User, UserRole } from '../../../shared/models/users'
import { UserAdminFlag } from '../../../shared/models/users/user-flag.model'
import { NSFWPolicyType } from '../../../shared/models/videos/nsfw-policy.type'
isUserP2PEnabledValid,
isUserPasswordValid,
isUserRoleValid,
- isUserUsernameValid,
isUserVideoLanguages,
isUserVideoQuotaDailyValid,
isUserVideoQuotaValid,
import { VideoLiveModel } from '../video/video-live'
import { VideoPlaylistModel } from '../video/video-playlist'
import { UserNotificationSettingModel } from './user-notification-setting'
+import { forceNumber } from '@shared/core-utils'
enum ScopeNames {
FOR_ME_API = 'FOR_ME_API',
password: string
@AllowNull(false)
- @Is('UserUsername', value => throwIfNotValid(value, isUserUsernameValid, 'user name'))
@Column
username: string
@AllowNull(false)
@Is('UserNSFWPolicy', value => throwIfNotValid(value, isUserNSFWPolicyValid, 'NSFW policy'))
- @Column(DataType.ENUM(...values(NSFW_POLICY_TYPES)))
+ @Column(DataType.ENUM(...Object.values(NSFW_POLICY_TYPES)))
nsfwPolicy: NSFWPolicyType
@AllowNull(false)
@Column
lastLoginDate: Date
+ @AllowNull(true)
+ @Default(null)
+ @Column
+ otpSecret: string
+
@CreatedAt
createdAt: Date
}
if (blocked !== undefined) {
- Object.assign(where, {
- blocked: blocked
- })
+ Object.assign(where, { blocked })
}
const query: FindOptions = {
}
}
- return UserModel.count(query)
+ return UserModel.unscoped().count(query)
}
- const totalUsers = await UserModel.count()
+ const totalUsers = await UserModel.unscoped().count()
const totalDailyActiveUsers = await getActiveUsers(1)
const totalWeeklyActiveUsers = await getActiveUsers(7)
const totalMonthlyActiveUsers = await getActiveUsers(30)
.then(u => u.map(u => u.username))
}
- canGetVideo (video: MVideoWithRights) {
- const videoUserId = video.VideoChannel.Account.userId
-
- if (video.isBlacklisted()) {
- return videoUserId === this.id || this.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST)
- }
-
- if (video.privacy === VideoPrivacy.PRIVATE) {
- return video.VideoChannel && videoUserId === this.id || this.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST)
- }
-
- if (video.privacy === VideoPrivacy.INTERNAL) return true
-
- return false
- }
-
hasRight (right: UserRight) {
return hasUserRight(this.role, right)
}
autoPlayNextVideoPlaylist: this.autoPlayNextVideoPlaylist,
videoLanguages: this.videoLanguages,
- role: this.role,
- roleLabel: USER_ROLE_LABELS[this.role],
+ role: {
+ id: this.role,
+ label: USER_ROLE_LABELS[this.role]
+ },
videoQuota: this.videoQuota,
videoQuotaDaily: this.videoQuotaDaily,
videoQuotaUsed: videoQuotaUsed !== undefined
- ? parseInt(videoQuotaUsed + '', 10) + LiveQuotaStore.Instance.getLiveQuotaOf(this.id)
+ ? forceNumber(videoQuotaUsed) + LiveQuotaStore.Instance.getLiveQuotaOf(this.id)
: undefined,
videoQuotaUsedDaily: videoQuotaUsedDaily !== undefined
- ? parseInt(videoQuotaUsedDaily + '', 10) + LiveQuotaStore.Instance.getLiveQuotaOf(this.id)
+ ? forceNumber(videoQuotaUsedDaily) + LiveQuotaStore.Instance.getLiveQuotaOf(this.id)
: undefined,
videosCount: videosCount !== undefined
- ? parseInt(videosCount + '', 10)
+ ? forceNumber(videosCount)
: undefined,
abusesCount: abusesCount
- ? parseInt(abusesCount, 10)
+ ? forceNumber(abusesCount)
: undefined,
abusesAcceptedCount: abusesAcceptedCount
- ? parseInt(abusesAcceptedCount, 10)
+ ? forceNumber(abusesAcceptedCount)
: undefined,
abusesCreatedCount: abusesCreatedCount !== undefined
- ? parseInt(abusesCreatedCount + '', 10)
+ ? forceNumber(abusesCreatedCount)
: undefined,
videoCommentsCount: videoCommentsCount !== undefined
- ? parseInt(videoCommentsCount + '', 10)
+ ? forceNumber(videoCommentsCount)
: undefined,
noInstanceConfigWarningModal: this.noInstanceConfigWarningModal,
pluginAuth: this.pluginAuth,
- lastLoginDate: this.lastLoginDate
+ lastLoginDate: this.lastLoginDate,
+
+ twoFactorEnabled: !!this.otpSecret
}
if (parameters.withAdminFlags) {