From 265ba139ebf56bbdc1c65f6ea4f367774c691fc0 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 3 Jan 2018 16:38:50 +0100 Subject: Send account activitypub update events --- server/middlewares/sort.ts | 9 ++++++++- server/middlewares/validators/account.ts | 19 +++++++++++++++++-- server/middlewares/validators/sort.ts | 3 +++ 3 files changed, 28 insertions(+), 3 deletions(-) (limited to 'server/middlewares') diff --git a/server/middlewares/sort.ts b/server/middlewares/sort.ts index fdd6d419f..4f524b49a 100644 --- a/server/middlewares/sort.ts +++ b/server/middlewares/sort.ts @@ -2,6 +2,12 @@ import * as express from 'express' import 'express-validator' import { SortType } from '../helpers/utils' +function setAccountsSort (req: express.Request, res: express.Response, next: express.NextFunction) { + if (!req.query.sort) req.query.sort = '-createdAt' + + return next() +} + function setUsersSort (req: express.Request, res: express.Response, next: express.NextFunction) { if (!req.query.sort) req.query.sort = '-createdAt' @@ -82,5 +88,6 @@ export { setFollowersSort, setFollowingSort, setJobsSort, - setVideoCommentThreadsSort + setVideoCommentThreadsSort, + setAccountsSort } diff --git a/server/middlewares/validators/account.ts b/server/middlewares/validators/account.ts index 3573a9a50..ebc2fcf2d 100644 --- a/server/middlewares/validators/account.ts +++ b/server/middlewares/validators/account.ts @@ -1,6 +1,7 @@ import * as express from 'express' import { param } from 'express-validator/check' -import { isAccountNameValid, isLocalAccountNameExist } from '../../helpers/custom-validators/accounts' +import { isAccountIdExist, isAccountNameValid, isLocalAccountNameExist } from '../../helpers/custom-validators/accounts' +import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' import { logger } from '../../helpers/logger' import { areValidationErrors } from './utils' @@ -17,8 +18,22 @@ const localAccountValidator = [ } ] +const accountsGetValidator = [ + param('id').custom(isIdOrUUIDValid).withMessage('Should have a valid id'), + + async (req: express.Request, res: express.Response, next: express.NextFunction) => { + logger.debug('Checking accountsGetValidator parameters', { parameters: req.params }) + + if (areValidationErrors(req, res)) return + if (!await isAccountIdExist(req.params.id, res)) return + + return next() + } +] + // --------------------------------------------------------------------------- export { - localAccountValidator + localAccountValidator, + accountsGetValidator } diff --git a/server/middlewares/validators/sort.ts b/server/middlewares/validators/sort.ts index e1d8d7d1b..72c6b34e3 100644 --- a/server/middlewares/validators/sort.ts +++ b/server/middlewares/validators/sort.ts @@ -6,6 +6,7 @@ import { areValidationErrors } from './utils' // Initialize constants here for better performances const SORTABLE_USERS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.USERS) +const SORTABLE_ACCOUNTS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.ACCOUNTS) const SORTABLE_JOBS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.JOBS) const SORTABLE_VIDEO_ABUSES_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_ABUSES) const SORTABLE_VIDEOS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEOS) @@ -16,6 +17,7 @@ const SORTABLE_FOLLOWERS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.FOLLOW const SORTABLE_FOLLOWING_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.FOLLOWING) const usersSortValidator = checkSort(SORTABLE_USERS_COLUMNS) +const accountsSortValidator = checkSort(SORTABLE_ACCOUNTS_COLUMNS) const jobsSortValidator = checkSort(SORTABLE_JOBS_COLUMNS) const videoAbusesSortValidator = checkSort(SORTABLE_VIDEO_ABUSES_COLUMNS) const videosSortValidator = checkSort(SORTABLE_VIDEOS_COLUMNS) @@ -33,6 +35,7 @@ export { videoChannelsSortValidator, videosSortValidator, blacklistSortValidator, + accountsSortValidator, followersSortValidator, followingSortValidator, jobsSortValidator, -- cgit v1.2.3