aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
Diffstat (limited to 'server/models')
-rw-r--r--server/models/account/account.ts4
-rw-r--r--server/models/oauth/oauth-token.ts26
2 files changed, 20 insertions, 10 deletions
diff --git a/server/models/account/account.ts b/server/models/account/account.ts
index 6bbfc6f4e..580d920ce 100644
--- a/server/models/account/account.ts
+++ b/server/models/account/account.ts
@@ -134,8 +134,8 @@ export class AccountModel extends Model<AccountModel> {
134 return undefined 134 return undefined
135 } 135 }
136 136
137 static load (id: number) { 137 static load (id: number, transaction?: Sequelize.Transaction) {
138 return AccountModel.findById(id) 138 return AccountModel.findById(id, { transaction })
139 } 139 }
140 140
141 static loadByUUID (uuid: string) { 141 static loadByUUID (uuid: string) {
diff --git a/server/models/oauth/oauth-token.ts b/server/models/oauth/oauth-token.ts
index 4c53848dc..1dd5e0289 100644
--- a/server/models/oauth/oauth-token.ts
+++ b/server/models/oauth/oauth-token.ts
@@ -1,9 +1,10 @@
1import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' 1import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript'
2import { logger } from '../../helpers/logger' 2import { logger } from '../../helpers/logger'
3import { AccountModel } from '../account/account'
4import { UserModel } from '../account/user' 3import { UserModel } from '../account/user'
5import { OAuthClientModel } from './oauth-client' 4import { OAuthClientModel } from './oauth-client'
6import { Transaction } from 'sequelize' 5import { Transaction } from 'sequelize'
6import { AccountModel } from '../account/account'
7import { ActorModel } from '../activitypub/actor'
7 8
8export type OAuthTokenInfo = { 9export type OAuthTokenInfo = {
9 refreshToken: string 10 refreshToken: string
@@ -17,18 +18,27 @@ export type OAuthTokenInfo = {
17} 18}
18 19
19enum ScopeNames { 20enum ScopeNames {
20 WITH_ACCOUNT = 'WITH_ACCOUNT' 21 WITH_USER = 'WITH_USER'
21} 22}
22 23
23@Scopes({ 24@Scopes({
24 [ScopeNames.WITH_ACCOUNT]: { 25 [ScopeNames.WITH_USER]: {
25 include: [ 26 include: [
26 { 27 {
27 model: () => UserModel, 28 model: () => UserModel.unscoped(),
29 required: true,
28 include: [ 30 include: [
29 { 31 {
30 model: () => AccountModel, 32 attributes: [ 'id' ],
31 required: true 33 model: () => AccountModel.unscoped(),
34 required: true,
35 include: [
36 {
37 attributes: [ 'id' ],
38 model: () => ActorModel.unscoped(),
39 required: true
40 }
41 ]
32 } 42 }
33 ] 43 ]
34 } 44 }
@@ -138,7 +148,7 @@ export class OAuthTokenModel extends Model<OAuthTokenModel> {
138 } 148 }
139 } 149 }
140 150
141 return OAuthTokenModel.scope(ScopeNames.WITH_ACCOUNT).findOne(query).then(token => { 151 return OAuthTokenModel.scope(ScopeNames.WITH_USER).findOne(query).then(token => {
142 if (token) token['user'] = token.User 152 if (token) token['user'] = token.User
143 153
144 return token 154 return token
@@ -152,7 +162,7 @@ export class OAuthTokenModel extends Model<OAuthTokenModel> {
152 } 162 }
153 } 163 }
154 164
155 return OAuthTokenModel.scope(ScopeNames.WITH_ACCOUNT) 165 return OAuthTokenModel.scope(ScopeNames.WITH_USER)
156 .findOne(query) 166 .findOne(query)
157 .then(token => { 167 .then(token => {
158 if (token) { 168 if (token) {