Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Add ability to auto block videos from auto tags

Chocobozzz1f79ed40cfc9
diff --git a/client/src/app/+admin/admin-moderation.component.ts b/client/src/app/+admin/admin-moderation.component.ts
index e03c5982e6..9c6a24bb12 100644
--- a/client/src/app/+admin/admin-moderation.component.ts
+++ b/client/src/app/+admin/admin-moderation.component.ts
@@ -71,7 +71,7 @@ export class AdminModerationComponent implements OnInit {
if (this.hasRight(UserRight.MANAGE_SERVER_BLOCKLIST_SUBSCRIPTIONS)) {
item.children.push({
- label: $localize`Blocklist subscriptions`,
+ label: $localize`Subscriptions`,
routerLink: '/admin/moderation/blocklist/subscriptions'
})
}
@@ -81,20 +81,30 @@ export class AdminModerationComponent implements OnInit {
this.menuEntries.push(item)
}
- if (this.hasRight(UserRight.MANAGE_INSTANCE_WATCHED_WORDS)) {
+ if (this.hasRight(UserRight.MANAGE_INSTANCE_WATCHED_WORDS) || this.hasRight(UserRight.MANAGE_INSTANCE_AUTO_TAGS)) {
const item: HorizontalMenuEntry = {
label: $localize`Watched words`,
routerLink: '',
- children: [
- {
- label: $localize`Lists`,
- routerLink: '/admin/moderation/watched-words/list'
- },
- {
- label: $localize`Subscriptions`,
- routerLink: '/admin/moderation/watched-words/subscriptions'
- }
- ]
+ children: []
+ }
+
+ if (this.hasRight(UserRight.MANAGE_INSTANCE_WATCHED_WORDS)) {
+ item.children.push({
+ label: $localize`Lists`,
+ routerLink: '/admin/moderation/watched-words/list'
+ })
+
+ item.children.push({
+ label: $localize`Subscriptions`,
+ routerLink: '/admin/moderation/watched-words/subscriptions'
+ })
+ }
+
+ if (this.hasRight(UserRight.MANAGE_INSTANCE_AUTO_TAGS)) {
+ item.children.push({
+ label: $localize`Auto tag policies`,
+ routerLink: '/admin/moderation/watched-words/automatic-tag-policies'
+ })
}
item.routerLink = item.children[0].routerLink
diff --git a/client/src/app/+admin/moderation/automatic-tag-policies/automatic-tag-policies-admin.component.html b/client/src/app/+admin/moderation/automatic-tag-policies/automatic-tag-policies-admin.component.html
new file mode 100644
index 0000000000..cb8053a48c
--- /dev/null
+++ b/client/src/app/+admin/moderation/automatic-tag-policies/automatic-tag-policies-admin.component.html
@@ -0,0 +1,10 @@
+<strong class="d-block mb-3" i18n>Automatically block videos:</strong>
+
+@for (tag of tags; track tag; let i = $index) {
+ <div class="form-group ms-3">
+ <my-peertube-checkbox
+ [inputName]="'tag-' + i" [(ngModel)]="tag.autoBlock" [labelInnerHTML]="getLabelText(tag)"
+ (ngModelChange)="updatePolicies()"
+ ></my-peertube-checkbox>
+ </div>
+}
diff --git a/client/src/app/+admin/moderation/automatic-tag-policies/automatic-tag-policies-admin.component.ts b/client/src/app/+admin/moderation/automatic-tag-policies/automatic-tag-policies-admin.component.ts
new file mode 100644
index 0000000000..ae3a68fce5
--- /dev/null
+++ b/client/src/app/+admin/moderation/automatic-tag-policies/automatic-tag-policies-admin.component.ts
@@ -0,0 +1,48 @@
+import { Component, OnInit, inject } from '@angular/core'
+import { FormsModule } from '@angular/forms'
+import { ActivatedRoute } from '@angular/router'
+import { HtmlRendererService, Notifier } from '@app/core'
+import { PeertubeCheckboxComponent } from '@app/shared/shared-forms/peertube-checkbox.component'
+import { AutomaticTagService } from '@app/shared/shared-moderation/automatic-tag.service'
+import { AutomaticTagAvailableType } from '@peertube/peertube-models'
+import { AutomaticTagPoliciesAdminTag } from './automatic-tag-policies-admin.resolver'
+
+@Component({
+ templateUrl: './automatic-tag-policies-admin.component.html',
+ imports: [
+ FormsModule,
+ PeertubeCheckboxComponent
+ ]
+})
+export class AutomaticTagPoliciesAdminComponent implements OnInit {
+ private autoTagsService = inject(AutomaticTagService)
+ private notifier = inject(Notifier)
+ private html = inject(HtmlRendererService)
+ private route = inject(ActivatedRoute)
+
+ tags: AutomaticTagPoliciesAdminTag[] = []
+
+ ngOnInit () {
+ this.tags = this.route.snapshot.data['tags']
+ }
+
+ getLabelText (tag: { name: string, type: AutomaticTagAvailableType }) {
+ const text = tag.name === 'external-link'
+ ? $localize`That contain <strong>an external link</strong>`
+ : $localize`That contain any word from your <strong>${tag.name}</strong> watched word list`
+
+ return this.html.toSimpleSafeHtml(text)
+ }
+
+ updatePolicies () {
+ this.autoTagsService.updateServerVideoPolicies({
+ autoBlock: this.tags.filter(t => t.autoBlock).map(t => t.name)
+ }).subscribe({
+ next: () => {
+ this.notifier.success($localize`Video auto-block policies updated`)
+ },
+
+ error: err => this.notifier.handleError(err)
+ })
+ }
+}
diff --git a/client/src/app/+admin/moderation/automatic-tag-policies/automatic-tag-policies-admin.resolver.ts b/client/src/app/+admin/moderation/automatic-tag-policies/automatic-tag-policies-admin.resolver.ts
new file mode 100644
index 0000000000..f581b830d1
--- /dev/null
+++ b/client/src/app/+admin/moderation/automatic-tag-policies/automatic-tag-policies-admin.resolver.ts
@@ -0,0 +1,25 @@
+import { inject } from '@angular/core'
+import { ResolveFn } from '@angular/router'
+import { AutomaticTagService } from '@app/shared/shared-moderation/automatic-tag.service'
+import { AutomaticTagAvailableType } from '@peertube/peertube-models'
+import { forkJoin, map } from 'rxjs'
+
+export type AutomaticTagPoliciesAdminTag = {
+ name: string
+ autoBlock: boolean
+ type: AutomaticTagAvailableType
+}
+
+export const automaticTagPoliciesAdminResolver: ResolveFn<AutomaticTagPoliciesAdminTag[]> = () => {
+ const autoTagService = inject(AutomaticTagService)
+
+ return forkJoin([
+ autoTagService.getServerAutomaticTagAvailable(),
+ autoTagService.getServerVideoPolicies()
+ ]).pipe(
+ map(([ resAvailable, policies ]) => {
+ return resAvailable.available
+ .map(a => ({ name: a.name, type: a.type, autoBlock: policies.autoBlock.includes(a.name) }))
+ })
+ )
+}
diff --git a/client/src/app/+admin/moderation/moderation.routes.ts b/client/src/app/+admin/moderation/moderation.routes.ts
index 39d1cbd34f..5b8cfe95e3 100644
--- a/client/src/app/+admin/moderation/moderation.routes.ts
+++ b/client/src/app/+admin/moderation/moderation.routes.ts
@@ -11,6 +11,8 @@ import { UserRight } from '@peertube/peertube-models'
import { RegistrationListComponent } from './registration-list'
import { WatchedWordsListAdminComponent } from './watched-words-list/watched-words-list-admin.component'
import { WatchedWordsSubscriptionsComponent } from './watched-words-subscriptions/watched-words-subscriptions.component'
+import { AutomaticTagPoliciesAdminComponent } from './automatic-tag-policies/automatic-tag-policies-admin.component'
+import { automaticTagPoliciesAdminResolver } from './automatic-tag-policies/automatic-tag-policies-admin.resolver'
export const moderationRoutes: Routes = [
{
@@ -58,11 +60,6 @@ export const moderationRoutes: Routes = [
redirectTo: 'video-blocks/list',
pathMatch: 'full'
},
- {
- path: 'video-blacklist',
- redirectTo: 'video-blocks/list',
- pathMatch: 'full'
- },
{
path: 'video-blocks/list',
component: VideoBlockListComponent,
@@ -129,7 +126,7 @@ export const moderationRoutes: Routes = [
data: {
userRight: UserRight.MANAGE_SERVER_BLOCKLIST_SUBSCRIPTIONS,
meta: {
- title: $localize`Blocklist subscriptions`
+ title: $localize`Mute list subscriptions`
}
}
},
@@ -156,6 +153,21 @@ export const moderationRoutes: Routes = [
title: $localize`Watched words subscriptions`
}
}
+ },
+
+ {
+ path: 'watched-words/automatic-tag-policies',
+ component: AutomaticTagPoliciesAdminComponent,
+ resolve: {
+ tags: automaticTagPoliciesAdminResolver
+ },
+ canActivate: [ UserRightGuard ],
+ data: {
+ userRight: UserRight.MANAGE_INSTANCE_AUTO_TAGS,
+ meta: {
+ title: $localize`Auto tag policies`
+ }
+ }
}
]
}
diff --git a/client/src/app/+admin/moderation/video-block-list/video-block-list.component.html b/client/src/app/+admin/moderation/video-block-list/video-block-list.component.html
index 2688574258..e267d7cd41 100644
--- a/client/src/app/+admin/moderation/video-block-list/video-block-list.component.html
+++ b/client/src/app/+admin/moderation/video-block-list/video-block-list.component.html
@@ -25,7 +25,9 @@
>
<div>
@if (videoBlock.type === 2) {
- <span i18n-title title="The video was blocked due to automatic blocking of new videos" class="pt-badge badge-info badge-small" i18n>Auto block</span>
+ <span i18n-title title="The video was blocked due to automatic blocking of new videos on this instance" class="pt-badge badge-info badge-small" i18n>Auto block - Instance policy</span>
+ } @else if (videoBlock.type === 3) {
+ <span i18n-title title="The video was blocked due to automatic blocking of videos with specific tags" class="pt-badge badge-info badge-small" i18n>Auto block - Auto-tag policy</span>
}
</div>
</my-video-cell>
diff --git a/client/src/app/+admin/moderation/video-block-list/video-block-list.component.ts b/client/src/app/+admin/moderation/video-block-list/video-block-list.component.ts
index c3b7f2519a..752aee1245 100644
--- a/client/src/app/+admin/moderation/video-block-list/video-block-list.component.ts
+++ b/client/src/app/+admin/moderation/video-block-list/video-block-list.component.ts
@@ -62,8 +62,9 @@ export class VideoBlockListComponent implements OnInit {
title: $localize`Block type`,
options: [
{ value: 'all', label: $localize`All` },
- { value: VideoBlacklistType['AUTO_BEFORE_PUBLISHED'], label: $localize`Automatic blocks` },
- { value: VideoBlacklistType['MANUAL'], label: $localize`Manual blocks` }
+ { value: VideoBlacklistType.AUTO_BY_INSTANCE_POLICY, label: $localize`Auto-block by instance policy` },
+ { value: VideoBlacklistType.AUTO_BY_AUTO_TAG_POLICY, label: $localize`Auto-block by auto-tag policy` },
+ { value: VideoBlacklistType.MANUAL, label: $localize`Manual blocks` }
]
}
]
@@ -89,13 +90,13 @@ export class VideoBlockListComponent implements OnInit {
{
label: () => $localize`Internal actions`,
isHeader: true,
- isDisplayed: videoBlock => videoBlock.type === VideoBlacklistType.AUTO_BEFORE_PUBLISHED,
+ isDisplayed: videoBlock => videoBlock.type !== VideoBlacklistType.MANUAL,
enableBulk: true
},
{
label: () => $localize`Switch to manual block`,
handler: videoBlocks => this.switchVideosBlockToManual(videoBlocks),
- isDisplayed: videoBlock => videoBlock.type === VideoBlacklistType.AUTO_BEFORE_PUBLISHED,
+ isDisplayed: videoBlock => videoBlock.type !== VideoBlacklistType.MANUAL,
enableBulk: true
}
],
diff --git a/client/src/app/+admin/moderation/watched-words-list/watched-words-list-admin.component.html b/client/src/app/+admin/moderation/watched-words-list/watched-words-list-admin.component.html
index 6196ed6f85..886ab84c5a 100644
--- a/client/src/app/+admin/moderation/watched-words-list/watched-words-list-admin.component.html
+++ b/client/src/app/+admin/moderation/watched-words-list/watched-words-list-admin.component.html
@@ -1,6 +1,7 @@
<div class="callout callout-primary mb-4">
<div i18n>Video name/description and comments that contain any of the watched words are automatically tagged with the name of the list.</div>
- <div i18n>These automatic tags can be used to filter comments and videos.</div>
+ <div i18n>These automatic tags can be used to filter comments and videos. They can also be used to <a routerLink="/admin/moderation/watched-words/automatic-tag-policies">automatically block</a> videos.</div>
+
</div>
<my-watched-words-list-admin-owner mode="admin"></my-watched-words-list-admin-owner>
diff --git a/client/src/app/+admin/moderation/watched-words-list/watched-words-list-admin.component.ts b/client/src/app/+admin/moderation/watched-words-list/watched-words-list-admin.component.ts
index 09f7d298c4..c6aef99379 100644
--- a/client/src/app/+admin/moderation/watched-words-list/watched-words-list-admin.component.ts
+++ b/client/src/app/+admin/moderation/watched-words-list/watched-words-list-admin.component.ts
@@ -1,10 +1,12 @@
import { Component } from '@angular/core'
+import { RouterLink } from '@angular/router'
import { WatchedWordsListAdminOwnerComponent } from '@app/shared/shared-watched-words/watched-words-list-admin-owner.component'
@Component({
templateUrl: './watched-words-list-admin.component.html',
imports: [
+ RouterLink,
WatchedWordsListAdminOwnerComponent
]
})
diff --git a/client/src/app/+admin/routes.ts b/client/src/app/+admin/routes.ts
index 43abebf708..83b9bcdfce 100644
--- a/client/src/app/+admin/routes.ts
+++ b/client/src/app/+admin/routes.ts
@@ -15,6 +15,7 @@ import { FindInBulkService } from '@app/shared/shared-search/find-in-bulk.servic
import { SearchService } from '@app/shared/shared-search/search.service'
import { TwoFactorService } from '@app/shared/shared-users/two-factor.service'
import { UserAdminService } from '@app/shared/shared-users/user-admin.service'
+import { AutomaticTagService } from '@app/shared/shared-moderation/automatic-tag.service'
import { VideoCommentService } from '@app/shared/shared-video-comment/video-comment.service'
import { WatchedWordsListService } from '@app/shared/shared-watched-words/watched-words-list.service'
import { AdminModerationComponent } from './admin-moderation.component'
@@ -51,7 +52,8 @@ const commonConfig = {
DynamicElementService,
FindInBulkService,
SearchService,
- WatchedWordsListService
+ WatchedWordsListService,
+ AutomaticTagService
]
}
diff --git a/client/src/app/+my-library/my-auto-tag-policies/my-auto-tag-policies.component.ts b/client/src/app/+my-library/my-auto-tag-policies/my-auto-tag-policies.component.ts
index e6f3795a70..d009aa22cd 100644
--- a/client/src/app/+my-library/my-auto-tag-policies/my-auto-tag-policies.component.ts
+++ b/client/src/app/+my-library/my-auto-tag-policies/my-auto-tag-policies.component.ts
@@ -3,9 +3,8 @@ import { FormsModule } from '@angular/forms'
import { ActivatedRoute } from '@angular/router'
import { AuthService, HtmlRendererService, Notifier } from '@app/core'
import { PeertubeCheckboxComponent } from '@app/shared/shared-forms/peertube-checkbox.component'
-
+import { AutomaticTagService } from '@app/shared/shared-moderation/automatic-tag.service'
import { AutomaticTagAvailableType } from '@peertube/peertube-models'
-import { AutomaticTagService } from './automatic-tag.service'
import { AutoTagPoliciesTag } from './my-auto-tag-policies.resolver'
@Component({
diff --git a/client/src/app/+my-library/my-auto-tag-policies/my-auto-tag-policies.resolver.ts b/client/src/app/+my-library/my-auto-tag-policies/my-auto-tag-policies.resolver.ts
index 105005e6ab..0009bc9dcc 100644
--- a/client/src/app/+my-library/my-auto-tag-policies/my-auto-tag-policies.resolver.ts
+++ b/client/src/app/+my-library/my-auto-tag-policies/my-auto-tag-policies.resolver.ts
@@ -1,9 +1,9 @@
import { inject } from '@angular/core'
import { ResolveFn } from '@angular/router'
import { AuthService } from '@app/core'
+import { AutomaticTagService } from '@app/shared/shared-moderation/automatic-tag.service'
import { AutomaticTagAvailableType } from '@peertube/peertube-models'
import { forkJoin, map } from 'rxjs'
-import { AutomaticTagService } from './automatic-tag.service'
export type AutoTagPoliciesTag = {
name: string
diff --git a/client/src/app/+my-library/routes.ts b/client/src/app/+my-library/routes.ts
index bc6e8fb4ca..11aecb9d96 100644
--- a/client/src/app/+my-library/routes.ts
+++ b/client/src/app/+my-library/routes.ts
@@ -10,7 +10,7 @@ import { LiveVideoService } from '@app/shared/shared-video-live/live-video.servi
import { WatchedWordsListService } from '@app/shared/shared-watched-words/watched-words-list.service'
import { LoginGuard } from '../core'
import { CommentsOnMyVideosComponent } from './comments-on-my-videos/comments-on-my-videos.component'
-import { AutomaticTagService } from './my-auto-tag-policies/automatic-tag.service'
+import { AutomaticTagService } from '@app/shared/shared-moderation/automatic-tag.service'
import { MyAutoTagPoliciesComponent } from './my-auto-tag-policies/my-auto-tag-policies.component'
import { autoTagPoliciesResolver } from './my-auto-tag-policies/my-auto-tag-policies.resolver'
import { MyChannelSpaceComponent } from './my-channel-space.component'
diff --git a/client/src/app/+my-library/my-auto-tag-policies/automatic-tag.service.ts b/client/src/app/shared/shared-moderation/automatic-tag.service.ts
similarity index 59%
rename from client/src/app/+my-library/my-auto-tag-policies/automatic-tag.service.ts
rename to client/src/app/shared/shared-moderation/automatic-tag.service.ts
index 18a5c11f4b..afdbdf4608 100644
--- a/client/src/app/+my-library/my-auto-tag-policies/automatic-tag.service.ts
+++ b/client/src/app/shared/shared-moderation/automatic-tag.service.ts
@@ -1,7 +1,7 @@
import { HttpClient } from '@angular/common/http'
import { Injectable, inject } from '@angular/core'
import { RestExtractor } from '@app/core'
-import { AutomaticTagAvailable, CommentAutomaticTagPolicies } from '@peertube/peertube-models'
+import { AutomaticTagAvailable, CommentAutomaticTagPolicies, VideoAutoTagPolicies, VideoAutomaticTagPoliciesUpdate } from '@peertube/peertube-models'
import { catchError } from 'rxjs/operators'
import { environment } from '../../../environments/environment'
@@ -39,4 +39,27 @@ export class AutomaticTagService {
return this.authHttp.put(url, { review: options.review })
.pipe(catchError(res => this.restExtractor.handleError(res)))
}
+
+ // ---------------------------------------------------------------------------
+
+ getServerAutomaticTagAvailable () {
+ const url = AutomaticTagService.BASE_AUTOMATIC_TAGS_URL + 'server/available'
+
+ return this.authHttp.get<AutomaticTagAvailable>(url)
+ .pipe(catchError(res => this.restExtractor.handleError(res)))
+ }
+
+ getServerVideoPolicies () {
+ const url = AutomaticTagService.BASE_AUTOMATIC_TAGS_URL + 'policies/server/videos'
+
+ return this.authHttp.get<VideoAutoTagPolicies>(url)
+ .pipe(catchError(res => this.restExtractor.handleError(res)))
+ }
+
+ updateServerVideoPolicies (options: VideoAutomaticTagPoliciesUpdate) {
+ const url = AutomaticTagService.BASE_AUTOMATIC_TAGS_URL + 'policies/server/videos'
+
+ return this.authHttp.put(url, options)
+ .pipe(catchError(res => this.restExtractor.handleError(res)))
+ }
}
diff --git a/packages/models/src/moderation/automatic-tag-policy.enum.ts b/packages/models/src/moderation/automatic-tag-policy.enum.ts
index 38d8f41fc8..238c33ee0f 100644
--- a/packages/models/src/moderation/automatic-tag-policy.enum.ts
+++ b/packages/models/src/moderation/automatic-tag-policy.enum.ts
@@ -1,6 +1,7 @@
export const AutomaticTagPolicy = {
NONE: 1,
- REVIEW_COMMENT: 2
+ REVIEW_COMMENT: 2,
+ AUTO_BLACKLIST_VIDEO: 3
} as const
export type AutomaticTagPolicyType = typeof AutomaticTagPolicy[keyof typeof AutomaticTagPolicy]
diff --git a/packages/models/src/moderation/index.ts b/packages/models/src/moderation/index.ts
index 2fc83ddd78..5299d4861d 100644
--- a/packages/models/src/moderation/index.ts
+++ b/packages/models/src/moderation/index.ts
@@ -3,6 +3,8 @@ export * from './automatic-tag-available.model.js'
export * from './account-block.model.js'
export * from './comment-automatic-tag-policies-update.model.js'
export * from './comment-automatic-tag-policies.model.js'
+export * from './video-automatic-tag-policies-update.model.js'
+export * from './video-automatic-tag-policies.model.js'
export * from './automatic-tag-policy.enum.js'
export * from './auto-mute-list.model.js'
export * from './block-status.model.js'
diff --git a/packages/models/src/moderation/video-automatic-tag-policies-update.model.ts b/packages/models/src/moderation/video-automatic-tag-policies-update.model.ts
new file mode 100644
index 0000000000..96c6d9838b
--- /dev/null
+++ b/packages/models/src/moderation/video-automatic-tag-policies-update.model.ts
@@ -0,0 +1,3 @@
+export interface VideoAutomaticTagPoliciesUpdate {
+ autoBlock: string[]
+}
diff --git a/packages/models/src/moderation/video-automatic-tag-policies.model.ts b/packages/models/src/moderation/video-automatic-tag-policies.model.ts
new file mode 100644
index 0000000000..547a35a3d7
--- /dev/null
+++ b/packages/models/src/moderation/video-automatic-tag-policies.model.ts
@@ -0,0 +1,3 @@
+export interface VideoAutoTagPolicies {
+ autoBlock: string[]
+}
diff --git a/packages/models/src/videos/blacklist/video-blacklist.model.ts b/packages/models/src/videos/blacklist/video-blacklist.model.ts
index 1ca5bbbb75..71d33ddd86 100644
--- a/packages/models/src/videos/blacklist/video-blacklist.model.ts
+++ b/packages/models/src/videos/blacklist/video-blacklist.model.ts
@@ -2,7 +2,8 @@ import { Video } from '../video.model.js'
export const VideoBlacklistType = {
MANUAL: 1,
- AUTO_BEFORE_PUBLISHED: 2
+ AUTO_BY_INSTANCE_POLICY: 2,
+ AUTO_BY_AUTO_TAG_POLICY: 3
} as const
export type VideoBlacklistType_Type = typeof VideoBlacklistType[keyof typeof VideoBlacklistType]
diff --git a/packages/server-commands/src/moderation/automatic-tags-command.ts b/packages/server-commands/src/moderation/automatic-tags-command.ts
index fb6dfaa88b..cb504e6985 100644
--- a/packages/server-commands/src/moderation/automatic-tags-command.ts
+++ b/packages/server-commands/src/moderation/automatic-tags-command.ts
@@ -3,15 +3,18 @@ import {
AutomaticTagAvailable,
CommentAutomaticTagPolicies,
CommentAutomaticTagPoliciesUpdate,
- HttpStatusCode
+ HttpStatusCode,
+ VideoAutoTagPolicies,
+ VideoAutomaticTagPoliciesUpdate
} from '@peertube/peertube-models'
import { AbstractCommand, OverrideCommandOptions } from '../shared/index.js'
export class AutomaticTagsCommand extends AbstractCommand {
-
- getCommentPolicies (options: OverrideCommandOptions & {
- accountName: string
- }) {
+ getCommentPolicies (
+ options: OverrideCommandOptions & {
+ accountName: string
+ }
+ ) {
const path = '/api/v1/automatic-tags/policies/accounts/' + options.accountName + '/comments'
return this.getRequestBody<CommentAutomaticTagPolicies>({
@@ -23,9 +26,11 @@ export class AutomaticTagsCommand extends AbstractCommand {
})
}
- updateCommentPolicies (options: OverrideCommandOptions & CommentAutomaticTagPoliciesUpdate & {
- accountName: string
- }) {
+ updateCommentPolicies (
+ options: OverrideCommandOptions & CommentAutomaticTagPoliciesUpdate & {
+ accountName: string
+ }
+ ) {
const path = '/api/v1/automatic-tags/policies/accounts/' + options.accountName + '/comments'
return this.putBodyRequest({
@@ -40,9 +45,11 @@ export class AutomaticTagsCommand extends AbstractCommand {
// ---------------------------------------------------------------------------
- getAccountAvailable (options: OverrideCommandOptions & {
- accountName: string
- }) {
+ getAccountAvailable (
+ options: OverrideCommandOptions & {
+ accountName: string
+ }
+ ) {
const path = '/api/v1/automatic-tags/accounts/' + options.accountName + '/available'
return this.getRequestBody<AutomaticTagAvailable>({
@@ -65,4 +72,31 @@ export class AutomaticTagsCommand extends AbstractCommand {
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
+
+ // ---------------------------------------------------------------------------
+
+ getServerVideoPolicies (options: OverrideCommandOptions = {}) {
+ const path = '/api/v1/automatic-tags/policies/server/videos'
+
+ return this.getRequestBody<VideoAutoTagPolicies>({
+ ...options,
+
+ path,
+ implicitToken: true,
+ defaultExpectedStatus: HttpStatusCode.OK_200
+ })
+ }
+
+ updateServerVideoPolicies (options: OverrideCommandOptions & VideoAutomaticTagPoliciesUpdate) {
+ const path = '/api/v1/automatic-tags/policies/server/videos'
+
+ return this.putBodyRequest({
+ ...options,
+
+ path,
+ fields: pick(options, [ 'autoBlock' ]),
+ implicitToken: true,
+ defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
+ })
+ }
}
diff --git a/packages/tests/src/api/check-params/auto-tags.ts b/packages/tests/src/api/check-params/auto-tags.ts
index 011d000785..949217697d 100644
--- a/packages/tests/src/api/check-params/auto-tags.ts
+++ b/packages/tests/src/api/check-params/auto-tags.ts
@@ -131,6 +131,60 @@ describe('Test auto tag policies API validator', function () {
})
})
+ describe('When getting server auto tag video policies', function () {
+ it('Should fail without token', async function () {
+ await server.autoTags.getServerVideoPolicies({ token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
+ })
+
+ it('Should fail with a user that does not have enough rights', async function () {
+ await server.autoTags.getServerVideoPolicies({ token: userToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
+ })
+
+ it('Should succeed with the correct params', async function () {
+ await server.autoTags.getServerVideoPolicies()
+ })
+ })
+
+ describe('When updating server auto tag video policies', function () {
+ const baseParams = () => ({ autoBlock: [ 'external-link' ] })
+
+ it('Should fail without token', async function () {
+ await server.autoTags.updateServerVideoPolicies({
+ ...baseParams(),
+ token: null,
+ expectedStatus: HttpStatusCode.UNAUTHORIZED_401
+ })
+ })
+
+ it('Should fail with a user that does not have enough rights', async function () {
+ await server.autoTags.updateServerVideoPolicies({
+ ...baseParams(),
+ token: userToken,
+ expectedStatus: HttpStatusCode.FORBIDDEN_403
+ })
+ })
+
+ it('Should fail with invalid autoBlock array', async function () {
+ await server.autoTags.updateServerVideoPolicies({
+ ...baseParams(),
+ autoBlock: 'toto' as any,
+ expectedStatus: HttpStatusCode.BAD_REQUEST_400
+ })
+ })
+
+ it('Should fail with autoBlock array that does not contain available tags', async function () {
+ await server.autoTags.updateServerVideoPolicies({
+ ...baseParams(),
+ autoBlock: [ 'unknown-tag' ],
+ expectedStatus: HttpStatusCode.BAD_REQUEST_400
+ })
+ })
+
+ it('Should succeed with the correct params', async function () {
+ await server.autoTags.updateServerVideoPolicies(baseParams())
+ })
+ })
+
after(async function () {
await cleanupTests([ server ])
})
diff --git a/packages/tests/src/api/moderation/video-blacklist.ts b/packages/tests/src/api/moderation/video-blacklist.ts
index a69b2266fc..da93211024 100644
--- a/packages/tests/src/api/moderation/video-blacklist.ts
+++ b/packages/tests/src/api/moderation/video-blacklist.ts
@@ -118,7 +118,7 @@ describe('Test video blacklist', function () {
})
it('Should display nothing when applying automatic type filter', async function () {
- const body = await command.list({ type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED })
+ const body = await command.list({ type: VideoBlacklistType.AUTO_BY_INSTANCE_POLICY })
expect(body.total).to.equal(0)
const blacklistedVideos = body.data
@@ -306,7 +306,7 @@ describe('Test video blacklist', function () {
await makeActivityPubGetRequest(servers[0].url, `/videos/watch/${video3UUID}/dislikes`, HttpStatusCode.UNAUTHORIZED_401)
})
- it('Should remove the video from blacklist and refederate the video', async function () {
+ it('Should remove the video from blacklist and re-federate the video', async function () {
await command.remove({ videoId: video4UUID })
await waitJobs(servers)
@@ -317,7 +317,7 @@ describe('Test video blacklist', function () {
}
})
- it('Should not crash when unfederating an internal blacklisted video', async function () {
+ it('Should not crash when un-federating an internal blacklisted video', async function () {
const video = await servers[0].videos.quickUpload({ name: 'internal video', privacy: VideoPrivacy.INTERNAL })
await command.add({ videoId: video.uuid, reason: 'super reason', unfederate: true })
})
@@ -372,7 +372,7 @@ describe('Test video blacklist', function () {
it('Should auto blacklist a public video on upload', async function () {
const video = await servers[0].videos.quickUpload({ token: userWithoutFlag, name: 'blacklisted 1' })
- const body = await command.list({ sort: '-createdAt', type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED })
+ const body = await command.list({ sort: '-createdAt', type: VideoBlacklistType.AUTO_BY_INSTANCE_POLICY })
expect(body.total).to.equal(1)
expect(body.data[0].video.name).to.equal('blacklisted 1')
@@ -382,7 +382,7 @@ describe('Test video blacklist', function () {
it('Should auto blacklist an unlisted video on upload', async function () {
const video = await servers[0].videos.quickUpload({ token: userWithoutFlag, name: 'blacklisted 2', privacy: VideoPrivacy.UNLISTED })
- const body = await command.list({ sort: '-createdAt', type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED })
+ const body = await command.list({ sort: '-createdAt', type: VideoBlacklistType.AUTO_BY_INSTANCE_POLICY })
expect(body.total).to.equal(2)
expect(body.data[0].video.name).to.equal('blacklisted 2')
@@ -399,7 +399,7 @@ describe('Test video blacklist', function () {
}
})
- const body = await command.list({ sort: '-createdAt', type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED })
+ const body = await command.list({ sort: '-createdAt', type: VideoBlacklistType.AUTO_BY_INSTANCE_POLICY })
expect(body.total).to.equal(3)
expect(body.data[0].video.name).to.equal('blacklisted 3')
@@ -414,7 +414,7 @@ describe('Test video blacklist', function () {
}
const { video } = await servers[0].videoImports.importVideo({ token: userWithoutFlag, attributes })
- const body = await command.list({ sort: '-createdAt', type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED })
+ const body = await command.list({ sort: '-createdAt', type: VideoBlacklistType.AUTO_BY_INSTANCE_POLICY })
expect(body.total).to.equal(4)
expect(body.data[0].video.name).to.equal('URL import')
@@ -429,7 +429,7 @@ describe('Test video blacklist', function () {
}
const { video } = await servers[0].videoImports.importVideo({ token: userWithoutFlag, attributes })
- const body = await command.list({ sort: '-createdAt', type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED })
+ const body = await command.list({ sort: '-createdAt', type: VideoBlacklistType.AUTO_BY_INSTANCE_POLICY })
expect(body.total).to.equal(5)
expect(body.data[0].video.name).to.equal('Torrent import')
@@ -439,11 +439,187 @@ describe('Test video blacklist', function () {
it('Should not auto blacklist a video on upload if the user has the bypass blacklist flag', async function () {
await servers[0].videos.upload({ token: userWithFlag, attributes: { name: 'not blacklisted' } })
- const body = await command.list({ type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED })
+ const body = await command.list({ type: VideoBlacklistType.AUTO_BY_INSTANCE_POLICY })
expect(body.total).to.equal(5)
})
})
+ describe('When auto blacklist videos using automatic tags policies', function () {
+ let userToken: string
+ let userChannelId: number
+
+ async function listAutoBlacklistedVideos () {
+ const { data } = await command.list({ sort: '-createdAt' })
+
+ return data.filter(b => b.type === VideoBlacklistType.AUTO_BY_AUTO_TAG_POLICY)
+ }
+
+ async function expectVideoAutoBlacklisted (name: string) {
+ const data = await listAutoBlacklistedVideos()
+ const entry = data.find(b => b.video.name === name)
+
+ expect(entry, `Cannot find auto blacklisted video ${name}`).to.not.be.undefined
+
+ return entry
+ }
+
+ before(async function () {
+ await servers[0].config.disableAutoBlacklist()
+ })
+
+ describe('With built-in external link auto tag', function () {
+ before(async function () {
+ userToken = await servers[0].users.generateUserAndToken('auto_tag_policy_user')
+
+ const { videoChannels } = await servers[0].users.getMyInfo({ token: userToken })
+ userChannelId = videoChannels[0].id
+ })
+
+ it('Should setup server video auto-block policy for external-link tag', async function () {
+ await servers[0].autoTags.updateServerVideoPolicies({ autoBlock: [ 'external-link' ] })
+
+ const policies = await servers[0].autoTags.getServerVideoPolicies()
+ expect(policies.autoBlock).to.have.members([ 'external-link' ])
+ })
+
+ it('Should auto-blacklist video with external link when policy is set', async function () {
+ const beforeCount = (await listAutoBlacklistedVideos()).length
+
+ await servers[0].videos.upload({
+ token: userToken,
+ attributes: { name: 'video with link', description: 'Check example.com' }
+ })
+ await waitJobs(servers)
+
+ const data = await listAutoBlacklistedVideos()
+ expect(data).to.have.lengthOf(beforeCount + 1)
+ expect(data[0].video.name).to.equal('video with link')
+ })
+
+ it('Should not auto-blacklist video without matching tags', async function () {
+ const beforeCount = (await listAutoBlacklistedVideos()).length
+
+ await servers[0].videos.upload({
+ token: userToken,
+ attributes: { name: 'video without link', description: 'No external URL' }
+ })
+ await waitJobs(servers)
+
+ const data = await listAutoBlacklistedVideos()
+ expect(data).to.have.lengthOf(beforeCount)
+ })
+
+ it('Should clear policy and not auto-blacklist matching videos', async function () {
+ await servers[0].autoTags.updateServerVideoPolicies({ autoBlock: [] })
+
+ const policies = await servers[0].autoTags.getServerVideoPolicies()
+ expect(policies.autoBlock).to.have.lengthOf(0)
+
+ const beforeCount = (await listAutoBlacklistedVideos()).length
+
+ await servers[0].videos.upload({
+ token: userToken,
+ attributes: { name: 'video with link 2', description: 'Another example.com' }
+ })
+ await waitJobs(servers)
+
+ const data = await listAutoBlacklistedVideos()
+ expect(data).to.have.lengthOf(beforeCount)
+ })
+ })
+
+ describe('With watched words auto tags', function () {
+ before(async function () {
+ await servers[0].watchedWordsLists.createList({
+ listName: 'forbidden words',
+ words: [ 'badword' ]
+ })
+
+ await servers[0].autoTags.updateServerVideoPolicies({
+ autoBlock: [ 'forbidden words' ]
+ })
+ })
+
+ it('Should auto-blacklist video with watched words on upload', async function () {
+ const beforeCount = (await listAutoBlacklistedVideos()).length
+
+ await servers[0].videos.upload({
+ token: userToken,
+ attributes: { name: 'watched word upload', description: 'Contains badword' }
+ })
+ await waitJobs(servers)
+
+ const data = await listAutoBlacklistedVideos()
+ expect(data).to.have.lengthOf(beforeCount + 1)
+ await expectVideoAutoBlacklisted('watched word upload')
+ })
+
+ it('Should auto-blacklist video with watched words on update', async function () {
+ const beforeCount = (await listAutoBlacklistedVideos()).length
+ const { uuid } = await servers[0].videos.quickUpload({ token: userToken, name: 'watched word update' })
+
+ await waitJobs(servers)
+
+ await servers[0].videos.update({
+ token: userToken,
+ id: uuid,
+ attributes: { description: 'Contains badword after update' }
+ })
+ await waitJobs(servers)
+
+ const data = await listAutoBlacklistedVideos()
+ expect(data).to.have.lengthOf(beforeCount + 1)
+ await expectVideoAutoBlacklisted('watched word update')
+ })
+
+ it('Should auto-blacklist video with watched words on local import', async function () {
+ const beforeCount = (await listAutoBlacklistedVideos()).length
+
+ await servers[0].videoImports.importVideo({
+ token: userToken,
+ attributes: {
+ channelId: userChannelId,
+ targetUrl: FIXTURE_URLS.goodVideo,
+ name: 'watched word local import',
+ description: 'Contains badword from local import'
+ }
+ })
+ await waitJobs(servers)
+
+ const data = await listAutoBlacklistedVideos()
+ expect(data).to.have.lengthOf(beforeCount + 1)
+ await expectVideoAutoBlacklisted('watched word local import')
+ })
+
+ it('Should auto-blacklist video with watched words from federation', async function () {
+ const beforeCount = (await listAutoBlacklistedVideos()).length
+
+ await servers[1].videos.upload({
+ attributes: { name: 'watched word federation', description: 'Contains badword from remote server' }
+ })
+ await waitJobs(servers)
+
+ const data = await listAutoBlacklistedVideos()
+ expect(data).to.have.lengthOf(beforeCount + 1)
+ await expectVideoAutoBlacklisted('watched word federation')
+ })
+
+ it('Should not auto-blacklist a video if a word is added to the watched words list after the video upload', async function () {
+ const beforeCount = (await listAutoBlacklistedVideos()).length
+
+ await servers[0].videos.quickUpload({ token: userToken, name: 'banana' })
+ await waitJobs(servers)
+
+ await servers[0].watchedWordsLists.createList({ listName: 'banana forbidden', words: [ 'banana' ] })
+ await waitJobs(servers)
+
+ const afterCount = (await listAutoBlacklistedVideos()).length
+
+ expect(afterCount).to.equal(beforeCount)
+ })
+ })
+ })
+
after(async function () {
await cleanupTests(servers)
})
diff --git a/server/core/controllers/api/automatic-tags.ts b/server/core/controllers/api/automatic-tags.ts
index d48140aa4d..a15bad1e10 100644
--- a/server/core/controllers/api/automatic-tags.ts
+++ b/server/core/controllers/api/automatic-tags.ts
@@ -1,7 +1,17 @@
-import { AutomaticTagPolicy, CommentAutomaticTagPoliciesUpdate, HttpStatusCode, UserRight } from '@peertube/peertube-models'
+import {
+ AutomaticTagPolicy,
+ CommentAutomaticTagPoliciesUpdate,
+ HttpStatusCode,
+ UserRight,
+ VideoAutomaticTagPoliciesUpdate
+} from '@peertube/peertube-models'
import { AutomaticTagger } from '@server/lib/automatic-tags/automatic-tagger.js'
import { setAccountAutomaticTagsPolicy } from '@server/lib/automatic-tags/automatic-tags.js'
-import { manageAccountAutomaticTagsValidator, updateAutomaticTagPoliciesValidator } from '@server/middlewares/validators/automatic-tags.js'
+import {
+ manageAccountAutomaticTagsValidator,
+ updateAutomaticTagPoliciesValidator,
+ updateServerVideoAutomaticTagPoliciesValidator
+} from '@server/middlewares/validators/automatic-tags.js'
import { getServerAccount } from '@server/models/application/application.js'
import express from 'express'
import { apiRateLimiter, asyncMiddleware, authenticate, ensureUserHasRight } from '../../middlewares/index.js'
@@ -27,6 +37,23 @@ automaticTagRouter.put(
// ---------------------------------------------------------------------------
+automaticTagRouter.get(
+ '/policies/server/videos',
+ authenticate,
+ ensureUserHasRight(UserRight.MANAGE_INSTANCE_AUTO_TAGS),
+ asyncMiddleware(getServerVideoAutomaticTagPolicies)
+)
+
+automaticTagRouter.put(
+ '/policies/server/videos',
+ authenticate,
+ ensureUserHasRight(UserRight.MANAGE_INSTANCE_AUTO_TAGS),
+ asyncMiddleware(updateServerVideoAutomaticTagPoliciesValidator),
+ asyncMiddleware(updateServerVideoAutomaticTagPolicies)
+)
+
+// ---------------------------------------------------------------------------
+
automaticTagRouter.get(
'/accounts/:accountName/available',
authenticate,
@@ -76,3 +103,22 @@ async function getServerAutomaticTagAvailable (req: express.Request, res: expres
return res.json(result)
}
+
+async function getServerVideoAutomaticTagPolicies (req: express.Request, res: express.Response) {
+ const serverAccount = await getServerAccount()
+ const result = await AutomaticTagger.getVideoAutomaticTagPolicies(serverAccount)
+
+ return res.json(result)
+}
+
+async function updateServerVideoAutomaticTagPolicies (req: express.Request, res: express.Response) {
+ const serverAccount = await getServerAccount()
+
+ await setAccountAutomaticTagsPolicy({
+ account: serverAccount,
+ policy: AutomaticTagPolicy.AUTO_BLACKLIST_VIDEO,
+ tags: (req.body as VideoAutomaticTagPoliciesUpdate).autoBlock
+ })
+
+ return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
+}
diff --git a/server/core/controllers/api/videos/source.ts b/server/core/controllers/api/videos/source.ts
index fa25178923..53ebd3dda5 100644
--- a/server/core/controllers/api/videos/source.ts
+++ b/server/core/controllers/api/videos/source.ts
@@ -135,6 +135,7 @@ async function replaceVideoSourceResumable (req: express.Request, res: express.R
await autoBlacklistVideoIfNeeded({
video,
user,
+ automaticTagsByAccount: null,
isRemote: false,
isNew: false,
isNewFile: true,
diff --git a/server/core/controllers/api/videos/update.ts b/server/core/controllers/api/videos/update.ts
index f9a6b42918..f73e89dc42 100644
--- a/server/core/controllers/api/videos/update.ts
+++ b/server/core/controllers/api/videos/update.ts
@@ -194,8 +194,9 @@ async function updateVideo (req: express.Request, res: express.Response) {
})
}
+ let automaticTagsByAccount: Record<number, string[]>
if (oldName !== video.name || oldDescription !== video.description) {
- const automaticTagsByAccount = await new AutomaticTagger().buildVideoAutomaticTags({
+ automaticTagsByAccount = await new AutomaticTagger().buildVideoAutomaticTags({
serverAccount: await getServerAccount(),
video,
transaction: t
@@ -209,6 +210,7 @@ async function updateVideo (req: express.Request, res: express.Response) {
isRemote: false,
isNew: false,
isNewFile: false,
+ automaticTagsByAccount,
transaction: t
})
diff --git a/server/core/helpers/custom-validators/video-blacklist.ts b/server/core/helpers/custom-validators/video-blacklist.ts
index 15a13ae5f0..e8593a79e1 100644
--- a/server/core/helpers/custom-validators/video-blacklist.ts
+++ b/server/core/helpers/custom-validators/video-blacklist.ts
@@ -5,18 +5,15 @@ import { exists } from './misc.js'
const VIDEO_BLACKLIST_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_BLACKLIST
-function isVideoBlacklistReasonValid (value: string) {
+export function isVideoBlacklistReasonValid (value: string) {
return value === null || validator.default.isLength(value, VIDEO_BLACKLIST_CONSTRAINTS_FIELDS.REASON)
}
-function isVideoBlacklistTypeValid (value: any) {
+export function isVideoBlacklistTypeValid (value: any) {
return exists(value) &&
- (value === VideoBlacklistType.AUTO_BEFORE_PUBLISHED || value === VideoBlacklistType.MANUAL)
-}
-
-// ---------------------------------------------------------------------------
-
-export {
- isVideoBlacklistReasonValid,
- isVideoBlacklistTypeValid
+ (
+ value === VideoBlacklistType.AUTO_BY_INSTANCE_POLICY ||
+ value === VideoBlacklistType.AUTO_BY_AUTO_TAG_POLICY ||
+ value === VideoBlacklistType.MANUAL
+ )
}
diff --git a/server/core/initializers/constants.ts b/server/core/initializers/constants.ts
index c8aff53310..1a0b575b53 100644
--- a/server/core/initializers/constants.ts
+++ b/server/core/initializers/constants.ts
@@ -62,7 +62,7 @@ import { CONFIG, registerConfigChangedHandler } from './config.js'
// ---------------------------------------------------------------------------
-export const LAST_MIGRATION_VERSION = 1045
+export const LAST_MIGRATION_VERSION = 1050
// ---------------------------------------------------------------------------
diff --git a/server/core/initializers/migrations/1035-blocklist-subscriptions.ts b/server/core/initializers/migrations/1050-blocklist-subscriptions.ts
similarity index 100%
rename from server/core/initializers/migrations/1035-blocklist-subscriptions.ts
rename to server/core/initializers/migrations/1050-blocklist-subscriptions.ts
diff --git a/server/core/lib/activitypub/videos/shared/abstract-builder.ts b/server/core/lib/activitypub/videos/shared/abstract-builder.ts
index 4f234d4a3d..5421942bda 100644
--- a/server/core/lib/activitypub/videos/shared/abstract-builder.ts
+++ b/server/core/lib/activitypub/videos/shared/abstract-builder.ts
@@ -242,7 +242,7 @@ export abstract class APVideoAbstractBuilder {
}) {
const { video, transaction, oldVideo } = options
- if (video.name === oldVideo?.name && video.description === oldVideo.description) return
+ if (video.name === oldVideo?.name && video.description === oldVideo.description) return {}
const automaticTagsByAccount = await new AutomaticTagger().buildVideoAutomaticTags({
serverAccount: await getServerAccount(),
@@ -250,5 +250,7 @@ export abstract class APVideoAbstractBuilder {
transaction
})
await setAndSaveVideoAutomaticTags({ video, automaticTagsByAccount, transaction })
+
+ return automaticTagsByAccount
}
}
diff --git a/server/core/lib/activitypub/videos/shared/creator.ts b/server/core/lib/activitypub/videos/shared/creator.ts
index cebb4840fc..076f254ac1 100644
--- a/server/core/lib/activitypub/videos/shared/creator.ts
+++ b/server/core/lib/activitypub/videos/shared/creator.ts
@@ -40,13 +40,14 @@ export class APVideoCreator extends APVideoAbstractBuilder {
await this.insertOrReplaceLive(videoCreated, t)
await this.insertOrReplaceStoryboard(videoCreated, t)
- await this.setAutomaticTags({ video: videoCreated, transaction: t })
+ const automaticTagsByAccount = await this.setAutomaticTags({ video: videoCreated, transaction: t })
// We added a video in this channel, set it as updated
await channel.setAsUpdated(t)
const autoBlacklisted = await autoBlacklistVideoIfNeeded({
video: videoCreated,
+ automaticTagsByAccount,
user: undefined,
isRemote: true,
isNew: true,
diff --git a/server/core/lib/activitypub/videos/updater.ts b/server/core/lib/activitypub/videos/updater.ts
index f17115bb20..70d9c283ee 100644
--- a/server/core/lib/activitypub/videos/updater.ts
+++ b/server/core/lib/activitypub/videos/updater.ts
@@ -67,11 +67,14 @@ export class APVideoUpdater extends APVideoAbstractBuilder {
runInReadCommittedTransaction(t => this.setTags(videoUpdated, t)),
runInReadCommittedTransaction(t => this.setTrackers(videoUpdated, t)),
runInReadCommittedTransaction(t => this.setStoryboard(videoUpdated, t)),
- runInReadCommittedTransaction(t => this.setAutomaticTags({ video: videoUpdated, transaction: t, oldVideo })),
runInReadCommittedTransaction(t => this.setThumbnails(videoUpdated, t)),
this.setOrDeleteLive(videoUpdated)
])
+ const automaticTagsByAccount = await runInReadCommittedTransaction(t => {
+ return this.setAutomaticTags({ video: videoUpdated, transaction: t, oldVideo })
+ })
+
await runInReadCommittedTransaction(t => this.setCaptions(videoUpdated, t))
await this.updateChapters(videoUpdated)
@@ -79,6 +82,7 @@ export class APVideoUpdater extends APVideoAbstractBuilder {
await autoBlacklistVideoIfNeeded({
video: videoUpdated,
+ automaticTagsByAccount,
user: undefined,
isRemote: true,
isNew: false,
diff --git a/server/core/lib/automatic-tags/automatic-tagger.ts b/server/core/lib/automatic-tags/automatic-tagger.ts
index 21fc2f66ca..3b11bec87d 100644
--- a/server/core/lib/automatic-tags/automatic-tagger.ts
+++ b/server/core/lib/automatic-tags/automatic-tagger.ts
@@ -1,4 +1,4 @@
-import { AutomaticTagAvailable, AutomaticTagPolicy, CommentAutomaticTagPolicies } from '@peertube/peertube-models'
+import { AutomaticTagAvailable, AutomaticTagPolicy, CommentAutomaticTagPolicies, VideoAutoTagPolicies } from '@peertube/peertube-models'
import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
import { WEBSERVER } from '@server/initializers/constants.js'
import { AccountAutomaticTagPolicyModel } from '@server/models/automatic-tag/account-automatic-tag-policy.js'
@@ -48,7 +48,7 @@ export class AutomaticTagger {
async buildVideoAutomaticTags (options: {
serverAccount: MAccount
- video: MVideo
+ video: Pick<MVideo, 'name' | 'description'>
transaction?: Transaction
}) {
const { video, serverAccount, transaction } = options
@@ -71,7 +71,7 @@ export class AutomaticTagger {
} catch (err) {
logger.error('Cannot build video automatic tags', { video, err, ...lTags() })
- return []
+ return {}
}
}
@@ -139,6 +139,16 @@ export class AutomaticTagger {
return result
}
+ static async getVideoAutomaticTagPolicies (account: MAccountId) {
+ const policies = await AccountAutomaticTagPolicyModel.listOfAccount(account)
+
+ const result: VideoAutoTagPolicies = {
+ autoBlock: policies.filter(p => p.policy === AutomaticTagPolicy.AUTO_BLACKLIST_VIDEO).map(p => p.name)
+ }
+
+ return result
+ }
+
static async getAutomaticTagAvailable (account: MAccountId) {
const result: AutomaticTagAvailable = {
available: [
diff --git a/server/core/lib/job-queue/handlers/video-import.ts b/server/core/lib/job-queue/handlers/video-import.ts
index 1bbf3bf06e..d5b5175a0d 100644
--- a/server/core/lib/job-queue/handlers/video-import.ts
+++ b/server/core/lib/job-queue/handlers/video-import.ts
@@ -13,8 +13,6 @@ import {
import { retryTransactionWrapper } from '@server/helpers/database-utils.js'
import { YoutubeDLWrapper } from '@server/helpers/youtube-dl/index.js'
import { CONFIG } from '@server/initializers/config.js'
-import { AutomaticTagger } from '@server/lib/automatic-tags/automatic-tagger.js'
-import { setAndSaveVideoAutomaticTags } from '@server/lib/automatic-tags/automatic-tags.js'
import { isPostImportVideoAccepted } from '@server/lib/moderation.js'
import { Hooks } from '@server/lib/plugins/hooks.js'
import { ServerConfigManager } from '@server/lib/server-config-manager.js'
@@ -27,7 +25,6 @@ import { addLocalOrRemoteStoryboardJobIfNeeded, buildMoveVideoJob } from '@serve
import { VideoPathManager } from '@server/lib/video-path-manager.js'
import { buildNextVideoState } from '@server/lib/video-state.js'
import { createTorrentAndSetInfoHash, downloadWebTorrentVideo } from '@server/lib/webtorrent.js'
-import { getServerAccount } from '@server/models/application/application.js'
import { UserModel } from '@server/models/user/user.js'
import { VideoCaptionModel } from '@server/models/video/video-caption.js'
import { MUserId, MVideoFile, MVideoFull } from '@server/types/models/index.js'
@@ -241,13 +238,6 @@ async function processFile (options: {
await replaceChaptersIfNotExist({ video, chapters: containerChapters, transaction: t })
- const automaticTagsByAccount = await new AutomaticTagger().buildVideoAutomaticTags({
- serverAccount: await getServerAccount(),
- video,
- transaction: t
- })
- await setAndSaveVideoAutomaticTags({ video, automaticTagsByAccount, transaction: t })
-
// Now we can federate the video (reload from database, we need more attributes)
const videoForFederation = await VideoModel.loadFull(video.uuid, t)
await federateVideoIfNeeded(videoForFederation, true, t)
diff --git a/server/core/lib/local-video-creator.ts b/server/core/lib/local-video-creator.ts
index d198dfc5c8..2931a401f2 100644
--- a/server/core/lib/local-video-creator.ts
+++ b/server/core/lib/local-video-creator.ts
@@ -199,6 +199,7 @@ export class LocalVideoCreator {
await autoBlacklistVideoIfNeeded({
video: this.video,
user: this.options.user,
+ automaticTagsByAccount,
isRemote: false,
isNew: true,
isNewFile: true,
diff --git a/server/core/lib/video-blacklist.ts b/server/core/lib/video-blacklist.ts
index b021b2b629..8a40744c47 100644
--- a/server/core/lib/video-blacklist.ts
+++ b/server/core/lib/video-blacklist.ts
@@ -1,7 +1,17 @@
-import { LiveVideoError, UserAdminFlag, UserRight, VideoBlacklistCreate, VideoBlacklistType } from '@peertube/peertube-models'
+import {
+ AutomaticTagPolicy,
+ LiveVideoError,
+ UserAdminFlag,
+ UserRight,
+ VideoBlacklistCreate,
+ VideoBlacklistType,
+ VideoBlacklistType_Type
+} from '@peertube/peertube-models'
import { afterCommitIfTransaction } from '@server/helpers/database-utils.js'
import { englishLanguage, t } from '@server/helpers/i18n.js'
import { sequelizeTypescript } from '@server/initializers/database.js'
+import { getServerAccount } from '@server/models/application/application.js'
+import { AccountAutomaticTagPolicyModel } from '@server/models/automatic-tag/account-automatic-tag-policy.js'
import { VideoModel } from '@server/models/video/video.js'
import {
MUser,
@@ -26,33 +36,60 @@ const lTags = loggerTagsFactory('blacklist')
export async function autoBlacklistVideoIfNeeded (parameters: {
video: MVideoWithBlacklistLight
- user?: MUser
isRemote: boolean
isNew: boolean
isNewFile: boolean
+ automaticTagsByAccount: Record<number, string[]>
+ user?: MUser
notify?: boolean
transaction?: Transaction
}) {
- const { video, user, isRemote, isNew, isNewFile, notify = true, transaction } = parameters
- const doAutoBlacklist = await Hooks.wrapFun(
- autoBlacklistNeeded,
+ const { video, user, isRemote, isNew, isNewFile, automaticTagsByAccount, notify = true, transaction } = parameters
+
+ // Already blacklisted
+ if (video.VideoBlacklist) return false
+
+ const doAutoBlacklistByInstancePolicy = await Hooks.wrapFun(
+ _autoBlacklistByInstancePolicyNeeded,
{ video, user, isRemote, isNew, isNewFile },
'filter:video.auto-blacklist.result'
)
- if (!doAutoBlacklist) return false
+ if (doAutoBlacklistByInstancePolicy) {
+ await _autoBlacklist({ video, notify, user, transaction, type: VideoBlacklistType.AUTO_BY_INSTANCE_POLICY })
+
+ return true
+ }
+
+ if (await _autoBlacklistByAutoTagPolicyNeeded({ video, user, automaticTagsByAccount, transaction })) {
+ await _autoBlacklist({ video, notify, user, transaction, type: VideoBlacklistType.AUTO_BY_AUTO_TAG_POLICY })
- const videoBlacklistToCreate = {
- videoId: video.id,
- unfederated: true,
- reason: t('The video has been automatically blocked. A moderator review is required.', user?.getLanguage() ?? englishLanguage),
- type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED
+ return true
}
+
+ return false
+}
+
+async function _autoBlacklist (options: {
+ video: MVideoWithBlacklistLight
+ notify: boolean
+ user: MUser
+ transaction: Transaction
+ type: VideoBlacklistType_Type
+}) {
+ const { video, notify, user, transaction, type } = options
+
const [ videoBlacklist ] = await VideoBlacklistModel.findOrCreate<MVideoBlacklistVideo>({
where: {
videoId: video.id
},
- defaults: videoBlacklistToCreate,
+ defaults: {
+ videoId: video.id,
+ unfederated: true,
+ reason: t('The video has been automatically blocked. A moderator review is required.', user?.getLanguage() ?? englishLanguage),
+
+ type
+ },
transaction
})
video.VideoBlacklist = videoBlacklist
@@ -60,16 +97,55 @@ export async function autoBlacklistVideoIfNeeded (parameters: {
videoBlacklist.Video = video
if (notify) {
- afterCommitIfTransaction(transaction, () => {
- Notifier.Instance.notifyOnVideoAutoBlacklist(videoBlacklist)
- })
+ afterCommitIfTransaction(transaction, () => Notifier.Instance.notifyOnVideoAutoBlacklist(videoBlacklist))
}
logger.info('Video %s auto-blacklisted.', video.uuid, lTags(video.uuid))
+}
+
+function _autoBlacklistByInstancePolicyNeeded (parameters: {
+ video: MVideoWithBlacklistLight
+ isRemote: boolean
+ isNew: boolean
+ isNewFile: boolean
+ user?: MUser
+}) {
+ const { user, isRemote, isNew, isNewFile } = parameters
+
+ if (!CONFIG.AUTO_BLACKLIST.VIDEOS.OF_USERS.ENABLED || !user) return false
+ if (isRemote || (isNew === false && isNewFile === false)) return false
+
+ if (user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) || user.hasAdminFlag(UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST)) return false
return true
}
+async function _autoBlacklistByAutoTagPolicyNeeded (options: {
+ video: MVideoWithBlacklistLight
+ transaction: Transaction
+ automaticTagsByAccount: Record<number, string[]>
+ user?: MUser
+}) {
+ const { user, video, transaction, automaticTagsByAccount } = options
+
+ if (!automaticTagsByAccount || Object.keys(automaticTagsByAccount).length === 0) return false
+
+ if (video.isLocal() && user?.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST)) return false
+
+ const accountId = (await getServerAccount()).id
+ const tags = automaticTagsByAccount[accountId]
+ if (!tags || tags.length === 0) return false
+
+ return AccountAutomaticTagPolicyModel.hasPolicyOnTags({
+ accountId,
+ policy: AutomaticTagPolicy.AUTO_BLACKLIST_VIDEO,
+ tags: automaticTagsByAccount[accountId],
+ transaction
+ })
+}
+
+// ---------------------------------------------------------------------------
+
export async function blacklistVideo (videoInstance: MVideoAccountLight, options: VideoBlacklistCreate) {
const blacklist: MVideoBlacklistVideo = await VideoBlacklistModel.create({
videoId: videoInstance.id,
@@ -108,7 +184,7 @@ export async function unblacklistVideo (videoBlacklist: MVideoBlacklist, video:
Notifier.Instance.notifyOnVideoUnblacklist(video)
- if (videoBlacklistType === VideoBlacklistType.AUTO_BEFORE_PUBLISHED) {
+ if (videoBlacklistType === VideoBlacklistType.AUTO_BY_INSTANCE_POLICY) {
const videoWithSchedule = video as MVideoWithRights & MVideoWithSchedule
videoWithSchedule.ScheduleVideoUpdate = await videoWithSchedule.$get('ScheduleVideoUpdate')
@@ -119,26 +195,3 @@ export async function unblacklistVideo (videoBlacklist: MVideoBlacklist, video:
Notifier.Instance.notifyOnNewVideoOrLiveIfNeeded(videoWithSchedule)
}
}
-
-// ---------------------------------------------------------------------------
-// Private
-// ---------------------------------------------------------------------------
-
-function autoBlacklistNeeded (parameters: {
- video: MVideoWithBlacklistLight
- isRemote: boolean
- isNew: boolean
- isNewFile: boolean
- user?: MUser
-}) {
- const { user, video, isRemote, isNew, isNewFile } = parameters
-
- // Already blacklisted
- if (video.VideoBlacklist) return false
- if (!CONFIG.AUTO_BLACKLIST.VIDEOS.OF_USERS.ENABLED || !user) return false
- if (isRemote || (isNew === false && isNewFile === false)) return false
-
- if (user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) || user.hasAdminFlag(UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST)) return false
-
- return true
-}
diff --git a/server/core/lib/video-pre-import.ts b/server/core/lib/video-pre-import.ts
index a1b61a1e55..62c71f55b0 100644
--- a/server/core/lib/video-pre-import.ts
+++ b/server/core/lib/video-pre-import.ts
@@ -43,6 +43,9 @@ import { getLocalVideoActivityPubUrl } from './activitypub/url.js'
import { createLocalVideoThumbnailsFromUrl, createLocalVideoThumbnailsFromImage } from './thumbnail.js'
import { createLocalCaption } from './video-captions.js'
import { replaceChapters, replaceChaptersFromDescriptionIfNeeded } from './video-chapters.js'
+import { AutomaticTagger } from './automatic-tags/automatic-tagger.js'
+import { getServerAccount } from '@server/models/application/application.js'
+import { setAndSaveVideoAutomaticTags } from './automatic-tags/automatic-tags.js'
// ---------------------------------------------------------------------------
@@ -73,8 +76,16 @@ export async function insertFromImportIntoDB (parameters: {
await VideoPasswordModel.addPasswords(videoPasswords, video.id, t)
}
+ const automaticTagsByAccount = await new AutomaticTagger().buildVideoAutomaticTags({
+ serverAccount: await getServerAccount(),
+ video,
+ transaction: t
+ })
+ await setAndSaveVideoAutomaticTags({ video, automaticTagsByAccount, transaction: t })
+
await autoBlacklistVideoIfNeeded({
video: videoCreated,
+ automaticTagsByAccount,
user,
notify: false,
isRemote: false,
diff --git a/server/core/middlewares/validators/automatic-tags.ts b/server/core/middlewares/validators/automatic-tags.ts
index a60d84c24f..c1aa44dd12 100644
--- a/server/core/middlewares/validators/automatic-tags.ts
+++ b/server/core/middlewares/validators/automatic-tags.ts
@@ -1,6 +1,8 @@
-import { CommentAutomaticTagPoliciesUpdate } from '@peertube/peertube-models'
+import { CommentAutomaticTagPoliciesUpdate, VideoAutomaticTagPoliciesUpdate } from '@peertube/peertube-models'
import { isStringArray } from '@server/helpers/custom-validators/search.js'
import { AutomaticTagger } from '@server/lib/automatic-tags/automatic-tagger.js'
+import { getServerAccount } from '@server/models/application/application.js'
+import { MAccount } from '@server/types/models/index.js'
import express from 'express'
import { body, param } from 'express-validator'
import { doesAccountHandleExist } from './shared/accounts.js'
@@ -29,15 +31,49 @@ export const updateAutomaticTagPoliciesValidator = [
const body = req.body as CommentAutomaticTagPoliciesUpdate
- const tagsObj = await AutomaticTagger.getAutomaticTagAvailable(res.locals.account)
- const available = new Set(tagsObj.available.map(({ name }) => name))
+ if (!await checkTags({ account: res.locals.account, tags: body.review, req, res })) return
- for (const name of body.review) {
- if (!available.has(name)) {
- return res.fail({ message: `${name} is not an available automatic tag` })
- }
- }
+ return next()
+ }
+]
+
+export const updateServerVideoAutomaticTagPoliciesValidator = [
+ body('autoBlock')
+ .custom(isStringArray).withMessage('Should have a valid autoBlock array'),
+
+ async (req: express.Request, res: express.Response, next: express.NextFunction) => {
+ if (areValidationErrors(req, res)) return
+
+ const body = req.body as VideoAutomaticTagPoliciesUpdate
+
+ const serverAccount = await getServerAccount()
+ if (!await checkTags({ account: serverAccount, tags: body.autoBlock, req, res })) return
return next()
}
]
+
+// ---------------------------------------------------------------------------
+// Private
+// ---------------------------------------------------------------------------
+
+async function checkTags (options: {
+ account: MAccount
+ tags: string[]
+ req: express.Request
+ res: express.Response
+}) {
+ const { account, tags, req, res } = options
+
+ const tagsObj = await AutomaticTagger.getAutomaticTagAvailable(account)
+ const available = new Set(tagsObj.available.map(({ name }) => name))
+
+ for (const name of tags) {
+ if (!available.has(name)) {
+ res.fail({ message: req.t(`{name} is not an available automatic tag`, { name }) })
+ return false
+ }
+ }
+
+ return true
+}
diff --git a/support/doc/api/openapi.yaml b/support/doc/api/openapi.yaml
index a38b02d262..1c6a334a67 100644
--- a/support/doc/api/openapi.yaml
+++ b/support/doc/api/openapi.yaml
@@ -8384,6 +8384,47 @@ paths:
schema:
$ref: '#/components/schemas/AutomaticTagAvailable'
+ /api/v1/automatic-tags/policies/server/videos:
+ get:
+ tags:
+ - Automatic Tags
+ summary: Get server auto tag policies for videos
+ description: "**PeerTube >= 8.3**"
+ security:
+ - OAuth2:
+ - admin
+ - moderator
+ responses:
+ '200':
+ description: successful operation
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/VideoAutoTagPolicies'
+ put:
+ tags:
+ - Automatic Tags
+ summary: Update server auto tag policies for videos
+ description: "**PeerTube >= 8.3**"
+ security:
+ - OAuth2:
+ - admin
+ - moderator
+ requestBody:
+ content:
+ application/json:
+ schema:
+ type: object
+ properties:
+ autoBlock:
+ description: 'Auto tags that will automatically block videos matching these tags'
+ type: array
+ items:
+ type: string
+ responses:
+ '204':
+ description: successful operation
+
/api/v1/watched-words/accounts/{accountName}/lists:
get:
tags:
@@ -10772,6 +10813,13 @@ components:
description: 'Auto tags that automatically set the comment in review state'
items:
type: string
+ VideoAutoTagPolicies:
+ properties:
+ autoBlock:
+ type: array
+ description: 'Auto tags that will automatically block videos matching these tags'
+ items:
+ type: string
AutomaticTagAvailable:
properties:
available: