diff options
Diffstat (limited to 'server/models')
-rw-r--r-- | server/models/account/user.ts | 9 | ||||
-rw-r--r-- | server/models/oauth/oauth-token.ts | 21 |
2 files changed, 29 insertions, 1 deletions
diff --git a/server/models/account/user.ts b/server/models/account/user.ts index 680b1d52d..e56b0bf40 100644 --- a/server/models/account/user.ts +++ b/server/models/account/user.ts | |||
@@ -1,5 +1,7 @@ | |||
1 | import * as Sequelize from 'sequelize' | 1 | import * as Sequelize from 'sequelize' |
2 | import { | 2 | import { |
3 | AfterDelete, | ||
4 | AfterUpdate, | ||
3 | AllowNull, | 5 | AllowNull, |
4 | BeforeCreate, | 6 | BeforeCreate, |
5 | BeforeUpdate, | 7 | BeforeUpdate, |
@@ -39,6 +41,7 @@ import { AccountModel } from './account' | |||
39 | import { NSFWPolicyType } from '../../../shared/models/videos/nsfw-policy.type' | 41 | import { NSFWPolicyType } from '../../../shared/models/videos/nsfw-policy.type' |
40 | import { values } from 'lodash' | 42 | import { values } from 'lodash' |
41 | import { NSFW_POLICY_TYPES } from '../../initializers' | 43 | import { NSFW_POLICY_TYPES } from '../../initializers' |
44 | import { clearCacheByUserId } from '../../lib/oauth-model' | ||
42 | 45 | ||
43 | enum ScopeNames { | 46 | enum ScopeNames { |
44 | WITH_VIDEO_CHANNEL = 'WITH_VIDEO_CHANNEL' | 47 | WITH_VIDEO_CHANNEL = 'WITH_VIDEO_CHANNEL' |
@@ -168,6 +171,12 @@ export class UserModel extends Model<UserModel> { | |||
168 | } | 171 | } |
169 | } | 172 | } |
170 | 173 | ||
174 | @AfterUpdate | ||
175 | @AfterDelete | ||
176 | static removeTokenCache (instance: UserModel) { | ||
177 | return clearCacheByUserId(instance.id) | ||
178 | } | ||
179 | |||
171 | static countTotal () { | 180 | static countTotal () { |
172 | return this.count() | 181 | return this.count() |
173 | } | 182 | } |
diff --git a/server/models/oauth/oauth-token.ts b/server/models/oauth/oauth-token.ts index 1dd5e0289..ef9592c04 100644 --- a/server/models/oauth/oauth-token.ts +++ b/server/models/oauth/oauth-token.ts | |||
@@ -1,10 +1,23 @@ | |||
1 | import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' | 1 | import { |
2 | AfterDelete, | ||
3 | AfterUpdate, | ||
4 | AllowNull, | ||
5 | BelongsTo, | ||
6 | Column, | ||
7 | CreatedAt, | ||
8 | ForeignKey, | ||
9 | Model, | ||
10 | Scopes, | ||
11 | Table, | ||
12 | UpdatedAt | ||
13 | } from 'sequelize-typescript' | ||
2 | import { logger } from '../../helpers/logger' | 14 | import { logger } from '../../helpers/logger' |
3 | import { UserModel } from '../account/user' | 15 | import { UserModel } from '../account/user' |
4 | import { OAuthClientModel } from './oauth-client' | 16 | import { OAuthClientModel } from './oauth-client' |
5 | import { Transaction } from 'sequelize' | 17 | import { Transaction } from 'sequelize' |
6 | import { AccountModel } from '../account/account' | 18 | import { AccountModel } from '../account/account' |
7 | import { ActorModel } from '../activitypub/actor' | 19 | import { ActorModel } from '../activitypub/actor' |
20 | import { clearCacheByToken } from '../../lib/oauth-model' | ||
8 | 21 | ||
9 | export type OAuthTokenInfo = { | 22 | export type OAuthTokenInfo = { |
10 | refreshToken: string | 23 | refreshToken: string |
@@ -112,6 +125,12 @@ export class OAuthTokenModel extends Model<OAuthTokenModel> { | |||
112 | }) | 125 | }) |
113 | OAuthClients: OAuthClientModel[] | 126 | OAuthClients: OAuthClientModel[] |
114 | 127 | ||
128 | @AfterUpdate | ||
129 | @AfterDelete | ||
130 | static removeTokenCache (token: OAuthTokenModel) { | ||
131 | return clearCacheByToken(token.accessToken) | ||
132 | } | ||
133 | |||
115 | static getByRefreshTokenAndPopulateClient (refreshToken: string) { | 134 | static getByRefreshTokenAndPopulateClient (refreshToken: string) { |
116 | const query = { | 135 | const query = { |
117 | where: { | 136 | where: { |