aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/account
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-11-14 10:57:56 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-11-27 19:40:51 +0100
commite34c85e527100c0b5c44567bd951e95be41b8d7e (patch)
tree39697c5a4dda2c2e07142a8522538db783fce2fd /server/models/account
parent1e1265b36c09df1465aa2b4866815c957b6a532e (diff)
downloadPeerTube-e34c85e527100c0b5c44567bd951e95be41b8d7e.tar.gz
PeerTube-e34c85e527100c0b5c44567bd951e95be41b8d7e.tar.zst
PeerTube-e34c85e527100c0b5c44567bd951e95be41b8d7e.zip
Fix issues on server start
Diffstat (limited to 'server/models/account')
-rw-r--r--server/models/account/account.ts36
-rw-r--r--server/models/account/user.ts21
2 files changed, 25 insertions, 32 deletions
diff --git a/server/models/account/account.ts b/server/models/account/account.ts
index 6ef29c8b7..cd6c822f1 100644
--- a/server/models/account/account.ts
+++ b/server/models/account/account.ts
@@ -22,8 +22,8 @@ import {
22 22
23 AccountMethods 23 AccountMethods
24} from './account-interface' 24} from './account-interface'
25import LoadApplication = AccountMethods.LoadApplication
26import { sendDeleteAccount } from '../../lib/activitypub/send-request' 25import { sendDeleteAccount } from '../../lib/activitypub/send-request'
26import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
27 27
28let Account: Sequelize.Model<AccountInstance, AccountAttributes> 28let Account: Sequelize.Model<AccountInstance, AccountAttributes>
29let loadAccountByPodAndUUID: AccountMethods.LoadAccountByPodAndUUID 29let loadAccountByPodAndUUID: AccountMethods.LoadAccountByPodAndUUID
@@ -60,14 +60,14 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes
60 type: DataTypes.STRING, 60 type: DataTypes.STRING,
61 allowNull: false, 61 allowNull: false,
62 validate: { 62 validate: {
63 usernameValid: value => { 63 nameValid: value => {
64 const res = isUserUsernameValid(value) 64 const res = isUserUsernameValid(value)
65 if (res === false) throw new Error('Username is not valid.') 65 if (res === false) throw new Error('Name is not valid.')
66 } 66 }
67 } 67 }
68 }, 68 },
69 url: { 69 url: {
70 type: DataTypes.STRING, 70 type: DataTypes.STRING(CONSTRAINTS_FIELDS.ACCOUNTS.URL.max),
71 allowNull: false, 71 allowNull: false,
72 validate: { 72 validate: {
73 urlValid: value => { 73 urlValid: value => {
@@ -77,7 +77,7 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes
77 } 77 }
78 }, 78 },
79 publicKey: { 79 publicKey: {
80 type: DataTypes.STRING, 80 type: DataTypes.STRING(CONSTRAINTS_FIELDS.ACCOUNTS.PUBLIC_KEY.max),
81 allowNull: false, 81 allowNull: false,
82 validate: { 82 validate: {
83 publicKeyValid: value => { 83 publicKeyValid: value => {
@@ -87,7 +87,7 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes
87 } 87 }
88 }, 88 },
89 privateKey: { 89 privateKey: {
90 type: DataTypes.STRING, 90 type: DataTypes.STRING(CONSTRAINTS_FIELDS.ACCOUNTS.PRIVATE_KEY.max),
91 allowNull: false, 91 allowNull: false,
92 validate: { 92 validate: {
93 privateKeyValid: value => { 93 privateKeyValid: value => {
@@ -110,14 +110,14 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes
110 type: DataTypes.INTEGER, 110 type: DataTypes.INTEGER,
111 allowNull: false, 111 allowNull: false,
112 validate: { 112 validate: {
113 followersCountValid: value => { 113 followingCountValid: value => {
114 const res = isAccountFollowingCountValid(value) 114 const res = isAccountFollowingCountValid(value)
115 if (res === false) throw new Error('Following count is not valid.') 115 if (res === false) throw new Error('Following count is not valid.')
116 } 116 }
117 } 117 }
118 }, 118 },
119 inboxUrl: { 119 inboxUrl: {
120 type: DataTypes.STRING, 120 type: DataTypes.STRING(CONSTRAINTS_FIELDS.ACCOUNTS.URL.max),
121 allowNull: false, 121 allowNull: false,
122 validate: { 122 validate: {
123 inboxUrlValid: value => { 123 inboxUrlValid: value => {
@@ -127,7 +127,7 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes
127 } 127 }
128 }, 128 },
129 outboxUrl: { 129 outboxUrl: {
130 type: DataTypes.STRING, 130 type: DataTypes.STRING(CONSTRAINTS_FIELDS.ACCOUNTS.URL.max),
131 allowNull: false, 131 allowNull: false,
132 validate: { 132 validate: {
133 outboxUrlValid: value => { 133 outboxUrlValid: value => {
@@ -137,7 +137,7 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes
137 } 137 }
138 }, 138 },
139 sharedInboxUrl: { 139 sharedInboxUrl: {
140 type: DataTypes.STRING, 140 type: DataTypes.STRING(CONSTRAINTS_FIELDS.ACCOUNTS.URL.max),
141 allowNull: false, 141 allowNull: false,
142 validate: { 142 validate: {
143 sharedInboxUrlValid: value => { 143 sharedInboxUrlValid: value => {
@@ -147,7 +147,7 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes
147 } 147 }
148 }, 148 },
149 followersUrl: { 149 followersUrl: {
150 type: DataTypes.STRING, 150 type: DataTypes.STRING(CONSTRAINTS_FIELDS.ACCOUNTS.URL.max),
151 allowNull: false, 151 allowNull: false,
152 validate: { 152 validate: {
153 followersUrlValid: value => { 153 followersUrlValid: value => {
@@ -157,7 +157,7 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes
157 } 157 }
158 }, 158 },
159 followingUrl: { 159 followingUrl: {
160 type: DataTypes.STRING, 160 type: DataTypes.STRING(CONSTRAINTS_FIELDS.ACCOUNTS.URL.max),
161 allowNull: false, 161 allowNull: false,
162 validate: { 162 validate: {
163 followingUrlValid: value => { 163 followingUrlValid: value => {
@@ -241,7 +241,7 @@ function associate (models) {
241 241
242 Account.belongsTo(models.Application, { 242 Account.belongsTo(models.Application, {
243 foreignKey: { 243 foreignKey: {
244 name: 'userId', 244 name: 'applicationId',
245 allowNull: true 245 allowNull: true
246 }, 246 },
247 onDelete: 'cascade' 247 onDelete: 'cascade'
@@ -256,7 +256,7 @@ function associate (models) {
256 hooks: true 256 hooks: true
257 }) 257 })
258 258
259 Account.hasMany(models.AccountFollower, { 259 Account.hasMany(models.AccountFollow, {
260 foreignKey: { 260 foreignKey: {
261 name: 'accountId', 261 name: 'accountId',
262 allowNull: false 262 allowNull: false
@@ -265,7 +265,7 @@ function associate (models) {
265 onDelete: 'cascade' 265 onDelete: 'cascade'
266 }) 266 })
267 267
268 Account.hasMany(models.AccountFollower, { 268 Account.hasMany(models.AccountFollow, {
269 foreignKey: { 269 foreignKey: {
270 name: 'targetAccountId', 270 name: 'targetAccountId',
271 allowNull: false 271 allowNull: false
@@ -329,7 +329,7 @@ getFollowerSharedInboxUrls = function (this: AccountInstance) {
329 attributes: [ 'sharedInboxUrl' ], 329 attributes: [ 'sharedInboxUrl' ],
330 include: [ 330 include: [
331 { 331 {
332 model: Account['sequelize'].models.AccountFollower, 332 model: Account['sequelize'].models.AccountFollow,
333 where: { 333 where: {
334 targetAccountId: this.id 334 targetAccountId: this.id
335 } 335 }
@@ -523,9 +523,9 @@ async function createListAcceptedFollowForApiQuery (type: 'followers' | 'followi
523 523
524 for (const selection of selections) { 524 for (const selection of selections) {
525 let query = 'SELECT ' + selection + ' FROM "Account" ' + 525 let query = 'SELECT ' + selection + ' FROM "Account" ' +
526 'INNER JOIN "AccountFollower" ON "AccountFollower"."' + firstJoin + '" = "Account"."id" ' + 526 'INNER JOIN "AccountFollow" ON "AccountFollow"."' + firstJoin + '" = "Account"."id" ' +
527 'INNER JOIN "Account" AS "Follows" ON "Followers"."id" = "Follows"."' + secondJoin + '" ' + 527 'INNER JOIN "Account" AS "Follows" ON "Followers"."id" = "Follows"."' + secondJoin + '" ' +
528 'WHERE "Account"."id" = $id AND "AccountFollower"."state" = \'accepted\' ' + 528 'WHERE "Account"."id" = $id AND "AccountFollow"."state" = \'accepted\' ' +
529 'LIMIT ' + start 529 'LIMIT ' + start
530 530
531 if (count !== undefined) query += ', ' + count 531 if (count !== undefined) query += ', ' + count
diff --git a/server/models/account/user.ts b/server/models/account/user.ts
index 7390baf91..8f7c9b013 100644
--- a/server/models/account/user.ts
+++ b/server/models/account/user.ts
@@ -1,23 +1,16 @@
1import * as Sequelize from 'sequelize' 1import * as Sequelize from 'sequelize'
2 2import { hasUserRight, USER_ROLE_LABELS, UserRight } from '../../../shared'
3import { getSort, addMethodsToModel } from '../utils'
4import { 3import {
5 cryptPassword,
6 comparePassword, 4 comparePassword,
5 cryptPassword,
6 isUserDisplayNSFWValid,
7 isUserPasswordValid, 7 isUserPasswordValid,
8 isUserRoleValid,
8 isUserUsernameValid, 9 isUserUsernameValid,
9 isUserDisplayNSFWValid, 10 isUserVideoQuotaValid
10 isUserVideoQuotaValid,
11 isUserRoleValid
12} from '../../helpers' 11} from '../../helpers'
13import { UserRight, USER_ROLE_LABELS, hasUserRight } from '../../../shared' 12import { addMethodsToModel, getSort } from '../utils'
14 13import { UserAttributes, UserInstance, UserMethods } from './user-interface'
15import {
16 UserInstance,
17 UserAttributes,
18
19 UserMethods
20} from './user-interface'
21 14
22let User: Sequelize.Model<UserInstance, UserAttributes> 15let User: Sequelize.Model<UserInstance, UserAttributes>
23let isPasswordMatch: UserMethods.IsPasswordMatch 16let isPasswordMatch: UserMethods.IsPasswordMatch