import * as Sequelize from 'sequelize'
import {
+ AfterDelete,
+ AfterUpdate,
AllowNull,
BeforeCreate,
BeforeUpdate,
isUserAutoPlayVideoValid,
isUserBlockedReasonValid,
isUserBlockedValid,
- isUserNSFWPolicyValid,
isUserEmailVerifiedValid,
+ isUserNSFWPolicyValid,
isUserPasswordValid,
isUserRoleValid,
isUserUsernameValid,
- isUserVideoQuotaValid,
- isUserVideoQuotaDailyValid
+ isUserVideoQuotaDailyValid,
+ isUserVideoQuotaValid
} from '../../helpers/custom-validators/users'
import { comparePassword, cryptPassword } from '../../helpers/peertube-crypto'
import { OAuthTokenModel } from '../oauth/oauth-token'
import { NSFWPolicyType } from '../../../shared/models/videos/nsfw-policy.type'
import { values } from 'lodash'
import { NSFW_POLICY_TYPES } from '../../initializers'
+import { clearCacheByUserId } from '../../lib/oauth-model'
enum ScopeNames {
WITH_VIDEO_CHANNEL = 'WITH_VIDEO_CHANNEL'
}
}
+ @AfterUpdate
+ @AfterDelete
+ static removeTokenCache (instance: UserModel) {
+ return clearCacheByUserId(instance.id)
+ }
+
static countTotal () {
return this.count()
}
}
}
+ static autoComplete (search: string) {
+ const query = {
+ where: {
+ username: {
+ [ Sequelize.Op.like ]: `%${search}%`
+ }
+ },
+ limit: 10
+ }
+
+ return UserModel.findAll(query)
+ .then(u => u.map(u => u.username))
+ }
+
hasRight (right: UserRight) {
return hasUserRight(this.role, right)
}