import { Component, OnInit } from '@angular/core'
import { Router } from '@angular/router'
-import { AuthService, ServerService } from './core'
+import { AuthService, ServerService } from '@app/core'
@Component({
selector: 'my-app',
}
}
- isInAdmin () {
- return this.router.url.indexOf('/admin/') !== -1
- }
-
toggleMenu () {
window.scrollTo(0, 0)
this.isMenuDisplayed = !this.isMenuDisplayed
import { Account as ServerAccount } from '../../../../../shared/models/actors/account.model'
import { Avatar } from '../../../../../shared/models/avatars/avatar.model'
-import { environment } from '../../../environments/environment'
import { getAbsoluteAPIUrl } from '../misc/utils'
export class Account implements ServerAccount {
id: number
uuid: string
+ url: string
name: string
displayName: string
host: string
.submit-container {
text-align: right;
- position: relative;
- bottom: $button-height;
.message-submit {
display: inline-block;
<div class="comment">
<div class="comment-account-date">
- <div class="comment-account">{{ comment.by }}</div>
+ <a target="_blank" [href]="comment.account.url" class="comment-account">{{ comment.by }}</a>
<div class="comment-date">{{ comment.createdAt | myFromNow }}</div>
</div>
<div>{{ comment.text }}</div>
<div class="comment-actions">
<div *ngIf="isUserLoggedIn()" (click)="onWantToReply()" class="comment-action-reply">Reply</div>
+ <div *ngIf="isRemovableByUser()" (click)="onWantToDelete()" class="comment-action-delete">Delete</div>
</div>
<my-video-comment-add
[video]="video"
[inReplyToCommentId]="inReplyToCommentId"
[commentTree]="commentChild"
- (wantedToReply)="onWantedToReply($event)"
+ (wantedToReply)="onWantToReply($event)"
+ (wantedToDelete)="onWantToDelete($event)"
(resetReply)="onResetReply()"
></my-video-comment>
</div>
margin-bottom: 4px;
.comment-account {
+ @include disable-default-a-behaviour;
+
+ color: #000;
font-weight: $font-bold;
}
.comment-actions {
margin: 10px 0;
+ display: flex;
- .comment-action-reply {
+ .comment-action-reply, .comment-action-delete {
color: #585858;
cursor: pointer;
+ margin-right: 10px;
+
+ &:hover {
+ color: #000;
+ }
}
}
}
import { Component, EventEmitter, Input, Output } from '@angular/core'
import { Account as AccountInterface } from '../../../../../../shared/models/actors'
+import { UserRight } from '../../../../../../shared/models/users'
import { VideoCommentThreadTree } from '../../../../../../shared/models/videos/video-comment.model'
import { AuthService } from '../../../core/auth'
import { Account } from '../../../shared/account/account.model'
@Input() commentTree: VideoCommentThreadTree
@Input() inReplyToCommentId: number
+ @Output() wantedToDelete = new EventEmitter<VideoComment>()
@Output() wantedToReply = new EventEmitter<VideoComment>()
+ @Output() threadCreated = new EventEmitter<VideoCommentThreadTree>()
@Output() resetReply = new EventEmitter()
constructor (private authService: AuthService) {}
comment: this.comment,
children: []
}
+
+ this.threadCreated.emit(this.commentTree)
}
this.commentTree.children.push({
this.resetReply.emit()
}
- onWantToReply () {
- this.wantedToReply.emit(this.comment)
+ onWantToReply (comment?: VideoComment) {
+ this.wantedToReply.emit(comment || this.comment)
}
- isUserLoggedIn () {
- return this.authService.isLoggedIn()
+ onWantToDelete (comment?: VideoComment) {
+ this.wantedToDelete.emit(comment || this.comment)
}
- // Event from child comment
- onWantedToReply (comment: VideoComment) {
- this.wantedToReply.emit(comment)
+ isUserLoggedIn () {
+ return this.authService.isLoggedIn()
}
onResetReply () {
getAvatarUrl (account: AccountInterface) {
return Account.GET_ACCOUNT_AVATAR_URL(account)
}
+
+ isRemovableByUser () {
+ return this.isUserLoggedIn() &&
+ (
+ this.user.account.id === this.comment.account.id ||
+ this.user.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT)
+ )
+ }
}
.catch((res) => this.restExtractor.handleError(res))
}
+ deleteVideoComment (videoId: number | string, commentId: number) {
+ const url = `${VideoCommentService.BASE_VIDEO_URL + videoId}/comments/${commentId}`
+
+ return this.authHttp
+ .delete(url)
+ .map(this.restExtractor.extractDataBool)
+ .catch((res) => this.restExtractor.handleError(res))
+ }
+
private extractVideoComment (videoComment: VideoCommentServerModel) {
return new VideoComment(videoComment)
}
[inReplyToCommentId]="inReplyToCommentId"
[commentTree]="threadComments[comment.id]"
(wantedToReply)="onWantedToReply($event)"
+ (wantedToDelete)="onWantedToDelete($event)"
+ (threadCreated)="onThreadCreated($event)"
(resetReply)="onResetReply()"
></my-video-comment>
import { Component, Input, OnInit } from '@angular/core'
+import { ConfirmService } from '@app/core'
import { NotificationsService } from 'angular2-notifications'
-import { VideoCommentThreadTree } from '../../../../../../shared/models/videos/video-comment.model'
+import { VideoComment as VideoCommentInterface, VideoCommentThreadTree } from '../../../../../../shared/models/videos/video-comment.model'
import { AuthService } from '../../../core/auth'
import { ComponentPagination } from '../../../shared/rest/component-pagination.model'
import { User } from '../../../shared/users'
constructor (
private authService: AuthService,
private notificationsService: NotificationsService,
+ private confirmService: ConfirmService,
private videoCommentService: VideoCommentService
) {}
}
}
- viewReplies (comment: VideoComment) {
+ viewReplies (comment: VideoCommentInterface) {
this.threadLoading[comment.id] = true
this.videoCommentService.getVideoThreadComments(this.video.id, comment.id)
this.inReplyToCommentId = undefined
}
+ onThreadCreated (commentTree: VideoCommentThreadTree) {
+ this.viewReplies(commentTree.comment)
+ }
+
+ onWantedToDelete (commentToDelete: VideoComment) {
+ let message = 'Do you really want to delete this comment?'
+ if (commentToDelete.totalReplies !== 0) message += `${commentToDelete.totalReplies} would be deleted too.`
+
+ this.confirmService.confirm(message, 'Delete').subscribe(
+ res => {
+ if (res === false) return
+
+ this.videoCommentService.deleteVideoComment(commentToDelete.videoId, commentToDelete.id)
+ .subscribe(
+ () => {
+ // Delete the comment in the tree
+ if (commentToDelete.inReplyToCommentId) {
+ const thread = this.threadComments[commentToDelete.threadId]
+ if (!thread) {
+ console.error(`Cannot find thread ${commentToDelete.threadId} of the comment to delete ${commentToDelete.id}`)
+ return
+ }
+
+ this.deleteLocalCommentThread(thread, commentToDelete)
+ return
+ }
+
+ // Delete the thread
+ this.comments = this.comments.filter(c => c.id !== commentToDelete.id)
+ this.componentPagination.totalItems--
+ },
+
+ err => this.notificationsService.error('Error', err.message)
+ )
+ }
+ )
+ }
+
isUserLoggedIn () {
return this.authService.isLoggedIn()
}
}
}
- protected hasMoreComments () {
+ private hasMoreComments () {
// No results
if (this.componentPagination.totalItems === 0) return false
const maxPage = this.componentPagination.totalItems / this.componentPagination.itemsPerPage
return maxPage > this.componentPagination.currentPage
}
+
+ private deleteLocalCommentThread (parentComment: VideoCommentThreadTree, commentToDelete: VideoComment) {
+ for (const commentChild of parentComment.children) {
+ if (commentChild.comment.id === commentToDelete.id) {
+ parentComment.children = parentComment.children.filter(c => c.comment.id !== commentToDelete.id)
+ return
+ }
+
+ this.deleteLocalCommentThread(commentChild, commentToDelete)
+ }
+ }
}
blacklistVideo (event: Event) {
event.preventDefault()
- this.confirmService.confirm('Do you really want to blacklist this video ?', 'Blacklist').subscribe(
+ this.confirmService.confirm('Do you really want to blacklist this video?', 'Blacklist').subscribe(
res => {
if (res === false) return
"lib": [
"es2017",
"dom"
- ]
+ ],
+ "baseUrl": "src",
+ "paths": {
+ "@app/*": [ "app/*" ]
+ }
}
}
import { ResultList } from '../../../../shared/models'
import { VideoCommentCreate } from '../../../../shared/models/videos/video-comment.model'
import { retryTransactionWrapper } from '../../../helpers/database-utils'
+import { logger } from '../../../helpers/logger'
import { getFormattedObjects } from '../../../helpers/utils'
import { sequelizeTypescript } from '../../../initializers'
import { buildFormattedCommentTree, createVideoComment } from '../../../lib/video-comment'
import { asyncMiddleware, authenticate, paginationValidator, setPagination, setVideoCommentThreadsSort } from '../../../middlewares'
import { videoCommentThreadsSortValidator } from '../../../middlewares/validators'
import {
- addVideoCommentReplyValidator, addVideoCommentThreadValidator, listVideoCommentThreadsValidator,
- listVideoThreadCommentsValidator
+ addVideoCommentReplyValidator, addVideoCommentThreadValidator, listVideoCommentThreadsValidator, listVideoThreadCommentsValidator,
+ removeVideoCommentValidator
} from '../../../middlewares/validators/video-comments'
import { VideoModel } from '../../../models/video/video'
import { VideoCommentModel } from '../../../models/video/video-comment'
asyncMiddleware(addVideoCommentReplyValidator),
asyncMiddleware(addVideoCommentReplyRetryWrapper)
)
+videoCommentRouter.delete('/:videoId/comments/:commentId',
+ authenticate,
+ asyncMiddleware(removeVideoCommentValidator),
+ asyncMiddleware(removeVideoCommentRetryWrapper)
+)
// ---------------------------------------------------------------------------
}, t)
})
}
+
+async function removeVideoCommentRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) {
+ const options = {
+ arguments: [ req, res ],
+ errorMessage: 'Cannot remove the video comment with many retries.'
+ }
+
+ await retryTransactionWrapper(removeVideoComment, options)
+
+ return res.type('json').status(204).end()
+}
+
+async function removeVideoComment (req: express.Request, res: express.Response) {
+ const videoCommentInstance: VideoCommentModel = res.locals.videoComment
+
+ await sequelizeTypescript.transaction(async t => {
+ await videoCommentInstance.destroy({ transaction: t })
+ })
+
+ logger.info('Video comment %d deleted.', videoCommentInstance.id)
+}
import { isActivityPubUrlValid } from './misc'
import { isDislikeActivityValid, isLikeActivityValid } from './rate'
import { isUndoActivityValid } from './undo'
-import { isVideoCommentCreateActivityValid } from './video-comments'
+import { isVideoCommentCreateActivityValid, isVideoCommentDeleteActivityValid } from './video-comments'
import {
isVideoFlagValid,
isVideoTorrentCreateActivityValid,
function checkDeleteActivity (activity: any) {
return isVideoTorrentDeleteActivityValid(activity) ||
- isActorDeleteActivityValid(activity)
+ isActorDeleteActivityValid(activity) ||
+ isVideoCommentDeleteActivityValid(activity)
}
function checkFollowActivity (activity: any) {
isActivityPubUrlValid(comment.url)
}
+function isVideoCommentDeleteActivityValid (activity: any) {
+ return isBaseActivityValid(activity, 'Delete')
+}
+
// ---------------------------------------------------------------------------
export {
- isVideoCommentCreateActivityValid
+ isVideoCommentCreateActivityValid,
+ isVideoCommentDeleteActivityValid
}
// ---------------------------------------------------------------------------
import { ActorModel } from '../../../models/activitypub/actor'
import { VideoModel } from '../../../models/video/video'
import { VideoChannelModel } from '../../../models/video/video-channel'
+import { VideoCommentModel } from '../../../models/video/video-comment'
import { getOrCreateActorAndServerAndModel } from '../actor'
async function processDeleteActivity (activity: ActivityDelete) {
}
{
- let videoObject = await VideoModel.loadByUrlAndPopulateAccount(activity.id)
- if (videoObject !== undefined) {
- return processDeleteVideo(actor, videoObject)
+ const videoCommentInstance = await VideoCommentModel.loadByUrlAndPopulateAccount(activity.id)
+ if (videoCommentInstance) {
+ return processDeleteVideoComment(actor, videoCommentInstance)
+ }
+ }
+
+ {
+ const videoInstance = await VideoModel.loadByUrlAndPopulateAccount(activity.id)
+ if (videoInstance) {
+ return processDeleteVideo(actor, videoInstance)
}
}
logger.info('Remote video channel with uuid %s removed.', videoChannelToRemove.Actor.uuid)
}
+
+async function processDeleteVideoComment (actor: ActorModel, videoComment: VideoCommentModel) {
+ const options = {
+ arguments: [ actor, videoComment ],
+ errorMessage: 'Cannot remove the remote video comment with many retries.'
+ }
+
+ await retryTransactionWrapper(deleteRemoteVideoComment, options)
+}
+
+function deleteRemoteVideoComment (actor: ActorModel, videoComment: VideoCommentModel) {
+ logger.debug('Removing remote video comment "%s".', videoComment.url)
+
+ return sequelizeTypescript.transaction(async t => {
+ await videoComment.destroy({ transaction: t })
+
+ logger.info('Remote video comment %s removed.', videoComment.url)
+ })
+}
import { ActivityDelete } from '../../../../shared/models/activitypub'
import { ActorModel } from '../../../models/activitypub/actor'
import { VideoModel } from '../../../models/video/video'
+import { VideoCommentModel } from '../../../models/video/video-comment'
import { VideoShareModel } from '../../../models/video/video-share'
import { broadcastToFollowers } from './misc'
return broadcastToFollowers(data, byActor, [ byActor ], t)
}
+async function sendDeleteVideoComment (videoComment: VideoCommentModel, t: Transaction) {
+ const byActor = videoComment.Account.Actor
+
+ const data = deleteActivityData(videoComment.url, byActor)
+
+ const actorsInvolved = await VideoShareModel.loadActorsByShare(videoComment.Video.id, t)
+ actorsInvolved.push(videoComment.Video.VideoChannel.Account.Actor)
+ actorsInvolved.push(byActor)
+
+ return broadcastToFollowers(data, byActor, actorsInvolved, t)
+}
+
// ---------------------------------------------------------------------------
export {
sendDeleteVideo,
- sendDeleteActor
+ sendDeleteActor,
+ sendDeleteVideoComment
}
// ---------------------------------------------------------------------------
import * as express from 'express'
import { body, param } from 'express-validator/check'
+import { UserRight } from '../../../shared'
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 { UserModel } from '../../models/account/user'
import { VideoModel } from '../../models/video/video'
import { VideoCommentModel } from '../../models/video/video-comment'
import { areValidationErrors } from './utils'
}
]
+const removeVideoCommentValidator = [
+ 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 removeVideoCommentValidator 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
+
+ // Check if the user who did the request is able to delete the video
+ if (!checkUserCanDeleteVideoComment(res.locals.oauth.token.User, res.locals.videoComment, res)) return
+
+ return next()
+ }
+]
+
// ---------------------------------------------------------------------------
export {
listVideoThreadCommentsValidator,
addVideoCommentThreadValidator,
addVideoCommentReplyValidator,
- videoCommentGetValidator
+ videoCommentGetValidator,
+ removeVideoCommentValidator
}
// ---------------------------------------------------------------------------
return true
}
+
+function checkUserCanDeleteVideoComment (user: UserModel, videoComment: VideoCommentModel, res: express.Response) {
+ const account = videoComment.Account
+ if (user.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT) === false && account.userId !== user.id) {
+ res.status(403)
+ .json({ error: 'Cannot remove video comment of another user' })
+ .end()
+ return false
+ }
+
+ return true
+}
}
// Check if the user can delete the video
- // The user can delete it if s/he is an admin
+ // The user can delete it if he has the right
// Or if s/he is the video's account
const account = video.VideoChannel.Account
if (user.hasRight(UserRight.REMOVE_ANY_VIDEO) === false && account.userId !== user.id) {
return {
id: this.id,
+ url: this.url,
uuid: this.uuid,
host: this.getHost(),
score,
import { VideoComment } from '../../../shared/models/videos/video-comment.model'
import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
import { CONSTRAINTS_FIELDS } from '../../initializers'
+import { sendDeleteVideoComment } from '../../lib/activitypub/send'
import { AccountModel } from '../account/account'
import { ActorModel } from '../activitypub/actor'
import { AvatarModel } from '../avatar/avatar'
import { ServerModel } from '../server/server'
import { getSort, throwIfNotValid } from '../utils'
import { VideoModel } from './video'
+import { VideoChannelModel } from './video-channel'
enum ScopeNames {
WITH_ACCOUNT = 'WITH_ACCOUNT',
include: [
{
model: () => VideoModel,
- required: false
+ required: true,
+ include: [
+ {
+ model: () => VideoChannelModel.unscoped(),
+ required: true,
+ include: [
+ {
+ model: () => AccountModel,
+ required: true,
+ include: [
+ {
+ model: () => ActorModel,
+ required: true
+ }
+ ]
+ }
+ ]
+ }
+ ]
}
]
}
Account: AccountModel
@AfterDestroy
- static sendDeleteIfOwned (instance: VideoCommentModel) {
- // TODO
- return undefined
+ static async sendDeleteIfOwned (instance: VideoCommentModel) {
+ if (instance.isOwned()) {
+ await sendDeleteVideoComment(instance, undefined)
+ }
}
static loadById (id: number, t?: Sequelize.Transaction) {
return VideoCommentModel.findOne(query)
}
+ static loadByUrlAndPopulateAccount (url: string, t?: Sequelize.Transaction) {
+ const query: IFindOptions<VideoCommentModel> = {
+ where: {
+ url
+ }
+ }
+
+ if (t !== undefined) query.transaction = t
+
+ return VideoCommentModel.scope([ ScopeNames.WITH_ACCOUNT ]).findOne(query)
+ }
+
static listThreadsForApi (videoId: number, start: number, count: number, sort: string) {
const query = {
offset: start,
})
}
+ isOwned () {
+ return this.Account.isOwned()
+ }
+
toFormattedJSON () {
return {
id: this.id,
enum ScopeNames {
AVAILABLE_FOR_LIST = 'AVAILABLE_FOR_LIST',
- WITH_ACCOUNT = 'WITH_ACCOUNT',
+ WITH_ACCOUNT_API = 'WITH_ACCOUNT_API',
+ WITH_ACCOUNT_DETAILS = 'WITH_ACCOUNT_DETAILS',
WITH_TAGS = 'WITH_TAGS',
WITH_FILES = 'WITH_FILES',
WITH_SHARES = 'WITH_SHARES',
privacy: VideoPrivacy.PUBLIC
}
},
- [ScopeNames.WITH_ACCOUNT]: {
+ [ScopeNames.WITH_ACCOUNT_API]: {
+ include: [
+ {
+ model: () => VideoChannelModel.unscoped(),
+ required: true,
+ include: [
+ {
+ attributes: [ 'name' ],
+ model: () => AccountModel.unscoped(),
+ required: true,
+ include: [
+ {
+ attributes: [ 'serverId' ],
+ model: () => ActorModel.unscoped(),
+ required: true,
+ include: [
+ {
+ model: () => ServerModel.unscoped(),
+ required: false
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ },
+ [ScopeNames.WITH_ACCOUNT_DETAILS]: {
include: [
{
model: () => VideoChannelModel,
},
{
fields: [ 'channelId' ]
+ },
+ {
+ fields: [ 'id', 'privacy' ]
}
]
})
order: [ getSort(sort) ]
}
- return VideoModel.scope([ ScopeNames.AVAILABLE_FOR_LIST, ScopeNames.WITH_ACCOUNT ])
+ return VideoModel.scope([ ScopeNames.AVAILABLE_FOR_LIST, ScopeNames.WITH_ACCOUNT_API ])
.findAndCountAll(query)
.then(({ rows, count }) => {
return {
if (t !== undefined) query.transaction = t
- return VideoModel.scope([ ScopeNames.WITH_ACCOUNT, ScopeNames.WITH_FILES ]).findOne(query)
+ return VideoModel.scope([ ScopeNames.WITH_ACCOUNT_DETAILS, ScopeNames.WITH_FILES ]).findOne(query)
}
static loadByUUIDOrURL (uuid: string, url: string, t?: Sequelize.Transaction) {
}
return VideoModel
- .scope([ ScopeNames.WITH_TAGS, ScopeNames.WITH_FILES, ScopeNames.WITH_ACCOUNT ])
+ .scope([ ScopeNames.WITH_TAGS, ScopeNames.WITH_FILES, ScopeNames.WITH_ACCOUNT_DETAILS ])
.findById(id, options)
}
}
return VideoModel
- .scope([ ScopeNames.WITH_TAGS, ScopeNames.WITH_FILES, ScopeNames.WITH_ACCOUNT ])
+ .scope([ ScopeNames.WITH_TAGS, ScopeNames.WITH_FILES, ScopeNames.WITH_ACCOUNT_DETAILS ])
.findOne(options)
}
ScopeNames.WITH_SHARES,
ScopeNames.WITH_TAGS,
ScopeNames.WITH_FILES,
- ScopeNames.WITH_ACCOUNT,
+ ScopeNames.WITH_ACCOUNT_DETAILS,
ScopeNames.WITH_COMMENTS
])
.findOne(options)
import * as chai from 'chai'
import 'mocha'
import {
- flushTests, killallServers, makeGetRequest, makePostBodyRequest, runServer, ServerInfo, setAccessTokensToServers,
- uploadVideo
+ createUser,
+ flushTests, killallServers, makeDeleteRequest, makeGetRequest, makePostBodyRequest, runServer, ServerInfo, setAccessTokensToServers,
+ uploadVideo, userLogin
} from '../../utils'
import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
import { addVideoCommentThread } from '../../utils/videos/video-comments'
let pathComment: string
let server: ServerInfo
let videoUUID: string
+ let userAccessToken: string
let commentId: number
// ---------------------------------------------------------------
commentId = res.body.comment.id
pathComment = '/api/v1/videos/' + videoUUID + '/comments/' + commentId
}
+
+ {
+ const user = {
+ username: 'user1',
+ password: 'my super password'
+ }
+ await createUser(server.url, server.accessToken, user.username, user.password)
+ userAccessToken = await userLogin(server, user)
+ }
})
describe('When listing video comment threads', function () {
})
})
+ describe('When removing video comments', function () {
+ it('Should fail with a non authenticated user', async function () {
+ await makeDeleteRequest({ url: server.url, path: pathComment, token: 'none', statusCodeExpected: 401 })
+ })
+
+ it('Should fail with another user', async function () {
+ await makeDeleteRequest({ url: server.url, path: pathComment, token: userAccessToken, statusCodeExpected: 403 })
+ })
+
+ it('Should fail with an incorrect video', async function () {
+ const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comments/' + commentId
+ await makeDeleteRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: 404 })
+ })
+
+ it('Should fail with an incorrect comment', async function () {
+ const path = '/api/v1/videos/' + videoUUID + '/comments/124'
+ await makeDeleteRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: 404 })
+ })
+
+ it('Should succeed with the correct parameters', async function () {
+ await makeDeleteRequest({ url: server.url, path: pathComment, token: server.accessToken, statusCodeExpected: 204 })
+ })
+ })
+
describe('When a video has comments disabled', function () {
before(async function () {
const res = await uploadVideo(server.url, server.accessToken, { commentsEnabled: false })
updateVideo, uploadVideo, userLogin, viewVideo, wait, webtorrentAdd
} from '../../utils'
import {
- addVideoCommentReply, addVideoCommentThread, getVideoCommentThreads,
+ addVideoCommentReply, addVideoCommentThread, deleteVideoComment, getVideoCommentThreads,
getVideoThreadComments
} from '../../utils/videos/video-comments'
}
})
+ it('Should delete the thread comments', async function () {
+ this.timeout(10000)
+
+ const res1 = await getVideoCommentThreads(servers[0].url, videoUUID, 0, 5)
+ const threadId = res1.body.data.find(c => c.text === 'my super first comment').id
+ await deleteVideoComment(servers[0].url, servers[0].accessToken, videoUUID, threadId)
+
+ await wait(5000)
+ })
+
+ it('Should have the thread comments deleted on other servers too', async function () {
+ for (const server of servers) {
+ const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5)
+
+ expect(res.body.total).to.equal(1)
+ expect(res.body.data).to.be.an('array')
+ expect(res.body.data).to.have.lengthOf(1)
+
+ {
+ const comment: VideoComment = res.body.data[0]
+ expect(comment).to.not.be.undefined
+ expect(comment.inReplyToCommentId).to.be.null
+ expect(comment.account.name).to.equal('root')
+ expect(comment.account.host).to.equal('localhost:9003')
+ expect(comment.totalReplies).to.equal(0)
+ expect(dateIsValid(comment.createdAt as string)).to.be.true
+ expect(dateIsValid(comment.updatedAt as string)).to.be.true
+ }
+ }
+ })
+
it('Should disable comments', async function () {
this.timeout(20000)
uploadVideo
} from '../../utils/index'
import {
- addVideoCommentReply, addVideoCommentThread, getVideoCommentThreads,
+ addVideoCommentReply, addVideoCommentThread, deleteVideoComment, getVideoCommentThreads,
getVideoThreadComments
} from '../../utils/videos/video-comments'
let videoId
let videoUUID
let threadId
+ let replyToDeleteId: number
before(async function () {
this.timeout(10000)
expect(comment.id).to.equal(comment.threadId)
expect(comment.account.name).to.equal('root')
expect(comment.account.host).to.equal('localhost:9001')
+ expect(comment.account.url).to.equal('http://localhost:9001/accounts/root')
expect(comment.totalReplies).to.equal(0)
expect(dateIsValid(comment.createdAt as string)).to.be.true
expect(dateIsValid(comment.updatedAt as string)).to.be.true
const secondChild = tree.children[1]
expect(secondChild.comment.text).to.equal('my second answer to thread 1')
expect(secondChild.children).to.have.lengthOf(0)
+
+ replyToDeleteId = secondChild.comment.id
})
it('Should create other threads', async function () {
expect(res.body.data[2].totalReplies).to.equal(0)
})
+ it('Should delete a reply', async function () {
+ await deleteVideoComment(server.url, server.accessToken, videoId, replyToDeleteId)
+
+ const res = await getVideoThreadComments(server.url, videoUUID, threadId)
+
+ const tree: VideoCommentThreadTree = res.body
+ expect(tree.comment.text).equal('my super first comment')
+ expect(tree.children).to.have.lengthOf(1)
+
+ const firstChild = tree.children[0]
+ expect(firstChild.comment.text).to.equal('my super answer to thread 1')
+ expect(firstChild.children).to.have.lengthOf(1)
+
+ const childOfFirstChild = firstChild.children[0]
+ expect(childOfFirstChild.comment.text).to.equal('my super answer to answer of thread 1')
+ expect(childOfFirstChild.children).to.have.lengthOf(0)
+ })
+
+ it('Should delete a complete thread', async function () {
+ await deleteVideoComment(server.url, server.accessToken, videoId, threadId)
+
+ const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5, 'createdAt')
+ expect(res.body.total).to.equal(2)
+ expect(res.body.data).to.be.an('array')
+ expect(res.body.data).to.have.lengthOf(2)
+
+ expect(res.body.data[0].text).to.equal('super thread 2')
+ expect(res.body.data[0].totalReplies).to.equal(0)
+ expect(res.body.data[1].text).to.equal('super thread 3')
+ expect(res.body.data[1].totalReplies).to.equal(0)
+ })
+
after(async function () {
killallServers([ server ])
import * as request from 'supertest'
+import { makeDeleteRequest } from '../'
function getVideoCommentThreads (url: string, videoId: number | string, start: number, count: number, sort?: string) {
const path = '/api/v1/videos/' + videoId + '/comment-threads'
.expect(expectedStatus)
}
+function deleteVideoComment (
+ url: string,
+ token: string,
+ videoId: number | string,
+ commentId: number,
+ statusCodeExpected = 204
+) {
+ const path = '/api/v1/videos/' + videoId + '/comments/' + commentId
+
+ return makeDeleteRequest({
+ url,
+ path,
+ token,
+ statusCodeExpected
+ })
+}
+
// ---------------------------------------------------------------------------
export {
getVideoCommentThreads,
getVideoThreadComments,
addVideoCommentThread,
- addVideoCommentReply
+ addVideoCommentReply,
+ deleteVideoComment
}
export interface Account {
id: number
uuid: string
+ url: string
name: string
displayName: string
host: string
MANAGE_VIDEO_BLACKLIST,
MANAGE_JOBS,
REMOVE_ANY_VIDEO,
- REMOVE_ANY_VIDEO_CHANNEL
+ REMOVE_ANY_VIDEO_CHANNEL,
+ REMOVE_ANY_VIDEO_COMMENT
}
UserRight.MANAGE_VIDEO_BLACKLIST,
UserRight.MANAGE_VIDEO_ABUSES,
UserRight.REMOVE_ANY_VIDEO,
- UserRight.REMOVE_ANY_VIDEO_CHANNEL
+ UserRight.REMOVE_ANY_VIDEO_CHANNEL,
+ UserRight.REMOVE_ANY_VIDEO_COMMENT
],
[UserRole.USER]: []
export interface VideoChannel {
id: number
name: string
+ url: string
description: string
isLocal: boolean
createdAt: Date | string