aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-11-16 11:55:17 +0100
committerChocobozzz <me@florianbigard.com>2020-11-16 13:48:58 +0100
commitf1273314593a4a7dc7ec9594ce0c6c3ae8f62b34 (patch)
treecf1f3949e64a24a820833950d7b2bbf9ccd40013
parent0f8d00e3144060270d7fe603865fccaf18649c47 (diff)
downloadPeerTube-f1273314593a4a7dc7ec9594ce0c6c3ae8f62b34.tar.gz
PeerTube-f1273314593a4a7dc7ec9594ce0c6c3ae8f62b34.tar.zst
PeerTube-f1273314593a4a7dc7ec9594ce0c6c3ae8f62b34.zip
Add admin view to manage comments
-rw-r--r--client/src/app/+admin/moderation/video-block-list/video-block-list.component.scss8
-rw-r--r--client/src/app/+admin/moderation/video-comment-list/video-comment-list.component.html36
-rw-r--r--client/src/app/+admin/moderation/video-comment-list/video-comment-list.component.scss51
-rw-r--r--client/src/app/+admin/moderation/video-comment-list/video-comment-list.component.ts86
-rw-r--r--client/src/app/shared/shared-main/feeds/feed.component.html2
-rw-r--r--client/src/app/shared/shared-main/feeds/feed.component.scss2
-rw-r--r--client/src/app/shared/shared-video-comment/video-comment.model.ts11
-rw-r--r--client/src/app/shared/shared-video-comment/video-comment.service.ts7
-rw-r--r--server/middlewares/validators/users.ts1
-rw-r--r--server/middlewares/validators/videos/video-comments.ts3
-rw-r--r--server/models/video/video-comment.ts84
-rw-r--r--server/tests/api/check-params/users.ts12
-rw-r--r--server/tests/api/check-params/video-comments.ts48
-rw-r--r--server/tests/api/videos/multiple-servers.ts2
-rw-r--r--server/tests/api/videos/video-comments.ts354
-rw-r--r--shared/extra-utils/videos/video-comments.ts37
16 files changed, 503 insertions, 241 deletions
diff --git a/client/src/app/+admin/moderation/video-block-list/video-block-list.component.scss b/client/src/app/+admin/moderation/video-block-list/video-block-list.component.scss
index c92d1c39c..0e34150c1 100644
--- a/client/src/app/+admin/moderation/video-block-list/video-block-list.component.scss
+++ b/client/src/app/+admin/moderation/video-block-list/video-block-list.component.scss
@@ -1,12 +1,8 @@
1@import 'mixins'; 1@import 'mixins';
2 2
3my-global-icon { 3my-global-icon {
4 @include apply-svg-color(#7d7d7d); 4 width: 24px;
5 5 height: 24px;
6 width: 12px;
7 height: 12px;
8 position: relative;
9 top: -1px;
10} 6}
11 7
12.input-group { 8.input-group {
diff --git a/client/src/app/+admin/moderation/video-comment-list/video-comment-list.component.html b/client/src/app/+admin/moderation/video-comment-list/video-comment-list.component.html
index b4f66a75f..45c5fe28f 100644
--- a/client/src/app/+admin/moderation/video-comment-list/video-comment-list.component.html
+++ b/client/src/app/+admin/moderation/video-comment-list/video-comment-list.component.html
@@ -1,9 +1,11 @@
1<h1> 1<h1>
2 <my-global-icon iconName="cross" aria-hidden="true"></my-global-icon> 2 <my-global-icon iconName="message-circle" aria-hidden="true"></my-global-icon>
3 <ng-container i18n>Video comments</ng-container> 3 <ng-container i18n>Video comments</ng-container>
4
5 <my-feed [syndicationItems]="syndicationItems"></my-feed>
4</h1> 6</h1>
5 7
6this view does show comments from muted accounts so you can delete them 8<em>This view also shows comments from muted accounts.</em>
7 9
8<p-table 10<p-table
9 [value]="comments" [lazy]="true" [paginator]="totalRecords > 0" [totalRecords]="totalRecords" [rows]="rowsPerPage" [rowsPerPageOptions]="rowsPerPageOptions" 11 [value]="comments" [lazy]="true" [paginator]="totalRecords > 0" [totalRecords]="totalRecords" [rows]="rowsPerPage" [rowsPerPageOptions]="rowsPerPageOptions"
@@ -29,7 +31,7 @@ this view does show comments from muted accounts so you can delete them
29 </div> 31 </div>
30 <input 32 <input
31 type="text" name="table-filter" id="table-filter" i18n-placeholder placeholder="Filter..." 33 type="text" name="table-filter" id="table-filter" i18n-placeholder placeholder="Filter..."
32 (keyup)="onSearch($event)" 34 (keyup)="onInputSearch($event)"
33 > 35 >
34 <a class="glyphicon glyphicon-remove-sign form-control-feedback form-control-clear" (click)="resetTableFilter()"></a> 36 <a class="glyphicon glyphicon-remove-sign form-control-feedback form-control-clear" (click)="resetTableFilter()"></a>
35 <span class="sr-only" i18n>Clear filters</span> 37 <span class="sr-only" i18n>Clear filters</span>
@@ -41,9 +43,9 @@ this view does show comments from muted accounts so you can delete them
41 <ng-template pTemplate="header"> 43 <ng-template pTemplate="header">
42 <tr> 44 <tr>
43 <th style="width: 40px"></th> 45 <th style="width: 40px"></th>
44 <th style="width: 100px;" i18n>Account</th> 46 <th style="width: 300px" i18n>Account</th>
45 <th style="width: 100px;" i18n>Video</th> 47 <th style="width: 300px" i18n>Video</th>
46 <th style="width: 100px;" i18n>Comment</th> 48 <th i18n>Comment</th>
47 <th style="width: 150px;" i18n pSortableColumn="createdAt">Date <p-sortIcon field="createdAt"></p-sortIcon></th> 49 <th style="width: 150px;" i18n pSortableColumn="createdAt">Date <p-sortIcon field="createdAt"></p-sortIcon></th>
48 <th style="width: 150px;"></th> 50 <th style="width: 150px;"></th>
49 </tr> 51 </tr>
@@ -58,14 +60,28 @@ this view does show comments from muted accounts so you can delete them
58 </td> 60 </td>
59 61
60 <td> 62 <td>
61 {{ videoComment.by }} 63 <a [href]="videoComment.account.localUrl" i18n-title title="Open account in a new tab" target="_blank" rel="noopener noreferrer">
64 <div class="chip two-lines">
65 <img
66 class="avatar"
67 [src]="videoComment.accountAvatarUrl"
68 alt=""
69 >
70 <div>
71 {{ videoComment.account.displayName }}
72 <span>{{ videoComment.by }}</span>
73 </div>
74 </div>
75 </a>
62 </td> 76 </td>
63 77
64 <td> 78 <td class="video">
65 {{ videoComment.video.name }} 79 <em i18n>Commented video</em>
80
81 <a [href]="videoComment.localUrl" target="_blank" rel="noopener noreferrer">{{ videoComment.video.name }}</a>
66 </td> 82 </td>
67 83
68 <td> 84 <td class="comment-html">
69 <div [innerHTML]="videoComment.textHtml"></div> 85 <div [innerHTML]="videoComment.textHtml"></div>
70 </td> 86 </td>
71 87
diff --git a/client/src/app/+admin/moderation/video-comment-list/video-comment-list.component.scss b/client/src/app/+admin/moderation/video-comment-list/video-comment-list.component.scss
index c92d1c39c..b3746b0c5 100644
--- a/client/src/app/+admin/moderation/video-comment-list/video-comment-list.component.scss
+++ b/client/src/app/+admin/moderation/video-comment-list/video-comment-list.component.scss
@@ -1,12 +1,22 @@
1@import 'mixins'; 1@import 'mixins';
2 2
3my-global-icon { 3h1 {
4 @include apply-svg-color(#7d7d7d); 4 my-feed {
5 margin-left: 5px;
6 display: inline-block;
7
8 ::ng-deep {
9 my-global-icon {
10 width: 15px !important;
11 top: 0 !important;
12 }
13 }
14 }
15}
5 16
6 width: 12px; 17my-global-icon {
7 height: 12px; 18 width: 24px;
8 position: relative; 19 height: 24px;
9 top: -1px;
10} 20}
11 21
12.input-group { 22.input-group {
@@ -25,3 +35,32 @@ my-global-icon {
25 flex-grow: 1; 35 flex-grow: 1;
26 } 36 }
27} 37}
38
39.video {
40 display: flex;
41 flex-direction: column;
42
43 em {
44 font-size: 11px;
45 }
46
47 a {
48 @include ellipsis
49 }
50}
51
52.comment-html {
53 ::ng-deep {
54 > div {
55 max-height: 22px;
56 }
57
58 div, p {
59 @include ellipsis;
60 }
61
62 p {
63 margin: 0;
64 }
65 }
66}
diff --git a/client/src/app/+admin/moderation/video-comment-list/video-comment-list.component.ts b/client/src/app/+admin/moderation/video-comment-list/video-comment-list.component.ts
index fdd5ec76e..d26047125 100644
--- a/client/src/app/+admin/moderation/video-comment-list/video-comment-list.component.ts
+++ b/client/src/app/+admin/moderation/video-comment-list/video-comment-list.component.ts
@@ -1,16 +1,17 @@
1import { SortMeta } from 'primeng/api' 1import { SortMeta } from 'primeng/api'
2import { filter } from 'rxjs/operators' 2import { filter } from 'rxjs/operators'
3import { AfterViewInit, Component, OnInit } from '@angular/core' 3import { AfterViewInit, Component, OnInit } from '@angular/core'
4import { DomSanitizer } from '@angular/platform-browser'
5import { ActivatedRoute, Params, Router } from '@angular/router' 4import { ActivatedRoute, Params, Router } from '@angular/router'
6import { ConfirmService, MarkdownService, Notifier, RestPagination, RestTable, ServerService } from '@app/core' 5import { AuthService, ConfirmService, MarkdownService, Notifier, RestPagination, RestTable } from '@app/core'
7import { DropdownAction, VideoService } from '@app/shared/shared-main' 6import { DropdownAction } from '@app/shared/shared-main'
7import { BulkService } from '@app/shared/shared-moderation'
8import { VideoCommentAdmin, VideoCommentService } from '@app/shared/shared-video-comment' 8import { VideoCommentAdmin, VideoCommentService } from '@app/shared/shared-video-comment'
9import { FeedFormat, UserRight } from '@shared/models'
9 10
10@Component({ 11@Component({
11 selector: 'my-video-comment-list', 12 selector: 'my-video-comment-list',
12 templateUrl: './video-comment-list.component.html', 13 templateUrl: './video-comment-list.component.html',
13 styleUrls: [ './video-comment-list.component.scss' ] 14 styleUrls: [ '../../../shared/shared-moderation/moderation.scss', './video-comment-list.component.scss' ]
14}) 15})
15export class VideoCommentListComponent extends RestTable implements OnInit, AfterViewInit { 16export class VideoCommentListComponent extends RestTable implements OnInit, AfterViewInit {
16 comments: VideoCommentAdmin[] 17 comments: VideoCommentAdmin[]
@@ -20,26 +21,54 @@ export class VideoCommentListComponent extends RestTable implements OnInit, Afte
20 21
21 videoCommentActions: DropdownAction<VideoCommentAdmin>[][] = [] 22 videoCommentActions: DropdownAction<VideoCommentAdmin>[][] = []
22 23
24 syndicationItems = [
25 {
26 format: FeedFormat.RSS,
27 label: 'media rss 2.0',
28 url: VideoCommentService.BASE_FEEDS_URL + FeedFormat.RSS.toLowerCase()
29 },
30 {
31 format: FeedFormat.ATOM,
32 label: 'atom 1.0',
33 url: VideoCommentService.BASE_FEEDS_URL + FeedFormat.ATOM.toLowerCase()
34 },
35 {
36 format: FeedFormat.JSON,
37 label: 'json 1.0',
38 url: VideoCommentService.BASE_FEEDS_URL + FeedFormat.JSON.toLowerCase()
39 }
40 ]
41
42 get authUser () {
43 return this.auth.getUser()
44 }
45
23 constructor ( 46 constructor (
47 private auth: AuthService,
24 private notifier: Notifier, 48 private notifier: Notifier,
25 private serverService: ServerService,
26 private confirmService: ConfirmService, 49 private confirmService: ConfirmService,
27 private videoCommentService: VideoCommentService, 50 private videoCommentService: VideoCommentService,
28 private markdownRenderer: MarkdownService, 51 private markdownRenderer: MarkdownService,
29 private sanitizer: DomSanitizer,
30 private videoService: VideoService,
31 private route: ActivatedRoute, 52 private route: ActivatedRoute,
32 private router: Router 53 private router: Router,
54 private bulkService: BulkService
33 ) { 55 ) {
34 super() 56 super()
35 57
36 this.videoCommentActions = [ 58 this.videoCommentActions = [
37 [ 59 [
60 {
61 label: $localize`Delete this comment`,
62 handler: comment => this.deleteComment(comment),
63 isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT)
64 },
38 65
39 // remove this comment, 66 {
40 67 label: $localize`Delete all comments of this account`,
41 // remove all comments of this account 68 description: $localize`Comments are deleted after a few minutes`,
42 69 handler: comment => this.deleteUserComments(comment),
70 isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT)
71 }
43 ] 72 ]
44 ] 73 ]
45 } 74 }
@@ -60,7 +89,7 @@ export class VideoCommentListComponent extends RestTable implements OnInit, Afte
60 if (this.search) this.setTableFilter(this.search) 89 if (this.search) this.setTableFilter(this.search)
61 } 90 }
62 91
63 onSearch (event: Event) { 92 onInputSearch (event: Event) {
64 this.onSearch(event) 93 this.onSearch(event)
65 this.setQueryParams((event.target as HTMLInputElement).value) 94 this.setQueryParams((event.target as HTMLInputElement).value)
66 } 95 }
@@ -84,7 +113,7 @@ export class VideoCommentListComponent extends RestTable implements OnInit, Afte
84 } 113 }
85 114
86 toHtml (text: string) { 115 toHtml (text: string) {
87 return this.markdownRenderer.textMarkdownToHTML(text) 116 return this.markdownRenderer.textMarkdownToHTML(text, true, true)
88 } 117 }
89 118
90 protected loadData () { 119 protected loadData () {
@@ -108,4 +137,33 @@ export class VideoCommentListComponent extends RestTable implements OnInit, Afte
108 err => this.notifier.error(err.message) 137 err => this.notifier.error(err.message)
109 ) 138 )
110 } 139 }
140
141 private deleteComment (comment: VideoCommentAdmin) {
142 this.videoCommentService.deleteVideoComment(comment.video.id, comment.id)
143 .subscribe(
144 () => this.loadData(),
145
146 err => this.notifier.error(err.message)
147 )
148 }
149
150 private async deleteUserComments (comment: VideoCommentAdmin) {
151 const message = $localize`Do you really want to delete all comments of ${comment.by}?`
152 const res = await this.confirmService.confirm(message, $localize`Delete`)
153 if (res === false) return
154
155 const options = {
156 accountName: comment.by,
157 scope: 'instance' as 'instance'
158 }
159
160 this.bulkService.removeCommentsOf(options)
161 .subscribe(
162 () => {
163 this.notifier.success($localize`Comments of ${options.accountName} will be deleted in a few minutes`)
164 },
165
166 err => this.notifier.error(err.message)
167 )
168 }
111} 169}
diff --git a/client/src/app/shared/shared-main/feeds/feed.component.html b/client/src/app/shared/shared-main/feeds/feed.component.html
index 13883fd9b..a00011785 100644
--- a/client/src/app/shared/shared-main/feeds/feed.component.html
+++ b/client/src/app/shared/shared-main/feeds/feed.component.html
@@ -1,4 +1,4 @@
1<div class="video-feed"> 1<div class="feed">
2 <my-global-icon 2 <my-global-icon
3 *ngIf="syndicationItems.length !== 0" [ngbPopover]="feedsList" [autoClose]="true" placement="bottom left auto" 3 *ngIf="syndicationItems.length !== 0" [ngbPopover]="feedsList" [autoClose]="true" placement="bottom left auto"
4 class="icon-syndication" role="button" iconName="syndication" 4 class="icon-syndication" role="button" iconName="syndication"
diff --git a/client/src/app/shared/shared-main/feeds/feed.component.scss b/client/src/app/shared/shared-main/feeds/feed.component.scss
index 34dd0e937..333d59440 100644
--- a/client/src/app/shared/shared-main/feeds/feed.component.scss
+++ b/client/src/app/shared/shared-main/feeds/feed.component.scss
@@ -1,7 +1,7 @@
1@import '_variables'; 1@import '_variables';
2@import '_mixins'; 2@import '_mixins';
3 3
4.video-feed { 4.feed {
5 width: min-content; 5 width: min-content;
6 6
7 a { 7 a {
diff --git a/client/src/app/shared/shared-video-comment/video-comment.model.ts b/client/src/app/shared/shared-video-comment/video-comment.model.ts
index 1589091e5..eeee397af 100644
--- a/client/src/app/shared/shared-video-comment/video-comment.model.ts
+++ b/client/src/app/shared/shared-video-comment/video-comment.model.ts
@@ -59,12 +59,14 @@ export class VideoCommentAdmin implements VideoCommentAdminServerModel {
59 createdAt: Date | string 59 createdAt: Date | string
60 updatedAt: Date | string 60 updatedAt: Date | string
61 61
62 account: AccountInterface 62 account: AccountInterface & { localUrl?: string }
63 localUrl: string
63 64
64 video: { 65 video: {
65 id: number 66 id: number
66 uuid: string 67 uuid: string
67 name: string 68 name: string
69 localUrl: string
68 } 70 }
69 71
70 by: string 72 by: string
@@ -85,14 +87,19 @@ export class VideoCommentAdmin implements VideoCommentAdminServerModel {
85 this.video = { 87 this.video = {
86 id: hash.video.id, 88 id: hash.video.id,
87 uuid: hash.video.uuid, 89 uuid: hash.video.uuid,
88 name: hash.video.name 90 name: hash.video.name,
91 localUrl: '/videos/watch/' + hash.video.uuid
89 } 92 }
90 93
94 this.localUrl = this.video.localUrl + ';threadId=' + this.threadId
95
91 this.account = hash.account 96 this.account = hash.account
92 97
93 if (this.account) { 98 if (this.account) {
94 this.by = Actor.CREATE_BY_STRING(this.account.name, this.account.host) 99 this.by = Actor.CREATE_BY_STRING(this.account.name, this.account.host)
95 this.accountAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.account) 100 this.accountAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.account)
101
102 this.account.localUrl = '/accounts/' + this.by
96 } 103 }
97 } 104 }
98} 105}
diff --git a/client/src/app/shared/shared-video-comment/video-comment.service.ts b/client/src/app/shared/shared-video-comment/video-comment.service.ts
index e318e069d..1ab996a76 100644
--- a/client/src/app/shared/shared-video-comment/video-comment.service.ts
+++ b/client/src/app/shared/shared-video-comment/video-comment.service.ts
@@ -19,8 +19,9 @@ import { SortMeta } from 'primeng/api'
19 19
20@Injectable() 20@Injectable()
21export class VideoCommentService { 21export class VideoCommentService {
22 static BASE_FEEDS_URL = environment.apiUrl + '/feeds/video-comments.'
23
22 private static BASE_VIDEO_URL = environment.apiUrl + '/api/v1/videos/' 24 private static BASE_VIDEO_URL = environment.apiUrl + '/api/v1/videos/'
23 private static BASE_FEEDS_URL = environment.apiUrl + '/feeds/video-comments.'
24 25
25 constructor ( 26 constructor (
26 private authHttp: HttpClient, 27 private authHttp: HttpClient,
@@ -56,7 +57,7 @@ export class VideoCommentService {
56 search?: string 57 search?: string
57 }): Observable<ResultList<VideoCommentAdmin>> { 58 }): Observable<ResultList<VideoCommentAdmin>> {
58 const { pagination, sort, search } = options 59 const { pagination, sort, search } = options
59 const url = VideoCommentService.BASE_VIDEO_URL + '/comments' 60 const url = VideoCommentService.BASE_VIDEO_URL + 'comments'
60 61
61 let params = new HttpParams() 62 let params = new HttpParams()
62 params = this.restService.addRestGetParams(params, pagination, sort) 63 params = this.restService.addRestGetParams(params, pagination, sort)
@@ -172,7 +173,7 @@ export class VideoCommentService {
172 173
173 private buildParamsFromSearch (search: string, params: HttpParams) { 174 private buildParamsFromSearch (search: string, params: HttpParams) {
174 const filters = this.restService.parseQueryStringFilter(search, { 175 const filters = this.restService.parseQueryStringFilter(search, {
175 state: { 176 isLocal: {
176 prefix: 'local:', 177 prefix: 'local:',
177 isBoolean: true, 178 isBoolean: true,
178 handler: v => { 179 handler: v => {
diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts
index 452c7fb93..c91c378b3 100644
--- a/server/middlewares/validators/users.ts
+++ b/server/middlewares/validators/users.ts
@@ -41,6 +41,7 @@ import { Hooks } from '@server/lib/plugins/hooks'
41const usersListValidator = [ 41const usersListValidator = [
42 query('blocked') 42 query('blocked')
43 .optional() 43 .optional()
44 .customSanitizer(toBooleanOrNull)
44 .isBoolean().withMessage('Should be a valid boolean banned state'), 45 .isBoolean().withMessage('Should be a valid boolean banned state'),
45 46
46 (req: express.Request, res: express.Response, next: express.NextFunction) => { 47 (req: express.Request, res: express.Response, next: express.NextFunction) => {
diff --git a/server/middlewares/validators/videos/video-comments.ts b/server/middlewares/validators/videos/video-comments.ts
index 55fb60b98..a3c9febc4 100644
--- a/server/middlewares/validators/videos/video-comments.ts
+++ b/server/middlewares/validators/videos/video-comments.ts
@@ -2,7 +2,7 @@ import * as express from 'express'
2import { body, param, query } from 'express-validator' 2import { body, param, query } from 'express-validator'
3import { MUserAccountUrl } from '@server/types/models' 3import { MUserAccountUrl } from '@server/types/models'
4import { UserRight } from '../../../../shared' 4import { UserRight } from '../../../../shared'
5import { exists, isBooleanValid, isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' 5import { exists, isBooleanValid, isIdOrUUIDValid, isIdValid, toBooleanOrNull } from '../../../helpers/custom-validators/misc'
6import { 6import {
7 doesVideoCommentExist, 7 doesVideoCommentExist,
8 doesVideoCommentThreadExist, 8 doesVideoCommentThreadExist,
@@ -18,6 +18,7 @@ import { areValidationErrors } from '../utils'
18const listVideoCommentsValidator = [ 18const listVideoCommentsValidator = [
19 query('isLocal') 19 query('isLocal')
20 .optional() 20 .optional()
21 .customSanitizer(toBooleanOrNull)
21 .custom(isBooleanValid) 22 .custom(isBooleanValid)
22 .withMessage('Should have a valid is local boolean'), 23 .withMessage('Should have a valid is local boolean'),
23 24
diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts
index 70aed75d6..ed4a345eb 100644
--- a/server/models/video/video-comment.ts
+++ b/server/models/video/video-comment.ts
@@ -323,14 +323,8 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
323 }) { 323 }) {
324 const { start, count, sort, isLocal, search, searchAccount, searchVideo } = parameters 324 const { start, count, sort, isLocal, search, searchAccount, searchVideo } = parameters
325 325
326 const query: FindAndCountOptions = {
327 offset: start,
328 limit: count,
329 order: getCommentSort(sort)
330 }
331
332 const where: WhereOptions = { 326 const where: WhereOptions = {
333 isDeleted: false 327 deletedAt: null
334 } 328 }
335 329
336 const whereAccount: WhereOptions = {} 330 const whereAccount: WhereOptions = {}
@@ -338,11 +332,11 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
338 const whereVideo: WhereOptions = {} 332 const whereVideo: WhereOptions = {}
339 333
340 if (isLocal === true) { 334 if (isLocal === true) {
341 Object.assign(where, { 335 Object.assign(whereActor, {
342 serverId: null 336 serverId: null
343 }) 337 })
344 } else if (isLocal === false) { 338 } else if (isLocal === false) {
345 Object.assign(where, { 339 Object.assign(whereActor, {
346 serverId: { 340 serverId: {
347 [Op.ne]: null 341 [Op.ne]: null
348 } 342 }
@@ -350,43 +344,57 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
350 } 344 }
351 345
352 if (search) { 346 if (search) {
353 Object.assign(where, searchAttribute(search, 'text')) 347 Object.assign(where, {
354 Object.assign(whereActor, searchAttribute(search, 'preferredUsername')) 348 [Op.or]: [
355 Object.assign(whereAccount, searchAttribute(search, 'name')) 349 searchAttribute(search, 'text'),
356 Object.assign(whereVideo, searchAttribute(search, 'name')) 350 searchAttribute(search, '$Account.Actor.preferredUsername$'),
351 searchAttribute(search, '$Account.name$'),
352 searchAttribute(search, '$Video.name$')
353 ]
354 })
357 } 355 }
358 356
359 if (searchAccount) { 357 if (searchAccount) {
360 Object.assign(whereActor, searchAttribute(search, 'preferredUsername')) 358 Object.assign(whereActor, {
361 Object.assign(whereAccount, searchAttribute(search, 'name')) 359 [Op.or]: [
360 searchAttribute(searchAccount, '$Account.Actor.preferredUsername$'),
361 searchAttribute(searchAccount, '$Account.name$')
362 ]
363 })
362 } 364 }
363 365
364 if (searchVideo) { 366 if (searchVideo) {
365 Object.assign(whereVideo, searchAttribute(search, 'name')) 367 Object.assign(whereVideo, searchAttribute(searchVideo, 'name'))
366 } 368 }
367 369
368 query.include = [ 370 const query: FindAndCountOptions = {
369 { 371 offset: start,
370 model: AccountModel.unscoped(), 372 limit: count,
371 required: !!searchAccount, 373 order: getCommentSort(sort),
372 where: whereAccount, 374 where,
373 include: [ 375 include: [
374 { 376 {
375 attributes: { 377 model: AccountModel.unscoped(),
376 exclude: unusedActorAttributesForAPI 378 required: true,
377 }, 379 where: whereAccount,
378 model: ActorModel, // Default scope includes avatar and server 380 include: [
379 required: true, 381 {
380 where: whereActor 382 attributes: {
381 } 383 exclude: unusedActorAttributesForAPI
382 ] 384 },
383 }, 385 model: ActorModel, // Default scope includes avatar and server
384 { 386 required: true,
385 model: VideoModel.unscoped(), 387 where: whereActor
386 required: true, 388 }
387 where: whereVideo 389 ]
388 } 390 },
389 ] 391 {
392 model: VideoModel.unscoped(),
393 required: true,
394 where: whereVideo
395 }
396 ]
397 }
390 398
391 return VideoCommentModel 399 return VideoCommentModel
392 .findAndCountAll(query) 400 .findAndCountAll(query)
diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts
index 3e53c445d..2a220be83 100644
--- a/server/tests/api/check-params/users.ts
+++ b/server/tests/api/check-params/users.ts
@@ -154,18 +154,6 @@ describe('Test users API validators', function () {
154 await checkBadSortPagination(server.url, path, server.accessToken) 154 await checkBadSortPagination(server.url, path, server.accessToken)
155 }) 155 })
156 156
157 it('Should fail with a bad blocked/banned user filter', async function () {
158 await makeGetRequest({
159 url: server.url,
160 path,
161 query: {
162 blocked: 42
163 },
164 token: server.accessToken,
165 statusCodeExpected: 400
166 })
167 })
168
169 it('Should fail with a non authenticated user', async function () { 157 it('Should fail with a non authenticated user', async function () {
170 await makeGetRequest({ 158 await makeGetRequest({
171 url: server.url, 159 url: server.url,
diff --git a/server/tests/api/check-params/video-comments.ts b/server/tests/api/check-params/video-comments.ts
index 181282ce1..662d4a70d 100644
--- a/server/tests/api/check-params/video-comments.ts
+++ b/server/tests/api/check-params/video-comments.ts
@@ -296,6 +296,54 @@ describe('Test video comments API validator', function () {
296 it('Should return conflict on comment thread add') 296 it('Should return conflict on comment thread add')
297 }) 297 })
298 298
299 describe('When listing admin comments threads', function () {
300 const path = '/api/v1/videos/comments'
301
302 it('Should fail with a bad start pagination', async function () {
303 await checkBadStartPagination(server.url, path, server.accessToken)
304 })
305
306 it('Should fail with a bad count pagination', async function () {
307 await checkBadCountPagination(server.url, path, server.accessToken)
308 })
309
310 it('Should fail with an incorrect sort', async function () {
311 await checkBadSortPagination(server.url, path, server.accessToken)
312 })
313
314 it('Should fail with a non authenticated user', async function () {
315 await makeGetRequest({
316 url: server.url,
317 path,
318 statusCodeExpected: 401
319 })
320 })
321
322 it('Should fail with a non admin user', async function () {
323 await makeGetRequest({
324 url: server.url,
325 path,
326 token: userAccessToken,
327 statusCodeExpected: 403
328 })
329 })
330
331 it('Should succeed with the correct params', async function () {
332 await makeGetRequest({
333 url: server.url,
334 path,
335 token: server.accessToken,
336 query: {
337 isLocal: false,
338 search: 'toto',
339 searchAccount: 'toto',
340 searchVideo: 'toto'
341 },
342 statusCodeExpected: 200
343 })
344 })
345 })
346
299 after(async function () { 347 after(async function () {
300 await cleanupTests([ server ]) 348 await cleanupTests([ server ])
301 }) 349 })
diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts
index d7b04373f..c90fd09fb 100644
--- a/server/tests/api/videos/multiple-servers.ts
+++ b/server/tests/api/videos/multiple-servers.ts
@@ -158,7 +158,7 @@ describe('Test multiple servers', function () {
158 }) 158 })
159 159
160 it('Should upload the video on server 2 and propagate on each server', async function () { 160 it('Should upload the video on server 2 and propagate on each server', async function () {
161 this.timeout(50000) 161 this.timeout(100000)
162 162
163 const user = { 163 const user = {
164 username: 'user1', 164 username: 'user1',
diff --git a/server/tests/api/videos/video-comments.ts b/server/tests/api/videos/video-comments.ts
index afb58e95a..18a86bead 100644
--- a/server/tests/api/videos/video-comments.ts
+++ b/server/tests/api/videos/video-comments.ts
@@ -2,7 +2,7 @@
2 2
3import * as chai from 'chai' 3import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model' 5import { VideoComment, VideoCommentAdmin, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model'
6import { cleanupTests, testImage } from '../../../../shared/extra-utils' 6import { cleanupTests, testImage } from '../../../../shared/extra-utils'
7import { 7import {
8 createUser, 8 createUser,
@@ -18,9 +18,11 @@ import {
18 addVideoCommentReply, 18 addVideoCommentReply,
19 addVideoCommentThread, 19 addVideoCommentThread,
20 deleteVideoComment, 20 deleteVideoComment,
21 getAdminVideoComments,
21 getVideoCommentThreads, 22 getVideoCommentThreads,
22 getVideoThreadComments 23 getVideoThreadComments
23} from '../../../../shared/extra-utils/videos/video-comments' 24} from '../../../../shared/extra-utils/videos/video-comments'
25import { isLocalLiveVideoAccepted } from '@server/lib/moderation'
24 26
25const expect = chai.expect 27const expect = chai.expect
26 28
@@ -59,186 +61,248 @@ describe('Test video comments', function () {
59 userAccessTokenServer1 = await getAccessToken(server.url, 'user1', 'password') 61 userAccessTokenServer1 = await getAccessToken(server.url, 'user1', 'password')
60 }) 62 })
61 63
62 it('Should not have threads on this video', async function () { 64 describe('User comments', function () {
63 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5)
64 65
65 expect(res.body.total).to.equal(0) 66 it('Should not have threads on this video', async function () {
66 expect(res.body.data).to.be.an('array') 67 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5)
67 expect(res.body.data).to.have.lengthOf(0)
68 })
69 68
70 it('Should create a thread in this video', async function () { 69 expect(res.body.total).to.equal(0)
71 const text = 'my super first comment' 70 expect(res.body.data).to.be.an('array')
72 71 expect(res.body.data).to.have.lengthOf(0)
73 const res = await addVideoCommentThread(server.url, server.accessToken, videoUUID, text) 72 })
74 const comment = res.body.comment
75
76 expect(comment.inReplyToCommentId).to.be.null
77 expect(comment.text).equal('my super first comment')
78 expect(comment.videoId).to.equal(videoId)
79 expect(comment.id).to.equal(comment.threadId)
80 expect(comment.account.name).to.equal('root')
81 expect(comment.account.host).to.equal('localhost:' + server.port)
82 expect(comment.account.url).to.equal('http://localhost:' + server.port + '/accounts/root')
83 expect(comment.totalReplies).to.equal(0)
84 expect(comment.totalRepliesFromVideoAuthor).to.equal(0)
85 expect(dateIsValid(comment.createdAt as string)).to.be.true
86 expect(dateIsValid(comment.updatedAt as string)).to.be.true
87 })
88 73
89 it('Should list threads of this video', async function () { 74 it('Should create a thread in this video', async function () {
90 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5) 75 const text = 'my super first comment'
76
77 const res = await addVideoCommentThread(server.url, server.accessToken, videoUUID, text)
78 const comment = res.body.comment
79
80 expect(comment.inReplyToCommentId).to.be.null
81 expect(comment.text).equal('my super first comment')
82 expect(comment.videoId).to.equal(videoId)
83 expect(comment.id).to.equal(comment.threadId)
84 expect(comment.account.name).to.equal('root')
85 expect(comment.account.host).to.equal('localhost:' + server.port)
86 expect(comment.account.url).to.equal('http://localhost:' + server.port + '/accounts/root')
87 expect(comment.totalReplies).to.equal(0)
88 expect(comment.totalRepliesFromVideoAuthor).to.equal(0)
89 expect(dateIsValid(comment.createdAt as string)).to.be.true
90 expect(dateIsValid(comment.updatedAt as string)).to.be.true
91 })
91 92
92 expect(res.body.total).to.equal(1) 93 it('Should list threads of this video', async function () {
93 expect(res.body.data).to.be.an('array') 94 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5)
94 expect(res.body.data).to.have.lengthOf(1)
95 95
96 const comment: VideoComment = res.body.data[0] 96 expect(res.body.total).to.equal(1)
97 expect(comment.inReplyToCommentId).to.be.null 97 expect(res.body.data).to.be.an('array')
98 expect(comment.text).equal('my super first comment') 98 expect(res.body.data).to.have.lengthOf(1)
99 expect(comment.videoId).to.equal(videoId)
100 expect(comment.id).to.equal(comment.threadId)
101 expect(comment.account.name).to.equal('root')
102 expect(comment.account.host).to.equal('localhost:' + server.port)
103 99
104 await testImage(server.url, 'avatar-resized', comment.account.avatar.path, '.png') 100 const comment: VideoComment = res.body.data[0]
101 expect(comment.inReplyToCommentId).to.be.null
102 expect(comment.text).equal('my super first comment')
103 expect(comment.videoId).to.equal(videoId)
104 expect(comment.id).to.equal(comment.threadId)
105 expect(comment.account.name).to.equal('root')
106 expect(comment.account.host).to.equal('localhost:' + server.port)
105 107
106 expect(comment.totalReplies).to.equal(0) 108 await testImage(server.url, 'avatar-resized', comment.account.avatar.path, '.png')
107 expect(comment.totalRepliesFromVideoAuthor).to.equal(0)
108 expect(dateIsValid(comment.createdAt as string)).to.be.true
109 expect(dateIsValid(comment.updatedAt as string)).to.be.true
110 109
111 threadId = comment.threadId 110 expect(comment.totalReplies).to.equal(0)
112 }) 111 expect(comment.totalRepliesFromVideoAuthor).to.equal(0)
112 expect(dateIsValid(comment.createdAt as string)).to.be.true
113 expect(dateIsValid(comment.updatedAt as string)).to.be.true
113 114
114 it('Should get all the thread created', async function () { 115 threadId = comment.threadId
115 const res = await getVideoThreadComments(server.url, videoUUID, threadId) 116 })
116 117
117 const rootComment = res.body.comment 118 it('Should get all the thread created', async function () {
118 expect(rootComment.inReplyToCommentId).to.be.null 119 const res = await getVideoThreadComments(server.url, videoUUID, threadId)
119 expect(rootComment.text).equal('my super first comment')
120 expect(rootComment.videoId).to.equal(videoId)
121 expect(dateIsValid(rootComment.createdAt as string)).to.be.true
122 expect(dateIsValid(rootComment.updatedAt as string)).to.be.true
123 })
124 120
125 it('Should create multiple replies in this thread', async function () { 121 const rootComment = res.body.comment
126 const text1 = 'my super answer to thread 1' 122 expect(rootComment.inReplyToCommentId).to.be.null
127 const childCommentRes = await addVideoCommentReply(server.url, server.accessToken, videoId, threadId, text1) 123 expect(rootComment.text).equal('my super first comment')
128 const childCommentId = childCommentRes.body.comment.id 124 expect(rootComment.videoId).to.equal(videoId)
125 expect(dateIsValid(rootComment.createdAt as string)).to.be.true
126 expect(dateIsValid(rootComment.updatedAt as string)).to.be.true
127 })
129 128
130 const text2 = 'my super answer to answer of thread 1' 129 it('Should create multiple replies in this thread', async function () {
131 await addVideoCommentReply(server.url, server.accessToken, videoId, childCommentId, text2) 130 const text1 = 'my super answer to thread 1'
131 const childCommentRes = await addVideoCommentReply(server.url, server.accessToken, videoId, threadId, text1)
132 const childCommentId = childCommentRes.body.comment.id
132 133
133 const text3 = 'my second answer to thread 1' 134 const text2 = 'my super answer to answer of thread 1'
134 await addVideoCommentReply(server.url, server.accessToken, videoId, threadId, text3) 135 await addVideoCommentReply(server.url, server.accessToken, videoId, childCommentId, text2)
135 })
136 136
137 it('Should get correctly the replies', async function () { 137 const text3 = 'my second answer to thread 1'
138 const res = await getVideoThreadComments(server.url, videoUUID, threadId) 138 await addVideoCommentReply(server.url, server.accessToken, videoId, threadId, text3)
139 })
139 140
140 const tree: VideoCommentThreadTree = res.body 141 it('Should get correctly the replies', async function () {
141 expect(tree.comment.text).equal('my super first comment') 142 const res = await getVideoThreadComments(server.url, videoUUID, threadId)
142 expect(tree.children).to.have.lengthOf(2)
143 143
144 const firstChild = tree.children[0] 144 const tree: VideoCommentThreadTree = res.body
145 expect(firstChild.comment.text).to.equal('my super answer to thread 1') 145 expect(tree.comment.text).equal('my super first comment')
146 expect(firstChild.children).to.have.lengthOf(1) 146 expect(tree.children).to.have.lengthOf(2)
147 147
148 const childOfFirstChild = firstChild.children[0] 148 const firstChild = tree.children[0]
149 expect(childOfFirstChild.comment.text).to.equal('my super answer to answer of thread 1') 149 expect(firstChild.comment.text).to.equal('my super answer to thread 1')
150 expect(childOfFirstChild.children).to.have.lengthOf(0) 150 expect(firstChild.children).to.have.lengthOf(1)
151 151
152 const secondChild = tree.children[1] 152 const childOfFirstChild = firstChild.children[0]
153 expect(secondChild.comment.text).to.equal('my second answer to thread 1') 153 expect(childOfFirstChild.comment.text).to.equal('my super answer to answer of thread 1')
154 expect(secondChild.children).to.have.lengthOf(0) 154 expect(childOfFirstChild.children).to.have.lengthOf(0)
155 155
156 replyToDeleteId = secondChild.comment.id 156 const secondChild = tree.children[1]
157 }) 157 expect(secondChild.comment.text).to.equal('my second answer to thread 1')
158 expect(secondChild.children).to.have.lengthOf(0)
158 159
159 it('Should create other threads', async function () { 160 replyToDeleteId = secondChild.comment.id
160 const text1 = 'super thread 2' 161 })
161 await addVideoCommentThread(server.url, server.accessToken, videoUUID, text1)
162 162
163 const text2 = 'super thread 3' 163 it('Should create other threads', async function () {
164 await addVideoCommentThread(server.url, server.accessToken, videoUUID, text2) 164 const text1 = 'super thread 2'
165 }) 165 await addVideoCommentThread(server.url, server.accessToken, videoUUID, text1)
166 166
167 it('Should list the threads', async function () { 167 const text2 = 'super thread 3'
168 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5, 'createdAt') 168 await addVideoCommentThread(server.url, server.accessToken, videoUUID, text2)
169 })
169 170
170 expect(res.body.total).to.equal(3) 171 it('Should list the threads', async function () {
171 expect(res.body.data).to.be.an('array') 172 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5, 'createdAt')
172 expect(res.body.data).to.have.lengthOf(3)
173 173
174 expect(res.body.data[0].text).to.equal('my super first comment') 174 expect(res.body.total).to.equal(3)
175 expect(res.body.data[0].totalReplies).to.equal(3) 175 expect(res.body.data).to.be.an('array')
176 expect(res.body.data[1].text).to.equal('super thread 2') 176 expect(res.body.data).to.have.lengthOf(3)
177 expect(res.body.data[1].totalReplies).to.equal(0) 177
178 expect(res.body.data[2].text).to.equal('super thread 3') 178 expect(res.body.data[0].text).to.equal('my super first comment')
179 expect(res.body.data[2].totalReplies).to.equal(0) 179 expect(res.body.data[0].totalReplies).to.equal(3)
180 }) 180 expect(res.body.data[1].text).to.equal('super thread 2')
181 expect(res.body.data[1].totalReplies).to.equal(0)
182 expect(res.body.data[2].text).to.equal('super thread 3')
183 expect(res.body.data[2].totalReplies).to.equal(0)
184 })
181 185
182 it('Should delete a reply', async function () { 186 it('Should delete a reply', async function () {
183 await deleteVideoComment(server.url, server.accessToken, videoId, replyToDeleteId) 187 await deleteVideoComment(server.url, server.accessToken, videoId, replyToDeleteId)
184 188
185 const res = await getVideoThreadComments(server.url, videoUUID, threadId) 189 const res = await getVideoThreadComments(server.url, videoUUID, threadId)
186 190
187 const tree: VideoCommentThreadTree = res.body 191 const tree: VideoCommentThreadTree = res.body
188 expect(tree.comment.text).equal('my super first comment') 192 expect(tree.comment.text).equal('my super first comment')
189 expect(tree.children).to.have.lengthOf(2) 193 expect(tree.children).to.have.lengthOf(2)
190 194
191 const firstChild = tree.children[0] 195 const firstChild = tree.children[0]
192 expect(firstChild.comment.text).to.equal('my super answer to thread 1') 196 expect(firstChild.comment.text).to.equal('my super answer to thread 1')
193 expect(firstChild.children).to.have.lengthOf(1) 197 expect(firstChild.children).to.have.lengthOf(1)
194 198
195 const childOfFirstChild = firstChild.children[0] 199 const childOfFirstChild = firstChild.children[0]
196 expect(childOfFirstChild.comment.text).to.equal('my super answer to answer of thread 1') 200 expect(childOfFirstChild.comment.text).to.equal('my super answer to answer of thread 1')
197 expect(childOfFirstChild.children).to.have.lengthOf(0) 201 expect(childOfFirstChild.children).to.have.lengthOf(0)
198 202
199 const deletedChildOfFirstChild = tree.children[1] 203 const deletedChildOfFirstChild = tree.children[1]
200 expect(deletedChildOfFirstChild.comment.text).to.equal('') 204 expect(deletedChildOfFirstChild.comment.text).to.equal('')
201 expect(deletedChildOfFirstChild.comment.isDeleted).to.be.true 205 expect(deletedChildOfFirstChild.comment.isDeleted).to.be.true
202 expect(deletedChildOfFirstChild.comment.deletedAt).to.not.be.null 206 expect(deletedChildOfFirstChild.comment.deletedAt).to.not.be.null
203 expect(deletedChildOfFirstChild.comment.account).to.be.null 207 expect(deletedChildOfFirstChild.comment.account).to.be.null
204 expect(deletedChildOfFirstChild.children).to.have.lengthOf(0) 208 expect(deletedChildOfFirstChild.children).to.have.lengthOf(0)
205 }) 209 })
210
211 it('Should delete a complete thread', async function () {
212 await deleteVideoComment(server.url, server.accessToken, videoId, threadId)
213
214 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5, 'createdAt')
215 expect(res.body.total).to.equal(3)
216 expect(res.body.data).to.be.an('array')
217 expect(res.body.data).to.have.lengthOf(3)
218
219 expect(res.body.data[0].text).to.equal('')
220 expect(res.body.data[0].isDeleted).to.be.true
221 expect(res.body.data[0].deletedAt).to.not.be.null
222 expect(res.body.data[0].account).to.be.null
223 expect(res.body.data[0].totalReplies).to.equal(3)
224 expect(res.body.data[1].text).to.equal('super thread 2')
225 expect(res.body.data[1].totalReplies).to.equal(0)
226 expect(res.body.data[2].text).to.equal('super thread 3')
227 expect(res.body.data[2].totalReplies).to.equal(0)
228 })
206 229
207 it('Should delete a complete thread', async function () { 230 it('Should count replies from the video author correctly', async function () {
208 await deleteVideoComment(server.url, server.accessToken, videoId, threadId) 231 const text = 'my super first comment'
209 232 await addVideoCommentThread(server.url, server.accessToken, videoUUID, text)
210 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5, 'createdAt') 233 let res = await getVideoCommentThreads(server.url, videoUUID, 0, 5)
211 expect(res.body.total).to.equal(3) 234 const comment: VideoComment = res.body.data[0]
212 expect(res.body.data).to.be.an('array') 235 const threadId2 = comment.threadId
213 expect(res.body.data).to.have.lengthOf(3) 236
214 237 const text2 = 'a first answer to thread 4 by a third party'
215 expect(res.body.data[0].text).to.equal('') 238 await addVideoCommentReply(server.url, userAccessTokenServer1, videoId, threadId2, text2)
216 expect(res.body.data[0].isDeleted).to.be.true 239
217 expect(res.body.data[0].deletedAt).to.not.be.null 240 const text3 = 'my second answer to thread 4'
218 expect(res.body.data[0].account).to.be.null 241 await addVideoCommentReply(server.url, server.accessToken, videoId, threadId2, text3)
219 expect(res.body.data[0].totalReplies).to.equal(3) 242
220 expect(res.body.data[1].text).to.equal('super thread 2') 243 res = await getVideoThreadComments(server.url, videoUUID, threadId2)
221 expect(res.body.data[1].totalReplies).to.equal(0) 244 const tree: VideoCommentThreadTree = res.body
222 expect(res.body.data[2].text).to.equal('super thread 3') 245 expect(tree.comment.totalReplies).to.equal(tree.comment.totalRepliesFromVideoAuthor + 1)
223 expect(res.body.data[2].totalReplies).to.equal(0) 246 })
224 }) 247 })
225 248
226 it('Should count replies from the video author correctly', async function () { 249 describe('All instance comments', function () {
227 const text = 'my super first comment' 250 async function getComments (options: any = {}) {
228 await addVideoCommentThread(server.url, server.accessToken, videoUUID, text) 251 const res = await getAdminVideoComments(Object.assign({
229 let res = await getVideoCommentThreads(server.url, videoUUID, 0, 5) 252 url: server.url,
230 const comment: VideoComment = res.body.data[0] 253 token: server.accessToken,
231 const threadId2 = comment.threadId 254 start: 0,
255 count: 10
256 }, options))
257
258 return { comments: res.body.data as VideoCommentAdmin[], total: res.body.total as number }
259 }
260
261 it('Should list instance comments as admin', async function () {
262 const { comments } = await getComments({ start: 0, count: 1 })
263
264 expect(comments[0].text).to.equal('my second answer to thread 4')
265 })
266
267 it('Should filter instance comments by isLocal', async function () {
268 const { total, comments } = await getComments({ isLocal: false })
269
270 expect(comments).to.have.lengthOf(0)
271 expect(total).to.equal(0)
272 })
273
274 it('Should search instance comments by account', async function () {
275 const { total, comments } = await getComments({ searchAccount: 'user' })
276
277 expect(comments).to.have.lengthOf(1)
278 expect(total).to.equal(1)
279
280 expect(comments[0].text).to.equal('a first answer to thread 4 by a third party')
281 })
232 282
233 const text2 = 'a first answer to thread 4 by a third party' 283 it('Should search instance comments by video', async function () {
234 await addVideoCommentReply(server.url, userAccessTokenServer1, videoId, threadId2, text2) 284 {
285 const { total, comments } = await getComments({ searchVideo: 'video' })
235 286
236 const text3 = 'my second answer to thread 4' 287 expect(comments).to.have.lengthOf(7)
237 await addVideoCommentReply(server.url, server.accessToken, videoId, threadId2, text3) 288 expect(total).to.equal(7)
289 }
238 290
239 res = await getVideoThreadComments(server.url, videoUUID, threadId2) 291 {
240 const tree: VideoCommentThreadTree = res.body 292 const { total, comments } = await getComments({ searchVideo: 'hello' })
241 expect(tree.comment.totalReplies).to.equal(tree.comment.totalRepliesFromVideoAuthor + 1) 293
294 expect(comments).to.have.lengthOf(0)
295 expect(total).to.equal(0)
296 }
297 })
298
299 it('Should search instance comments', async function () {
300 const { total, comments } = await getComments({ search: 'super thread 3' })
301
302 expect(comments).to.have.lengthOf(1)
303 expect(total).to.equal(1)
304 expect(comments[0].text).to.equal('super thread 3')
305 })
242 }) 306 })
243 307
244 after(async function () { 308 after(async function () {
diff --git a/shared/extra-utils/videos/video-comments.ts b/shared/extra-utils/videos/video-comments.ts
index 831e5e7d4..0b0df81dc 100644
--- a/shared/extra-utils/videos/video-comments.ts
+++ b/shared/extra-utils/videos/video-comments.ts
@@ -1,7 +1,41 @@
1/* eslint-disable @typescript-eslint/no-floating-promises */ 1/* eslint-disable @typescript-eslint/no-floating-promises */
2 2
3import * as request from 'supertest' 3import * as request from 'supertest'
4import { makeDeleteRequest } from '../requests/requests' 4import { makeDeleteRequest, makeGetRequest } from '../requests/requests'
5
6function getAdminVideoComments (options: {
7 url: string
8 token: string
9 start: number
10 count: number
11 sort?: string
12 isLocal?: boolean
13 search?: string
14 searchAccount?: string
15 searchVideo?: string
16}) {
17 const { url, token, start, count, sort, isLocal, search, searchAccount, searchVideo } = options
18 const path = '/api/v1/videos/comments'
19
20 const query = {
21 start,
22 count,
23 sort: sort || '-createdAt'
24 }
25
26 if (isLocal !== undefined) Object.assign(query, { isLocal })
27 if (search !== undefined) Object.assign(query, { search })
28 if (searchAccount !== undefined) Object.assign(query, { searchAccount })
29 if (searchVideo !== undefined) Object.assign(query, { searchVideo })
30
31 return makeGetRequest({
32 url,
33 path,
34 token,
35 query,
36 statusCodeExpected: 200
37 })
38}
5 39
6function getVideoCommentThreads (url: string, videoId: number | string, start: number, count: number, sort?: string, token?: string) { 40function getVideoCommentThreads (url: string, videoId: number | string, start: number, count: number, sort?: string, token?: string) {
7 const path = '/api/v1/videos/' + videoId + '/comment-threads' 41 const path = '/api/v1/videos/' + videoId + '/comment-threads'
@@ -88,6 +122,7 @@ function deleteVideoComment (
88 122
89export { 123export {
90 getVideoCommentThreads, 124 getVideoCommentThreads,
125 getAdminVideoComments,
91 getVideoThreadComments, 126 getVideoThreadComments,
92 addVideoCommentThread, 127 addVideoCommentThread,
93 addVideoCommentReply, 128 addVideoCommentReply,