From da854ddd502cd70685ef779c673b9e63757b8aa0 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 28 Dec 2017 11:16:08 +0100 Subject: Propagate old comment on new follow --- server/middlewares/activitypub.ts | 3 ++- server/middlewares/oauth.ts | 3 +-- server/middlewares/servers.ts | 2 +- server/middlewares/sort.ts | 2 +- server/middlewares/user-right.ts | 2 +- server/middlewares/validators/account.ts | 2 +- .../middlewares/validators/activitypub/activity.ts | 4 ++-- .../validators/activitypub/signature.ts | 7 +++++-- server/middlewares/validators/follows.ts | 4 +++- server/middlewares/validators/oembed.ts | 3 ++- server/middlewares/validators/pagination.ts | 2 +- server/middlewares/validators/sort.ts | 4 ++-- server/middlewares/validators/users.ts | 9 +++------ server/middlewares/validators/utils.ts | 2 +- server/middlewares/validators/video-blacklist.ts | 2 +- server/middlewares/validators/video-channels.ts | 5 ++--- server/middlewares/validators/video-comments.ts | 22 +++++++++++++++++++--- server/middlewares/validators/videos.ts | 17 ++++------------- server/middlewares/validators/webfinger.ts | 3 ++- 19 files changed, 54 insertions(+), 44 deletions(-) (limited to 'server/middlewares') diff --git a/server/middlewares/activitypub.ts b/server/middlewares/activitypub.ts index c00a6affa..1488b42ab 100644 --- a/server/middlewares/activitypub.ts +++ b/server/middlewares/activitypub.ts @@ -1,7 +1,8 @@ import { eachSeries } from 'async' import { NextFunction, Request, RequestHandler, Response } from 'express' import { ActivityPubSignature } from '../../shared' -import { isSignatureVerified, logger } from '../helpers' +import { logger } from '../helpers/logger' +import { isSignatureVerified } from '../helpers/peertube-crypto' import { ACCEPT_HEADERS, ACTIVITY_PUB } from '../initializers' import { getOrCreateActorAndServerAndModel } from '../lib/activitypub' import { ActorModel } from '../models/activitypub/actor' diff --git a/server/middlewares/oauth.ts b/server/middlewares/oauth.ts index 3faecdbcc..e59168ea8 100644 --- a/server/middlewares/oauth.ts +++ b/server/middlewares/oauth.ts @@ -1,9 +1,8 @@ import 'express-validator' import * as express from 'express' import * as OAuthServer from 'express-oauth-server' - +import { logger } from '../helpers/logger' import { OAUTH_LIFETIME } from '../initializers' -import { logger } from '../helpers' const oAuthServer = new OAuthServer({ accessTokenLifetime: OAUTH_LIFETIME.ACCESS_TOKEN, diff --git a/server/middlewares/servers.ts b/server/middlewares/servers.ts index e16bc4a86..a9dcad2d4 100644 --- a/server/middlewares/servers.ts +++ b/server/middlewares/servers.ts @@ -1,6 +1,6 @@ import * as express from 'express' import 'express-validator' -import { getHostWithPort } from '../helpers' +import { getHostWithPort } from '../helpers/utils' function setBodyHostsPort (req: express.Request, res: express.Response, next: express.NextFunction) { if (!req.body.hosts) return next() diff --git a/server/middlewares/sort.ts b/server/middlewares/sort.ts index 0eb50db89..fdd6d419f 100644 --- a/server/middlewares/sort.ts +++ b/server/middlewares/sort.ts @@ -1,6 +1,6 @@ import * as express from 'express' import 'express-validator' -import { SortType } from '../helpers' +import { SortType } from '../helpers/utils' function setUsersSort (req: express.Request, res: express.Response, next: express.NextFunction) { if (!req.query.sort) req.query.sort = '-createdAt' diff --git a/server/middlewares/user-right.ts b/server/middlewares/user-right.ts index 5d63ebaf4..5bb5bdfbd 100644 --- a/server/middlewares/user-right.ts +++ b/server/middlewares/user-right.ts @@ -1,7 +1,7 @@ import * as express from 'express' import 'express-validator' import { UserRight } from '../../shared' -import { logger } from '../helpers' +import { logger } from '../helpers/logger' import { UserModel } from '../models/account/user' function ensureUserHasRight (userRight: UserRight) { diff --git a/server/middlewares/validators/account.ts b/server/middlewares/validators/account.ts index 6951dfc80..3573a9a50 100644 --- a/server/middlewares/validators/account.ts +++ b/server/middlewares/validators/account.ts @@ -1,7 +1,7 @@ import * as express from 'express' import { param } from 'express-validator/check' -import { logger } from '../../helpers' import { isAccountNameValid, isLocalAccountNameExist } from '../../helpers/custom-validators/accounts' +import { logger } from '../../helpers/logger' import { areValidationErrors } from './utils' const localAccountValidator = [ diff --git a/server/middlewares/validators/activitypub/activity.ts b/server/middlewares/validators/activitypub/activity.ts index e0225f30c..208e23f86 100644 --- a/server/middlewares/validators/activitypub/activity.ts +++ b/server/middlewares/validators/activitypub/activity.ts @@ -1,7 +1,7 @@ import * as express from 'express' import { body } from 'express-validator/check' -import { logger } from '../../../helpers' -import { isRootActivityValid } from '../../../helpers/custom-validators/activitypub' +import { isRootActivityValid } from '../../../helpers/custom-validators/activitypub/activity' +import { logger } from '../../../helpers/logger' import { areValidationErrors } from '../utils' const activityPubValidator = [ diff --git a/server/middlewares/validators/activitypub/signature.ts b/server/middlewares/validators/activitypub/signature.ts index d41bb6a8d..4efe9aafa 100644 --- a/server/middlewares/validators/activitypub/signature.ts +++ b/server/middlewares/validators/activitypub/signature.ts @@ -1,8 +1,11 @@ import * as express from 'express' import { body } from 'express-validator/check' -import { logger } from '../../../helpers' -import { isSignatureCreatorValid, isSignatureTypeValid, isSignatureValueValid } from '../../../helpers/custom-validators/activitypub' +import { + isSignatureCreatorValid, isSignatureTypeValid, + isSignatureValueValid +} from '../../../helpers/custom-validators/activitypub/signature' import { isDateValid } from '../../../helpers/custom-validators/misc' +import { logger } from '../../../helpers/logger' import { areValidationErrors } from '../utils' const signatureValidator = [ diff --git a/server/middlewares/validators/follows.ts b/server/middlewares/validators/follows.ts index 2240d30db..7dadf6a19 100644 --- a/server/middlewares/validators/follows.ts +++ b/server/middlewares/validators/follows.ts @@ -1,7 +1,9 @@ import * as express from 'express' import { body, param } from 'express-validator/check' -import { getServerActor, isTestInstance, logger } from '../../helpers' +import { isTestInstance } from '../../helpers/core-utils' import { isEachUniqueHostValid, isHostValid } from '../../helpers/custom-validators/servers' +import { logger } from '../../helpers/logger' +import { getServerActor } from '../../helpers/utils' import { CONFIG } from '../../initializers' import { ActorFollowModel } from '../../models/activitypub/actor-follow' import { areValidationErrors } from './utils' diff --git a/server/middlewares/validators/oembed.ts b/server/middlewares/validators/oembed.ts index fb7b726e5..cd9b27b16 100644 --- a/server/middlewares/validators/oembed.ts +++ b/server/middlewares/validators/oembed.ts @@ -1,9 +1,10 @@ import * as express from 'express' import { query } from 'express-validator/check' import { join } from 'path' -import { isTestInstance, logger } from '../../helpers' +import { isTestInstance } from '../../helpers/core-utils' import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' import { isVideoExist } from '../../helpers/custom-validators/videos' +import { logger } from '../../helpers/logger' import { CONFIG } from '../../initializers' import { areValidationErrors } from './utils' diff --git a/server/middlewares/validators/pagination.ts b/server/middlewares/validators/pagination.ts index 25debfa6e..e1ed8cd65 100644 --- a/server/middlewares/validators/pagination.ts +++ b/server/middlewares/validators/pagination.ts @@ -1,6 +1,6 @@ import * as express from 'express' import { query } from 'express-validator/check' -import { logger } from '../../helpers' +import { logger } from '../../helpers/logger' import { areValidationErrors } from './utils' const paginationValidator = [ diff --git a/server/middlewares/validators/sort.ts b/server/middlewares/validators/sort.ts index 56855bda0..e1d8d7d1b 100644 --- a/server/middlewares/validators/sort.ts +++ b/server/middlewares/validators/sort.ts @@ -1,6 +1,6 @@ -import { query } from 'express-validator/check' import * as express from 'express' -import { logger } from '../../helpers' +import { query } from 'express-validator/check' +import { logger } from '../../helpers/logger' import { SORTABLE_COLUMNS } from '../../initializers' import { areValidationErrors } from './utils' diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts index a6fdbe268..db40a5c88 100644 --- a/server/middlewares/validators/users.ts +++ b/server/middlewares/validators/users.ts @@ -1,17 +1,14 @@ import * as express from 'express' import 'express-validator' import { body, param } from 'express-validator/check' -import { isSignupAllowed, logger } from '../../helpers' import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' import { - isUserDisplayNSFWValid, - isUserAutoPlayVideoValid, - isUserPasswordValid, - isUserRoleValid, - isUserUsernameValid, + isUserAutoPlayVideoValid, isUserDisplayNSFWValid, isUserPasswordValid, isUserRoleValid, isUserUsernameValid, isUserVideoQuotaValid } from '../../helpers/custom-validators/users' import { isVideoExist } from '../../helpers/custom-validators/videos' +import { logger } from '../../helpers/logger' +import { isSignupAllowed } from '../../helpers/utils' import { UserModel } from '../../models/account/user' import { areValidationErrors } from './utils' diff --git a/server/middlewares/validators/utils.ts b/server/middlewares/validators/utils.ts index 61f76b457..55b140103 100644 --- a/server/middlewares/validators/utils.ts +++ b/server/middlewares/validators/utils.ts @@ -1,6 +1,6 @@ import * as express from 'express' import { validationResult } from 'express-validator/check' -import { logger } from '../../helpers' +import { logger } from '../../helpers/logger' function areValidationErrors (req: express.Request, res: express.Response) { const errors = validationResult(req) diff --git a/server/middlewares/validators/video-blacklist.ts b/server/middlewares/validators/video-blacklist.ts index 98099fe3f..3c1ef1b4e 100644 --- a/server/middlewares/validators/video-blacklist.ts +++ b/server/middlewares/validators/video-blacklist.ts @@ -1,8 +1,8 @@ import * as express from 'express' import { param } from 'express-validator/check' -import { logger } from '../../helpers' import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' import { isVideoExist } from '../../helpers/custom-validators/videos' +import { logger } from '../../helpers/logger' import { VideoModel } from '../../models/video/video' import { VideoBlacklistModel } from '../../models/video/video-blacklist' import { areValidationErrors } from './utils' diff --git a/server/middlewares/validators/video-channels.ts b/server/middlewares/validators/video-channels.ts index 0e6eff493..86bddde82 100644 --- a/server/middlewares/validators/video-channels.ts +++ b/server/middlewares/validators/video-channels.ts @@ -1,14 +1,13 @@ import * as express from 'express' import { body, param } from 'express-validator/check' import { UserRight } from '../../../shared' -import { logger } from '../../helpers' import { isAccountIdExist } from '../../helpers/custom-validators/accounts' import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' import { - isVideoChannelDescriptionValid, - isVideoChannelExist, + isVideoChannelDescriptionValid, isVideoChannelExist, isVideoChannelNameValid } from '../../helpers/custom-validators/video-channels' +import { logger } from '../../helpers/logger' import { UserModel } from '../../models/account/user' import { VideoChannelModel } from '../../models/video/video-channel' import { areValidationErrors } from './utils' diff --git a/server/middlewares/validators/video-comments.ts b/server/middlewares/validators/video-comments.ts index 1d19fac58..fdd092571 100644 --- a/server/middlewares/validators/video-comments.ts +++ b/server/middlewares/validators/video-comments.ts @@ -1,9 +1,9 @@ import * as express from 'express' import { body, param } from 'express-validator/check' -import { logger } from '../../helpers' import { isIdOrUUIDValid, isIdValid } from '../../helpers/custom-validators/misc' import { isValidVideoCommentText } from '../../helpers/custom-validators/video-comments' import { isVideoExist } from '../../helpers/custom-validators/videos' +import { logger } from '../../helpers/logger' import { VideoModel } from '../../models/video/video' import { VideoCommentModel } from '../../models/video/video-comment' import { areValidationErrors } from './utils' @@ -66,13 +66,29 @@ const addVideoCommentReplyValidator = [ } ] +const videoCommentGetValidator = [ + param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), + param('commentId').custom(isIdValid).not().isEmpty().withMessage('Should have a valid commentId'), + + async (req: express.Request, res: express.Response, next: express.NextFunction) => { + logger.debug('Checking videoCommentGetValidator parameters.', { parameters: req.params }) + + if (areValidationErrors(req, res)) return + if (!await isVideoExist(req.params.videoId, res)) return + if (!await isVideoCommentExist(req.params.commentId, res.locals.video, res)) return + + return next() + } +] + // --------------------------------------------------------------------------- export { listVideoCommentThreadsValidator, listVideoThreadCommentsValidator, addVideoCommentThreadValidator, - addVideoCommentReplyValidator + addVideoCommentReplyValidator, + videoCommentGetValidator } // --------------------------------------------------------------------------- @@ -109,7 +125,7 @@ async function isVideoCommentThreadExist (id: number, video: VideoModel, res: ex } async function isVideoCommentExist (id: number, video: VideoModel, res: express.Response) { - const videoComment = await VideoCommentModel.loadById(id) + const videoComment = await VideoCommentModel.loadByIdAndPopulateVideoAndAccountAndReply(id) if (!videoComment) { res.status(404) diff --git a/server/middlewares/validators/videos.ts b/server/middlewares/validators/videos.ts index b52d5f285..bffc50322 100644 --- a/server/middlewares/validators/videos.ts +++ b/server/middlewares/validators/videos.ts @@ -2,22 +2,13 @@ import * as express from 'express' import 'express-validator' import { body, param, query } from 'express-validator/check' import { UserRight, VideoPrivacy } from '../../../shared' -import { getDurationFromVideoFile, logger } from '../../helpers' import { isIdOrUUIDValid, isIdValid } from '../../helpers/custom-validators/misc' import { - isVideoAbuseReasonValid, - isVideoCategoryValid, - isVideoDescriptionValid, - isVideoExist, - isVideoFile, - isVideoLanguageValid, - isVideoLicenceValid, - isVideoNameValid, - isVideoNSFWValid, - isVideoPrivacyValid, - isVideoRatingTypeValid, - isVideoTagsValid + isVideoAbuseReasonValid, isVideoCategoryValid, isVideoDescriptionValid, isVideoExist, isVideoFile, isVideoLanguageValid, + isVideoLicenceValid, isVideoNameValid, isVideoNSFWValid, isVideoPrivacyValid, isVideoRatingTypeValid, isVideoTagsValid } from '../../helpers/custom-validators/videos' +import { getDurationFromVideoFile } from '../../helpers/ffmpeg-utils' +import { logger } from '../../helpers/logger' import { CONSTRAINTS_FIELDS } from '../../initializers' import { UserModel } from '../../models/account/user' import { VideoModel } from '../../models/video/video' diff --git a/server/middlewares/validators/webfinger.ts b/server/middlewares/validators/webfinger.ts index 894c72498..3dbec6e44 100644 --- a/server/middlewares/validators/webfinger.ts +++ b/server/middlewares/validators/webfinger.ts @@ -1,7 +1,8 @@ import * as express from 'express' import { query } from 'express-validator/check' -import { getHostWithPort, logger } from '../../helpers' import { isWebfingerResourceValid } from '../../helpers/custom-validators/webfinger' +import { logger } from '../../helpers/logger' +import { getHostWithPort } from '../../helpers/utils' import { ActorModel } from '../../models/activitypub/actor' import { areValidationErrors } from './utils' -- cgit v1.2.3