aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/shared-moderation
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-07-01 16:05:30 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-07-10 14:02:41 +0200
commitd95d15598847c7f020aa056e7e6e0c02d2bbf732 (patch)
treea8a593f1269688caf9e5f99559996f346290fec5 /client/src/app/shared/shared-moderation
parent72493e44e9b455a04c4f093ed6c6ffa300b98d8b (diff)
downloadPeerTube-d95d15598847c7f020aa056e7e6e0c02d2bbf732.tar.gz
PeerTube-d95d15598847c7f020aa056e7e6e0c02d2bbf732.tar.zst
PeerTube-d95d15598847c7f020aa056e7e6e0c02d2bbf732.zip
Use 3 tables to represent abuses
Diffstat (limited to 'client/src/app/shared/shared-moderation')
-rw-r--r--client/src/app/shared/shared-moderation/abuse.service.ts (renamed from client/src/app/shared/shared-moderation/video-abuse.service.ts)32
-rw-r--r--client/src/app/shared/shared-moderation/index.ts2
-rw-r--r--client/src/app/shared/shared-moderation/shared-moderation.module.ts4
-rw-r--r--client/src/app/shared/shared-moderation/video-report.component.ts29
4 files changed, 35 insertions, 32 deletions
diff --git a/client/src/app/shared/shared-moderation/video-abuse.service.ts b/client/src/app/shared/shared-moderation/abuse.service.ts
index 44dea44a5..f45018d5c 100644
--- a/client/src/app/shared/shared-moderation/video-abuse.service.ts
+++ b/client/src/app/shared/shared-moderation/abuse.service.ts
@@ -5,12 +5,12 @@ import { catchError, map } from 'rxjs/operators'
5import { HttpClient, HttpParams } from '@angular/common/http' 5import { HttpClient, HttpParams } from '@angular/common/http'
6import { Injectable } from '@angular/core' 6import { Injectable } from '@angular/core'
7import { RestExtractor, RestPagination, RestService } from '@app/core' 7import { RestExtractor, RestPagination, RestService } from '@app/core'
8import { ResultList, VideoAbuse, VideoAbuseCreate, VideoAbuseState, VideoAbuseUpdate } from '@shared/models' 8import { AbuseUpdate, ResultList, Abuse, AbuseCreate, AbuseState } from '@shared/models'
9import { environment } from '../../../environments/environment' 9import { environment } from '../../../environments/environment'
10 10
11@Injectable() 11@Injectable()
12export class VideoAbuseService { 12export class AbuseService {
13 private static BASE_VIDEO_ABUSE_URL = environment.apiUrl + '/api/v1/videos/' 13 private static BASE_ABUSE_URL = environment.apiUrl + '/api/v1/abuses'
14 14
15 constructor ( 15 constructor (
16 private authHttp: HttpClient, 16 private authHttp: HttpClient,
@@ -18,13 +18,13 @@ export class VideoAbuseService {
18 private restExtractor: RestExtractor 18 private restExtractor: RestExtractor
19 ) {} 19 ) {}
20 20
21 getVideoAbuses (options: { 21 getAbuses (options: {
22 pagination: RestPagination, 22 pagination: RestPagination,
23 sort: SortMeta, 23 sort: SortMeta,
24 search?: string 24 search?: string
25 }): Observable<ResultList<VideoAbuse>> { 25 }): Observable<ResultList<Abuse>> {
26 const { pagination, sort, search } = options 26 const { pagination, sort, search } = options
27 const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + 'abuse' 27 const url = AbuseService.BASE_ABUSE_URL + 'abuse'
28 28
29 let params = new HttpParams() 29 let params = new HttpParams()
30 params = this.restService.addRestGetParams(params, pagination, sort) 30 params = this.restService.addRestGetParams(params, pagination, sort)
@@ -35,9 +35,9 @@ export class VideoAbuseService {
35 state: { 35 state: {
36 prefix: 'state:', 36 prefix: 'state:',
37 handler: v => { 37 handler: v => {
38 if (v === 'accepted') return VideoAbuseState.ACCEPTED 38 if (v === 'accepted') return AbuseState.ACCEPTED
39 if (v === 'pending') return VideoAbuseState.PENDING 39 if (v === 'pending') return AbuseState.PENDING
40 if (v === 'rejected') return VideoAbuseState.REJECTED 40 if (v === 'rejected') return AbuseState.REJECTED
41 41
42 return undefined 42 return undefined
43 } 43 }
@@ -59,14 +59,14 @@ export class VideoAbuseService {
59 params = this.restService.addObjectParams(params, filters) 59 params = this.restService.addObjectParams(params, filters)
60 } 60 }
61 61
62 return this.authHttp.get<ResultList<VideoAbuse>>(url, { params }) 62 return this.authHttp.get<ResultList<Abuse>>(url, { params })
63 .pipe( 63 .pipe(
64 catchError(res => this.restExtractor.handleError(res)) 64 catchError(res => this.restExtractor.handleError(res))
65 ) 65 )
66 } 66 }
67 67
68 reportVideo (parameters: { id: number } & VideoAbuseCreate) { 68 reportVideo (parameters: AbuseCreate) {
69 const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + parameters.id + '/abuse' 69 const url = AbuseService.BASE_ABUSE_URL
70 70
71 const body = omit(parameters, [ 'id' ]) 71 const body = omit(parameters, [ 'id' ])
72 72
@@ -77,8 +77,8 @@ export class VideoAbuseService {
77 ) 77 )
78 } 78 }
79 79
80 updateVideoAbuse (videoAbuse: VideoAbuse, abuseUpdate: VideoAbuseUpdate) { 80 updateAbuse (abuse: Abuse, abuseUpdate: AbuseUpdate) {
81 const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + videoAbuse.video.uuid + '/abuse/' + videoAbuse.id 81 const url = AbuseService.BASE_ABUSE_URL + '/' + abuse.id
82 82
83 return this.authHttp.put(url, abuseUpdate) 83 return this.authHttp.put(url, abuseUpdate)
84 .pipe( 84 .pipe(
@@ -87,8 +87,8 @@ export class VideoAbuseService {
87 ) 87 )
88 } 88 }
89 89
90 removeVideoAbuse (videoAbuse: VideoAbuse) { 90 removeAbuse (abuse: Abuse) {
91 const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + videoAbuse.video.uuid + '/abuse/' + videoAbuse.id 91 const url = AbuseService.BASE_ABUSE_URL + '/' + abuse.id
92 92
93 return this.authHttp.delete(url) 93 return this.authHttp.delete(url)
94 .pipe( 94 .pipe(
diff --git a/client/src/app/shared/shared-moderation/index.ts b/client/src/app/shared/shared-moderation/index.ts
index 8e74254f6..d6c4a10be 100644
--- a/client/src/app/shared/shared-moderation/index.ts
+++ b/client/src/app/shared/shared-moderation/index.ts
@@ -1,3 +1,4 @@
1export * from './abuse.service'
1export * from './account-block.model' 2export * from './account-block.model'
2export * from './account-blocklist.component' 3export * from './account-blocklist.component'
3export * from './batch-domains-modal.component' 4export * from './batch-domains-modal.component'
@@ -6,7 +7,6 @@ export * from './bulk.service'
6export * from './server-blocklist.component' 7export * from './server-blocklist.component'
7export * from './user-ban-modal.component' 8export * from './user-ban-modal.component'
8export * from './user-moderation-dropdown.component' 9export * from './user-moderation-dropdown.component'
9export * from './video-abuse.service'
10export * from './video-block.component' 10export * from './video-block.component'
11export * from './video-block.service' 11export * from './video-block.service'
12export * from './video-report.component' 12export * from './video-report.component'
diff --git a/client/src/app/shared/shared-moderation/shared-moderation.module.ts b/client/src/app/shared/shared-moderation/shared-moderation.module.ts
index f7e64dfa3..742193e58 100644
--- a/client/src/app/shared/shared-moderation/shared-moderation.module.ts
+++ b/client/src/app/shared/shared-moderation/shared-moderation.module.ts
@@ -8,7 +8,7 @@ import { BlocklistService } from './blocklist.service'
8import { BulkService } from './bulk.service' 8import { BulkService } from './bulk.service'
9import { UserBanModalComponent } from './user-ban-modal.component' 9import { UserBanModalComponent } from './user-ban-modal.component'
10import { UserModerationDropdownComponent } from './user-moderation-dropdown.component' 10import { UserModerationDropdownComponent } from './user-moderation-dropdown.component'
11import { VideoAbuseService } from './video-abuse.service' 11import { AbuseService } from './abuse.service'
12import { VideoBlockComponent } from './video-block.component' 12import { VideoBlockComponent } from './video-block.component'
13import { VideoBlockService } from './video-block.service' 13import { VideoBlockService } from './video-block.service'
14import { VideoReportComponent } from './video-report.component' 14import { VideoReportComponent } from './video-report.component'
@@ -39,7 +39,7 @@ import { VideoReportComponent } from './video-report.component'
39 providers: [ 39 providers: [
40 BlocklistService, 40 BlocklistService,
41 BulkService, 41 BulkService,
42 VideoAbuseService, 42 AbuseService,
43 VideoBlockService 43 VideoBlockService
44 ] 44 ]
45}) 45})
diff --git a/client/src/app/shared/shared-moderation/video-report.component.ts b/client/src/app/shared/shared-moderation/video-report.component.ts
index 11c805636..b8d9f8d27 100644
--- a/client/src/app/shared/shared-moderation/video-report.component.ts
+++ b/client/src/app/shared/shared-moderation/video-report.component.ts
@@ -3,13 +3,13 @@ import { buildVideoEmbed, buildVideoLink } from 'src/assets/player/utils'
3import { Component, Input, OnInit, ViewChild } from '@angular/core' 3import { Component, Input, OnInit, ViewChild } from '@angular/core'
4import { DomSanitizer, SafeHtml } from '@angular/platform-browser' 4import { DomSanitizer, SafeHtml } from '@angular/platform-browser'
5import { Notifier } from '@app/core' 5import { Notifier } from '@app/core'
6import { FormReactive, FormValidatorService, VideoAbuseValidatorsService } from '@app/shared/shared-forms' 6import { AbuseValidatorsService, FormReactive, FormValidatorService } from '@app/shared/shared-forms'
7import { NgbModal } from '@ng-bootstrap/ng-bootstrap' 7import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
8import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref' 8import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
9import { I18n } from '@ngx-translate/i18n-polyfill' 9import { I18n } from '@ngx-translate/i18n-polyfill'
10import { videoAbusePredefinedReasonsMap, VideoAbusePredefinedReasonsString } from '@shared/models/videos/abuse/video-abuse-reason.model' 10import { abusePredefinedReasonsMap, AbusePredefinedReasonsString } from '@shared/models'
11import { Video } from '../shared-main' 11import { Video } from '../shared-main'
12import { VideoAbuseService } from './video-abuse.service' 12import { AbuseService } from './abuse.service'
13 13
14@Component({ 14@Component({
15 selector: 'my-video-report', 15 selector: 'my-video-report',
@@ -22,7 +22,7 @@ export class VideoReportComponent extends FormReactive implements OnInit {
22 @ViewChild('modal', { static: true }) modal: NgbModal 22 @ViewChild('modal', { static: true }) modal: NgbModal
23 23
24 error: string = null 24 error: string = null
25 predefinedReasons: { id: VideoAbusePredefinedReasonsString, label: string, description?: string, help?: string }[] = [] 25 predefinedReasons: { id: AbusePredefinedReasonsString, label: string, description?: string, help?: string }[] = []
26 embedHtml: SafeHtml 26 embedHtml: SafeHtml
27 27
28 private openedModal: NgbModalRef 28 private openedModal: NgbModalRef
@@ -30,8 +30,8 @@ export class VideoReportComponent extends FormReactive implements OnInit {
30 constructor ( 30 constructor (
31 protected formValidatorService: FormValidatorService, 31 protected formValidatorService: FormValidatorService,
32 private modalService: NgbModal, 32 private modalService: NgbModal,
33 private videoAbuseValidatorsService: VideoAbuseValidatorsService, 33 private abuseValidatorsService: AbuseValidatorsService,
34 private videoAbuseService: VideoAbuseService, 34 private abuseService: AbuseService,
35 private notifier: Notifier, 35 private notifier: Notifier,
36 private sanitizer: DomSanitizer, 36 private sanitizer: DomSanitizer,
37 private i18n: I18n 37 private i18n: I18n
@@ -69,8 +69,8 @@ export class VideoReportComponent extends FormReactive implements OnInit {
69 69
70 ngOnInit () { 70 ngOnInit () {
71 this.buildForm({ 71 this.buildForm({
72 reason: this.videoAbuseValidatorsService.VIDEO_ABUSE_REASON, 72 reason: this.abuseValidatorsService.ABUSE_REASON,
73 predefinedReasons: mapValues(videoAbusePredefinedReasonsMap, r => null), 73 predefinedReasons: mapValues(abusePredefinedReasonsMap, r => null),
74 timestamp: { 74 timestamp: {
75 hasStart: null, 75 hasStart: null,
76 startAt: null, 76 startAt: null,
@@ -136,15 +136,18 @@ export class VideoReportComponent extends FormReactive implements OnInit {
136 136
137 report () { 137 report () {
138 const reason = this.form.get('reason').value 138 const reason = this.form.get('reason').value
139 const predefinedReasons = Object.keys(pickBy(this.form.get('predefinedReasons').value)) as VideoAbusePredefinedReasonsString[] 139 const predefinedReasons = Object.keys(pickBy(this.form.get('predefinedReasons').value)) as AbusePredefinedReasonsString[]
140 const { hasStart, startAt, hasEnd, endAt } = this.form.get('timestamp').value 140 const { hasStart, startAt, hasEnd, endAt } = this.form.get('timestamp').value
141 141
142 this.videoAbuseService.reportVideo({ 142 this.abuseService.reportVideo({
143 id: this.video.id, 143 accountId: this.video.account.id,
144 reason, 144 reason,
145 predefinedReasons, 145 predefinedReasons,
146 startAt: hasStart && startAt ? startAt : undefined, 146 video: {
147 endAt: hasEnd && endAt ? endAt : undefined 147 id: this.video.id,
148 startAt: hasStart && startAt ? startAt : undefined,
149 endAt: hasEnd && endAt ? endAt : undefined
150 }
148 }).subscribe( 151 }).subscribe(
149 () => { 152 () => {
150 this.notifier.success(this.i18n('Video reported.')) 153 this.notifier.success(this.i18n('Video reported.'))