diff options
author | Chocobozzz <me@florianbigard.com> | 2018-08-08 14:58:21 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-08-08 15:22:58 +0200 |
commit | e69219184b1a3262ec5e617d30337b6431c9840c (patch) | |
tree | 959b32e1ed28047052604941870563e946be9de1 /server/models | |
parent | 6b09aba90dfe4c61331b66b1a6ef1f58ddc61485 (diff) | |
download | PeerTube-e69219184b1a3262ec5e617d30337b6431c9840c.tar.gz PeerTube-e69219184b1a3262ec5e617d30337b6431c9840c.tar.zst PeerTube-e69219184b1a3262ec5e617d30337b6431c9840c.zip |
Implement user blocking on server side
Diffstat (limited to 'server/models')
-rw-r--r-- | server/models/account/user.ts | 7 | ||||
-rw-r--r-- | server/models/oauth/oauth-token.ts | 8 |
2 files changed, 12 insertions, 3 deletions
diff --git a/server/models/account/user.ts b/server/models/account/user.ts index 1b1fc5ee8..ea6d63312 100644 --- a/server/models/account/user.ts +++ b/server/models/account/user.ts | |||
@@ -21,6 +21,7 @@ import { hasUserRight, USER_ROLE_LABELS, UserRight } from '../../../shared' | |||
21 | import { User, UserRole } from '../../../shared/models/users' | 21 | import { User, UserRole } from '../../../shared/models/users' |
22 | import { | 22 | import { |
23 | isUserAutoPlayVideoValid, | 23 | isUserAutoPlayVideoValid, |
24 | isUserBlockedValid, | ||
24 | isUserNSFWPolicyValid, | 25 | isUserNSFWPolicyValid, |
25 | isUserPasswordValid, | 26 | isUserPasswordValid, |
26 | isUserRoleValid, | 27 | isUserRoleValid, |
@@ -101,6 +102,12 @@ export class UserModel extends Model<UserModel> { | |||
101 | autoPlayVideo: boolean | 102 | autoPlayVideo: boolean |
102 | 103 | ||
103 | @AllowNull(false) | 104 | @AllowNull(false) |
105 | @Default(false) | ||
106 | @Is('UserBlocked', value => throwIfNotValid(value, isUserBlockedValid, 'blocked boolean')) | ||
107 | @Column | ||
108 | blocked: boolean | ||
109 | |||
110 | @AllowNull(false) | ||
104 | @Is('UserRole', value => throwIfNotValid(value, isUserRoleValid, 'role')) | 111 | @Is('UserRole', value => throwIfNotValid(value, isUserRoleValid, 'role')) |
105 | @Column | 112 | @Column |
106 | role: number | 113 | role: number |
diff --git a/server/models/oauth/oauth-token.ts b/server/models/oauth/oauth-token.ts index 026c30135..4c53848dc 100644 --- a/server/models/oauth/oauth-token.ts +++ b/server/models/oauth/oauth-token.ts | |||
@@ -3,6 +3,7 @@ import { logger } from '../../helpers/logger' | |||
3 | import { AccountModel } from '../account/account' | 3 | import { AccountModel } from '../account/account' |
4 | import { UserModel } from '../account/user' | 4 | import { UserModel } from '../account/user' |
5 | import { OAuthClientModel } from './oauth-client' | 5 | import { OAuthClientModel } from './oauth-client' |
6 | import { Transaction } from 'sequelize' | ||
6 | 7 | ||
7 | export type OAuthTokenInfo = { | 8 | export type OAuthTokenInfo = { |
8 | refreshToken: string | 9 | refreshToken: string |
@@ -125,7 +126,7 @@ export class OAuthTokenModel extends Model<OAuthTokenModel> { | |||
125 | } as OAuthTokenInfo | 126 | } as OAuthTokenInfo |
126 | }) | 127 | }) |
127 | .catch(err => { | 128 | .catch(err => { |
128 | logger.info('getRefreshToken error.', { err }) | 129 | logger.error('getRefreshToken error.', { err }) |
129 | throw err | 130 | throw err |
130 | }) | 131 | }) |
131 | } | 132 | } |
@@ -163,11 +164,12 @@ export class OAuthTokenModel extends Model<OAuthTokenModel> { | |||
163 | }) | 164 | }) |
164 | } | 165 | } |
165 | 166 | ||
166 | static deleteUserToken (userId: number) { | 167 | static deleteUserToken (userId: number, t?: Transaction) { |
167 | const query = { | 168 | const query = { |
168 | where: { | 169 | where: { |
169 | userId | 170 | userId |
170 | } | 171 | }, |
172 | transaction: t | ||
171 | } | 173 | } |
172 | 174 | ||
173 | return OAuthTokenModel.destroy(query) | 175 | return OAuthTokenModel.destroy(query) |