From e34c85e527100c0b5c44567bd951e95be41b8d7e Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 14 Nov 2017 10:57:56 +0100 Subject: Fix issues on server start --- server/models/account/account.ts | 36 ++++++++++++++++++------------------ server/models/account/user.ts | 21 +++++++-------------- 2 files changed, 25 insertions(+), 32 deletions(-) (limited to 'server/models/account') 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 { AccountMethods } from './account-interface' -import LoadApplication = AccountMethods.LoadApplication import { sendDeleteAccount } from '../../lib/activitypub/send-request' +import { CONSTRAINTS_FIELDS } from '../../initializers/constants' let Account: Sequelize.Model let loadAccountByPodAndUUID: AccountMethods.LoadAccountByPodAndUUID @@ -60,14 +60,14 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes type: DataTypes.STRING, allowNull: false, validate: { - usernameValid: value => { + nameValid: value => { const res = isUserUsernameValid(value) - if (res === false) throw new Error('Username is not valid.') + if (res === false) throw new Error('Name is not valid.') } } }, url: { - type: DataTypes.STRING, + type: DataTypes.STRING(CONSTRAINTS_FIELDS.ACCOUNTS.URL.max), allowNull: false, validate: { urlValid: value => { @@ -77,7 +77,7 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes } }, publicKey: { - type: DataTypes.STRING, + type: DataTypes.STRING(CONSTRAINTS_FIELDS.ACCOUNTS.PUBLIC_KEY.max), allowNull: false, validate: { publicKeyValid: value => { @@ -87,7 +87,7 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes } }, privateKey: { - type: DataTypes.STRING, + type: DataTypes.STRING(CONSTRAINTS_FIELDS.ACCOUNTS.PRIVATE_KEY.max), allowNull: false, validate: { privateKeyValid: value => { @@ -110,14 +110,14 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes type: DataTypes.INTEGER, allowNull: false, validate: { - followersCountValid: value => { + followingCountValid: value => { const res = isAccountFollowingCountValid(value) if (res === false) throw new Error('Following count is not valid.') } } }, inboxUrl: { - type: DataTypes.STRING, + type: DataTypes.STRING(CONSTRAINTS_FIELDS.ACCOUNTS.URL.max), allowNull: false, validate: { inboxUrlValid: value => { @@ -127,7 +127,7 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes } }, outboxUrl: { - type: DataTypes.STRING, + type: DataTypes.STRING(CONSTRAINTS_FIELDS.ACCOUNTS.URL.max), allowNull: false, validate: { outboxUrlValid: value => { @@ -137,7 +137,7 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes } }, sharedInboxUrl: { - type: DataTypes.STRING, + type: DataTypes.STRING(CONSTRAINTS_FIELDS.ACCOUNTS.URL.max), allowNull: false, validate: { sharedInboxUrlValid: value => { @@ -147,7 +147,7 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes } }, followersUrl: { - type: DataTypes.STRING, + type: DataTypes.STRING(CONSTRAINTS_FIELDS.ACCOUNTS.URL.max), allowNull: false, validate: { followersUrlValid: value => { @@ -157,7 +157,7 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes } }, followingUrl: { - type: DataTypes.STRING, + type: DataTypes.STRING(CONSTRAINTS_FIELDS.ACCOUNTS.URL.max), allowNull: false, validate: { followingUrlValid: value => { @@ -241,7 +241,7 @@ function associate (models) { Account.belongsTo(models.Application, { foreignKey: { - name: 'userId', + name: 'applicationId', allowNull: true }, onDelete: 'cascade' @@ -256,7 +256,7 @@ function associate (models) { hooks: true }) - Account.hasMany(models.AccountFollower, { + Account.hasMany(models.AccountFollow, { foreignKey: { name: 'accountId', allowNull: false @@ -265,7 +265,7 @@ function associate (models) { onDelete: 'cascade' }) - Account.hasMany(models.AccountFollower, { + Account.hasMany(models.AccountFollow, { foreignKey: { name: 'targetAccountId', allowNull: false @@ -329,7 +329,7 @@ getFollowerSharedInboxUrls = function (this: AccountInstance) { attributes: [ 'sharedInboxUrl' ], include: [ { - model: Account['sequelize'].models.AccountFollower, + model: Account['sequelize'].models.AccountFollow, where: { targetAccountId: this.id } @@ -523,9 +523,9 @@ async function createListAcceptedFollowForApiQuery (type: 'followers' | 'followi for (const selection of selections) { let query = 'SELECT ' + selection + ' FROM "Account" ' + - 'INNER JOIN "AccountFollower" ON "AccountFollower"."' + firstJoin + '" = "Account"."id" ' + + 'INNER JOIN "AccountFollow" ON "AccountFollow"."' + firstJoin + '" = "Account"."id" ' + 'INNER JOIN "Account" AS "Follows" ON "Followers"."id" = "Follows"."' + secondJoin + '" ' + - 'WHERE "Account"."id" = $id AND "AccountFollower"."state" = \'accepted\' ' + + 'WHERE "Account"."id" = $id AND "AccountFollow"."state" = \'accepted\' ' + 'LIMIT ' + start 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 @@ import * as Sequelize from 'sequelize' - -import { getSort, addMethodsToModel } from '../utils' +import { hasUserRight, USER_ROLE_LABELS, UserRight } from '../../../shared' import { - cryptPassword, comparePassword, + cryptPassword, + isUserDisplayNSFWValid, isUserPasswordValid, + isUserRoleValid, isUserUsernameValid, - isUserDisplayNSFWValid, - isUserVideoQuotaValid, - isUserRoleValid + isUserVideoQuotaValid } from '../../helpers' -import { UserRight, USER_ROLE_LABELS, hasUserRight } from '../../../shared' - -import { - UserInstance, - UserAttributes, - - UserMethods -} from './user-interface' +import { addMethodsToModel, getSort } from '../utils' +import { UserAttributes, UserInstance, UserMethods } from './user-interface' let User: Sequelize.Model let isPasswordMatch: UserMethods.IsPasswordMatch -- cgit v1.2.3