From 792dbaf07f83fbe3f1d209cd9edf190442c7d2f3 Mon Sep 17 00:00:00 2001 From: Green-Star Date: Fri, 22 Sep 2017 09:13:43 +0200 Subject: Handle blacklist (#84) * Client: Add list blacklist feature * Server: Add list blacklist feature * Client: Add videoId column * Server: Add some video infos in the REST api * Client: Add video information in the blacklist list * Fix sortable columns :) * Client: Add removeFromBlacklist feature * Server: Add removeFromBlacklist feature * Move to TypeScript * Move to TypeScript and Promises * Server: Fix blacklist list sort * Server: Fetch videos informations * Use common shared interface for client and server * Add check-params remove blacklisted video tests * Add check-params list blacklisted videos tests * Add list blacklist tests * Add remove from blacklist tests * Add video blacklist management tests * Fix rebase onto develop issues * Server: Add sort on blacklist id column * Server: Add blacklists library * Add blacklist id sort test * Add check-params tests for blacklist list pagination, count and sort * Fix coding style * Increase Remote API tests timeout * Increase Request scheduler API tests timeout * Fix typo * Increase video transcoding API tests timeout * Move tests to Typescript * Use lodash orderBy method * Fix typos * Client: Remove optional tests in blacklist model attributes * Move blacklist routes from 'blacklists' to 'blacklist' * CLient: Remove blacklist-list.component.scss * Rename 'blacklists' files to 'blacklist' * Use only BlacklistedVideo interface * Server: Use getFormattedObjects method in listBlacklist method * Client: Use new coding style * Server: Use new sort validator methods * Server: Use new checkParams methods * Client: Fix sortable columns --- client/src/app/+admin/admin-routing.module.ts | 4 +- client/src/app/+admin/admin.module.ts | 7 ++- .../blacklist-list/blacklist-list.component.html | 26 +++++++++ .../blacklist-list/blacklist-list.component.ts | 65 ++++++++++++++++++++++ .../app/+admin/blacklist/blacklist-list/index.ts | 1 + .../app/+admin/blacklist/blacklist.component.ts | 8 +++ .../src/app/+admin/blacklist/blacklist.routes.ts | 27 +++++++++ client/src/app/+admin/blacklist/index.ts | 4 ++ .../+admin/blacklist/shared/blacklist.service.ts | 44 +++++++++++++++ client/src/app/+admin/blacklist/shared/index.ts | 1 + 10 files changed, 185 insertions(+), 2 deletions(-) create mode 100644 client/src/app/+admin/blacklist/blacklist-list/blacklist-list.component.html create mode 100644 client/src/app/+admin/blacklist/blacklist-list/blacklist-list.component.ts create mode 100644 client/src/app/+admin/blacklist/blacklist-list/index.ts create mode 100644 client/src/app/+admin/blacklist/blacklist.component.ts create mode 100644 client/src/app/+admin/blacklist/blacklist.routes.ts create mode 100644 client/src/app/+admin/blacklist/index.ts create mode 100644 client/src/app/+admin/blacklist/shared/blacklist.service.ts create mode 100644 client/src/app/+admin/blacklist/shared/index.ts (limited to 'client/src/app/+admin') diff --git a/client/src/app/+admin/admin-routing.module.ts b/client/src/app/+admin/admin-routing.module.ts index a3845b72c..0cd3e54c2 100644 --- a/client/src/app/+admin/admin-routing.module.ts +++ b/client/src/app/+admin/admin-routing.module.ts @@ -9,6 +9,7 @@ import { RequestSchedulersRoutes } from './request-schedulers' import { UsersRoutes } from './users' import { VideoAbusesRoutes } from './video-abuses' import { AdminGuard } from './admin-guard.service' +import { BlacklistRoutes } from './blacklist' const adminRoutes: Routes = [ { @@ -25,7 +26,8 @@ const adminRoutes: Routes = [ ...FriendsRoutes, ...RequestSchedulersRoutes, ...UsersRoutes, - ...VideoAbusesRoutes + ...VideoAbusesRoutes, + ...BlacklistRoutes ] } ] diff --git a/client/src/app/+admin/admin.module.ts b/client/src/app/+admin/admin.module.ts index 786dbc15c..c2dd60774 100644 --- a/client/src/app/+admin/admin.module.ts +++ b/client/src/app/+admin/admin.module.ts @@ -6,6 +6,7 @@ import { FriendsComponent, FriendAddComponent, FriendListComponent, FriendServic import { RequestSchedulersComponent, RequestSchedulersStatsComponent, RequestSchedulersService } from './request-schedulers' import { UsersComponent, UserAddComponent, UserUpdateComponent, UserListComponent, UserService } from './users' import { VideoAbusesComponent, VideoAbuseListComponent } from './video-abuses' +import { BlacklistComponent, BlacklistListComponent, BlacklistService } from './blacklist' import { SharedModule } from '../shared' import { AdminGuard } from './admin-guard.service' @@ -30,6 +31,9 @@ import { AdminGuard } from './admin-guard.service' UserUpdateComponent, UserListComponent, + BlacklistComponent, + BlacklistListComponent, + VideoAbusesComponent, VideoAbuseListComponent ], @@ -42,7 +46,8 @@ import { AdminGuard } from './admin-guard.service' FriendService, RequestSchedulersService, UserService, - AdminGuard + AdminGuard, + BlacklistService ] }) export class AdminModule { } diff --git a/client/src/app/+admin/blacklist/blacklist-list/blacklist-list.component.html b/client/src/app/+admin/blacklist/blacklist-list/blacklist-list.component.html new file mode 100644 index 000000000..5d4636ee9 --- /dev/null +++ b/client/src/app/+admin/blacklist/blacklist-list/blacklist-list.component.html @@ -0,0 +1,26 @@ +
+
+

Blacklisted videos

+ + + + + + + + + + + + + + + + + + +
+
diff --git a/client/src/app/+admin/blacklist/blacklist-list/blacklist-list.component.ts b/client/src/app/+admin/blacklist/blacklist-list/blacklist-list.component.ts new file mode 100644 index 000000000..b308054ed --- /dev/null +++ b/client/src/app/+admin/blacklist/blacklist-list/blacklist-list.component.ts @@ -0,0 +1,65 @@ +import { Component, OnInit } from '@angular/core' +import { SortMeta } from 'primeng/components/common/sortmeta' + +import { NotificationsService } from 'angular2-notifications' + +import { ConfirmService } from '../../../core' +import { RestTable, RestPagination } from '../../../shared' +import { BlacklistService } from '../shared' +import { BlacklistedVideo } from '../../../../../../shared' + +@Component({ + selector: 'my-blacklist-list', + templateUrl: './blacklist-list.component.html', + styleUrls: [] +}) +export class BlacklistListComponent extends RestTable implements OnInit { + blacklist: BlacklistedVideo[] = [] + totalRecords = 0 + rowsPerPage = 10 + sort: SortMeta = { field: 'id', order: 1 } + pagination: RestPagination = { count: this.rowsPerPage, start: 0 } + + constructor ( + private notificationsService: NotificationsService, + private confirmService: ConfirmService, + private blacklistService: BlacklistService + ) { + super() + } + + ngOnInit () { + this.loadData() + } + + removeVideoFromBlacklist (entry: BlacklistedVideo) { + const confirmMessage = 'Do you really want to remove this video from the blacklist ? It will be available again in the video list.' + + this.confirmService.confirm(confirmMessage, 'Remove').subscribe( + res => { + if (res === false) return + + this.blacklistService.removeVideoFromBlacklist(entry).subscribe( + status => { + this.notificationsService.success('Success', `Video ${entry.name} removed from the blacklist.`) + this.loadData() + }, + + err => this.notificationsService.error('Error', err.message) + ) + } + ) + } + + protected loadData () { + this.blacklistService.getBlacklist(this.pagination, this.sort) + .subscribe( + resultList => { + this.blacklist = resultList.data + this.totalRecords = resultList.total + }, + + err => this.notificationsService.error('Error', err.message) + ) + } +} diff --git a/client/src/app/+admin/blacklist/blacklist-list/index.ts b/client/src/app/+admin/blacklist/blacklist-list/index.ts new file mode 100644 index 000000000..45f60a2b9 --- /dev/null +++ b/client/src/app/+admin/blacklist/blacklist-list/index.ts @@ -0,0 +1 @@ +export * from './blacklist-list.component' diff --git a/client/src/app/+admin/blacklist/blacklist.component.ts b/client/src/app/+admin/blacklist/blacklist.component.ts new file mode 100644 index 000000000..ce8fe4298 --- /dev/null +++ b/client/src/app/+admin/blacklist/blacklist.component.ts @@ -0,0 +1,8 @@ +import { Component } from '@angular/core' + +@Component({ + template: '' +}) + +export class BlacklistComponent { +} diff --git a/client/src/app/+admin/blacklist/blacklist.routes.ts b/client/src/app/+admin/blacklist/blacklist.routes.ts new file mode 100644 index 000000000..780347ca8 --- /dev/null +++ b/client/src/app/+admin/blacklist/blacklist.routes.ts @@ -0,0 +1,27 @@ +import { Routes } from '@angular/router' + +import { BlacklistComponent } from './blacklist.component' +import { BlacklistListComponent } from './blacklist-list' + +export const BlacklistRoutes: Routes = [ + { + path: 'blacklist', + component: BlacklistComponent, + children: [ + { + path: '', + redirectTo: 'list', + pathMatch: 'full' + }, + { + path: 'list', + component: BlacklistListComponent, + data: { + meta: { + title: 'Blacklisted videos' + } + } + } + ] + } +] diff --git a/client/src/app/+admin/blacklist/index.ts b/client/src/app/+admin/blacklist/index.ts new file mode 100644 index 000000000..675dc1263 --- /dev/null +++ b/client/src/app/+admin/blacklist/index.ts @@ -0,0 +1,4 @@ +export * from './shared' +export * from './blacklist-list' +export * from './blacklist.component' +export * from './blacklist.routes' diff --git a/client/src/app/+admin/blacklist/shared/blacklist.service.ts b/client/src/app/+admin/blacklist/shared/blacklist.service.ts new file mode 100644 index 000000000..1b090c9c5 --- /dev/null +++ b/client/src/app/+admin/blacklist/shared/blacklist.service.ts @@ -0,0 +1,44 @@ +import { Injectable } from '@angular/core' +import { HttpClient, HttpParams } from '@angular/common/http' +import { Observable } from 'rxjs/Observable' +import 'rxjs/add/operator/catch' +import 'rxjs/add/operator/map' + +import { SortMeta } from 'primeng/components/common/sortmeta' + +import { RestExtractor, RestPagination, RestService } from '../../../shared' +import { Utils } from '../../../shared' +import { BlacklistedVideo, ResultList } from '../../../../../../shared' + +@Injectable() +export class BlacklistService { + private static BASE_BLACKLISTS_URL = '/api/v1/blacklist/' + + constructor ( + private authHttp: HttpClient, + private restService: RestService, + private restExtractor: RestExtractor + ) {} + + getBlacklist (pagination: RestPagination, sort: SortMeta): Observable> { + let params = new HttpParams() + params = this.restService.addRestGetParams(params, pagination, sort) + + return this.authHttp.get>(BlacklistService.BASE_BLACKLISTS_URL, { params }) + .map(res => this.restExtractor.convertResultListDateToHuman(res)) + .map(res => this.restExtractor.applyToResultListData(res, this.formatBlacklistedVideo.bind(this))) + .catch(res => this.restExtractor.handleError(res)) + } + + removeVideoFromBlacklist (entry: BlacklistedVideo) { + return this.authHttp.delete(BlacklistService.BASE_BLACKLISTS_URL + entry.id) + .map(this.restExtractor.extractDataBool) + .catch(res => this.restExtractor.handleError(res)) + } + + private formatBlacklistedVideo (blacklistedVideo: BlacklistedVideo) { + return Object.assign(blacklistedVideo, { + createdAt: Utils.dateToHuman(blacklistedVideo.createdAt) + }) + } +} diff --git a/client/src/app/+admin/blacklist/shared/index.ts b/client/src/app/+admin/blacklist/shared/index.ts new file mode 100644 index 000000000..ad22e2d51 --- /dev/null +++ b/client/src/app/+admin/blacklist/shared/index.ts @@ -0,0 +1 @@ +export * from './blacklist.service' -- cgit v1.2.3