From 4faa4b4eae5e1dcdcad3d924b9a19d078d11de57 Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Mon, 13 Apr 2020 19:58:47 +0200 Subject: [PATCH 1/9] Predefined report reasons reporter UI --- .../moderation/moderation.component.scss | 14 +++ .../video-abuse-details.component.html | 9 ++ .../video-abuse-details.component.ts | 24 +++- .../video-abuse-list.component.ts | 11 +- client/src/app/shared/video-abuse/index.ts | 1 + .../video-abuse-predefined-reasons.model.ts | 14 +++ .../shared/video-abuse/video-abuse.service.ts | 9 +- .../video/modals/video-block.component.html | 4 +- .../video/modals/video-report.component.html | 105 ++++++++++++++---- .../video/modals/video-report.component.scss | 17 +++ .../video/modals/video-report.component.ts | 89 ++++++++++++++- client/src/app/shared/video/video.model.ts | 3 +- client/src/environments/environment.e2e.ts | 3 +- client/src/environments/environment.hmr.ts | 3 +- client/src/environments/environment.prod.ts | 3 +- client/src/environments/environment.ts | 3 +- client/src/sass/player/peertube-skin.scss | 2 +- server/controllers/api/videos/abuse.ts | 23 +++- .../helpers/custom-validators/video-abuses.ts | 16 ++- server/initializers/constants.ts | 2 +- server/initializers/database.ts | 6 +- .../migrations/0515-video-abuse-reason.ts | 28 +++++ .../migrations/0520-video-abuse-timestamp.ts | 28 +++++ .../validators/videos/video-abuses.ts | 22 +++- server/models/video/abuse-reason.ts | 27 +++++ server/models/video/video-abuse-reason.ts | 30 +++++ server/models/video/video-abuse.ts | 37 +++++- .../videos/abuse/video-abuse-create.model.ts | 2 + .../videos/abuse/video-abuse-reason.model.ts | 21 ++++ .../models/videos/abuse/video-abuse.model.ts | 4 + shared/models/videos/index.ts | 1 + 31 files changed, 499 insertions(+), 62 deletions(-) create mode 100644 client/src/app/shared/video-abuse/video-abuse-predefined-reasons.model.ts create mode 100644 server/initializers/migrations/0515-video-abuse-reason.ts create mode 100644 server/initializers/migrations/0520-video-abuse-timestamp.ts create mode 100644 server/models/video/abuse-reason.ts create mode 100644 server/models/video/video-abuse-reason.ts create mode 100644 shared/models/videos/abuse/video-abuse-reason.model.ts diff --git a/client/src/app/+admin/moderation/moderation.component.scss b/client/src/app/+admin/moderation/moderation.component.scss index ba68cf6f698..0ec420af9bb 100644 --- a/client/src/app/+admin/moderation/moderation.component.scss +++ b/client/src/app/+admin/moderation/moderation.component.scss @@ -42,6 +42,20 @@ } } +p-calendar { + display: block; + + ::ng-deep { + .ui-widget-content { + min-width: 400px; + } + + input { + @include peertube-input-text(100%); + } + } +} + .screenratio { div { @include miniature-thumbnail; diff --git a/client/src/app/+admin/moderation/video-abuse-list/video-abuse-details.component.html b/client/src/app/+admin/moderation/video-abuse-list/video-abuse-details.component.html index 453a282d1c8..a29fadca85c 100644 --- a/client/src/app/+admin/moderation/video-abuse-list/video-abuse-details.component.html +++ b/client/src/app/+admin/moderation/video-abuse-list/video-abuse-details.component.html @@ -57,6 +57,15 @@ +
+ + +
+
{{ reason }}
+
+
+
+
Note diff --git a/client/src/app/+admin/moderation/video-abuse-list/video-abuse-details.component.ts b/client/src/app/+admin/moderation/video-abuse-list/video-abuse-details.component.ts index d9cb19845f0..c12d0065d31 100644 --- a/client/src/app/+admin/moderation/video-abuse-list/video-abuse-details.component.ts +++ b/client/src/app/+admin/moderation/video-abuse-list/video-abuse-details.component.ts @@ -1,7 +1,8 @@ import { Component, Input } from '@angular/core' -import { Account } from '@app/shared/account/account.model' import { Actor } from '@app/shared/actor/actor.model' +import { VideoAbusePredefinedReasons } from '../../../../../../shared/models/videos/abuse/video-abuse-reason.model' import { ProcessedVideoAbuse } from './video-abuse-list.component' +import { I18n } from '@ngx-translate/i18n-polyfill' @Component({ selector: 'my-video-abuse-details', @@ -11,6 +12,27 @@ import { ProcessedVideoAbuse } from './video-abuse-list.component' export class VideoAbuseDetailsComponent { @Input() videoAbuse: ProcessedVideoAbuse + private predefinedReasonsTranslations: { [key: number]: string } + + constructor ( + private i18n: I18n + ) { + this.predefinedReasonsTranslations = { + [VideoAbusePredefinedReasons.VIOLENT_OR_REPULSIVE]: this.i18n('Violent or Repulsive'), + [VideoAbusePredefinedReasons.HATEFUL_OR_ABUSIVE]: this.i18n('Hateful or Abusive'), + [VideoAbusePredefinedReasons.SPAM_OR_MISLEADING]: this.i18n('Spam or Misleading'), + [VideoAbusePredefinedReasons.PRIVACY]: this.i18n('Privacy'), + [VideoAbusePredefinedReasons.RIGHTS]: this.i18n('Rights'), + [VideoAbusePredefinedReasons.SERVER_RULES]: this.i18n('Server rules'), + [VideoAbusePredefinedReasons.THUMBNAILS]: this.i18n('Thumbnails'), + [VideoAbusePredefinedReasons.CAPTIONS]: this.i18n('Captions') + } + } + + get predefinedReasons () { + return this.videoAbuse.predefinedReasons.map(r => this.predefinedReasonsTranslations[r]) + } + switchToDefaultAvatar ($event: Event) { ($event.target as HTMLImageElement).src = Actor.GET_DEFAULT_AVATAR_URL() } diff --git a/client/src/app/+admin/moderation/video-abuse-list/video-abuse-list.component.ts b/client/src/app/+admin/moderation/video-abuse-list/video-abuse-list.component.ts index a36acc2abda..86ad40dee90 100644 --- a/client/src/app/+admin/moderation/video-abuse-list/video-abuse-list.component.ts +++ b/client/src/app/+admin/moderation/video-abuse-list/video-abuse-list.component.ts @@ -11,13 +11,13 @@ import { ModerationCommentModalComponent } from './moderation-comment-modal.comp import { Video } from '../../../shared/video/video.model' import { MarkdownService } from '@app/shared/renderer' import { Actor } from '@app/shared/actor/actor.model' -import { buildVideoLink, buildVideoEmbed } from 'src/assets/player/utils' -import { getAbsoluteAPIUrl } from '@app/shared/misc/utils' +import { buildVideoEmbed } from 'src/assets/player/utils' import { DomSanitizer } from '@angular/platform-browser' import { BlocklistService } from '@app/shared/blocklist' import { VideoService } from '@app/shared/video/video.service' import { ActivatedRoute, Params, Router } from '@angular/router' import { filter } from 'rxjs/operators' +import { environment } from 'src/environments/environment' export type ProcessedVideoAbuse = VideoAbuse & { moderationCommentHtml?: string, @@ -259,12 +259,7 @@ export class VideoAbuseListComponent extends RestTable implements OnInit, AfterV } getVideoEmbed (videoAbuse: VideoAbuse) { - const absoluteAPIUrl = getAbsoluteAPIUrl() - const embedUrl = buildVideoLink({ - baseUrl: absoluteAPIUrl + '/videos/embed/' + videoAbuse.video.uuid, - warningTitle: false - }) - return buildVideoEmbed(embedUrl) + return buildVideoEmbed(`${environment.embedUrl}/videos/embed/${videoAbuse.video.uuid}`) } switchToDefaultAvatar ($event: Event) { diff --git a/client/src/app/shared/video-abuse/index.ts b/client/src/app/shared/video-abuse/index.ts index 92cbfb5f904..0c3a48d83b7 100644 --- a/client/src/app/shared/video-abuse/index.ts +++ b/client/src/app/shared/video-abuse/index.ts @@ -1 +1,2 @@ export * from './video-abuse.service' +export * from './video-abuse-predefined-reasons.model' diff --git a/client/src/app/shared/video-abuse/video-abuse-predefined-reasons.model.ts b/client/src/app/shared/video-abuse/video-abuse-predefined-reasons.model.ts new file mode 100644 index 00000000000..5969f48cea8 --- /dev/null +++ b/client/src/app/shared/video-abuse/video-abuse-predefined-reasons.model.ts @@ -0,0 +1,14 @@ +export enum PredefinedReasons { + violentOrRepulsive = 'violentOrRepulsive', + hatefulOrAbusive = 'hatefulOrAbusive', + spamOrMisleading = 'spamOrMisleading', + privacy = 'privacy', + rights = 'rights', + serverRules = 'serverRules', + thumbnails = 'thumbnails', + captions = 'captions' +} + +export type VideoAbusePredefinedReasons = { + [key in PredefinedReasons]?: boolean +} diff --git a/client/src/app/shared/video-abuse/video-abuse.service.ts b/client/src/app/shared/video-abuse/video-abuse.service.ts index 700a3023965..a8f31a96597 100644 --- a/client/src/app/shared/video-abuse/video-abuse.service.ts +++ b/client/src/app/shared/video-abuse/video-abuse.service.ts @@ -6,6 +6,7 @@ import { Observable } from 'rxjs' import { ResultList, VideoAbuse, VideoAbuseUpdate, VideoAbuseState } from '../../../../../shared' import { environment } from '../../../environments/environment' import { RestExtractor, RestPagination, RestService } from '../rest' +import { VideoAbusePredefinedReasons } from './video-abuse-predefined-reasons.model' @Injectable() export class VideoAbuseService { @@ -63,9 +64,11 @@ export class VideoAbuseService { ) } - reportVideo (id: number, reason: string) { - const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + id + '/abuse' - const body = { reason } + reportVideo (parameters: { id: number, reason: string, predefinedReasons?: VideoAbusePredefinedReasons, timestamp: any }) { + const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + parameters.id + '/abuse' + + delete parameters.id + const body = { ...parameters } return this.authHttp.post(url, body) .pipe( diff --git a/client/src/app/shared/video/modals/video-block.component.html b/client/src/app/shared/video/modals/video-block.component.html index a8dd30b5ea1..5e73d66c501 100644 --- a/client/src/app/shared/video/modals/video-block.component.html +++ b/client/src/app/shared/video/modals/video-block.component.html @@ -1,6 +1,6 @@ @@ -9,7 +9,7 @@
diff --git a/client/src/app/shared/video/modals/video-report.component.html b/client/src/app/shared/video/modals/video-report.component.html index e336b666038..d6beb6d2ad6 100644 --- a/client/src/app/shared/video/modals/video-report.component.html +++ b/client/src/app/shared/video/modals/video-report.component.html @@ -1,38 +1,97 @@