]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/account/user.ts
Correctly delete directories on import
[github/Chocobozzz/PeerTube.git] / server / models / account / user.ts
index 4b13e47a0dc306d76a62acc3a61da8979e2cb2ee..e56b0bf40b06bb988e8cf9c04f82ace36cd8ec50 100644 (file)
@@ -1,5 +1,7 @@
 import * as Sequelize from 'sequelize'
 import {
+  AfterDelete,
+  AfterUpdate,
   AllowNull,
   BeforeCreate,
   BeforeUpdate,
@@ -23,13 +25,13 @@ import {
   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'
@@ -39,7 +41,7 @@ import { AccountModel } from './account'
 import { NSFWPolicyType } from '../../../shared/models/videos/nsfw-policy.type'
 import { values } from 'lodash'
 import { NSFW_POLICY_TYPES } from '../../initializers'
-import { VideoFileModel } from '../video/video-file'
+import { clearCacheByUserId } from '../../lib/oauth-model'
 
 enum ScopeNames {
   WITH_VIDEO_CHANNEL = 'WITH_VIDEO_CHANNEL'
@@ -169,6 +171,12 @@ export class UserModel extends Model<UserModel> {
     }
   }
 
+  @AfterUpdate
+  @AfterDelete
+  static removeTokenCache (instance: UserModel) {
+    return clearCacheByUserId(instance.id)
+  }
+
   static countTotal () {
     return this.count()
   }
@@ -296,6 +304,20 @@ export class UserModel extends Model<UserModel> {
     }
   }
 
+  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)
   }
@@ -394,15 +416,4 @@ export class UserModel extends Model<UserModel> {
                       return parseInt(total, 10)
                     })
   }
-
-  static autocomplete (search: string) {
-    return UserModel.findAll({
-      where: {
-        username: {
-          [Sequelize.Op.like]: `%${search}%`
-        }
-      }
-    })
-      .then(u => u.map(u => u.username))
-  }
 }