X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Faccount%2Faccount.ts;h=61a88524c2d39662557d9ba524450f01b0566981;hb=25ed141c7c7631ef21d8764c1163fbf8a6591391;hp=9a29215018ef5122e8040d42a9271651564ffc88;hpb=54141398354e6e7b94aa3065a705a1251390111c;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/account/account.ts b/server/models/account/account.ts index 9a2921501..61a88524c 100644 --- a/server/models/account/account.ts +++ b/server/models/account/account.ts @@ -2,32 +2,25 @@ import * as Sequelize from 'sequelize' import { activityPubContextify, isAccountFollowersCountValid, - isAccountFollowersValid, isAccountFollowingCountValid, - isAccountFollowingValid, - isAccountInboxValid, - isAccountOutboxValid, isAccountPrivateKeyValid, isAccountPublicKeyValid, - isAccountSharedInboxValid, - isAccountUrlValid, isUserUsernameValid } from '../../helpers' +import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' import { CONFIG, CONSTRAINTS_FIELDS } from '../../initializers/constants' import { sendDeleteAccount } from '../../lib/activitypub/send/send-delete' - import { addMethodsToModel } from '../utils' import { AccountAttributes, AccountInstance, AccountMethods } from './account-interface' let Account: Sequelize.Model -let loadAccountByServerAndUUID: AccountMethods.LoadAccountByServerAndUUID let load: AccountMethods.Load let loadApplication: AccountMethods.LoadApplication let loadByUUID: AccountMethods.LoadByUUID let loadByUrl: AccountMethods.LoadByUrl let loadLocalByName: AccountMethods.LoadLocalByName let loadByNameAndHost: AccountMethods.LoadByNameAndHost -let listOwned: AccountMethods.ListOwned +let listByFollowersUrls: AccountMethods.ListByFollowersUrls let isOwned: AccountMethods.IsOwned let toActivityPubObject: AccountMethods.ToActivityPubObject let toFormattedJSON: AccountMethods.ToFormattedJSON @@ -62,7 +55,7 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes allowNull: false, validate: { urlValid: value => { - const res = isAccountUrlValid(value) + const res = isActivityPubUrlValid(value) if (res === false) throw new Error('URL is not valid.') } } @@ -112,7 +105,7 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes allowNull: false, validate: { inboxUrlValid: value => { - const res = isAccountInboxValid(value) + const res = isActivityPubUrlValid(value) if (res === false) throw new Error('Inbox URL is not valid.') } } @@ -122,7 +115,7 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes allowNull: false, validate: { outboxUrlValid: value => { - const res = isAccountOutboxValid(value) + const res = isActivityPubUrlValid(value) if (res === false) throw new Error('Outbox URL is not valid.') } } @@ -132,7 +125,7 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes allowNull: false, validate: { sharedInboxUrlValid: value => { - const res = isAccountSharedInboxValid(value) + const res = isActivityPubUrlValid(value) if (res === false) throw new Error('Shared inbox URL is not valid.') } } @@ -142,7 +135,7 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes allowNull: false, validate: { followersUrlValid: value => { - const res = isAccountFollowersValid(value) + const res = isActivityPubUrlValid(value) if (res === false) throw new Error('Followers URL is not valid.') } } @@ -152,7 +145,7 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes allowNull: false, validate: { followingUrlValid: value => { - const res = isAccountFollowingValid(value) + const res = isActivityPubUrlValid(value) if (res === false) throw new Error('Following URL is not valid.') } } @@ -185,14 +178,13 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes const classMethods = [ associate, - loadAccountByServerAndUUID, loadApplication, load, loadByUUID, loadByUrl, loadLocalByName, loadByNameAndHost, - listOwned + listByFollowersUrls ] const instanceMethods = [ isOwned, @@ -322,7 +314,7 @@ isOwned = function (this: AccountInstance) { return this.serverId === null } -getFollowerSharedInboxUrls = function (this: AccountInstance) { +getFollowerSharedInboxUrls = function (this: AccountInstance, t: Sequelize.Transaction) { const query: Sequelize.FindOptions = { attributes: [ 'sharedInboxUrl' ], include: [ @@ -334,7 +326,8 @@ getFollowerSharedInboxUrls = function (this: AccountInstance) { targetAccountId: this.id } } - ] + ], + transaction: t } return Account.findAll(query) @@ -355,16 +348,6 @@ getPublicKeyUrl = function (this: AccountInstance) { // ------------------------------ STATICS ------------------------------ -listOwned = function () { - const query: Sequelize.FindOptions = { - where: { - serverId: null - } - } - - return Account.findAll(query) -} - loadApplication = function () { return Account.findOne({ include: [ @@ -442,14 +425,15 @@ loadByUrl = function (url: string, transaction?: Sequelize.Transaction) { return Account.findOne(query) } -loadAccountByServerAndUUID = function (uuid: string, serverId: number, transaction: Sequelize.Transaction) { +listByFollowersUrls = function (followersUrls: string[], transaction?: Sequelize.Transaction) { const query: Sequelize.FindOptions = { where: { - serverId, - uuid + followersUrl: { + [Sequelize.Op.in]: followersUrls + } }, transaction } - return Account.find(query) + return Account.findAll(query) }