aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-11-16 13:49:09 +0100
committerChocobozzz <me@florianbigard.com>2020-11-16 13:57:14 +0100
commit19149d45b8f68569535f7188ef25e09e3d62c8b4 (patch)
tree92da0e0db2b0e277b2110a630f502433c86c9119
parent8872828d59a5152e27734711ae30ebe86e84f570 (diff)
parentf1273314593a4a7dc7ec9594ce0c6c3ae8f62b34 (diff)
downloadPeerTube-19149d45b8f68569535f7188ef25e09e3d62c8b4.tar.gz
PeerTube-19149d45b8f68569535f7188ef25e09e3d62c8b4.tar.zst
PeerTube-19149d45b8f68569535f7188ef25e09e3d62c8b4.zip
Merge branch 'feature/admin-comments' into develop
-rw-r--r--client/src/app/+admin/admin.component.ts11
-rw-r--r--client/src/app/+admin/admin.module.ts4
-rw-r--r--client/src/app/+admin/moderation/moderation.routes.ts24
-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/index.ts1
-rw-r--r--client/src/app/+admin/moderation/video-comment-list/video-comment-list.component.html118
-rw-r--r--client/src/app/+admin/moderation/video-comment-list/video-comment-list.component.scss66
-rw-r--r--client/src/app/+admin/moderation/video-comment-list/video-comment-list.component.ts169
-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.ts59
-rw-r--r--client/src/app/shared/shared-video-comment/video-comment.service.ts48
-rw-r--r--server/controllers/api/videos/comment.ts36
-rw-r--r--server/initializers/constants.ts3
-rw-r--r--server/middlewares/validators/sort.ts3
-rw-r--r--server/middlewares/validators/users.ts1
-rw-r--r--server/middlewares/validators/videos/video-comments.ts33
-rw-r--r--server/models/video/video-comment.ts140
-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/live/live.ts1
-rw-r--r--server/tests/api/videos/multiple-servers.ts2
-rw-r--r--server/tests/api/videos/video-comments.ts356
-rw-r--r--server/tests/api/videos/video-playlists.ts4
-rw-r--r--server/types/models/video/video-comment.ts9
-rw-r--r--shared/core-utils/users/user-role.ts3
-rw-r--r--shared/extra-utils/videos/video-comments.ts37
-rw-r--r--shared/models/users/user-right.enum.ts1
-rw-r--r--shared/models/videos/video-comment.model.ts20
29 files changed, 1036 insertions, 185 deletions
diff --git a/client/src/app/+admin/admin.component.ts b/client/src/app/+admin/admin.component.ts
index b661a5517..dd92ed2ca 100644
--- a/client/src/app/+admin/admin.component.ts
+++ b/client/src/app/+admin/admin.component.ts
@@ -62,6 +62,13 @@ export class AdminComponent implements OnInit {
62 iconName: 'cross' 62 iconName: 'cross'
63 }) 63 })
64 } 64 }
65 if (this.hasVideoCommentsRight()) {
66 moderationItems.children.push({
67 label: $localize`Video comments`,
68 routerLink: '/admin/moderation/video-comments/list',
69 iconName: 'message-circle'
70 })
71 }
65 if (this.hasAccountsBlocklistRight()) { 72 if (this.hasAccountsBlocklistRight()) {
66 moderationItems.children.push({ 73 moderationItems.children.push({
67 label: $localize`Muted accounts`, 74 label: $localize`Muted accounts`,
@@ -140,4 +147,8 @@ export class AdminComponent implements OnInit {
140 hasDebugRight () { 147 hasDebugRight () {
141 return this.auth.getUser().hasRight(UserRight.MANAGE_DEBUG) 148 return this.auth.getUser().hasRight(UserRight.MANAGE_DEBUG)
142 } 149 }
150
151 hasVideoCommentsRight () {
152 return this.auth.getUser().hasRight(UserRight.SEE_ALL_COMMENTS)
153 }
143} 154}
diff --git a/client/src/app/+admin/admin.module.ts b/client/src/app/+admin/admin.module.ts
index da517a55b..5c0864f48 100644
--- a/client/src/app/+admin/admin.module.ts
+++ b/client/src/app/+admin/admin.module.ts
@@ -7,6 +7,7 @@ import { SharedFormModule } from '@app/shared/shared-forms'
7import { SharedGlobalIconModule } from '@app/shared/shared-icons' 7import { SharedGlobalIconModule } from '@app/shared/shared-icons'
8import { SharedMainModule } from '@app/shared/shared-main' 8import { SharedMainModule } from '@app/shared/shared-main'
9import { SharedModerationModule } from '@app/shared/shared-moderation' 9import { SharedModerationModule } from '@app/shared/shared-moderation'
10import { SharedVideoCommentModule } from '@app/shared/shared-video-comment'
10import { AdminRoutingModule } from './admin-routing.module' 11import { AdminRoutingModule } from './admin-routing.module'
11import { AdminComponent } from './admin.component' 12import { AdminComponent } from './admin.component'
12import { ConfigComponent, EditCustomConfigComponent } from './config' 13import { ConfigComponent, EditCustomConfigComponent } from './config'
@@ -18,6 +19,7 @@ import { VideoRedundancyInformationComponent } from './follows/video-redundancie
18import { AbuseListComponent, VideoBlockListComponent } from './moderation' 19import { AbuseListComponent, VideoBlockListComponent } from './moderation'
19import { InstanceAccountBlocklistComponent, InstanceServerBlocklistComponent } from './moderation/instance-blocklist' 20import { InstanceAccountBlocklistComponent, InstanceServerBlocklistComponent } from './moderation/instance-blocklist'
20import { ModerationComponent } from './moderation/moderation.component' 21import { ModerationComponent } from './moderation/moderation.component'
22import { VideoCommentListComponent } from './moderation/video-comment-list'
21import { PluginListInstalledComponent } from './plugins/plugin-list-installed/plugin-list-installed.component' 23import { PluginListInstalledComponent } from './plugins/plugin-list-installed/plugin-list-installed.component'
22import { PluginSearchComponent } from './plugins/plugin-search/plugin-search.component' 24import { PluginSearchComponent } from './plugins/plugin-search/plugin-search.component'
23import { PluginShowInstalledComponent } from './plugins/plugin-show-installed/plugin-show-installed.component' 25import { PluginShowInstalledComponent } from './plugins/plugin-show-installed/plugin-show-installed.component'
@@ -37,6 +39,7 @@ import { UserCreateComponent, UserListComponent, UserPasswordComponent, UsersCom
37 SharedModerationModule, 39 SharedModerationModule,
38 SharedGlobalIconModule, 40 SharedGlobalIconModule,
39 SharedAbuseListModule, 41 SharedAbuseListModule,
42 SharedVideoCommentModule,
40 43
41 TableModule, 44 TableModule,
42 SelectButtonModule, 45 SelectButtonModule,
@@ -62,6 +65,7 @@ import { UserCreateComponent, UserListComponent, UserPasswordComponent, UsersCom
62 ModerationComponent, 65 ModerationComponent,
63 VideoBlockListComponent, 66 VideoBlockListComponent,
64 AbuseListComponent, 67 AbuseListComponent,
68 VideoCommentListComponent,
65 69
66 InstanceServerBlocklistComponent, 70 InstanceServerBlocklistComponent,
67 InstanceAccountBlocklistComponent, 71 InstanceAccountBlocklistComponent,
diff --git a/client/src/app/+admin/moderation/moderation.routes.ts b/client/src/app/+admin/moderation/moderation.routes.ts
index b60dd5334..2e28f0911 100644
--- a/client/src/app/+admin/moderation/moderation.routes.ts
+++ b/client/src/app/+admin/moderation/moderation.routes.ts
@@ -1,8 +1,9 @@
1import { Routes } from '@angular/router' 1import { Routes } from '@angular/router'
2import { AbuseListComponent } from '@app/+admin/moderation/abuse-list'
2import { InstanceAccountBlocklistComponent, InstanceServerBlocklistComponent } from '@app/+admin/moderation/instance-blocklist' 3import { InstanceAccountBlocklistComponent, InstanceServerBlocklistComponent } from '@app/+admin/moderation/instance-blocklist'
3import { ModerationComponent } from '@app/+admin/moderation/moderation.component' 4import { ModerationComponent } from '@app/+admin/moderation/moderation.component'
4import { AbuseListComponent } from '@app/+admin/moderation/abuse-list'
5import { VideoBlockListComponent } from '@app/+admin/moderation/video-block-list' 5import { VideoBlockListComponent } from '@app/+admin/moderation/video-block-list'
6import { VideoCommentListComponent } from './video-comment-list'
6import { UserRightGuard } from '@app/core' 7import { UserRightGuard } from '@app/core'
7import { UserRight } from '@shared/models' 8import { UserRight } from '@shared/models'
8 9
@@ -37,6 +38,7 @@ export const ModerationRoutes: Routes = [
37 } 38 }
38 } 39 }
39 }, 40 },
41
40 { 42 {
41 path: 'video-blacklist', 43 path: 'video-blacklist',
42 redirectTo: 'video-blocks/list', 44 redirectTo: 'video-blocks/list',
@@ -64,10 +66,28 @@ export const ModerationRoutes: Routes = [
64 data: { 66 data: {
65 userRight: UserRight.MANAGE_VIDEO_BLACKLIST, 67 userRight: UserRight.MANAGE_VIDEO_BLACKLIST,
66 meta: { 68 meta: {
67 title: $localize`Videos blocked` 69 title: $localize`Blocked videos`
68 } 70 }
69 } 71 }
70 }, 72 },
73
74 {
75 path: 'video-comments',
76 redirectTo: 'video-comments/list',
77 pathMatch: 'full'
78 },
79 {
80 path: 'video-comments/list',
81 component: VideoCommentListComponent,
82 canActivate: [ UserRightGuard ],
83 data: {
84 userRight: UserRight.SEE_ALL_COMMENTS,
85 meta: {
86 title: $localize`Video comments`
87 }
88 }
89 },
90
71 { 91 {
72 path: 'blocklist/accounts', 92 path: 'blocklist/accounts',
73 component: InstanceAccountBlocklistComponent, 93 component: InstanceAccountBlocklistComponent,
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/index.ts b/client/src/app/+admin/moderation/video-comment-list/index.ts
new file mode 100644
index 000000000..eb08b4177
--- /dev/null
+++ b/client/src/app/+admin/moderation/video-comment-list/index.ts
@@ -0,0 +1 @@
export * from './video-comment-list.component'
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
new file mode 100644
index 000000000..45c5fe28f
--- /dev/null
+++ b/client/src/app/+admin/moderation/video-comment-list/video-comment-list.component.html
@@ -0,0 +1,118 @@
1<h1>
2 <my-global-icon iconName="message-circle" aria-hidden="true"></my-global-icon>
3 <ng-container i18n>Video comments</ng-container>
4
5 <my-feed [syndicationItems]="syndicationItems"></my-feed>
6</h1>
7
8<em>This view also shows comments from muted accounts.</em>
9
10<p-table
11 [value]="comments" [lazy]="true" [paginator]="totalRecords > 0" [totalRecords]="totalRecords" [rows]="rowsPerPage" [rowsPerPageOptions]="rowsPerPageOptions"
12 [sortField]="sort.field" [sortOrder]="sort.order" (onLazyLoad)="loadLazy($event)" dataKey="id"
13 [showCurrentPageReport]="true" i18n-currentPageReportTemplate
14 currentPageReportTemplate="Showing {{'{first}'}} to {{'{last}'}} of {{'{totalRecords}'}} comments"
15 (onPage)="onPage($event)" [expandedRowKeys]="expandedRows"
16>
17 <ng-template pTemplate="caption">
18 <div class="caption">
19 <div class="ml-auto">
20 <div class="input-group has-feedback has-clear">
21 <div class="input-group-prepend c-hand" ngbDropdown placement="bottom-left auto" container="body">
22 <div class="input-group-text" ngbDropdownToggle>
23 <span class="caret" aria-haspopup="menu" role="button"></span>
24 </div>
25
26 <div role="menu" ngbDropdownMenu>
27 <h6 class="dropdown-header" i18n>Advanced comments filters</h6>
28 <a [routerLink]="[ '/admin/moderation/video-comments/list' ]" [queryParams]="{ 'search': 'local:true' }" class="dropdown-item" i18n>Local comments</a>
29 <a [routerLink]="[ '/admin/moderation/video-comments/list' ]" [queryParams]="{ 'search': 'local:false' }" class="dropdown-item" i18n>Remote comments</a>
30 </div>
31 </div>
32 <input
33 type="text" name="table-filter" id="table-filter" i18n-placeholder placeholder="Filter..."
34 (keyup)="onInputSearch($event)"
35 >
36 <a class="glyphicon glyphicon-remove-sign form-control-feedback form-control-clear" (click)="resetTableFilter()"></a>
37 <span class="sr-only" i18n>Clear filters</span>
38 </div>
39 </div>
40 </div>
41 </ng-template>
42
43 <ng-template pTemplate="header">
44 <tr>
45 <th style="width: 40px"></th>
46 <th style="width: 300px" i18n>Account</th>
47 <th style="width: 300px" i18n>Video</th>
48 <th i18n>Comment</th>
49 <th style="width: 150px;" i18n pSortableColumn="createdAt">Date <p-sortIcon field="createdAt"></p-sortIcon></th>
50 <th style="width: 150px;"></th>
51 </tr>
52 </ng-template>
53
54 <ng-template pTemplate="body" let-videoComment let-expanded="expanded">
55 <tr>
56 <td class="expand-cell c-hand" [pRowToggler]="videoComment" i18n-ngbTooltip ngbTooltip="More information" placement="top-left" container="body">
57 <span class="expander">
58 <i [ngClass]="expanded ? 'glyphicon glyphicon-menu-down' : 'glyphicon glyphicon-menu-right'"></i>
59 </span>
60 </td>
61
62 <td>
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>
76 </td>
77
78 <td class="video">
79 <em i18n>Commented video</em>
80
81 <a [href]="videoComment.localUrl" target="_blank" rel="noopener noreferrer">{{ videoComment.video.name }}</a>
82 </td>
83
84 <td class="comment-html">
85 <div [innerHTML]="videoComment.textHtml"></div>
86 </td>
87
88 <td>{{ videoComment.createdAt | date: 'short' }}</td>
89
90 <td class="action-cell">
91 <my-action-dropdown
92 [ngClass]="{ 'show': expanded }" placement="bottom-right" container="body"
93 i18n-label label="Actions" [actions]="videoCommentActions" [entry]="videoComment"
94 ></my-action-dropdown>
95 </td>
96 </tr>
97 </ng-template>
98
99 <ng-template pTemplate="rowexpansion" let-videoComment>
100 <tr>
101 <td class="expand-cell" colspan="5">
102 <div [innerHTML]="videoComment.textHtml"></div>
103 </td>
104 </tr>
105 </ng-template>
106
107 <ng-template pTemplate="emptymessage">
108 <tr>
109 <td colspan="5">
110 <div class="no-results">
111 <ng-container *ngIf="search" i18n>No comments found matching current filters.</ng-container>
112 <ng-container *ngIf="!search" i18n>No comments found.</ng-container>
113 </div>
114 </td>
115 </tr>
116 </ng-template>
117</p-table>
118
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
new file mode 100644
index 000000000..439835899
--- /dev/null
+++ b/client/src/app/+admin/moderation/video-comment-list/video-comment-list.component.scss
@@ -0,0 +1,66 @@
1@import 'mixins';
2
3h1 {
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}
16
17my-global-icon {
18 width: 24px;
19 height: 24px;
20}
21
22.input-group {
23 @include peertube-input-group(300px);
24
25 .dropdown-toggle::after {
26 margin-left: 0;
27 }
28}
29
30.caption {
31 justify-content: flex-end;
32
33 input {
34 @include peertube-input-text(250px);
35 flex-grow: 1;
36 }
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
new file mode 100644
index 000000000..d26047125
--- /dev/null
+++ b/client/src/app/+admin/moderation/video-comment-list/video-comment-list.component.ts
@@ -0,0 +1,169 @@
1import { SortMeta } from 'primeng/api'
2import { filter } from 'rxjs/operators'
3import { AfterViewInit, Component, OnInit } from '@angular/core'
4import { ActivatedRoute, Params, Router } from '@angular/router'
5import { AuthService, ConfirmService, MarkdownService, Notifier, RestPagination, RestTable } from '@app/core'
6import { DropdownAction } from '@app/shared/shared-main'
7import { BulkService } from '@app/shared/shared-moderation'
8import { VideoCommentAdmin, VideoCommentService } from '@app/shared/shared-video-comment'
9import { FeedFormat, UserRight } from '@shared/models'
10
11@Component({
12 selector: 'my-video-comment-list',
13 templateUrl: './video-comment-list.component.html',
14 styleUrls: [ '../../../shared/shared-moderation/moderation.scss', './video-comment-list.component.scss' ]
15})
16export class VideoCommentListComponent extends RestTable implements OnInit, AfterViewInit {
17 comments: VideoCommentAdmin[]
18 totalRecords = 0
19 sort: SortMeta = { field: 'createdAt', order: -1 }
20 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
21
22 videoCommentActions: DropdownAction<VideoCommentAdmin>[][] = []
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
46 constructor (
47 private auth: AuthService,
48 private notifier: Notifier,
49 private confirmService: ConfirmService,
50 private videoCommentService: VideoCommentService,
51 private markdownRenderer: MarkdownService,
52 private route: ActivatedRoute,
53 private router: Router,
54 private bulkService: BulkService
55 ) {
56 super()
57
58 this.videoCommentActions = [
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 },
65
66 {
67 label: $localize`Delete all comments of this account`,
68 description: $localize`Comments are deleted after a few minutes`,
69 handler: comment => this.deleteUserComments(comment),
70 isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT)
71 }
72 ]
73 ]
74 }
75
76 ngOnInit () {
77 this.initialize()
78
79 this.route.queryParams
80 .pipe(filter(params => params.search !== undefined && params.search !== null))
81 .subscribe(params => {
82 this.search = params.search
83 this.setTableFilter(params.search)
84 this.loadData()
85 })
86 }
87
88 ngAfterViewInit () {
89 if (this.search) this.setTableFilter(this.search)
90 }
91
92 onInputSearch (event: Event) {
93 this.onSearch(event)
94 this.setQueryParams((event.target as HTMLInputElement).value)
95 }
96
97 setQueryParams (search: string) {
98 const queryParams: Params = {}
99
100 if (search) Object.assign(queryParams, { search })
101 this.router.navigate([ '/admin/moderation/video-comments/list' ], { queryParams })
102 }
103
104 resetTableFilter () {
105 this.setTableFilter('')
106 this.setQueryParams('')
107 this.resetSearch()
108 }
109 /* END Table filter functions */
110
111 getIdentifier () {
112 return 'VideoCommentListComponent'
113 }
114
115 toHtml (text: string) {
116 return this.markdownRenderer.textMarkdownToHTML(text, true, true)
117 }
118
119 protected loadData () {
120 this.videoCommentService.getAdminVideoComments({
121 pagination: this.pagination,
122 sort: this.sort,
123 search: this.search
124 }).subscribe(
125 async resultList => {
126 this.totalRecords = resultList.total
127
128 this.comments = []
129
130 for (const c of resultList.data) {
131 this.comments.push(
132 new VideoCommentAdmin(c, await this.toHtml(c.text))
133 )
134 }
135 },
136
137 err => this.notifier.error(err.message)
138 )
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 }
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 e85443196..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
@@ -1,6 +1,6 @@
1import { getAbsoluteAPIUrl } from '@app/helpers' 1import { getAbsoluteAPIUrl } from '@app/helpers'
2import { Actor } from '@app/shared/shared-main' 2import { Actor } from '@app/shared/shared-main'
3import { Account as AccountInterface, VideoComment as VideoCommentServerModel } from '@shared/models' 3import { Account as AccountInterface, VideoComment as VideoCommentServerModel, VideoCommentAdmin as VideoCommentAdminServerModel } from '@shared/models'
4 4
5export class VideoComment implements VideoCommentServerModel { 5export class VideoComment implements VideoCommentServerModel {
6 id: number 6 id: number
@@ -46,3 +46,60 @@ export class VideoComment implements VideoCommentServerModel {
46 } 46 }
47 } 47 }
48} 48}
49
50export class VideoCommentAdmin implements VideoCommentAdminServerModel {
51 id: number
52 url: string
53 text: string
54 textHtml: string
55
56 threadId: number
57 inReplyToCommentId: number
58
59 createdAt: Date | string
60 updatedAt: Date | string
61
62 account: AccountInterface & { localUrl?: string }
63 localUrl: string
64
65 video: {
66 id: number
67 uuid: string
68 name: string
69 localUrl: string
70 }
71
72 by: string
73 accountAvatarUrl: string
74
75 constructor (hash: VideoCommentAdminServerModel, textHtml: string) {
76 this.id = hash.id
77 this.url = hash.url
78 this.text = hash.text
79 this.textHtml = textHtml
80
81 this.threadId = hash.threadId
82 this.inReplyToCommentId = hash.inReplyToCommentId
83
84 this.createdAt = new Date(hash.createdAt.toString())
85 this.updatedAt = new Date(hash.updatedAt.toString())
86
87 this.video = {
88 id: hash.video.id,
89 uuid: hash.video.uuid,
90 name: hash.video.name,
91 localUrl: '/videos/watch/' + hash.video.uuid
92 }
93
94 this.localUrl = this.video.localUrl + ';threadId=' + this.threadId
95
96 this.account = hash.account
97
98 if (this.account) {
99 this.by = Actor.CREATE_BY_STRING(this.account.name, this.account.host)
100 this.accountAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.account)
101
102 this.account.localUrl = '/accounts/' + this.by
103 }
104 }
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 81c65aa38..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
@@ -2,23 +2,26 @@ import { Observable } from 'rxjs'
2import { catchError, map } from 'rxjs/operators' 2import { catchError, map } from 'rxjs/operators'
3import { HttpClient, HttpParams } from '@angular/common/http' 3import { HttpClient, HttpParams } from '@angular/common/http'
4import { Injectable } from '@angular/core' 4import { Injectable } from '@angular/core'
5import { ComponentPaginationLight, RestExtractor, RestService } from '@app/core' 5import { ComponentPaginationLight, RestExtractor, RestPagination, RestService } from '@app/core'
6import { objectLineFeedToHtml } from '@app/helpers' 6import { objectLineFeedToHtml } from '@app/helpers'
7import { 7import {
8 FeedFormat, 8 FeedFormat,
9 ResultList, 9 ResultList,
10 VideoComment as VideoCommentServerModel, 10 VideoComment as VideoCommentServerModel,
11 VideoCommentAdmin,
11 VideoCommentCreate, 12 VideoCommentCreate,
12 VideoCommentThreadTree as VideoCommentThreadTreeServerModel 13 VideoCommentThreadTree as VideoCommentThreadTreeServerModel
13} from '@shared/models' 14} from '@shared/models'
14import { environment } from '../../../environments/environment' 15import { environment } from '../../../environments/environment'
15import { VideoCommentThreadTree } from './video-comment-thread-tree.model' 16import { VideoCommentThreadTree } from './video-comment-thread-tree.model'
16import { VideoComment } from './video-comment.model' 17import { VideoComment } from './video-comment.model'
18import { SortMeta } from 'primeng/api'
17 19
18@Injectable() 20@Injectable()
19export class VideoCommentService { 21export class VideoCommentService {
22 static BASE_FEEDS_URL = environment.apiUrl + '/feeds/video-comments.'
23
20 private static BASE_VIDEO_URL = environment.apiUrl + '/api/v1/videos/' 24 private static BASE_VIDEO_URL = environment.apiUrl + '/api/v1/videos/'
21 private static BASE_FEEDS_URL = environment.apiUrl + '/feeds/video-comments.'
22 25
23 constructor ( 26 constructor (
24 private authHttp: HttpClient, 27 private authHttp: HttpClient,
@@ -48,6 +51,27 @@ export class VideoCommentService {
48 ) 51 )
49 } 52 }
50 53
54 getAdminVideoComments (options: {
55 pagination: RestPagination,
56 sort: SortMeta,
57 search?: string
58 }): Observable<ResultList<VideoCommentAdmin>> {
59 const { pagination, sort, search } = options
60 const url = VideoCommentService.BASE_VIDEO_URL + 'comments'
61
62 let params = new HttpParams()
63 params = this.restService.addRestGetParams(params, pagination, sort)
64
65 if (search) {
66 params = this.buildParamsFromSearch(search, params)
67 }
68
69 return this.authHttp.get<ResultList<VideoCommentAdmin>>(url, { params })
70 .pipe(
71 catchError(res => this.restExtractor.handleError(res))
72 )
73 }
74
51 getVideoCommentThreads (parameters: { 75 getVideoCommentThreads (parameters: {
52 videoId: number | string, 76 videoId: number | string,
53 componentPagination: ComponentPaginationLight, 77 componentPagination: ComponentPaginationLight,
@@ -146,4 +170,24 @@ export class VideoCommentService {
146 170
147 return tree as VideoCommentThreadTree 171 return tree as VideoCommentThreadTree
148 } 172 }
173
174 private buildParamsFromSearch (search: string, params: HttpParams) {
175 const filters = this.restService.parseQueryStringFilter(search, {
176 isLocal: {
177 prefix: 'local:',
178 isBoolean: true,
179 handler: v => {
180 if (v === 'true') return v
181 if (v === 'false') return v
182
183 return undefined
184 }
185 },
186
187 searchAccount: { prefix: 'account:' },
188 searchVideo: { prefix: 'video:' }
189 })
190
191 return this.restService.addObjectParams(params, filters)
192 }
149} 193}
diff --git a/server/controllers/api/videos/comment.ts b/server/controllers/api/videos/comment.ts
index 45ff969d9..ccd76c093 100644
--- a/server/controllers/api/videos/comment.ts
+++ b/server/controllers/api/videos/comment.ts
@@ -1,5 +1,5 @@
1import * as express from 'express' 1import * as express from 'express'
2import { ResultList } from '../../../../shared/models' 2import { ResultList, UserRight } from '../../../../shared/models'
3import { VideoCommentCreate } from '../../../../shared/models/videos/video-comment.model' 3import { VideoCommentCreate } from '../../../../shared/models/videos/video-comment.model'
4import { auditLoggerFactory, CommentAuditView, getAuditIdFromRes } from '../../../helpers/audit-logger' 4import { auditLoggerFactory, CommentAuditView, getAuditIdFromRes } from '../../../helpers/audit-logger'
5import { getFormattedObjects } from '../../../helpers/utils' 5import { getFormattedObjects } from '../../../helpers/utils'
@@ -11,6 +11,7 @@ import {
11 asyncMiddleware, 11 asyncMiddleware,
12 asyncRetryTransactionMiddleware, 12 asyncRetryTransactionMiddleware,
13 authenticate, 13 authenticate,
14 ensureUserHasRight,
14 optionalAuthenticate, 15 optionalAuthenticate,
15 paginationValidator, 16 paginationValidator,
16 setDefaultPagination, 17 setDefaultPagination,
@@ -19,9 +20,11 @@ import {
19import { 20import {
20 addVideoCommentReplyValidator, 21 addVideoCommentReplyValidator,
21 addVideoCommentThreadValidator, 22 addVideoCommentThreadValidator,
23 listVideoCommentsValidator,
22 listVideoCommentThreadsValidator, 24 listVideoCommentThreadsValidator,
23 listVideoThreadCommentsValidator, 25 listVideoThreadCommentsValidator,
24 removeVideoCommentValidator, 26 removeVideoCommentValidator,
27 videoCommentsValidator,
25 videoCommentThreadsSortValidator 28 videoCommentThreadsSortValidator
26} from '../../../middlewares/validators' 29} from '../../../middlewares/validators'
27import { AccountModel } from '../../../models/account/account' 30import { AccountModel } from '../../../models/account/account'
@@ -61,6 +64,17 @@ videoCommentRouter.delete('/:videoId/comments/:commentId',
61 asyncRetryTransactionMiddleware(removeVideoComment) 64 asyncRetryTransactionMiddleware(removeVideoComment)
62) 65)
63 66
67videoCommentRouter.get('/comments',
68 authenticate,
69 ensureUserHasRight(UserRight.SEE_ALL_COMMENTS),
70 paginationValidator,
71 videoCommentsValidator,
72 setDefaultSort,
73 setDefaultPagination,
74 listVideoCommentsValidator,
75 asyncMiddleware(listComments)
76)
77
64// --------------------------------------------------------------------------- 78// ---------------------------------------------------------------------------
65 79
66export { 80export {
@@ -69,6 +83,26 @@ export {
69 83
70// --------------------------------------------------------------------------- 84// ---------------------------------------------------------------------------
71 85
86async function listComments (req: express.Request, res: express.Response) {
87 const options = {
88 start: req.query.start,
89 count: req.query.count,
90 sort: req.query.sort,
91
92 isLocal: req.query.isLocal,
93 search: req.query.search,
94 searchAccount: req.query.searchAccount,
95 searchVideo: req.query.searchVideo
96 }
97
98 const resultList = await VideoCommentModel.listCommentsForApi(options)
99
100 return res.json({
101 total: resultList.total,
102 data: resultList.data.map(c => c.toFormattedAdminJSON())
103 })
104}
105
72async function listVideoThreads (req: express.Request, res: express.Response) { 106async function listVideoThreads (req: express.Request, res: express.Response) {
73 const video = res.locals.onlyVideo 107 const video = res.locals.onlyVideo
74 const user = res.locals.oauth ? res.locals.oauth.token.User : undefined 108 const user = res.locals.oauth ? res.locals.oauth.token.User : undefined
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts
index 02e42a594..fde87d9f8 100644
--- a/server/initializers/constants.ts
+++ b/server/initializers/constants.ts
@@ -63,7 +63,10 @@ const SORTABLE_COLUMNS = {
63 JOBS: [ 'createdAt' ], 63 JOBS: [ 'createdAt' ],
64 VIDEO_CHANNELS: [ 'id', 'name', 'updatedAt', 'createdAt' ], 64 VIDEO_CHANNELS: [ 'id', 'name', 'updatedAt', 'createdAt' ],
65 VIDEO_IMPORTS: [ 'createdAt' ], 65 VIDEO_IMPORTS: [ 'createdAt' ],
66
66 VIDEO_COMMENT_THREADS: [ 'createdAt', 'totalReplies' ], 67 VIDEO_COMMENT_THREADS: [ 'createdAt', 'totalReplies' ],
68 VIDEO_COMMENTS: [ 'createdAt' ],
69
67 VIDEO_RATES: [ 'createdAt' ], 70 VIDEO_RATES: [ 'createdAt' ],
68 BLACKLISTS: [ 'id', 'name', 'duration', 'views', 'likes', 'dislikes', 'uuid', 'createdAt' ], 71 BLACKLISTS: [ 'id', 'name', 'duration', 'views', 'likes', 'dislikes', 'uuid', 'createdAt' ],
69 FOLLOWERS: [ 'createdAt', 'state', 'score' ], 72 FOLLOWERS: [ 'createdAt', 'state', 'score' ],
diff --git a/server/middlewares/validators/sort.ts b/server/middlewares/validators/sort.ts
index 29aba0436..e93ceb200 100644
--- a/server/middlewares/validators/sort.ts
+++ b/server/middlewares/validators/sort.ts
@@ -10,6 +10,7 @@ const SORTABLE_VIDEOS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEOS)
10const SORTABLE_VIDEOS_SEARCH_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEOS_SEARCH) 10const SORTABLE_VIDEOS_SEARCH_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEOS_SEARCH)
11const SORTABLE_VIDEO_CHANNELS_SEARCH_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_CHANNELS_SEARCH) 11const SORTABLE_VIDEO_CHANNELS_SEARCH_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_CHANNELS_SEARCH)
12const SORTABLE_VIDEO_IMPORTS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_IMPORTS) 12const SORTABLE_VIDEO_IMPORTS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_IMPORTS)
13const SORTABLE_VIDEO_COMMENTS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_COMMENT_THREADS)
13const SORTABLE_VIDEO_COMMENT_THREADS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_COMMENT_THREADS) 14const SORTABLE_VIDEO_COMMENT_THREADS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_COMMENT_THREADS)
14const SORTABLE_VIDEO_RATES_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_RATES) 15const SORTABLE_VIDEO_RATES_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_RATES)
15const SORTABLE_BLACKLISTS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.BLACKLISTS) 16const SORTABLE_BLACKLISTS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.BLACKLISTS)
@@ -33,6 +34,7 @@ const videosSortValidator = checkSort(SORTABLE_VIDEOS_COLUMNS)
33const videoImportsSortValidator = checkSort(SORTABLE_VIDEO_IMPORTS_COLUMNS) 34const videoImportsSortValidator = checkSort(SORTABLE_VIDEO_IMPORTS_COLUMNS)
34const videosSearchSortValidator = checkSort(SORTABLE_VIDEOS_SEARCH_COLUMNS) 35const videosSearchSortValidator = checkSort(SORTABLE_VIDEOS_SEARCH_COLUMNS)
35const videoChannelsSearchSortValidator = checkSort(SORTABLE_VIDEO_CHANNELS_SEARCH_COLUMNS) 36const videoChannelsSearchSortValidator = checkSort(SORTABLE_VIDEO_CHANNELS_SEARCH_COLUMNS)
37const videoCommentsValidator = checkSort(SORTABLE_VIDEO_COMMENTS_COLUMNS)
36const videoCommentThreadsSortValidator = checkSort(SORTABLE_VIDEO_COMMENT_THREADS_COLUMNS) 38const videoCommentThreadsSortValidator = checkSort(SORTABLE_VIDEO_COMMENT_THREADS_COLUMNS)
37const videoRatesSortValidator = checkSort(SORTABLE_VIDEO_RATES_COLUMNS) 39const videoRatesSortValidator = checkSort(SORTABLE_VIDEO_RATES_COLUMNS)
38const blacklistSortValidator = checkSort(SORTABLE_BLACKLISTS_COLUMNS) 40const blacklistSortValidator = checkSort(SORTABLE_BLACKLISTS_COLUMNS)
@@ -55,6 +57,7 @@ export {
55 abusesSortValidator, 57 abusesSortValidator,
56 videoChannelsSortValidator, 58 videoChannelsSortValidator,
57 videoImportsSortValidator, 59 videoImportsSortValidator,
60 videoCommentsValidator,
58 videosSearchSortValidator, 61 videosSearchSortValidator,
59 videosSortValidator, 62 videosSortValidator,
60 blacklistSortValidator, 63 blacklistSortValidator,
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 77f5c6ff3..a3c9febc4 100644
--- a/server/middlewares/validators/videos/video-comments.ts
+++ b/server/middlewares/validators/videos/video-comments.ts
@@ -1,8 +1,8 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body, param } 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 { 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,
@@ -15,6 +15,34 @@ import { Hooks } from '../../../lib/plugins/hooks'
15import { MCommentOwnerVideoReply, MVideo, MVideoFullLight } from '../../../types/models/video' 15import { MCommentOwnerVideoReply, MVideo, MVideoFullLight } from '../../../types/models/video'
16import { areValidationErrors } from '../utils' 16import { areValidationErrors } from '../utils'
17 17
18const listVideoCommentsValidator = [
19 query('isLocal')
20 .optional()
21 .customSanitizer(toBooleanOrNull)
22 .custom(isBooleanValid)
23 .withMessage('Should have a valid is local boolean'),
24
25 query('search')
26 .optional()
27 .custom(exists).withMessage('Should have a valid search'),
28
29 query('searchAccount')
30 .optional()
31 .custom(exists).withMessage('Should have a valid account search'),
32
33 query('searchVideo')
34 .optional()
35 .custom(exists).withMessage('Should have a valid video search'),
36
37 (req: express.Request, res: express.Response, next: express.NextFunction) => {
38 logger.debug('Checking listVideoCommentsValidator parameters.', { parameters: req.query })
39
40 if (areValidationErrors(req, res)) return
41
42 return next()
43 }
44]
45
18const listVideoCommentThreadsValidator = [ 46const listVideoCommentThreadsValidator = [
19 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), 47 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
20 48
@@ -116,6 +144,7 @@ export {
116 listVideoCommentThreadsValidator, 144 listVideoCommentThreadsValidator,
117 listVideoThreadCommentsValidator, 145 listVideoThreadCommentsValidator,
118 addVideoCommentThreadValidator, 146 addVideoCommentThreadValidator,
147 listVideoCommentsValidator,
119 addVideoCommentReplyValidator, 148 addVideoCommentReplyValidator,
120 videoCommentGetValidator, 149 videoCommentGetValidator,
121 removeVideoCommentValidator 150 removeVideoCommentValidator
diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts
index de27b3d87..ed4a345eb 100644
--- a/server/models/video/video-comment.ts
+++ b/server/models/video/video-comment.ts
@@ -1,6 +1,6 @@
1import * as Bluebird from 'bluebird' 1import * as Bluebird from 'bluebird'
2import { uniq } from 'lodash' 2import { uniq } from 'lodash'
3import { FindOptions, Op, Order, ScopeOptions, Sequelize, Transaction, WhereOptions } from 'sequelize' 3import { FindAndCountOptions, FindOptions, Op, Order, ScopeOptions, Sequelize, Transaction, WhereOptions } from 'sequelize'
4import { 4import {
5 AllowNull, 5 AllowNull,
6 BelongsTo, 6 BelongsTo,
@@ -20,13 +20,14 @@ import { MAccount, MAccountId, MUserAccountId } from '@server/types/models'
20import { VideoPrivacy } from '@shared/models' 20import { VideoPrivacy } from '@shared/models'
21import { ActivityTagObject, ActivityTombstoneObject } from '../../../shared/models/activitypub/objects/common-objects' 21import { ActivityTagObject, ActivityTombstoneObject } from '../../../shared/models/activitypub/objects/common-objects'
22import { VideoCommentObject } from '../../../shared/models/activitypub/objects/video-comment-object' 22import { VideoCommentObject } from '../../../shared/models/activitypub/objects/video-comment-object'
23import { VideoComment } from '../../../shared/models/videos/video-comment.model' 23import { VideoComment, VideoCommentAdmin } from '../../../shared/models/videos/video-comment.model'
24import { actorNameAlphabet } from '../../helpers/custom-validators/activitypub/actor' 24import { actorNameAlphabet } from '../../helpers/custom-validators/activitypub/actor'
25import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' 25import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
26import { regexpCapture } from '../../helpers/regexp' 26import { regexpCapture } from '../../helpers/regexp'
27import { CONSTRAINTS_FIELDS, WEBSERVER } from '../../initializers/constants' 27import { CONSTRAINTS_FIELDS, WEBSERVER } from '../../initializers/constants'
28import { 28import {
29 MComment, 29 MComment,
30 MCommentAdminFormattable,
30 MCommentAP, 31 MCommentAP,
31 MCommentFormattable, 32 MCommentFormattable,
32 MCommentId, 33 MCommentId,
@@ -40,7 +41,14 @@ import {
40import { VideoCommentAbuseModel } from '../abuse/video-comment-abuse' 41import { VideoCommentAbuseModel } from '../abuse/video-comment-abuse'
41import { AccountModel } from '../account/account' 42import { AccountModel } from '../account/account'
42import { ActorModel, unusedActorAttributesForAPI } from '../activitypub/actor' 43import { ActorModel, unusedActorAttributesForAPI } from '../activitypub/actor'
43import { buildBlockedAccountSQL, buildBlockedAccountSQLOptimized, buildLocalAccountIdsIn, getCommentSort, throwIfNotValid } from '../utils' 44import {
45 buildBlockedAccountSQL,
46 buildBlockedAccountSQLOptimized,
47 buildLocalAccountIdsIn,
48 getCommentSort,
49 searchAttribute,
50 throwIfNotValid
51} from '../utils'
44import { VideoModel } from './video' 52import { VideoModel } from './video'
45import { VideoChannelModel } from './video-channel' 53import { VideoChannelModel } from './video-channel'
46 54
@@ -303,6 +311,98 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
303 return VideoCommentModel.scope([ ScopeNames.WITH_IN_REPLY_TO, ScopeNames.WITH_ACCOUNT ]).findOne(query) 311 return VideoCommentModel.scope([ ScopeNames.WITH_IN_REPLY_TO, ScopeNames.WITH_ACCOUNT ]).findOne(query)
304 } 312 }
305 313
314 static listCommentsForApi (parameters: {
315 start: number
316 count: number
317 sort: string
318
319 isLocal?: boolean
320 search?: string
321 searchAccount?: string
322 searchVideo?: string
323 }) {
324 const { start, count, sort, isLocal, search, searchAccount, searchVideo } = parameters
325
326 const where: WhereOptions = {
327 deletedAt: null
328 }
329
330 const whereAccount: WhereOptions = {}
331 const whereActor: WhereOptions = {}
332 const whereVideo: WhereOptions = {}
333
334 if (isLocal === true) {
335 Object.assign(whereActor, {
336 serverId: null
337 })
338 } else if (isLocal === false) {
339 Object.assign(whereActor, {
340 serverId: {
341 [Op.ne]: null
342 }
343 })
344 }
345
346 if (search) {
347 Object.assign(where, {
348 [Op.or]: [
349 searchAttribute(search, 'text'),
350 searchAttribute(search, '$Account.Actor.preferredUsername$'),
351 searchAttribute(search, '$Account.name$'),
352 searchAttribute(search, '$Video.name$')
353 ]
354 })
355 }
356
357 if (searchAccount) {
358 Object.assign(whereActor, {
359 [Op.or]: [
360 searchAttribute(searchAccount, '$Account.Actor.preferredUsername$'),
361 searchAttribute(searchAccount, '$Account.name$')
362 ]
363 })
364 }
365
366 if (searchVideo) {
367 Object.assign(whereVideo, searchAttribute(searchVideo, 'name'))
368 }
369
370 const query: FindAndCountOptions = {
371 offset: start,
372 limit: count,
373 order: getCommentSort(sort),
374 where,
375 include: [
376 {
377 model: AccountModel.unscoped(),
378 required: true,
379 where: whereAccount,
380 include: [
381 {
382 attributes: {
383 exclude: unusedActorAttributesForAPI
384 },
385 model: ActorModel, // Default scope includes avatar and server
386 required: true,
387 where: whereActor
388 }
389 ]
390 },
391 {
392 model: VideoModel.unscoped(),
393 required: true,
394 where: whereVideo
395 }
396 ]
397 }
398
399 return VideoCommentModel
400 .findAndCountAll(query)
401 .then(({ rows, count }) => {
402 return { total: count, data: rows }
403 })
404 }
405
306 static async listThreadsForApi (parameters: { 406 static async listThreadsForApi (parameters: {
307 videoId: number 407 videoId: number
308 isVideoOwned: boolean 408 isVideoOwned: boolean
@@ -656,19 +756,51 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
656 id: this.id, 756 id: this.id,
657 url: this.url, 757 url: this.url,
658 text: this.text, 758 text: this.text,
759
659 threadId: this.getThreadId(), 760 threadId: this.getThreadId(),
660 inReplyToCommentId: this.inReplyToCommentId || null, 761 inReplyToCommentId: this.inReplyToCommentId || null,
661 videoId: this.videoId, 762 videoId: this.videoId,
763
662 createdAt: this.createdAt, 764 createdAt: this.createdAt,
663 updatedAt: this.updatedAt, 765 updatedAt: this.updatedAt,
664 deletedAt: this.deletedAt, 766 deletedAt: this.deletedAt,
767
665 isDeleted: this.isDeleted(), 768 isDeleted: this.isDeleted(),
769
666 totalRepliesFromVideoAuthor: this.get('totalRepliesFromVideoAuthor') || 0, 770 totalRepliesFromVideoAuthor: this.get('totalRepliesFromVideoAuthor') || 0,
667 totalReplies: this.get('totalReplies') || 0, 771 totalReplies: this.get('totalReplies') || 0,
668 account: this.Account ? this.Account.toFormattedJSON() : null 772
773 account: this.Account
774 ? this.Account.toFormattedJSON()
775 : null
669 } as VideoComment 776 } as VideoComment
670 } 777 }
671 778
779 toFormattedAdminJSON (this: MCommentAdminFormattable) {
780 return {
781 id: this.id,
782 url: this.url,
783 text: this.text,
784
785 threadId: this.getThreadId(),
786 inReplyToCommentId: this.inReplyToCommentId || null,
787 videoId: this.videoId,
788
789 createdAt: this.createdAt,
790 updatedAt: this.updatedAt,
791
792 video: {
793 id: this.Video.id,
794 uuid: this.Video.uuid,
795 name: this.Video.name
796 },
797
798 account: this.Account
799 ? this.Account.toFormattedJSON()
800 : null
801 } as VideoCommentAdmin
802 }
803
672 toActivityPubObject (this: MCommentAP, threadParentComments: MCommentOwner[]): VideoCommentObject | ActivityTombstoneObject { 804 toActivityPubObject (this: MCommentAP, threadParentComments: MCommentOwner[]): VideoCommentObject | ActivityTombstoneObject {
673 let inReplyTo: string 805 let inReplyTo: string
674 // New thread, so in AS we reply to the video 806 // New thread, so in AS we reply to the video
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/live/live.ts b/server/tests/api/live/live.ts
index aa2e1318a..94c966c9f 100644
--- a/server/tests/api/live/live.ts
+++ b/server/tests/api/live/live.ts
@@ -10,7 +10,6 @@ import {
10 checkLiveCleanup, 10 checkLiveCleanup,
11 checkLiveSegmentHash, 11 checkLiveSegmentHash,
12 checkResolutionsInMasterPlaylist, 12 checkResolutionsInMasterPlaylist,
13 checkSegmentHash,
14 cleanupTests, 13 cleanupTests,
15 createLive, 14 createLive,
16 doubleFollow, 15 doubleFollow,
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..141a80690 100644
--- a/server/tests/api/videos/video-comments.ts
+++ b/server/tests/api/videos/video-comments.ts
@@ -1,8 +1,8 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import * as chai from 'chai'
4import 'mocha' 3import 'mocha'
5import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model' 4import * as chai from 'chai'
5
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 { VideoComment, VideoCommentAdmin, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model'
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
120 expect(rootComment.videoId).to.equal(videoId) 121 const rootComment = res.body.comment
121 expect(dateIsValid(rootComment.createdAt as string)).to.be.true 122 expect(rootComment.inReplyToCommentId).to.be.null
122 expect(dateIsValid(rootComment.updatedAt as string)).to.be.true 123 expect(rootComment.text).equal('my super first comment')
123 }) 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 })
124 128
125 it('Should create multiple replies in this thread', async function () { 129 it('Should create multiple replies in this thread', async function () {
126 const text1 = 'my super answer to thread 1' 130 const text1 = 'my super answer to thread 1'
127 const childCommentRes = await addVideoCommentReply(server.url, server.accessToken, videoId, threadId, text1) 131 const childCommentRes = await addVideoCommentReply(server.url, server.accessToken, videoId, threadId, text1)
128 const childCommentId = childCommentRes.body.comment.id 132 const childCommentId = childCommentRes.body.comment.id
129 133
130 const text2 = 'my super answer to answer of thread 1' 134 const text2 = 'my super answer to answer of thread 1'
131 await addVideoCommentReply(server.url, server.accessToken, videoId, childCommentId, text2) 135 await addVideoCommentReply(server.url, server.accessToken, videoId, childCommentId, text2)
132 136
133 const text3 = 'my second answer to thread 1' 137 const text3 = 'my second answer to thread 1'
134 await addVideoCommentReply(server.url, server.accessToken, videoId, threadId, text3) 138 await addVideoCommentReply(server.url, server.accessToken, videoId, threadId, text3)
135 }) 139 })
136 140
137 it('Should get correctly the replies', async function () { 141 it('Should get correctly the replies', async function () {
138 const res = await getVideoThreadComments(server.url, videoUUID, threadId) 142 const res = await getVideoThreadComments(server.url, videoUUID, threadId)
139 143
140 const tree: VideoCommentThreadTree = res.body 144 const tree: VideoCommentThreadTree = res.body
141 expect(tree.comment.text).equal('my super first comment') 145 expect(tree.comment.text).equal('my super first comment')
142 expect(tree.children).to.have.lengthOf(2) 146 expect(tree.children).to.have.lengthOf(2)
143 147
144 const firstChild = tree.children[0] 148 const firstChild = tree.children[0]
145 expect(firstChild.comment.text).to.equal('my super answer to thread 1') 149 expect(firstChild.comment.text).to.equal('my super answer to thread 1')
146 expect(firstChild.children).to.have.lengthOf(1) 150 expect(firstChild.children).to.have.lengthOf(1)
147 151
148 const childOfFirstChild = firstChild.children[0] 152 const childOfFirstChild = firstChild.children[0]
149 expect(childOfFirstChild.comment.text).to.equal('my super answer to answer of thread 1') 153 expect(childOfFirstChild.comment.text).to.equal('my super answer to answer of thread 1')
150 expect(childOfFirstChild.children).to.have.lengthOf(0) 154 expect(childOfFirstChild.children).to.have.lengthOf(0)
151 155
152 const secondChild = tree.children[1] 156 const secondChild = tree.children[1]
153 expect(secondChild.comment.text).to.equal('my second answer to thread 1') 157 expect(secondChild.comment.text).to.equal('my second answer to thread 1')
154 expect(secondChild.children).to.have.lengthOf(0) 158 expect(secondChild.children).to.have.lengthOf(0)
155 159
156 replyToDeleteId = secondChild.comment.id 160 replyToDeleteId = secondChild.comment.id
157 }) 161 })
158 162
159 it('Should create other threads', async function () { 163 it('Should create other threads', async function () {
160 const text1 = 'super thread 2' 164 const text1 = 'super thread 2'
161 await addVideoCommentThread(server.url, server.accessToken, videoUUID, text1) 165 await addVideoCommentThread(server.url, server.accessToken, videoUUID, text1)
162 166
163 const text2 = 'super thread 3' 167 const text2 = 'super thread 3'
164 await addVideoCommentThread(server.url, server.accessToken, videoUUID, text2) 168 await addVideoCommentThread(server.url, server.accessToken, videoUUID, text2)
165 }) 169 })
166 170
167 it('Should list the threads', async function () { 171 it('Should list the threads', async function () {
168 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5, 'createdAt') 172 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5, 'createdAt')
169 173
170 expect(res.body.total).to.equal(3) 174 expect(res.body.total).to.equal(3)
171 expect(res.body.data).to.be.an('array') 175 expect(res.body.data).to.be.an('array')
172 expect(res.body.data).to.have.lengthOf(3) 176 expect(res.body.data).to.have.lengthOf(3)
173 177
174 expect(res.body.data[0].text).to.equal('my super first comment') 178 expect(res.body.data[0].text).to.equal('my super first comment')
175 expect(res.body.data[0].totalReplies).to.equal(3) 179 expect(res.body.data[0].totalReplies).to.equal(3)
176 expect(res.body.data[1].text).to.equal('super thread 2') 180 expect(res.body.data[1].text).to.equal('super thread 2')
177 expect(res.body.data[1].totalReplies).to.equal(0) 181 expect(res.body.data[1].totalReplies).to.equal(0)
178 expect(res.body.data[2].text).to.equal('super thread 3') 182 expect(res.body.data[2].text).to.equal('super thread 3')
179 expect(res.body.data[2].totalReplies).to.equal(0) 183 expect(res.body.data[2].totalReplies).to.equal(0)
180 }) 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 })
206 210
207 it('Should delete a complete thread', async function () { 211 it('Should delete a complete thread', async function () {
208 await deleteVideoComment(server.url, server.accessToken, videoId, threadId) 212 await deleteVideoComment(server.url, server.accessToken, videoId, threadId)
209 213
210 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5, 'createdAt') 214 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5, 'createdAt')
211 expect(res.body.total).to.equal(3) 215 expect(res.body.total).to.equal(3)
212 expect(res.body.data).to.be.an('array') 216 expect(res.body.data).to.be.an('array')
213 expect(res.body.data).to.have.lengthOf(3) 217 expect(res.body.data).to.have.lengthOf(3)
214 218
215 expect(res.body.data[0].text).to.equal('') 219 expect(res.body.data[0].text).to.equal('')
216 expect(res.body.data[0].isDeleted).to.be.true 220 expect(res.body.data[0].isDeleted).to.be.true
217 expect(res.body.data[0].deletedAt).to.not.be.null 221 expect(res.body.data[0].deletedAt).to.not.be.null
218 expect(res.body.data[0].account).to.be.null 222 expect(res.body.data[0].account).to.be.null
219 expect(res.body.data[0].totalReplies).to.equal(3) 223 expect(res.body.data[0].totalReplies).to.equal(3)
220 expect(res.body.data[1].text).to.equal('super thread 2') 224 expect(res.body.data[1].text).to.equal('super thread 2')
221 expect(res.body.data[1].totalReplies).to.equal(0) 225 expect(res.body.data[1].totalReplies).to.equal(0)
222 expect(res.body.data[2].text).to.equal('super thread 3') 226 expect(res.body.data[2].text).to.equal('super thread 3')
223 expect(res.body.data[2].totalReplies).to.equal(0) 227 expect(res.body.data[2].totalReplies).to.equal(0)
228 })
229
230 it('Should count replies from the video author correctly', async function () {
231 const text = 'my super first comment'
232 await addVideoCommentThread(server.url, server.accessToken, videoUUID, text)
233 let res = await getVideoCommentThreads(server.url, videoUUID, 0, 5)
234 const comment: VideoComment = res.body.data[0]
235 const threadId2 = comment.threadId
236
237 const text2 = 'a first answer to thread 4 by a third party'
238 await addVideoCommentReply(server.url, userAccessTokenServer1, videoId, threadId2, text2)
239
240 const text3 = 'my second answer to thread 4'
241 await addVideoCommentReply(server.url, server.accessToken, videoId, threadId2, text3)
242
243 res = await getVideoThreadComments(server.url, videoUUID, threadId2)
244 const tree: VideoCommentThreadTree = res.body
245 expect(tree.comment.totalReplies).to.equal(tree.comment.totalRepliesFromVideoAuthor + 1)
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 })
232 269
233 const text2 = 'a first answer to thread 4 by a third party' 270 expect(comments).to.have.lengthOf(0)
234 await addVideoCommentReply(server.url, userAccessTokenServer1, videoId, threadId2, text2) 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 })
282
283 it('Should search instance comments by video', async function () {
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/server/tests/api/videos/video-playlists.ts b/server/tests/api/videos/video-playlists.ts
index 0bfb5bcd4..b194665ba 100644
--- a/server/tests/api/videos/video-playlists.ts
+++ b/server/tests/api/videos/video-playlists.ts
@@ -628,7 +628,7 @@ describe('Test video playlists', function () {
628 let video3: string 628 let video3: string
629 629
630 before(async function () { 630 before(async function () {
631 this.timeout(30000) 631 this.timeout(60000)
632 632
633 groupUser1 = [ Object.assign({}, servers[0], { accessToken: userAccessTokenServer1 }) ] 633 groupUser1 = [ Object.assign({}, servers[0], { accessToken: userAccessTokenServer1 }) ]
634 groupWithoutToken1 = [ Object.assign({}, servers[0], { accessToken: undefined }) ] 634 groupWithoutToken1 = [ Object.assign({}, servers[0], { accessToken: undefined }) ]
@@ -656,6 +656,8 @@ describe('Test video playlists', function () {
656 video2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video 90' })).uuid 656 video2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video 90' })).uuid
657 video3 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 91', nsfw: true })).uuid 657 video3 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 91', nsfw: true })).uuid
658 658
659 await waitJobs(servers)
660
659 await addVideo({ videoId: video1, startTimestamp: 15, stopTimestamp: 28 }) 661 await addVideo({ videoId: video1, startTimestamp: 15, stopTimestamp: 28 })
660 await addVideo({ videoId: video2, startTimestamp: 35 }) 662 await addVideo({ videoId: video2, startTimestamp: 35 })
661 await addVideo({ videoId: video3 }) 663 await addVideo({ videoId: video3 })
diff --git a/server/types/models/video/video-comment.ts b/server/types/models/video/video-comment.ts
index f1c50c753..83479e7b2 100644
--- a/server/types/models/video/video-comment.ts
+++ b/server/types/models/video/video-comment.ts
@@ -1,7 +1,7 @@
1import { VideoCommentModel } from '../../../models/video/video-comment'
2import { PickWith, PickWithOpt } from '@shared/core-utils' 1import { PickWith, PickWithOpt } from '@shared/core-utils'
2import { VideoCommentModel } from '../../../models/video/video-comment'
3import { MAccountDefault, MAccountFormattable, MAccountUrl } from '../account' 3import { MAccountDefault, MAccountFormattable, MAccountUrl } from '../account'
4import { MVideoAccountLight, MVideoFeed, MVideoIdUrl, MVideoUrl } from './video' 4import { MVideo, MVideoAccountLight, MVideoFeed, MVideoIdUrl, MVideoUrl } from './video'
5 5
6type Use<K extends keyof VideoCommentModel, M> = PickWith<VideoCommentModel, K, M> 6type Use<K extends keyof VideoCommentModel, M> = PickWith<VideoCommentModel, K, M>
7 7
@@ -59,6 +59,11 @@ export type MCommentFormattable =
59 MCommentTotalReplies & 59 MCommentTotalReplies &
60 Use<'Account', MAccountFormattable> 60 Use<'Account', MAccountFormattable>
61 61
62export type MCommentAdminFormattable =
63 MComment &
64 Use<'Account', MAccountFormattable> &
65 Use<'Video', MVideo>
66
62export type MCommentAP = 67export type MCommentAP =
63 MComment & 68 MComment &
64 Use<'Account', MAccountUrl> & 69 Use<'Account', MAccountUrl> &
diff --git a/shared/core-utils/users/user-role.ts b/shared/core-utils/users/user-role.ts
index 2b322faf3..81cba1dad 100644
--- a/shared/core-utils/users/user-role.ts
+++ b/shared/core-utils/users/user-role.ts
@@ -22,7 +22,8 @@ const userRoleRights: { [ id in UserRole ]: UserRight[] } = {
22 UserRight.SEE_ALL_VIDEOS, 22 UserRight.SEE_ALL_VIDEOS,
23 UserRight.MANAGE_ACCOUNTS_BLOCKLIST, 23 UserRight.MANAGE_ACCOUNTS_BLOCKLIST,
24 UserRight.MANAGE_SERVERS_BLOCKLIST, 24 UserRight.MANAGE_SERVERS_BLOCKLIST,
25 UserRight.MANAGE_USERS 25 UserRight.MANAGE_USERS,
26 UserRight.SEE_ALL_COMMENTS
26 ], 27 ],
27 28
28 [UserRole.USER]: [] 29 [UserRole.USER]: []
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,
diff --git a/shared/models/users/user-right.enum.ts b/shared/models/users/user-right.enum.ts
index e815fa893..bbedc9f00 100644
--- a/shared/models/users/user-right.enum.ts
+++ b/shared/models/users/user-right.enum.ts
@@ -32,6 +32,7 @@ export const enum UserRight {
32 32
33 GET_ANY_LIVE, 33 GET_ANY_LIVE,
34 SEE_ALL_VIDEOS, 34 SEE_ALL_VIDEOS,
35 SEE_ALL_COMMENTS,
35 CHANGE_VIDEO_OWNERSHIP, 36 CHANGE_VIDEO_OWNERSHIP,
36 37
37 MANAGE_PLUGINS, 38 MANAGE_PLUGINS,
diff --git a/shared/models/videos/video-comment.model.ts b/shared/models/videos/video-comment.model.ts
index eec7dba1c..9730a3f76 100644
--- a/shared/models/videos/video-comment.model.ts
+++ b/shared/models/videos/video-comment.model.ts
@@ -16,6 +16,26 @@ export interface VideoComment {
16 account: Account 16 account: Account
17} 17}
18 18
19export interface VideoCommentAdmin {
20 id: number
21 url: string
22 text: string
23
24 threadId: number
25 inReplyToCommentId: number
26
27 createdAt: Date | string
28 updatedAt: Date | string
29
30 account: Account
31
32 video: {
33 id: number
34 uuid: string
35 name: string
36 }
37}
38
19export interface VideoCommentThreadTree { 39export interface VideoCommentThreadTree {
20 comment: VideoComment 40 comment: VideoComment
21 children: VideoCommentThreadTree[] 41 children: VideoCommentThreadTree[]