2017-06-10 16:15:25 -04:00
|
|
|
import * as express from 'express'
|
2019-07-25 10:23:44 -04:00
|
|
|
import { body, param, query, ValidationChain } from 'express-validator'
|
2020-09-25 10:19:35 -04:00
|
|
|
import { isAbleToUploadVideo } from '@server/lib/user'
|
2020-08-26 03:14:14 -04:00
|
|
|
import { getServerActor } from '@server/models/application/application'
|
2021-02-03 03:33:05 -05:00
|
|
|
import { ExpressPromiseHandler } from '@server/types/express'
|
2021-02-25 09:00:43 -05:00
|
|
|
import { MVideoWithRights } from '@server/types/models'
|
2020-08-26 03:14:14 -04:00
|
|
|
import { ServerErrorCode, UserRight, VideoChangeOwnershipStatus, VideoPrivacy } from '../../../../shared'
|
2021-02-03 03:33:05 -05:00
|
|
|
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
|
2020-08-26 03:14:14 -04:00
|
|
|
import { VideoChangeOwnershipAccept } from '../../../../shared/models/videos/video-change-ownership-accept.model'
|
2017-09-15 06:17:08 -04:00
|
|
|
import {
|
2021-01-19 07:43:33 -05:00
|
|
|
exists,
|
2018-06-14 12:06:56 -04:00
|
|
|
isBooleanValid,
|
|
|
|
isDateValid,
|
2020-12-08 15:16:10 -05:00
|
|
|
isFileFieldValid,
|
2018-06-14 12:06:56 -04:00
|
|
|
isIdOrUUIDValid,
|
|
|
|
isIdValid,
|
|
|
|
isUUIDValid,
|
2018-10-10 05:46:50 -04:00
|
|
|
toArray,
|
2019-07-25 10:23:44 -04:00
|
|
|
toBooleanOrNull,
|
2018-06-14 12:06:56 -04:00
|
|
|
toIntOrNull,
|
|
|
|
toValueOrNull
|
2018-10-05 05:15:06 -04:00
|
|
|
} from '../../../helpers/custom-validators/misc'
|
2020-08-26 03:14:14 -04:00
|
|
|
import { isNSFWQueryValid, isNumberArray, isStringArray } from '../../../helpers/custom-validators/search'
|
|
|
|
import { checkUserCanTerminateOwnershipChange, doesChangeVideoOwnershipExist } from '../../../helpers/custom-validators/video-ownership'
|
2018-06-14 12:06:56 -04:00
|
|
|
import {
|
|
|
|
isScheduleVideoUpdatePrivacyValid,
|
2018-02-13 12:17:05 -05:00
|
|
|
isVideoCategoryValid,
|
|
|
|
isVideoDescriptionValid,
|
2020-12-08 15:16:10 -05:00
|
|
|
isVideoFileMimeTypeValid,
|
|
|
|
isVideoFileSizeValid,
|
2018-10-10 05:46:50 -04:00
|
|
|
isVideoFilterValid,
|
2018-02-13 12:17:05 -05:00
|
|
|
isVideoImage,
|
|
|
|
isVideoLanguageValid,
|
|
|
|
isVideoLicenceValid,
|
|
|
|
isVideoNameValid,
|
2019-04-10 09:26:33 -04:00
|
|
|
isVideoOriginallyPublishedAtValid,
|
2018-02-13 12:17:05 -05:00
|
|
|
isVideoPrivacyValid,
|
2018-05-09 05:23:14 -04:00
|
|
|
isVideoSupportValid,
|
2018-09-19 05:16:23 -04:00
|
|
|
isVideoTagsValid
|
2018-10-05 05:15:06 -04:00
|
|
|
} from '../../../helpers/custom-validators/videos'
|
2020-08-26 03:14:14 -04:00
|
|
|
import { cleanUpReqFiles } from '../../../helpers/express-utils'
|
2020-11-20 11:16:55 -05:00
|
|
|
import { getDurationFromVideoFile } from '../../../helpers/ffprobe-utils'
|
2018-10-05 05:15:06 -04:00
|
|
|
import { logger } from '../../../helpers/logger'
|
2020-03-10 09:39:40 -04:00
|
|
|
import {
|
|
|
|
checkUserCanManageVideo,
|
|
|
|
doesVideoChannelOfAccountExist,
|
|
|
|
doesVideoExist,
|
|
|
|
doesVideoFileOfVideoExist
|
|
|
|
} from '../../../helpers/middlewares'
|
2019-08-20 07:52:49 -04:00
|
|
|
import { getVideoWithAttributes } from '../../../helpers/video'
|
2020-08-26 03:14:14 -04:00
|
|
|
import { CONFIG } from '../../../initializers/config'
|
|
|
|
import { CONSTRAINTS_FIELDS, OVERVIEWS } from '../../../initializers/constants'
|
|
|
|
import { isLocalVideoAccepted } from '../../../lib/moderation'
|
|
|
|
import { Hooks } from '../../../lib/plugins/hooks'
|
|
|
|
import { AccountModel } from '../../../models/account/account'
|
|
|
|
import { VideoModel } from '../../../models/video/video'
|
|
|
|
import { authenticatePromiseIfNeeded } from '../../oauth'
|
|
|
|
import { areValidationErrors } from '../utils'
|
2015-11-07 08:16:26 -05:00
|
|
|
|
2019-02-26 04:55:40 -05:00
|
|
|
const videosAddValidator = getCommonVideoEditAttributes().concat([
|
2018-06-22 09:42:55 -04:00
|
|
|
body('videofile')
|
2020-12-08 15:16:10 -05:00
|
|
|
.custom((value, { req }) => isFileFieldValid(req.files, 'videofile'))
|
|
|
|
.withMessage('Should have a file'),
|
|
|
|
body('name')
|
2021-02-25 04:01:33 -05:00
|
|
|
.trim()
|
2020-12-08 15:16:10 -05:00
|
|
|
.custom(isVideoNameValid)
|
|
|
|
.withMessage('Should have a valid name'),
|
2018-05-11 09:10:13 -04:00
|
|
|
body('channelId')
|
2019-07-25 10:23:44 -04:00
|
|
|
.customSanitizer(toIntOrNull)
|
2018-06-14 12:06:56 -04:00
|
|
|
.custom(isIdValid).withMessage('Should have correct video channel id'),
|
2017-09-15 06:17:08 -04:00
|
|
|
|
2017-11-27 11:30:46 -05:00
|
|
|
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
2017-09-15 06:17:08 -04:00
|
|
|
logger.debug('Checking videosAdd parameters', { parameters: req.body, files: req.files })
|
|
|
|
|
2018-07-31 09:09:34 -04:00
|
|
|
if (areValidationErrors(req, res)) return cleanUpReqFiles(req)
|
|
|
|
if (areErrorsInScheduleUpdate(req, res)) return cleanUpReqFiles(req)
|
2017-11-27 11:30:46 -05:00
|
|
|
|
2019-07-18 08:28:37 -04:00
|
|
|
const videoFile: Express.Multer.File & { duration?: number } = req.files['videofile'][0]
|
2017-11-27 11:30:46 -05:00
|
|
|
const user = res.locals.oauth.token.User
|
2017-09-15 06:17:08 -04:00
|
|
|
|
2019-03-19 04:26:50 -04:00
|
|
|
if (!await doesVideoChannelOfAccountExist(req.body.channelId, user, res)) return cleanUpReqFiles(req)
|
2017-11-27 11:30:46 -05:00
|
|
|
|
2020-12-08 15:16:10 -05:00
|
|
|
if (!isVideoFileMimeTypeValid(req.files)) {
|
|
|
|
res.status(HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415)
|
|
|
|
.json({
|
|
|
|
error: 'This file is not supported. Please, make sure it is of the following type: ' +
|
|
|
|
CONSTRAINTS_FIELDS.VIDEOS.EXTNAME.join(', ')
|
|
|
|
})
|
|
|
|
|
|
|
|
return cleanUpReqFiles(req)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isVideoFileSizeValid(videoFile.size.toString())) {
|
|
|
|
res.status(HttpStatusCode.PAYLOAD_TOO_LARGE_413)
|
|
|
|
.json({
|
|
|
|
error: 'This file is too large.'
|
|
|
|
})
|
|
|
|
|
|
|
|
return cleanUpReqFiles(req)
|
|
|
|
}
|
|
|
|
|
2020-09-25 10:19:35 -04:00
|
|
|
if (await isAbleToUploadVideo(user.id, videoFile.size) === false) {
|
2020-12-08 15:16:10 -05:00
|
|
|
res.status(HttpStatusCode.PAYLOAD_TOO_LARGE_413)
|
2017-11-27 11:30:46 -05:00
|
|
|
.json({ error: 'The user video quota is exceeded with this video.' })
|
|
|
|
|
2018-07-31 09:09:34 -04:00
|
|
|
return cleanUpReqFiles(req)
|
2017-11-27 11:30:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
let duration: number
|
|
|
|
|
|
|
|
try {
|
|
|
|
duration = await getDurationFromVideoFile(videoFile.path)
|
|
|
|
} catch (err) {
|
2018-03-26 09:54:13 -04:00
|
|
|
logger.error('Invalid input file in videosAddValidator.', { err })
|
2020-12-08 15:16:10 -05:00
|
|
|
res.status(HttpStatusCode.UNPROCESSABLE_ENTITY_422)
|
|
|
|
.json({ error: 'Video file unreadable.' })
|
2017-11-27 11:30:46 -05:00
|
|
|
|
2018-07-31 09:09:34 -04:00
|
|
|
return cleanUpReqFiles(req)
|
2017-11-27 11:30:46 -05:00
|
|
|
}
|
|
|
|
|
2019-07-18 08:28:37 -04:00
|
|
|
videoFile.duration = duration
|
|
|
|
|
|
|
|
if (!await isVideoAccepted(req, res, videoFile)) return cleanUpReqFiles(req)
|
2017-11-27 11:30:46 -05:00
|
|
|
|
|
|
|
return next()
|
2017-09-15 06:17:08 -04:00
|
|
|
}
|
2018-07-16 08:58:22 -04:00
|
|
|
])
|
2017-09-15 06:17:08 -04:00
|
|
|
|
2019-02-26 04:55:40 -05:00
|
|
|
const videosUpdateValidator = getCommonVideoEditAttributes().concat([
|
2017-10-24 13:41:09 -04:00
|
|
|
param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
|
2018-05-09 05:23:14 -04:00
|
|
|
body('name')
|
|
|
|
.optional()
|
2021-02-25 04:01:33 -05:00
|
|
|
.trim()
|
2018-05-09 05:23:14 -04:00
|
|
|
.custom(isVideoNameValid).withMessage('Should have a valid name'),
|
2018-05-11 09:10:13 -04:00
|
|
|
body('channelId')
|
|
|
|
.optional()
|
2019-07-25 10:23:44 -04:00
|
|
|
.customSanitizer(toIntOrNull)
|
2018-05-11 09:10:13 -04:00
|
|
|
.custom(isIdValid).withMessage('Should have correct video channel id'),
|
2017-09-15 06:17:08 -04:00
|
|
|
|
2017-11-27 11:30:46 -05:00
|
|
|
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
2017-09-15 06:17:08 -04:00
|
|
|
logger.debug('Checking videosUpdate parameters', { parameters: req.body })
|
|
|
|
|
2018-07-31 09:09:34 -04:00
|
|
|
if (areValidationErrors(req, res)) return cleanUpReqFiles(req)
|
|
|
|
if (areErrorsInScheduleUpdate(req, res)) return cleanUpReqFiles(req)
|
2019-03-19 04:26:50 -04:00
|
|
|
if (!await doesVideoExist(req.params.id, res)) return cleanUpReqFiles(req)
|
2017-11-27 11:30:46 -05:00
|
|
|
|
2018-02-22 03:03:45 -05:00
|
|
|
// Check if the user who did the request is able to update the video
|
2018-05-11 09:10:13 -04:00
|
|
|
const user = res.locals.oauth.token.User
|
2019-08-15 05:53:26 -04:00
|
|
|
if (!checkUserCanManageVideo(user, res.locals.videoAll, UserRight.UPDATE_ANY_VIDEO, res)) return cleanUpReqFiles(req)
|
2017-11-27 11:30:46 -05:00
|
|
|
|
2019-03-19 04:26:50 -04:00
|
|
|
if (req.body.channelId && !await doesVideoChannelOfAccountExist(req.body.channelId, user, res)) return cleanUpReqFiles(req)
|
2018-05-11 09:10:13 -04:00
|
|
|
|
2017-11-27 11:30:46 -05:00
|
|
|
return next()
|
2017-09-15 06:17:08 -04:00
|
|
|
}
|
2018-07-16 08:58:22 -04:00
|
|
|
])
|
2016-02-04 15:10:33 -05:00
|
|
|
|
2018-11-16 09:02:48 -05:00
|
|
|
async function checkVideoFollowConstraints (req: express.Request, res: express.Response, next: express.NextFunction) {
|
2019-08-20 07:52:49 -04:00
|
|
|
const video = getVideoWithAttributes(res)
|
2018-11-16 09:02:48 -05:00
|
|
|
|
|
|
|
// Anybody can watch local videos
|
|
|
|
if (video.isOwned() === true) return next()
|
|
|
|
|
|
|
|
// Logged user
|
|
|
|
if (res.locals.oauth) {
|
|
|
|
// Users can search or watch remote videos
|
|
|
|
if (CONFIG.SEARCH.REMOTE_URI.USERS === true) return next()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Anybody can search or watch remote videos
|
|
|
|
if (CONFIG.SEARCH.REMOTE_URI.ANONYMOUS === true) return next()
|
|
|
|
|
|
|
|
// Check our instance follows an actor that shared this video
|
|
|
|
const serverActor = await getServerActor()
|
|
|
|
if (await VideoModel.checkVideoHasInstanceFollow(video.id, serverActor.id) === true) return next()
|
|
|
|
|
2020-12-07 08:32:36 -05:00
|
|
|
return res.status(HttpStatusCode.FORBIDDEN_403)
|
2018-11-16 09:02:48 -05:00
|
|
|
.json({
|
2020-08-26 03:14:14 -04:00
|
|
|
errorCode: ServerErrorCode.DOES_NOT_RESPECT_FOLLOW_CONSTRAINTS,
|
|
|
|
error: 'Cannot get this video regarding follow constraints.',
|
|
|
|
originUrl: video.url
|
2018-11-16 09:02:48 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-02-04 09:00:47 -05:00
|
|
|
const videosCustomGetValidator = (
|
|
|
|
fetchType: 'all' | 'only-video' | 'only-video-with-rights' | 'only-immutable-attributes',
|
|
|
|
authenticateInQuery = false
|
|
|
|
) => {
|
2018-09-19 04:16:44 -04:00
|
|
|
return [
|
|
|
|
param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
|
2016-12-29 13:07:05 -05:00
|
|
|
|
2018-09-19 04:16:44 -04:00
|
|
|
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
|
|
|
logger.debug('Checking videosGet parameters', { parameters: req.params })
|
2017-10-31 10:20:35 -04:00
|
|
|
|
2018-09-19 04:16:44 -04:00
|
|
|
if (areValidationErrors(req, res)) return
|
2019-03-19 04:26:50 -04:00
|
|
|
if (!await doesVideoExist(req.params.id, res, fetchType)) return
|
2018-08-14 03:08:47 -04:00
|
|
|
|
2020-02-04 09:45:41 -05:00
|
|
|
// Controllers does not need to check video rights
|
|
|
|
if (fetchType === 'only-immutable-attributes') return next()
|
|
|
|
|
2021-02-25 05:17:53 -05:00
|
|
|
const video = getVideoWithAttributes(res) as MVideoWithRights
|
2018-08-14 03:08:47 -04:00
|
|
|
|
2018-09-19 04:16:44 -04:00
|
|
|
// Video private or blacklisted
|
2021-02-25 05:17:53 -05:00
|
|
|
if (video.requiresAuth()) {
|
2019-12-03 04:41:23 -05:00
|
|
|
await authenticatePromiseIfNeeded(req, res, authenticateInQuery)
|
2018-11-16 09:02:48 -05:00
|
|
|
|
2019-03-19 05:35:15 -04:00
|
|
|
const user = res.locals.oauth ? res.locals.oauth.token.User : null
|
2018-08-14 03:08:47 -04:00
|
|
|
|
2018-11-16 09:02:48 -05:00
|
|
|
// Only the owner or a user that have blacklist rights can see the video
|
2021-02-25 05:17:53 -05:00
|
|
|
if (!user || !user.canGetVideo(video)) {
|
2020-12-07 08:32:36 -05:00
|
|
|
return res.status(HttpStatusCode.FORBIDDEN_403)
|
2019-12-12 09:47:47 -05:00
|
|
|
.json({ error: 'Cannot get this private/internal or blacklisted video.' })
|
2018-11-16 09:02:48 -05:00
|
|
|
}
|
2018-08-14 03:08:47 -04:00
|
|
|
|
2018-11-16 09:02:48 -05:00
|
|
|
return next()
|
2018-09-19 04:16:44 -04:00
|
|
|
}
|
2017-10-31 10:20:35 -04:00
|
|
|
|
2018-09-19 04:16:44 -04:00
|
|
|
// Video is public, anyone can access it
|
|
|
|
if (video.privacy === VideoPrivacy.PUBLIC) return next()
|
2017-10-31 10:20:35 -04:00
|
|
|
|
2018-09-19 04:16:44 -04:00
|
|
|
// Video is unlisted, check we used the uuid to fetch it
|
|
|
|
if (video.privacy === VideoPrivacy.UNLISTED) {
|
|
|
|
if (isUUIDValid(req.params.id)) return next()
|
2018-01-31 08:40:42 -05:00
|
|
|
|
2018-09-19 04:16:44 -04:00
|
|
|
// Don't leak this unlisted video
|
2020-12-07 08:32:36 -05:00
|
|
|
return res.status(HttpStatusCode.NOT_FOUND_404).end()
|
2018-09-19 04:16:44 -04:00
|
|
|
}
|
2018-01-31 08:40:42 -05:00
|
|
|
}
|
2018-09-19 04:16:44 -04:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
const videosGetValidator = videosCustomGetValidator('all')
|
2019-12-03 04:41:23 -05:00
|
|
|
const videosDownloadValidator = videosCustomGetValidator('all', true)
|
2015-11-07 08:16:26 -05:00
|
|
|
|
2020-03-10 09:39:40 -04:00
|
|
|
const videoFileMetadataGetValidator = getCommonVideoEditAttributes().concat([
|
|
|
|
param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
|
|
|
|
param('videoFileId').custom(isIdValid).not().isEmpty().withMessage('Should have a valid videoFileId'),
|
|
|
|
|
|
|
|
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
|
|
|
logger.debug('Checking videoFileMetadataGet parameters', { parameters: req.params })
|
|
|
|
|
|
|
|
if (areValidationErrors(req, res)) return
|
|
|
|
if (!await doesVideoFileOfVideoExist(+req.params.videoFileId, req.params.id, res)) return
|
|
|
|
|
|
|
|
return next()
|
|
|
|
}
|
|
|
|
])
|
|
|
|
|
2017-09-15 06:17:08 -04:00
|
|
|
const videosRemoveValidator = [
|
2017-10-24 13:41:09 -04:00
|
|
|
param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
|
2015-11-07 08:16:26 -05:00
|
|
|
|
2017-11-27 11:30:46 -05:00
|
|
|
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
2017-09-15 06:17:08 -04:00
|
|
|
logger.debug('Checking videosRemove parameters', { parameters: req.params })
|
2015-11-07 08:16:26 -05:00
|
|
|
|
2017-11-27 11:30:46 -05:00
|
|
|
if (areValidationErrors(req, res)) return
|
2019-03-19 04:26:50 -04:00
|
|
|
if (!await doesVideoExist(req.params.id, res)) return
|
2017-11-27 11:30:46 -05:00
|
|
|
|
|
|
|
// Check if the user who did the request is able to delete the video
|
2019-08-15 05:53:26 -04:00
|
|
|
if (!checkUserCanManageVideo(res.locals.oauth.token.User, res.locals.videoAll, UserRight.REMOVE_ANY_VIDEO, res)) return
|
2017-11-27 11:30:46 -05:00
|
|
|
|
|
|
|
return next()
|
2017-09-15 06:17:08 -04:00
|
|
|
}
|
|
|
|
]
|
2015-11-07 08:16:26 -05:00
|
|
|
|
Users can change ownership of their video [#510] (#888)
* [#510] Create a new route to get the list of user names
To be able to transfer ownership to a user,
we need to be able to select him from the list of users.
Because the list could be too big, we add a autocomplete feature.
This commit does the following:
* Add a API endpoint to get a list of user names by searching its name
* [#510] The user can choose the next owner of the video
To be able to transfer ownership to a user,
we need the owner to be able to select the user.
The server can autocomplete the name of the user to give the ownership.
We add a dialog for the user to actually select it.
This commit does the following:
* Create a modal for the owner to select the next one
* Opens this modal with a button into the menu *more*
* Make the dependency injection
* [#510] When the user choose the next owner, create a request in database
For the change of ownership to happen, we need to store the temporary requests.
When the user make the request, save it to database.
This commit does the following:
* Create the model to persist change ownership requests
* Add an API to manage ownership operations
* Add a route to persist an ownership request
* [#510] A user can fetch its ownership requests sent to him
To be able to accept or refuse a change of ownership,
the user must be able to fetch them.
This commit does the following:
* Add an API to list ownership for a user
* Add the query to database model
* [#510] A user can validate an ownership requests sent to him - server
The user can accept or refuse any ownership request that was sent to him.
This commit focus only on the server part.
This commit does the following:
* Add an API for the user to accept or refuse a video ownership
* Add validators to ensure security access
* Add a query to load a specific video change ownership request
* [#510] A user can validate an ownership requests sent to him - web
The user can accept or refuse any ownership request that was sent to him.
This commit focus only on the web part.
This commit does the following:
* Add a page to list user ownership changes
* Add actions to accept or refuse them
* When accepting, show a modal requiring the channel to send the video
* Correct lint - to squash
* [#510] PR reviews - to squash
This commit does the following:
* Search parameter for user autocompletion is required from middleware directly
* [#510] PR reviews - to squash with creation in database commit
This commit does the following:
* Add the status attribute in model
* Set this attribute on instance creation
* Use AccountModel method `loadLocalByName`
* [#510] PR reviews - to squash with fetch ownership
This commit does the following:
* Add the scope `FULL` for database queries with includes
* Add classic pagination middlewares
* [#510] PR reviews - to squash with ownership validation - server
This commit does the following:
* Add a middleware to validate whether a user can validate an ownership
* Change the ownership status instead of deleting the row
* [#510] PR reviews - to squash with ownership validation - client
This commit does the following:
* Correct indentation of html files with two-spaces indentation
* Use event emitter instead of function for accept event
* Update the sort of ownership change table for a decreasing order by creation date
* Add the status in ownership change table
* Use classic method syntax
* code style - to squash
* Add new user right - to squash
* Move the change to my-account instead of video-watch - to squash
As requested in pull-request, move the action to change ownership into my videos page.
The rest of the logic was not really changed.
This commit does the following:
- Move the modal into my video page
- Create the generic component `button` to keep some styles and logic
* [#510] Add tests for the new feature
To avoid regression, we add tests for all api of ownership change.
This commit does the following:
- Create an end-to-end test for ownership change
- Divide it to one test per request
* [#510] Do not send twice the same request to avoid spam
We can send several time the same request to change ownership.
However, it will spam the user.
To avoid this, we do not save a request already existing in database.
This commit does the following:
- Check whether the request exist in database
- Add tests to verify this new condition
* [#510] Change icons
Change icons so they remains logic with the rest of the application.
This commit does the following:
- Add svg for missing icons
- Add icons in `my-button` component
- Use these new icons
* [#510] Add control about the user quota
The user should be able to accept a new video only if his quota allows it.
This commit does the following:
- Update the middleware to control the quota
- Add tests verifying the control
* Correct merge
- Use new modal system
- Move button to new directory `buttons`
* PR reviews - to squash
2018-09-04 02:57:13 -04:00
|
|
|
const videosChangeOwnershipValidator = [
|
|
|
|
param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
|
|
|
|
|
|
|
|
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
|
|
|
logger.debug('Checking changeOwnership parameters', { parameters: req.params })
|
|
|
|
|
|
|
|
if (areValidationErrors(req, res)) return
|
2019-03-19 04:26:50 -04:00
|
|
|
if (!await doesVideoExist(req.params.videoId, res)) return
|
Users can change ownership of their video [#510] (#888)
* [#510] Create a new route to get the list of user names
To be able to transfer ownership to a user,
we need to be able to select him from the list of users.
Because the list could be too big, we add a autocomplete feature.
This commit does the following:
* Add a API endpoint to get a list of user names by searching its name
* [#510] The user can choose the next owner of the video
To be able to transfer ownership to a user,
we need the owner to be able to select the user.
The server can autocomplete the name of the user to give the ownership.
We add a dialog for the user to actually select it.
This commit does the following:
* Create a modal for the owner to select the next one
* Opens this modal with a button into the menu *more*
* Make the dependency injection
* [#510] When the user choose the next owner, create a request in database
For the change of ownership to happen, we need to store the temporary requests.
When the user make the request, save it to database.
This commit does the following:
* Create the model to persist change ownership requests
* Add an API to manage ownership operations
* Add a route to persist an ownership request
* [#510] A user can fetch its ownership requests sent to him
To be able to accept or refuse a change of ownership,
the user must be able to fetch them.
This commit does the following:
* Add an API to list ownership for a user
* Add the query to database model
* [#510] A user can validate an ownership requests sent to him - server
The user can accept or refuse any ownership request that was sent to him.
This commit focus only on the server part.
This commit does the following:
* Add an API for the user to accept or refuse a video ownership
* Add validators to ensure security access
* Add a query to load a specific video change ownership request
* [#510] A user can validate an ownership requests sent to him - web
The user can accept or refuse any ownership request that was sent to him.
This commit focus only on the web part.
This commit does the following:
* Add a page to list user ownership changes
* Add actions to accept or refuse them
* When accepting, show a modal requiring the channel to send the video
* Correct lint - to squash
* [#510] PR reviews - to squash
This commit does the following:
* Search parameter for user autocompletion is required from middleware directly
* [#510] PR reviews - to squash with creation in database commit
This commit does the following:
* Add the status attribute in model
* Set this attribute on instance creation
* Use AccountModel method `loadLocalByName`
* [#510] PR reviews - to squash with fetch ownership
This commit does the following:
* Add the scope `FULL` for database queries with includes
* Add classic pagination middlewares
* [#510] PR reviews - to squash with ownership validation - server
This commit does the following:
* Add a middleware to validate whether a user can validate an ownership
* Change the ownership status instead of deleting the row
* [#510] PR reviews - to squash with ownership validation - client
This commit does the following:
* Correct indentation of html files with two-spaces indentation
* Use event emitter instead of function for accept event
* Update the sort of ownership change table for a decreasing order by creation date
* Add the status in ownership change table
* Use classic method syntax
* code style - to squash
* Add new user right - to squash
* Move the change to my-account instead of video-watch - to squash
As requested in pull-request, move the action to change ownership into my videos page.
The rest of the logic was not really changed.
This commit does the following:
- Move the modal into my video page
- Create the generic component `button` to keep some styles and logic
* [#510] Add tests for the new feature
To avoid regression, we add tests for all api of ownership change.
This commit does the following:
- Create an end-to-end test for ownership change
- Divide it to one test per request
* [#510] Do not send twice the same request to avoid spam
We can send several time the same request to change ownership.
However, it will spam the user.
To avoid this, we do not save a request already existing in database.
This commit does the following:
- Check whether the request exist in database
- Add tests to verify this new condition
* [#510] Change icons
Change icons so they remains logic with the rest of the application.
This commit does the following:
- Add svg for missing icons
- Add icons in `my-button` component
- Use these new icons
* [#510] Add control about the user quota
The user should be able to accept a new video only if his quota allows it.
This commit does the following:
- Update the middleware to control the quota
- Add tests verifying the control
* Correct merge
- Use new modal system
- Move button to new directory `buttons`
* PR reviews - to squash
2018-09-04 02:57:13 -04:00
|
|
|
|
|
|
|
// Check if the user who did the request is able to change the ownership of the video
|
2019-08-15 05:53:26 -04:00
|
|
|
if (!checkUserCanManageVideo(res.locals.oauth.token.User, res.locals.videoAll, UserRight.CHANGE_VIDEO_OWNERSHIP, res)) return
|
Users can change ownership of their video [#510] (#888)
* [#510] Create a new route to get the list of user names
To be able to transfer ownership to a user,
we need to be able to select him from the list of users.
Because the list could be too big, we add a autocomplete feature.
This commit does the following:
* Add a API endpoint to get a list of user names by searching its name
* [#510] The user can choose the next owner of the video
To be able to transfer ownership to a user,
we need the owner to be able to select the user.
The server can autocomplete the name of the user to give the ownership.
We add a dialog for the user to actually select it.
This commit does the following:
* Create a modal for the owner to select the next one
* Opens this modal with a button into the menu *more*
* Make the dependency injection
* [#510] When the user choose the next owner, create a request in database
For the change of ownership to happen, we need to store the temporary requests.
When the user make the request, save it to database.
This commit does the following:
* Create the model to persist change ownership requests
* Add an API to manage ownership operations
* Add a route to persist an ownership request
* [#510] A user can fetch its ownership requests sent to him
To be able to accept or refuse a change of ownership,
the user must be able to fetch them.
This commit does the following:
* Add an API to list ownership for a user
* Add the query to database model
* [#510] A user can validate an ownership requests sent to him - server
The user can accept or refuse any ownership request that was sent to him.
This commit focus only on the server part.
This commit does the following:
* Add an API for the user to accept or refuse a video ownership
* Add validators to ensure security access
* Add a query to load a specific video change ownership request
* [#510] A user can validate an ownership requests sent to him - web
The user can accept or refuse any ownership request that was sent to him.
This commit focus only on the web part.
This commit does the following:
* Add a page to list user ownership changes
* Add actions to accept or refuse them
* When accepting, show a modal requiring the channel to send the video
* Correct lint - to squash
* [#510] PR reviews - to squash
This commit does the following:
* Search parameter for user autocompletion is required from middleware directly
* [#510] PR reviews - to squash with creation in database commit
This commit does the following:
* Add the status attribute in model
* Set this attribute on instance creation
* Use AccountModel method `loadLocalByName`
* [#510] PR reviews - to squash with fetch ownership
This commit does the following:
* Add the scope `FULL` for database queries with includes
* Add classic pagination middlewares
* [#510] PR reviews - to squash with ownership validation - server
This commit does the following:
* Add a middleware to validate whether a user can validate an ownership
* Change the ownership status instead of deleting the row
* [#510] PR reviews - to squash with ownership validation - client
This commit does the following:
* Correct indentation of html files with two-spaces indentation
* Use event emitter instead of function for accept event
* Update the sort of ownership change table for a decreasing order by creation date
* Add the status in ownership change table
* Use classic method syntax
* code style - to squash
* Add new user right - to squash
* Move the change to my-account instead of video-watch - to squash
As requested in pull-request, move the action to change ownership into my videos page.
The rest of the logic was not really changed.
This commit does the following:
- Move the modal into my video page
- Create the generic component `button` to keep some styles and logic
* [#510] Add tests for the new feature
To avoid regression, we add tests for all api of ownership change.
This commit does the following:
- Create an end-to-end test for ownership change
- Divide it to one test per request
* [#510] Do not send twice the same request to avoid spam
We can send several time the same request to change ownership.
However, it will spam the user.
To avoid this, we do not save a request already existing in database.
This commit does the following:
- Check whether the request exist in database
- Add tests to verify this new condition
* [#510] Change icons
Change icons so they remains logic with the rest of the application.
This commit does the following:
- Add svg for missing icons
- Add icons in `my-button` component
- Use these new icons
* [#510] Add control about the user quota
The user should be able to accept a new video only if his quota allows it.
This commit does the following:
- Update the middleware to control the quota
- Add tests verifying the control
* Correct merge
- Use new modal system
- Move button to new directory `buttons`
* PR reviews - to squash
2018-09-04 02:57:13 -04:00
|
|
|
|
|
|
|
const nextOwner = await AccountModel.loadLocalByName(req.body.username)
|
|
|
|
if (!nextOwner) {
|
2020-12-07 08:32:36 -05:00
|
|
|
res.status(HttpStatusCode.BAD_REQUEST_400)
|
2018-10-10 02:57:00 -04:00
|
|
|
.json({ error: 'Changing video ownership to a remote account is not supported yet' })
|
|
|
|
|
Users can change ownership of their video [#510] (#888)
* [#510] Create a new route to get the list of user names
To be able to transfer ownership to a user,
we need to be able to select him from the list of users.
Because the list could be too big, we add a autocomplete feature.
This commit does the following:
* Add a API endpoint to get a list of user names by searching its name
* [#510] The user can choose the next owner of the video
To be able to transfer ownership to a user,
we need the owner to be able to select the user.
The server can autocomplete the name of the user to give the ownership.
We add a dialog for the user to actually select it.
This commit does the following:
* Create a modal for the owner to select the next one
* Opens this modal with a button into the menu *more*
* Make the dependency injection
* [#510] When the user choose the next owner, create a request in database
For the change of ownership to happen, we need to store the temporary requests.
When the user make the request, save it to database.
This commit does the following:
* Create the model to persist change ownership requests
* Add an API to manage ownership operations
* Add a route to persist an ownership request
* [#510] A user can fetch its ownership requests sent to him
To be able to accept or refuse a change of ownership,
the user must be able to fetch them.
This commit does the following:
* Add an API to list ownership for a user
* Add the query to database model
* [#510] A user can validate an ownership requests sent to him - server
The user can accept or refuse any ownership request that was sent to him.
This commit focus only on the server part.
This commit does the following:
* Add an API for the user to accept or refuse a video ownership
* Add validators to ensure security access
* Add a query to load a specific video change ownership request
* [#510] A user can validate an ownership requests sent to him - web
The user can accept or refuse any ownership request that was sent to him.
This commit focus only on the web part.
This commit does the following:
* Add a page to list user ownership changes
* Add actions to accept or refuse them
* When accepting, show a modal requiring the channel to send the video
* Correct lint - to squash
* [#510] PR reviews - to squash
This commit does the following:
* Search parameter for user autocompletion is required from middleware directly
* [#510] PR reviews - to squash with creation in database commit
This commit does the following:
* Add the status attribute in model
* Set this attribute on instance creation
* Use AccountModel method `loadLocalByName`
* [#510] PR reviews - to squash with fetch ownership
This commit does the following:
* Add the scope `FULL` for database queries with includes
* Add classic pagination middlewares
* [#510] PR reviews - to squash with ownership validation - server
This commit does the following:
* Add a middleware to validate whether a user can validate an ownership
* Change the ownership status instead of deleting the row
* [#510] PR reviews - to squash with ownership validation - client
This commit does the following:
* Correct indentation of html files with two-spaces indentation
* Use event emitter instead of function for accept event
* Update the sort of ownership change table for a decreasing order by creation date
* Add the status in ownership change table
* Use classic method syntax
* code style - to squash
* Add new user right - to squash
* Move the change to my-account instead of video-watch - to squash
As requested in pull-request, move the action to change ownership into my videos page.
The rest of the logic was not really changed.
This commit does the following:
- Move the modal into my video page
- Create the generic component `button` to keep some styles and logic
* [#510] Add tests for the new feature
To avoid regression, we add tests for all api of ownership change.
This commit does the following:
- Create an end-to-end test for ownership change
- Divide it to one test per request
* [#510] Do not send twice the same request to avoid spam
We can send several time the same request to change ownership.
However, it will spam the user.
To avoid this, we do not save a request already existing in database.
This commit does the following:
- Check whether the request exist in database
- Add tests to verify this new condition
* [#510] Change icons
Change icons so they remains logic with the rest of the application.
This commit does the following:
- Add svg for missing icons
- Add icons in `my-button` component
- Use these new icons
* [#510] Add control about the user quota
The user should be able to accept a new video only if his quota allows it.
This commit does the following:
- Update the middleware to control the quota
- Add tests verifying the control
* Correct merge
- Use new modal system
- Move button to new directory `buttons`
* PR reviews - to squash
2018-09-04 02:57:13 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
res.locals.nextOwner = nextOwner
|
|
|
|
|
|
|
|
return next()
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
const videosTerminateChangeOwnershipValidator = [
|
|
|
|
param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
|
|
|
|
|
|
|
|
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
|
|
|
logger.debug('Checking changeOwnership parameters', { parameters: req.params })
|
|
|
|
|
|
|
|
if (areValidationErrors(req, res)) return
|
|
|
|
if (!await doesChangeVideoOwnershipExist(req.params.id, res)) return
|
|
|
|
|
|
|
|
// Check if the user who did the request is able to change the ownership of the video
|
|
|
|
if (!checkUserCanTerminateOwnershipChange(res.locals.oauth.token.User, res.locals.videoChangeOwnership, res)) return
|
|
|
|
|
2019-03-19 05:35:15 -04:00
|
|
|
const videoChangeOwnership = res.locals.videoChangeOwnership
|
Users can change ownership of their video [#510] (#888)
* [#510] Create a new route to get the list of user names
To be able to transfer ownership to a user,
we need to be able to select him from the list of users.
Because the list could be too big, we add a autocomplete feature.
This commit does the following:
* Add a API endpoint to get a list of user names by searching its name
* [#510] The user can choose the next owner of the video
To be able to transfer ownership to a user,
we need the owner to be able to select the user.
The server can autocomplete the name of the user to give the ownership.
We add a dialog for the user to actually select it.
This commit does the following:
* Create a modal for the owner to select the next one
* Opens this modal with a button into the menu *more*
* Make the dependency injection
* [#510] When the user choose the next owner, create a request in database
For the change of ownership to happen, we need to store the temporary requests.
When the user make the request, save it to database.
This commit does the following:
* Create the model to persist change ownership requests
* Add an API to manage ownership operations
* Add a route to persist an ownership request
* [#510] A user can fetch its ownership requests sent to him
To be able to accept or refuse a change of ownership,
the user must be able to fetch them.
This commit does the following:
* Add an API to list ownership for a user
* Add the query to database model
* [#510] A user can validate an ownership requests sent to him - server
The user can accept or refuse any ownership request that was sent to him.
This commit focus only on the server part.
This commit does the following:
* Add an API for the user to accept or refuse a video ownership
* Add validators to ensure security access
* Add a query to load a specific video change ownership request
* [#510] A user can validate an ownership requests sent to him - web
The user can accept or refuse any ownership request that was sent to him.
This commit focus only on the web part.
This commit does the following:
* Add a page to list user ownership changes
* Add actions to accept or refuse them
* When accepting, show a modal requiring the channel to send the video
* Correct lint - to squash
* [#510] PR reviews - to squash
This commit does the following:
* Search parameter for user autocompletion is required from middleware directly
* [#510] PR reviews - to squash with creation in database commit
This commit does the following:
* Add the status attribute in model
* Set this attribute on instance creation
* Use AccountModel method `loadLocalByName`
* [#510] PR reviews - to squash with fetch ownership
This commit does the following:
* Add the scope `FULL` for database queries with includes
* Add classic pagination middlewares
* [#510] PR reviews - to squash with ownership validation - server
This commit does the following:
* Add a middleware to validate whether a user can validate an ownership
* Change the ownership status instead of deleting the row
* [#510] PR reviews - to squash with ownership validation - client
This commit does the following:
* Correct indentation of html files with two-spaces indentation
* Use event emitter instead of function for accept event
* Update the sort of ownership change table for a decreasing order by creation date
* Add the status in ownership change table
* Use classic method syntax
* code style - to squash
* Add new user right - to squash
* Move the change to my-account instead of video-watch - to squash
As requested in pull-request, move the action to change ownership into my videos page.
The rest of the logic was not really changed.
This commit does the following:
- Move the modal into my video page
- Create the generic component `button` to keep some styles and logic
* [#510] Add tests for the new feature
To avoid regression, we add tests for all api of ownership change.
This commit does the following:
- Create an end-to-end test for ownership change
- Divide it to one test per request
* [#510] Do not send twice the same request to avoid spam
We can send several time the same request to change ownership.
However, it will spam the user.
To avoid this, we do not save a request already existing in database.
This commit does the following:
- Check whether the request exist in database
- Add tests to verify this new condition
* [#510] Change icons
Change icons so they remains logic with the rest of the application.
This commit does the following:
- Add svg for missing icons
- Add icons in `my-button` component
- Use these new icons
* [#510] Add control about the user quota
The user should be able to accept a new video only if his quota allows it.
This commit does the following:
- Update the middleware to control the quota
- Add tests verifying the control
* Correct merge
- Use new modal system
- Move button to new directory `buttons`
* PR reviews - to squash
2018-09-04 02:57:13 -04:00
|
|
|
|
2020-01-31 10:56:52 -05:00
|
|
|
if (videoChangeOwnership.status !== VideoChangeOwnershipStatus.WAITING) {
|
2020-12-07 08:32:36 -05:00
|
|
|
res.status(HttpStatusCode.FORBIDDEN_403)
|
2020-01-31 10:56:52 -05:00
|
|
|
.json({ error: 'Ownership already accepted or refused' })
|
Users can change ownership of their video [#510] (#888)
* [#510] Create a new route to get the list of user names
To be able to transfer ownership to a user,
we need to be able to select him from the list of users.
Because the list could be too big, we add a autocomplete feature.
This commit does the following:
* Add a API endpoint to get a list of user names by searching its name
* [#510] The user can choose the next owner of the video
To be able to transfer ownership to a user,
we need the owner to be able to select the user.
The server can autocomplete the name of the user to give the ownership.
We add a dialog for the user to actually select it.
This commit does the following:
* Create a modal for the owner to select the next one
* Opens this modal with a button into the menu *more*
* Make the dependency injection
* [#510] When the user choose the next owner, create a request in database
For the change of ownership to happen, we need to store the temporary requests.
When the user make the request, save it to database.
This commit does the following:
* Create the model to persist change ownership requests
* Add an API to manage ownership operations
* Add a route to persist an ownership request
* [#510] A user can fetch its ownership requests sent to him
To be able to accept or refuse a change of ownership,
the user must be able to fetch them.
This commit does the following:
* Add an API to list ownership for a user
* Add the query to database model
* [#510] A user can validate an ownership requests sent to him - server
The user can accept or refuse any ownership request that was sent to him.
This commit focus only on the server part.
This commit does the following:
* Add an API for the user to accept or refuse a video ownership
* Add validators to ensure security access
* Add a query to load a specific video change ownership request
* [#510] A user can validate an ownership requests sent to him - web
The user can accept or refuse any ownership request that was sent to him.
This commit focus only on the web part.
This commit does the following:
* Add a page to list user ownership changes
* Add actions to accept or refuse them
* When accepting, show a modal requiring the channel to send the video
* Correct lint - to squash
* [#510] PR reviews - to squash
This commit does the following:
* Search parameter for user autocompletion is required from middleware directly
* [#510] PR reviews - to squash with creation in database commit
This commit does the following:
* Add the status attribute in model
* Set this attribute on instance creation
* Use AccountModel method `loadLocalByName`
* [#510] PR reviews - to squash with fetch ownership
This commit does the following:
* Add the scope `FULL` for database queries with includes
* Add classic pagination middlewares
* [#510] PR reviews - to squash with ownership validation - server
This commit does the following:
* Add a middleware to validate whether a user can validate an ownership
* Change the ownership status instead of deleting the row
* [#510] PR reviews - to squash with ownership validation - client
This commit does the following:
* Correct indentation of html files with two-spaces indentation
* Use event emitter instead of function for accept event
* Update the sort of ownership change table for a decreasing order by creation date
* Add the status in ownership change table
* Use classic method syntax
* code style - to squash
* Add new user right - to squash
* Move the change to my-account instead of video-watch - to squash
As requested in pull-request, move the action to change ownership into my videos page.
The rest of the logic was not really changed.
This commit does the following:
- Move the modal into my video page
- Create the generic component `button` to keep some styles and logic
* [#510] Add tests for the new feature
To avoid regression, we add tests for all api of ownership change.
This commit does the following:
- Create an end-to-end test for ownership change
- Divide it to one test per request
* [#510] Do not send twice the same request to avoid spam
We can send several time the same request to change ownership.
However, it will spam the user.
To avoid this, we do not save a request already existing in database.
This commit does the following:
- Check whether the request exist in database
- Add tests to verify this new condition
* [#510] Change icons
Change icons so they remains logic with the rest of the application.
This commit does the following:
- Add svg for missing icons
- Add icons in `my-button` component
- Use these new icons
* [#510] Add control about the user quota
The user should be able to accept a new video only if his quota allows it.
This commit does the following:
- Update the middleware to control the quota
- Add tests verifying the control
* Correct merge
- Use new modal system
- Move button to new directory `buttons`
* PR reviews - to squash
2018-09-04 02:57:13 -04:00
|
|
|
return
|
|
|
|
}
|
2020-01-31 10:56:52 -05:00
|
|
|
|
|
|
|
return next()
|
Users can change ownership of their video [#510] (#888)
* [#510] Create a new route to get the list of user names
To be able to transfer ownership to a user,
we need to be able to select him from the list of users.
Because the list could be too big, we add a autocomplete feature.
This commit does the following:
* Add a API endpoint to get a list of user names by searching its name
* [#510] The user can choose the next owner of the video
To be able to transfer ownership to a user,
we need the owner to be able to select the user.
The server can autocomplete the name of the user to give the ownership.
We add a dialog for the user to actually select it.
This commit does the following:
* Create a modal for the owner to select the next one
* Opens this modal with a button into the menu *more*
* Make the dependency injection
* [#510] When the user choose the next owner, create a request in database
For the change of ownership to happen, we need to store the temporary requests.
When the user make the request, save it to database.
This commit does the following:
* Create the model to persist change ownership requests
* Add an API to manage ownership operations
* Add a route to persist an ownership request
* [#510] A user can fetch its ownership requests sent to him
To be able to accept or refuse a change of ownership,
the user must be able to fetch them.
This commit does the following:
* Add an API to list ownership for a user
* Add the query to database model
* [#510] A user can validate an ownership requests sent to him - server
The user can accept or refuse any ownership request that was sent to him.
This commit focus only on the server part.
This commit does the following:
* Add an API for the user to accept or refuse a video ownership
* Add validators to ensure security access
* Add a query to load a specific video change ownership request
* [#510] A user can validate an ownership requests sent to him - web
The user can accept or refuse any ownership request that was sent to him.
This commit focus only on the web part.
This commit does the following:
* Add a page to list user ownership changes
* Add actions to accept or refuse them
* When accepting, show a modal requiring the channel to send the video
* Correct lint - to squash
* [#510] PR reviews - to squash
This commit does the following:
* Search parameter for user autocompletion is required from middleware directly
* [#510] PR reviews - to squash with creation in database commit
This commit does the following:
* Add the status attribute in model
* Set this attribute on instance creation
* Use AccountModel method `loadLocalByName`
* [#510] PR reviews - to squash with fetch ownership
This commit does the following:
* Add the scope `FULL` for database queries with includes
* Add classic pagination middlewares
* [#510] PR reviews - to squash with ownership validation - server
This commit does the following:
* Add a middleware to validate whether a user can validate an ownership
* Change the ownership status instead of deleting the row
* [#510] PR reviews - to squash with ownership validation - client
This commit does the following:
* Correct indentation of html files with two-spaces indentation
* Use event emitter instead of function for accept event
* Update the sort of ownership change table for a decreasing order by creation date
* Add the status in ownership change table
* Use classic method syntax
* code style - to squash
* Add new user right - to squash
* Move the change to my-account instead of video-watch - to squash
As requested in pull-request, move the action to change ownership into my videos page.
The rest of the logic was not really changed.
This commit does the following:
- Move the modal into my video page
- Create the generic component `button` to keep some styles and logic
* [#510] Add tests for the new feature
To avoid regression, we add tests for all api of ownership change.
This commit does the following:
- Create an end-to-end test for ownership change
- Divide it to one test per request
* [#510] Do not send twice the same request to avoid spam
We can send several time the same request to change ownership.
However, it will spam the user.
To avoid this, we do not save a request already existing in database.
This commit does the following:
- Check whether the request exist in database
- Add tests to verify this new condition
* [#510] Change icons
Change icons so they remains logic with the rest of the application.
This commit does the following:
- Add svg for missing icons
- Add icons in `my-button` component
- Use these new icons
* [#510] Add control about the user quota
The user should be able to accept a new video only if his quota allows it.
This commit does the following:
- Update the middleware to control the quota
- Add tests verifying the control
* Correct merge
- Use new modal system
- Move button to new directory `buttons`
* PR reviews - to squash
2018-09-04 02:57:13 -04:00
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
const videosAcceptChangeOwnershipValidator = [
|
|
|
|
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
|
|
|
const body = req.body as VideoChangeOwnershipAccept
|
2019-03-19 04:26:50 -04:00
|
|
|
if (!await doesVideoChannelOfAccountExist(body.channelId, res.locals.oauth.token.User, res)) return
|
Users can change ownership of their video [#510] (#888)
* [#510] Create a new route to get the list of user names
To be able to transfer ownership to a user,
we need to be able to select him from the list of users.
Because the list could be too big, we add a autocomplete feature.
This commit does the following:
* Add a API endpoint to get a list of user names by searching its name
* [#510] The user can choose the next owner of the video
To be able to transfer ownership to a user,
we need the owner to be able to select the user.
The server can autocomplete the name of the user to give the ownership.
We add a dialog for the user to actually select it.
This commit does the following:
* Create a modal for the owner to select the next one
* Opens this modal with a button into the menu *more*
* Make the dependency injection
* [#510] When the user choose the next owner, create a request in database
For the change of ownership to happen, we need to store the temporary requests.
When the user make the request, save it to database.
This commit does the following:
* Create the model to persist change ownership requests
* Add an API to manage ownership operations
* Add a route to persist an ownership request
* [#510] A user can fetch its ownership requests sent to him
To be able to accept or refuse a change of ownership,
the user must be able to fetch them.
This commit does the following:
* Add an API to list ownership for a user
* Add the query to database model
* [#510] A user can validate an ownership requests sent to him - server
The user can accept or refuse any ownership request that was sent to him.
This commit focus only on the server part.
This commit does the following:
* Add an API for the user to accept or refuse a video ownership
* Add validators to ensure security access
* Add a query to load a specific video change ownership request
* [#510] A user can validate an ownership requests sent to him - web
The user can accept or refuse any ownership request that was sent to him.
This commit focus only on the web part.
This commit does the following:
* Add a page to list user ownership changes
* Add actions to accept or refuse them
* When accepting, show a modal requiring the channel to send the video
* Correct lint - to squash
* [#510] PR reviews - to squash
This commit does the following:
* Search parameter for user autocompletion is required from middleware directly
* [#510] PR reviews - to squash with creation in database commit
This commit does the following:
* Add the status attribute in model
* Set this attribute on instance creation
* Use AccountModel method `loadLocalByName`
* [#510] PR reviews - to squash with fetch ownership
This commit does the following:
* Add the scope `FULL` for database queries with includes
* Add classic pagination middlewares
* [#510] PR reviews - to squash with ownership validation - server
This commit does the following:
* Add a middleware to validate whether a user can validate an ownership
* Change the ownership status instead of deleting the row
* [#510] PR reviews - to squash with ownership validation - client
This commit does the following:
* Correct indentation of html files with two-spaces indentation
* Use event emitter instead of function for accept event
* Update the sort of ownership change table for a decreasing order by creation date
* Add the status in ownership change table
* Use classic method syntax
* code style - to squash
* Add new user right - to squash
* Move the change to my-account instead of video-watch - to squash
As requested in pull-request, move the action to change ownership into my videos page.
The rest of the logic was not really changed.
This commit does the following:
- Move the modal into my video page
- Create the generic component `button` to keep some styles and logic
* [#510] Add tests for the new feature
To avoid regression, we add tests for all api of ownership change.
This commit does the following:
- Create an end-to-end test for ownership change
- Divide it to one test per request
* [#510] Do not send twice the same request to avoid spam
We can send several time the same request to change ownership.
However, it will spam the user.
To avoid this, we do not save a request already existing in database.
This commit does the following:
- Check whether the request exist in database
- Add tests to verify this new condition
* [#510] Change icons
Change icons so they remains logic with the rest of the application.
This commit does the following:
- Add svg for missing icons
- Add icons in `my-button` component
- Use these new icons
* [#510] Add control about the user quota
The user should be able to accept a new video only if his quota allows it.
This commit does the following:
- Update the middleware to control the quota
- Add tests verifying the control
* Correct merge
- Use new modal system
- Move button to new directory `buttons`
* PR reviews - to squash
2018-09-04 02:57:13 -04:00
|
|
|
|
|
|
|
const user = res.locals.oauth.token.User
|
2019-03-19 05:35:15 -04:00
|
|
|
const videoChangeOwnership = res.locals.videoChangeOwnership
|
2020-09-25 10:19:35 -04:00
|
|
|
const isAble = await isAbleToUploadVideo(user.id, videoChangeOwnership.Video.getMaxQualityFile().size)
|
Users can change ownership of their video [#510] (#888)
* [#510] Create a new route to get the list of user names
To be able to transfer ownership to a user,
we need to be able to select him from the list of users.
Because the list could be too big, we add a autocomplete feature.
This commit does the following:
* Add a API endpoint to get a list of user names by searching its name
* [#510] The user can choose the next owner of the video
To be able to transfer ownership to a user,
we need the owner to be able to select the user.
The server can autocomplete the name of the user to give the ownership.
We add a dialog for the user to actually select it.
This commit does the following:
* Create a modal for the owner to select the next one
* Opens this modal with a button into the menu *more*
* Make the dependency injection
* [#510] When the user choose the next owner, create a request in database
For the change of ownership to happen, we need to store the temporary requests.
When the user make the request, save it to database.
This commit does the following:
* Create the model to persist change ownership requests
* Add an API to manage ownership operations
* Add a route to persist an ownership request
* [#510] A user can fetch its ownership requests sent to him
To be able to accept or refuse a change of ownership,
the user must be able to fetch them.
This commit does the following:
* Add an API to list ownership for a user
* Add the query to database model
* [#510] A user can validate an ownership requests sent to him - server
The user can accept or refuse any ownership request that was sent to him.
This commit focus only on the server part.
This commit does the following:
* Add an API for the user to accept or refuse a video ownership
* Add validators to ensure security access
* Add a query to load a specific video change ownership request
* [#510] A user can validate an ownership requests sent to him - web
The user can accept or refuse any ownership request that was sent to him.
This commit focus only on the web part.
This commit does the following:
* Add a page to list user ownership changes
* Add actions to accept or refuse them
* When accepting, show a modal requiring the channel to send the video
* Correct lint - to squash
* [#510] PR reviews - to squash
This commit does the following:
* Search parameter for user autocompletion is required from middleware directly
* [#510] PR reviews - to squash with creation in database commit
This commit does the following:
* Add the status attribute in model
* Set this attribute on instance creation
* Use AccountModel method `loadLocalByName`
* [#510] PR reviews - to squash with fetch ownership
This commit does the following:
* Add the scope `FULL` for database queries with includes
* Add classic pagination middlewares
* [#510] PR reviews - to squash with ownership validation - server
This commit does the following:
* Add a middleware to validate whether a user can validate an ownership
* Change the ownership status instead of deleting the row
* [#510] PR reviews - to squash with ownership validation - client
This commit does the following:
* Correct indentation of html files with two-spaces indentation
* Use event emitter instead of function for accept event
* Update the sort of ownership change table for a decreasing order by creation date
* Add the status in ownership change table
* Use classic method syntax
* code style - to squash
* Add new user right - to squash
* Move the change to my-account instead of video-watch - to squash
As requested in pull-request, move the action to change ownership into my videos page.
The rest of the logic was not really changed.
This commit does the following:
- Move the modal into my video page
- Create the generic component `button` to keep some styles and logic
* [#510] Add tests for the new feature
To avoid regression, we add tests for all api of ownership change.
This commit does the following:
- Create an end-to-end test for ownership change
- Divide it to one test per request
* [#510] Do not send twice the same request to avoid spam
We can send several time the same request to change ownership.
However, it will spam the user.
To avoid this, we do not save a request already existing in database.
This commit does the following:
- Check whether the request exist in database
- Add tests to verify this new condition
* [#510] Change icons
Change icons so they remains logic with the rest of the application.
This commit does the following:
- Add svg for missing icons
- Add icons in `my-button` component
- Use these new icons
* [#510] Add control about the user quota
The user should be able to accept a new video only if his quota allows it.
This commit does the following:
- Update the middleware to control the quota
- Add tests verifying the control
* Correct merge
- Use new modal system
- Move button to new directory `buttons`
* PR reviews - to squash
2018-09-04 02:57:13 -04:00
|
|
|
if (isAble === false) {
|
2020-12-08 15:16:10 -05:00
|
|
|
res.status(HttpStatusCode.PAYLOAD_TOO_LARGE_413)
|
Users can change ownership of their video [#510] (#888)
* [#510] Create a new route to get the list of user names
To be able to transfer ownership to a user,
we need to be able to select him from the list of users.
Because the list could be too big, we add a autocomplete feature.
This commit does the following:
* Add a API endpoint to get a list of user names by searching its name
* [#510] The user can choose the next owner of the video
To be able to transfer ownership to a user,
we need the owner to be able to select the user.
The server can autocomplete the name of the user to give the ownership.
We add a dialog for the user to actually select it.
This commit does the following:
* Create a modal for the owner to select the next one
* Opens this modal with a button into the menu *more*
* Make the dependency injection
* [#510] When the user choose the next owner, create a request in database
For the change of ownership to happen, we need to store the temporary requests.
When the user make the request, save it to database.
This commit does the following:
* Create the model to persist change ownership requests
* Add an API to manage ownership operations
* Add a route to persist an ownership request
* [#510] A user can fetch its ownership requests sent to him
To be able to accept or refuse a change of ownership,
the user must be able to fetch them.
This commit does the following:
* Add an API to list ownership for a user
* Add the query to database model
* [#510] A user can validate an ownership requests sent to him - server
The user can accept or refuse any ownership request that was sent to him.
This commit focus only on the server part.
This commit does the following:
* Add an API for the user to accept or refuse a video ownership
* Add validators to ensure security access
* Add a query to load a specific video change ownership request
* [#510] A user can validate an ownership requests sent to him - web
The user can accept or refuse any ownership request that was sent to him.
This commit focus only on the web part.
This commit does the following:
* Add a page to list user ownership changes
* Add actions to accept or refuse them
* When accepting, show a modal requiring the channel to send the video
* Correct lint - to squash
* [#510] PR reviews - to squash
This commit does the following:
* Search parameter for user autocompletion is required from middleware directly
* [#510] PR reviews - to squash with creation in database commit
This commit does the following:
* Add the status attribute in model
* Set this attribute on instance creation
* Use AccountModel method `loadLocalByName`
* [#510] PR reviews - to squash with fetch ownership
This commit does the following:
* Add the scope `FULL` for database queries with includes
* Add classic pagination middlewares
* [#510] PR reviews - to squash with ownership validation - server
This commit does the following:
* Add a middleware to validate whether a user can validate an ownership
* Change the ownership status instead of deleting the row
* [#510] PR reviews - to squash with ownership validation - client
This commit does the following:
* Correct indentation of html files with two-spaces indentation
* Use event emitter instead of function for accept event
* Update the sort of ownership change table for a decreasing order by creation date
* Add the status in ownership change table
* Use classic method syntax
* code style - to squash
* Add new user right - to squash
* Move the change to my-account instead of video-watch - to squash
As requested in pull-request, move the action to change ownership into my videos page.
The rest of the logic was not really changed.
This commit does the following:
- Move the modal into my video page
- Create the generic component `button` to keep some styles and logic
* [#510] Add tests for the new feature
To avoid regression, we add tests for all api of ownership change.
This commit does the following:
- Create an end-to-end test for ownership change
- Divide it to one test per request
* [#510] Do not send twice the same request to avoid spam
We can send several time the same request to change ownership.
However, it will spam the user.
To avoid this, we do not save a request already existing in database.
This commit does the following:
- Check whether the request exist in database
- Add tests to verify this new condition
* [#510] Change icons
Change icons so they remains logic with the rest of the application.
This commit does the following:
- Add svg for missing icons
- Add icons in `my-button` component
- Use these new icons
* [#510] Add control about the user quota
The user should be able to accept a new video only if his quota allows it.
This commit does the following:
- Update the middleware to control the quota
- Add tests verifying the control
* Correct merge
- Use new modal system
- Move button to new directory `buttons`
* PR reviews - to squash
2018-09-04 02:57:13 -04:00
|
|
|
.json({ error: 'The user video quota is exceeded with this video.' })
|
2018-10-10 02:57:00 -04:00
|
|
|
|
Users can change ownership of their video [#510] (#888)
* [#510] Create a new route to get the list of user names
To be able to transfer ownership to a user,
we need to be able to select him from the list of users.
Because the list could be too big, we add a autocomplete feature.
This commit does the following:
* Add a API endpoint to get a list of user names by searching its name
* [#510] The user can choose the next owner of the video
To be able to transfer ownership to a user,
we need the owner to be able to select the user.
The server can autocomplete the name of the user to give the ownership.
We add a dialog for the user to actually select it.
This commit does the following:
* Create a modal for the owner to select the next one
* Opens this modal with a button into the menu *more*
* Make the dependency injection
* [#510] When the user choose the next owner, create a request in database
For the change of ownership to happen, we need to store the temporary requests.
When the user make the request, save it to database.
This commit does the following:
* Create the model to persist change ownership requests
* Add an API to manage ownership operations
* Add a route to persist an ownership request
* [#510] A user can fetch its ownership requests sent to him
To be able to accept or refuse a change of ownership,
the user must be able to fetch them.
This commit does the following:
* Add an API to list ownership for a user
* Add the query to database model
* [#510] A user can validate an ownership requests sent to him - server
The user can accept or refuse any ownership request that was sent to him.
This commit focus only on the server part.
This commit does the following:
* Add an API for the user to accept or refuse a video ownership
* Add validators to ensure security access
* Add a query to load a specific video change ownership request
* [#510] A user can validate an ownership requests sent to him - web
The user can accept or refuse any ownership request that was sent to him.
This commit focus only on the web part.
This commit does the following:
* Add a page to list user ownership changes
* Add actions to accept or refuse them
* When accepting, show a modal requiring the channel to send the video
* Correct lint - to squash
* [#510] PR reviews - to squash
This commit does the following:
* Search parameter for user autocompletion is required from middleware directly
* [#510] PR reviews - to squash with creation in database commit
This commit does the following:
* Add the status attribute in model
* Set this attribute on instance creation
* Use AccountModel method `loadLocalByName`
* [#510] PR reviews - to squash with fetch ownership
This commit does the following:
* Add the scope `FULL` for database queries with includes
* Add classic pagination middlewares
* [#510] PR reviews - to squash with ownership validation - server
This commit does the following:
* Add a middleware to validate whether a user can validate an ownership
* Change the ownership status instead of deleting the row
* [#510] PR reviews - to squash with ownership validation - client
This commit does the following:
* Correct indentation of html files with two-spaces indentation
* Use event emitter instead of function for accept event
* Update the sort of ownership change table for a decreasing order by creation date
* Add the status in ownership change table
* Use classic method syntax
* code style - to squash
* Add new user right - to squash
* Move the change to my-account instead of video-watch - to squash
As requested in pull-request, move the action to change ownership into my videos page.
The rest of the logic was not really changed.
This commit does the following:
- Move the modal into my video page
- Create the generic component `button` to keep some styles and logic
* [#510] Add tests for the new feature
To avoid regression, we add tests for all api of ownership change.
This commit does the following:
- Create an end-to-end test for ownership change
- Divide it to one test per request
* [#510] Do not send twice the same request to avoid spam
We can send several time the same request to change ownership.
However, it will spam the user.
To avoid this, we do not save a request already existing in database.
This commit does the following:
- Check whether the request exist in database
- Add tests to verify this new condition
* [#510] Change icons
Change icons so they remains logic with the rest of the application.
This commit does the following:
- Add svg for missing icons
- Add icons in `my-button` component
- Use these new icons
* [#510] Add control about the user quota
The user should be able to accept a new video only if his quota allows it.
This commit does the following:
- Update the middleware to control the quota
- Add tests verifying the control
* Correct merge
- Use new modal system
- Move button to new directory `buttons`
* PR reviews - to squash
2018-09-04 02:57:13 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
return next()
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2020-03-11 09:39:28 -04:00
|
|
|
const videosOverviewValidator = [
|
|
|
|
query('page')
|
|
|
|
.optional()
|
|
|
|
.isInt({ min: 1, max: OVERVIEWS.VIDEOS.SAMPLES_COUNT })
|
|
|
|
.withMessage('Should have a valid pagination'),
|
|
|
|
|
|
|
|
(req: express.Request, res: express.Response, next: express.NextFunction) => {
|
|
|
|
if (areValidationErrors(req, res)) return
|
|
|
|
|
|
|
|
return next()
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2019-02-26 04:55:40 -05:00
|
|
|
function getCommonVideoEditAttributes () {
|
2018-07-16 08:58:22 -04:00
|
|
|
return [
|
|
|
|
body('thumbnailfile')
|
|
|
|
.custom((value, { req }) => isVideoImage(req.files, 'thumbnailfile')).withMessage(
|
2020-01-31 10:56:52 -05:00
|
|
|
'This thumbnail file is not supported or too large. Please, make sure it is of the following type: ' +
|
|
|
|
CONSTRAINTS_FIELDS.VIDEOS.IMAGE.EXTNAME.join(', ')
|
|
|
|
),
|
2018-07-16 08:58:22 -04:00
|
|
|
body('previewfile')
|
|
|
|
.custom((value, { req }) => isVideoImage(req.files, 'previewfile')).withMessage(
|
2020-01-31 10:56:52 -05:00
|
|
|
'This preview file is not supported or too large. Please, make sure it is of the following type: ' +
|
|
|
|
CONSTRAINTS_FIELDS.VIDEOS.IMAGE.EXTNAME.join(', ')
|
|
|
|
),
|
2018-07-16 08:58:22 -04:00
|
|
|
|
|
|
|
body('category')
|
|
|
|
.optional()
|
|
|
|
.customSanitizer(toIntOrNull)
|
|
|
|
.custom(isVideoCategoryValid).withMessage('Should have a valid category'),
|
|
|
|
body('licence')
|
|
|
|
.optional()
|
|
|
|
.customSanitizer(toIntOrNull)
|
|
|
|
.custom(isVideoLicenceValid).withMessage('Should have a valid licence'),
|
|
|
|
body('language')
|
|
|
|
.optional()
|
|
|
|
.customSanitizer(toValueOrNull)
|
|
|
|
.custom(isVideoLanguageValid).withMessage('Should have a valid language'),
|
|
|
|
body('nsfw')
|
|
|
|
.optional()
|
2019-07-25 10:23:44 -04:00
|
|
|
.customSanitizer(toBooleanOrNull)
|
2018-07-16 08:58:22 -04:00
|
|
|
.custom(isBooleanValid).withMessage('Should have a valid NSFW attribute'),
|
|
|
|
body('waitTranscoding')
|
|
|
|
.optional()
|
2019-07-25 10:23:44 -04:00
|
|
|
.customSanitizer(toBooleanOrNull)
|
2018-07-16 08:58:22 -04:00
|
|
|
.custom(isBooleanValid).withMessage('Should have a valid wait transcoding attribute'),
|
|
|
|
body('privacy')
|
|
|
|
.optional()
|
2019-07-25 10:23:44 -04:00
|
|
|
.customSanitizer(toValueOrNull)
|
2018-07-16 08:58:22 -04:00
|
|
|
.custom(isVideoPrivacyValid).withMessage('Should have correct video privacy'),
|
|
|
|
body('description')
|
|
|
|
.optional()
|
|
|
|
.customSanitizer(toValueOrNull)
|
|
|
|
.custom(isVideoDescriptionValid).withMessage('Should have a valid description'),
|
|
|
|
body('support')
|
|
|
|
.optional()
|
|
|
|
.customSanitizer(toValueOrNull)
|
|
|
|
.custom(isVideoSupportValid).withMessage('Should have a valid support text'),
|
|
|
|
body('tags')
|
|
|
|
.optional()
|
|
|
|
.customSanitizer(toValueOrNull)
|
|
|
|
.custom(isVideoTagsValid).withMessage('Should have correct tags'),
|
|
|
|
body('commentsEnabled')
|
|
|
|
.optional()
|
2019-07-25 10:23:44 -04:00
|
|
|
.customSanitizer(toBooleanOrNull)
|
2018-07-16 08:58:22 -04:00
|
|
|
.custom(isBooleanValid).withMessage('Should have comments enabled boolean'),
|
2018-10-08 08:45:22 -04:00
|
|
|
body('downloadEnabled')
|
2019-01-12 08:45:23 -05:00
|
|
|
.optional()
|
2019-07-25 10:23:44 -04:00
|
|
|
.customSanitizer(toBooleanOrNull)
|
2018-10-06 13:17:21 -04:00
|
|
|
.custom(isBooleanValid).withMessage('Should have downloading enabled boolean'),
|
2019-02-11 08:09:23 -05:00
|
|
|
body('originallyPublishedAt')
|
2019-07-25 10:23:44 -04:00
|
|
|
.optional()
|
|
|
|
.customSanitizer(toValueOrNull)
|
|
|
|
.custom(isVideoOriginallyPublishedAtValid).withMessage('Should have a valid original publication date'),
|
2018-07-16 08:58:22 -04:00
|
|
|
body('scheduleUpdate')
|
|
|
|
.optional()
|
|
|
|
.customSanitizer(toValueOrNull),
|
|
|
|
body('scheduleUpdate.updateAt')
|
|
|
|
.optional()
|
|
|
|
.custom(isDateValid).withMessage('Should have a valid schedule update date'),
|
|
|
|
body('scheduleUpdate.privacy')
|
|
|
|
.optional()
|
2019-07-25 11:28:45 -04:00
|
|
|
.customSanitizer(toIntOrNull)
|
2018-07-16 08:58:22 -04:00
|
|
|
.custom(isScheduleVideoUpdatePrivacyValid).withMessage('Should have correct schedule update privacy')
|
2021-02-03 03:33:05 -05:00
|
|
|
] as (ValidationChain | ExpressPromiseHandler)[]
|
2018-07-16 08:58:22 -04:00
|
|
|
}
|
2018-08-02 09:34:09 -04:00
|
|
|
|
2018-10-10 05:46:50 -04:00
|
|
|
const commonVideosFiltersValidator = [
|
|
|
|
query('categoryOneOf')
|
|
|
|
.optional()
|
|
|
|
.customSanitizer(toArray)
|
|
|
|
.custom(isNumberArray).withMessage('Should have a valid one of category array'),
|
|
|
|
query('licenceOneOf')
|
|
|
|
.optional()
|
|
|
|
.customSanitizer(toArray)
|
|
|
|
.custom(isNumberArray).withMessage('Should have a valid one of licence array'),
|
|
|
|
query('languageOneOf')
|
|
|
|
.optional()
|
|
|
|
.customSanitizer(toArray)
|
|
|
|
.custom(isStringArray).withMessage('Should have a valid one of language array'),
|
|
|
|
query('tagsOneOf')
|
|
|
|
.optional()
|
|
|
|
.customSanitizer(toArray)
|
|
|
|
.custom(isStringArray).withMessage('Should have a valid one of tags array'),
|
|
|
|
query('tagsAllOf')
|
|
|
|
.optional()
|
|
|
|
.customSanitizer(toArray)
|
|
|
|
.custom(isStringArray).withMessage('Should have a valid all of tags array'),
|
|
|
|
query('nsfw')
|
|
|
|
.optional()
|
|
|
|
.custom(isNSFWQueryValid).withMessage('Should have a valid NSFW attribute'),
|
|
|
|
query('filter')
|
|
|
|
.optional()
|
|
|
|
.custom(isVideoFilterValid).withMessage('Should have a valid filter attribute'),
|
2020-01-08 08:15:16 -05:00
|
|
|
query('skipCount')
|
|
|
|
.optional()
|
|
|
|
.customSanitizer(toBooleanOrNull)
|
|
|
|
.custom(isBooleanValid).withMessage('Should have a valid skip count boolean'),
|
2021-01-19 07:43:33 -05:00
|
|
|
query('search')
|
|
|
|
.optional()
|
|
|
|
.custom(exists).withMessage('Should have a valid search'),
|
2018-10-10 05:46:50 -04:00
|
|
|
|
|
|
|
(req: express.Request, res: express.Response, next: express.NextFunction) => {
|
|
|
|
logger.debug('Checking commons video filters query', { parameters: req.query })
|
|
|
|
|
|
|
|
if (areValidationErrors(req, res)) return
|
|
|
|
|
2019-03-19 05:35:15 -04:00
|
|
|
const user = res.locals.oauth ? res.locals.oauth.token.User : undefined
|
2020-11-18 09:29:38 -05:00
|
|
|
if (
|
|
|
|
(req.query.filter === 'all-local' || req.query.filter === 'all') &&
|
|
|
|
(!user || user.hasRight(UserRight.SEE_ALL_VIDEOS) === false)
|
|
|
|
) {
|
2020-12-07 08:32:36 -05:00
|
|
|
res.status(HttpStatusCode.UNAUTHORIZED_401)
|
2018-10-10 05:46:50 -04:00
|
|
|
.json({ error: 'You are not allowed to see all local videos.' })
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
return next()
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2018-08-02 09:34:09 -04:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
videosAddValidator,
|
|
|
|
videosUpdateValidator,
|
|
|
|
videosGetValidator,
|
2020-03-10 09:39:40 -04:00
|
|
|
videoFileMetadataGetValidator,
|
2019-12-03 04:41:23 -05:00
|
|
|
videosDownloadValidator,
|
2018-11-16 09:02:48 -05:00
|
|
|
checkVideoFollowConstraints,
|
2018-09-19 04:16:44 -04:00
|
|
|
videosCustomGetValidator,
|
2018-08-02 09:34:09 -04:00
|
|
|
videosRemoveValidator,
|
|
|
|
|
Users can change ownership of their video [#510] (#888)
* [#510] Create a new route to get the list of user names
To be able to transfer ownership to a user,
we need to be able to select him from the list of users.
Because the list could be too big, we add a autocomplete feature.
This commit does the following:
* Add a API endpoint to get a list of user names by searching its name
* [#510] The user can choose the next owner of the video
To be able to transfer ownership to a user,
we need the owner to be able to select the user.
The server can autocomplete the name of the user to give the ownership.
We add a dialog for the user to actually select it.
This commit does the following:
* Create a modal for the owner to select the next one
* Opens this modal with a button into the menu *more*
* Make the dependency injection
* [#510] When the user choose the next owner, create a request in database
For the change of ownership to happen, we need to store the temporary requests.
When the user make the request, save it to database.
This commit does the following:
* Create the model to persist change ownership requests
* Add an API to manage ownership operations
* Add a route to persist an ownership request
* [#510] A user can fetch its ownership requests sent to him
To be able to accept or refuse a change of ownership,
the user must be able to fetch them.
This commit does the following:
* Add an API to list ownership for a user
* Add the query to database model
* [#510] A user can validate an ownership requests sent to him - server
The user can accept or refuse any ownership request that was sent to him.
This commit focus only on the server part.
This commit does the following:
* Add an API for the user to accept or refuse a video ownership
* Add validators to ensure security access
* Add a query to load a specific video change ownership request
* [#510] A user can validate an ownership requests sent to him - web
The user can accept or refuse any ownership request that was sent to him.
This commit focus only on the web part.
This commit does the following:
* Add a page to list user ownership changes
* Add actions to accept or refuse them
* When accepting, show a modal requiring the channel to send the video
* Correct lint - to squash
* [#510] PR reviews - to squash
This commit does the following:
* Search parameter for user autocompletion is required from middleware directly
* [#510] PR reviews - to squash with creation in database commit
This commit does the following:
* Add the status attribute in model
* Set this attribute on instance creation
* Use AccountModel method `loadLocalByName`
* [#510] PR reviews - to squash with fetch ownership
This commit does the following:
* Add the scope `FULL` for database queries with includes
* Add classic pagination middlewares
* [#510] PR reviews - to squash with ownership validation - server
This commit does the following:
* Add a middleware to validate whether a user can validate an ownership
* Change the ownership status instead of deleting the row
* [#510] PR reviews - to squash with ownership validation - client
This commit does the following:
* Correct indentation of html files with two-spaces indentation
* Use event emitter instead of function for accept event
* Update the sort of ownership change table for a decreasing order by creation date
* Add the status in ownership change table
* Use classic method syntax
* code style - to squash
* Add new user right - to squash
* Move the change to my-account instead of video-watch - to squash
As requested in pull-request, move the action to change ownership into my videos page.
The rest of the logic was not really changed.
This commit does the following:
- Move the modal into my video page
- Create the generic component `button` to keep some styles and logic
* [#510] Add tests for the new feature
To avoid regression, we add tests for all api of ownership change.
This commit does the following:
- Create an end-to-end test for ownership change
- Divide it to one test per request
* [#510] Do not send twice the same request to avoid spam
We can send several time the same request to change ownership.
However, it will spam the user.
To avoid this, we do not save a request already existing in database.
This commit does the following:
- Check whether the request exist in database
- Add tests to verify this new condition
* [#510] Change icons
Change icons so they remains logic with the rest of the application.
This commit does the following:
- Add svg for missing icons
- Add icons in `my-button` component
- Use these new icons
* [#510] Add control about the user quota
The user should be able to accept a new video only if his quota allows it.
This commit does the following:
- Update the middleware to control the quota
- Add tests verifying the control
* Correct merge
- Use new modal system
- Move button to new directory `buttons`
* PR reviews - to squash
2018-09-04 02:57:13 -04:00
|
|
|
videosChangeOwnershipValidator,
|
|
|
|
videosTerminateChangeOwnershipValidator,
|
|
|
|
videosAcceptChangeOwnershipValidator,
|
|
|
|
|
2019-02-26 04:55:40 -05:00
|
|
|
getCommonVideoEditAttributes,
|
2018-10-10 05:46:50 -04:00
|
|
|
|
2020-03-11 09:39:28 -04:00
|
|
|
commonVideosFiltersValidator,
|
|
|
|
|
|
|
|
videosOverviewValidator
|
2018-08-02 09:34:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
function areErrorsInScheduleUpdate (req: express.Request, res: express.Response) {
|
|
|
|
if (req.body.scheduleUpdate) {
|
|
|
|
if (!req.body.scheduleUpdate.updateAt) {
|
2018-11-16 04:05:25 -05:00
|
|
|
logger.warn('Invalid parameters: scheduleUpdate.updateAt is mandatory.')
|
|
|
|
|
2020-12-07 08:32:36 -05:00
|
|
|
res.status(HttpStatusCode.BAD_REQUEST_400)
|
2018-08-02 09:34:09 -04:00
|
|
|
.json({ error: 'Schedule update at is mandatory.' })
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
2019-07-18 08:28:37 -04:00
|
|
|
|
|
|
|
async function isVideoAccepted (req: express.Request, res: express.Response, videoFile: Express.Multer.File & { duration?: number }) {
|
|
|
|
// Check we accept this video
|
|
|
|
const acceptParameters = {
|
|
|
|
videoBody: req.body,
|
|
|
|
videoFile,
|
|
|
|
user: res.locals.oauth.token.User
|
|
|
|
}
|
2019-07-19 11:30:41 -04:00
|
|
|
const acceptedResult = await Hooks.wrapFun(
|
|
|
|
isLocalVideoAccepted,
|
|
|
|
acceptParameters,
|
2019-07-18 08:28:37 -04:00
|
|
|
'filter:api.video.upload.accept.result'
|
|
|
|
)
|
|
|
|
|
|
|
|
if (!acceptedResult || acceptedResult.accepted !== true) {
|
|
|
|
logger.info('Refused local video.', { acceptedResult, acceptParameters })
|
2020-12-07 08:32:36 -05:00
|
|
|
res.status(HttpStatusCode.FORBIDDEN_403)
|
2019-07-18 08:28:37 -04:00
|
|
|
.json({ error: acceptedResult.errorMessage || 'Refused local video' })
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|