From 74d63469355bad731cdd32defdc85913df3cbd5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Rizio?= Date: Tue, 4 Sep 2018 08:57:13 +0200 Subject: Users can change ownership of their video [#510] (#888) * [#510] Create a new route to get the list of user names To be able to transfer ownership to a user, we need to be able to select him from the list of users. Because the list could be too big, we add a autocomplete feature. This commit does the following: * Add a API endpoint to get a list of user names by searching its name * [#510] The user can choose the next owner of the video To be able to transfer ownership to a user, we need the owner to be able to select the user. The server can autocomplete the name of the user to give the ownership. We add a dialog for the user to actually select it. This commit does the following: * Create a modal for the owner to select the next one * Opens this modal with a button into the menu *more* * Make the dependency injection * [#510] When the user choose the next owner, create a request in database For the change of ownership to happen, we need to store the temporary requests. When the user make the request, save it to database. This commit does the following: * Create the model to persist change ownership requests * Add an API to manage ownership operations * Add a route to persist an ownership request * [#510] A user can fetch its ownership requests sent to him To be able to accept or refuse a change of ownership, the user must be able to fetch them. This commit does the following: * Add an API to list ownership for a user * Add the query to database model * [#510] A user can validate an ownership requests sent to him - server The user can accept or refuse any ownership request that was sent to him. This commit focus only on the server part. This commit does the following: * Add an API for the user to accept or refuse a video ownership * Add validators to ensure security access * Add a query to load a specific video change ownership request * [#510] A user can validate an ownership requests sent to him - web The user can accept or refuse any ownership request that was sent to him. This commit focus only on the web part. This commit does the following: * Add a page to list user ownership changes * Add actions to accept or refuse them * When accepting, show a modal requiring the channel to send the video * Correct lint - to squash * [#510] PR reviews - to squash This commit does the following: * Search parameter for user autocompletion is required from middleware directly * [#510] PR reviews - to squash with creation in database commit This commit does the following: * Add the status attribute in model * Set this attribute on instance creation * Use AccountModel method `loadLocalByName` * [#510] PR reviews - to squash with fetch ownership This commit does the following: * Add the scope `FULL` for database queries with includes * Add classic pagination middlewares * [#510] PR reviews - to squash with ownership validation - server This commit does the following: * Add a middleware to validate whether a user can validate an ownership * Change the ownership status instead of deleting the row * [#510] PR reviews - to squash with ownership validation - client This commit does the following: * Correct indentation of html files with two-spaces indentation * Use event emitter instead of function for accept event * Update the sort of ownership change table for a decreasing order by creation date * Add the status in ownership change table * Use classic method syntax * code style - to squash * Add new user right - to squash * Move the change to my-account instead of video-watch - to squash As requested in pull-request, move the action to change ownership into my videos page. The rest of the logic was not really changed. This commit does the following: - Move the modal into my video page - Create the generic component `button` to keep some styles and logic * [#510] Add tests for the new feature To avoid regression, we add tests for all api of ownership change. This commit does the following: - Create an end-to-end test for ownership change - Divide it to one test per request * [#510] Do not send twice the same request to avoid spam We can send several time the same request to change ownership. However, it will spam the user. To avoid this, we do not save a request already existing in database. This commit does the following: - Check whether the request exist in database - Add tests to verify this new condition * [#510] Change icons Change icons so they remains logic with the rest of the application. This commit does the following: - Add svg for missing icons - Add icons in `my-button` component - Use these new icons * [#510] Add control about the user quota The user should be able to accept a new video only if his quota allows it. This commit does the following: - Update the middleware to control the quota - Add tests verifying the control * Correct merge - Use new modal system - Move button to new directory `buttons` * PR reviews - to squash --- .../+admin/moderation/moderation.component.scss | 8 +-- .../my-account-accept-ownership.component.html | 34 ++++++++++ .../my-account-accept-ownership.component.scss | 10 +++ .../my-account-accept-ownership.component.ts | 79 ++++++++++++++++++++++ .../my-account-ownership.component.html | 54 +++++++++++++++ .../my-account-ownership.component.ts | 68 +++++++++++++++++++ .../app/+my-account/my-account-routing.module.ts | 10 +++ .../my-account-videos.component.html | 8 +++ .../my-account-videos.component.scss | 10 ++- .../my-account-videos.component.ts | 10 ++- .../video-change-ownership.component.html | 31 +++++++++ .../video-change-ownership.component.scss | 10 +++ .../video-change-ownership.component.ts | 75 ++++++++++++++++++++ .../src/app/+my-account/my-account.component.html | 2 + client/src/app/+my-account/my-account.module.ts | 9 +++ .../src/app/shared/buttons/button.component.html | 4 ++ .../src/app/shared/buttons/button.component.scss | 12 ++++ client/src/app/shared/buttons/button.component.ts | 18 +++++ .../src/app/shared/forms/form-validators/index.ts | 2 + .../video-accept-ownership-validators.service.ts | 18 +++++ .../video-change-ownership-validators.service.ts | 18 +++++ client/src/app/shared/shared.module.ts | 10 ++- client/src/app/shared/users/user.service.ts | 12 +++- client/src/app/shared/video-ownership/index.ts | 1 + .../video-ownership/video-ownership.service.ts | 67 ++++++++++++++++++ 25 files changed, 567 insertions(+), 13 deletions(-) create mode 100644 client/src/app/+my-account/my-account-ownership/my-account-accept-ownership/my-account-accept-ownership.component.html create mode 100644 client/src/app/+my-account/my-account-ownership/my-account-accept-ownership/my-account-accept-ownership.component.scss create mode 100644 client/src/app/+my-account/my-account-ownership/my-account-accept-ownership/my-account-accept-ownership.component.ts create mode 100644 client/src/app/+my-account/my-account-ownership/my-account-ownership.component.html create mode 100644 client/src/app/+my-account/my-account-ownership/my-account-ownership.component.ts create mode 100644 client/src/app/+my-account/my-account-videos/video-change-ownership/video-change-ownership.component.html create mode 100644 client/src/app/+my-account/my-account-videos/video-change-ownership/video-change-ownership.component.scss create mode 100644 client/src/app/+my-account/my-account-videos/video-change-ownership/video-change-ownership.component.ts create mode 100644 client/src/app/shared/buttons/button.component.html create mode 100644 client/src/app/shared/buttons/button.component.ts create mode 100644 client/src/app/shared/forms/form-validators/video-accept-ownership-validators.service.ts create mode 100644 client/src/app/shared/forms/form-validators/video-change-ownership-validators.service.ts create mode 100644 client/src/app/shared/video-ownership/index.ts create mode 100644 client/src/app/shared/video-ownership/video-ownership.service.ts (limited to 'client/src/app') diff --git a/client/src/app/+admin/moderation/moderation.component.scss b/client/src/app/+admin/moderation/moderation.component.scss index 5bb2c50a7..02ccfc8ca 100644 --- a/client/src/app/+admin/moderation/moderation.component.scss +++ b/client/src/app/+admin/moderation/moderation.component.scss @@ -17,8 +17,8 @@ } .moderation-expanded { - word-wrap: break-word; - overflow: visible !important; - text-overflow: unset !important; - white-space: unset !important; + word-wrap: break-word; + overflow: visible !important; + text-overflow: unset !important; + white-space: unset !important; } diff --git a/client/src/app/+my-account/my-account-ownership/my-account-accept-ownership/my-account-accept-ownership.component.html b/client/src/app/+my-account/my-account-ownership/my-account-accept-ownership/my-account-accept-ownership.component.html new file mode 100644 index 000000000..fd7d7d23b --- /dev/null +++ b/client/src/app/+my-account/my-account-ownership/my-account-accept-ownership/my-account-accept-ownership.component.html @@ -0,0 +1,34 @@ + + + + + + + diff --git a/client/src/app/+my-account/my-account-ownership/my-account-accept-ownership/my-account-accept-ownership.component.scss b/client/src/app/+my-account/my-account-ownership/my-account-accept-ownership/my-account-accept-ownership.component.scss new file mode 100644 index 000000000..ad6117413 --- /dev/null +++ b/client/src/app/+my-account/my-account-ownership/my-account-accept-ownership/my-account-accept-ownership.component.scss @@ -0,0 +1,10 @@ +@import '_variables'; +@import '_mixins'; + +select { + display: block; +} + +.form-group { + margin: 20px 0; +} \ No newline at end of file diff --git a/client/src/app/+my-account/my-account-ownership/my-account-accept-ownership/my-account-accept-ownership.component.ts b/client/src/app/+my-account/my-account-ownership/my-account-accept-ownership/my-account-accept-ownership.component.ts new file mode 100644 index 000000000..a68b452ec --- /dev/null +++ b/client/src/app/+my-account/my-account-ownership/my-account-accept-ownership/my-account-accept-ownership.component.ts @@ -0,0 +1,79 @@ +import { Component, ElementRef, EventEmitter, OnInit, Output, ViewChild } from '@angular/core' +import { NotificationsService } from 'angular2-notifications' +import { FormReactive } from '@app/shared' +import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' +import { VideoOwnershipService } from '@app/shared/video-ownership' +import { VideoChangeOwnership } from '../../../../../../shared/models/videos' +import { VideoAcceptOwnershipValidatorsService } from '@app/shared/forms/form-validators' +import { VideoChannel } from '@app/shared/video-channel/video-channel.model' +import { VideoChannelService } from '@app/shared/video-channel/video-channel.service' +import { I18n } from '@ngx-translate/i18n-polyfill' +import { AuthService } from '@app/core' +import { NgbModal } from '@ng-bootstrap/ng-bootstrap' + +@Component({ + selector: 'my-account-accept-ownership', + templateUrl: './my-account-accept-ownership.component.html', + styleUrls: [ './my-account-accept-ownership.component.scss' ] +}) +export class MyAccountAcceptOwnershipComponent extends FormReactive implements OnInit { + @Output() accepted = new EventEmitter() + + @ViewChild('modal') modal: ElementRef + + videoChangeOwnership: VideoChangeOwnership | undefined = undefined + + videoChannels: VideoChannel[] + + error: string = null + + constructor ( + protected formValidatorService: FormValidatorService, + private videoChangeOwnershipValidatorsService: VideoAcceptOwnershipValidatorsService, + private videoOwnershipService: VideoOwnershipService, + private notificationsService: NotificationsService, + private authService: AuthService, + private videoChannelService: VideoChannelService, + private modalService: NgbModal, + private i18n: I18n + ) { + super() + } + + ngOnInit () { + this.videoChannels = [] + + this.videoChannelService.listAccountVideoChannels(this.authService.getUser().account) + .subscribe(videoChannels => this.videoChannels = videoChannels.data) + + this.buildForm({ + channel: this.videoChangeOwnershipValidatorsService.CHANNEL + }) + } + + show (videoChangeOwnership: VideoChangeOwnership) { + this.videoChangeOwnership = videoChangeOwnership + this.modalService + .open(this.modal) + .result + .then(() => this.acceptOwnership()) + .catch(() => this.videoChangeOwnership = undefined) + } + + acceptOwnership () { + const channel = this.form.value['channel'] + + const videoChangeOwnership = this.videoChangeOwnership + this.videoOwnershipService + .acceptOwnership(videoChangeOwnership.id, { channelId: channel }) + .subscribe( + () => { + this.notificationsService.success(this.i18n('Success'), this.i18n('Ownership accepted')) + if (this.accepted) this.accepted.emit() + this.videoChangeOwnership = undefined + }, + + err => this.notificationsService.error(this.i18n('Error'), err.message) + ) + } +} diff --git a/client/src/app/+my-account/my-account-ownership/my-account-ownership.component.html b/client/src/app/+my-account/my-account-ownership/my-account-ownership.component.html new file mode 100644 index 000000000..379fd8bb1 --- /dev/null +++ b/client/src/app/+my-account/my-account-ownership/my-account-ownership.component.html @@ -0,0 +1,54 @@ + + + + Initiator + Video + + Created + + + Status + Action + + + + + + + + {{ createByString(videoChangeOwnership.initiatorAccount) }} + + + + + {{ videoChangeOwnership.video.name }} + + + {{ videoChangeOwnership.createdAt }} + {{ videoChangeOwnership.status }} + + + + Refuse + + + + + + + \ No newline at end of file diff --git a/client/src/app/+my-account/my-account-ownership/my-account-ownership.component.ts b/client/src/app/+my-account/my-account-ownership/my-account-ownership.component.ts new file mode 100644 index 000000000..13517b9f4 --- /dev/null +++ b/client/src/app/+my-account/my-account-ownership/my-account-ownership.component.ts @@ -0,0 +1,68 @@ +import { Component, OnInit, ViewChild } from '@angular/core' +import { NotificationsService } from 'angular2-notifications' +import { I18n } from '@ngx-translate/i18n-polyfill' +import { RestPagination, RestTable } from '@app/shared' +import { SortMeta } from 'primeng/components/common/sortmeta' +import { VideoChangeOwnership } from '../../../../../shared' +import { VideoOwnershipService } from '@app/shared/video-ownership' +import { Account } from '@app/shared/account/account.model' +import { MyAccountAcceptOwnershipComponent } +from '@app/+my-account/my-account-ownership/my-account-accept-ownership/my-account-accept-ownership.component' + +@Component({ + selector: 'my-account-ownership', + templateUrl: './my-account-ownership.component.html' +}) +export class MyAccountOwnershipComponent extends RestTable implements OnInit { + videoChangeOwnerships: VideoChangeOwnership[] = [] + totalRecords = 0 + rowsPerPage = 10 + sort: SortMeta = { field: 'createdAt', order: -1 } + pagination: RestPagination = { count: this.rowsPerPage, start: 0 } + + @ViewChild('myAccountAcceptOwnershipComponent') myAccountAcceptOwnershipComponent: MyAccountAcceptOwnershipComponent + + constructor ( + private notificationsService: NotificationsService, + private videoOwnershipService: VideoOwnershipService, + private i18n: I18n + ) { + super() + } + + ngOnInit () { + this.loadSort() + } + + protected loadData () { + return this.videoOwnershipService.getOwnershipChanges(this.pagination, this.sort) + .subscribe( + resultList => { + this.videoChangeOwnerships = resultList.data + this.totalRecords = resultList.total + }, + + err => this.notificationsService.error(this.i18n('Error'), err.message) + ) + } + + createByString (account: Account) { + return Account.CREATE_BY_STRING(account.name, account.host) + } + + openAcceptModal (videoChangeOwnership: VideoChangeOwnership) { + this.myAccountAcceptOwnershipComponent.show(videoChangeOwnership) + } + + accepted () { + this.loadData() + } + + refuse (videoChangeOwnership: VideoChangeOwnership) { + this.videoOwnershipService.refuseOwnership(videoChangeOwnership.id) + .subscribe( + () => this.loadData(), + err => this.notificationsService.error(this.i18n('Error'), err.message) + ) + } +} diff --git a/client/src/app/+my-account/my-account-routing.module.ts b/client/src/app/+my-account/my-account-routing.module.ts index c1c979151..4b2168e35 100644 --- a/client/src/app/+my-account/my-account-routing.module.ts +++ b/client/src/app/+my-account/my-account-routing.module.ts @@ -10,6 +10,7 @@ import { MyAccountVideoChannelCreateComponent } from '@app/+my-account/my-accoun import { MyAccountVideoChannelUpdateComponent } from '@app/+my-account/my-account-video-channels/my-account-video-channel-update.component' import { MyAccountVideoImportsComponent } from '@app/+my-account/my-account-video-imports/my-account-video-imports.component' import { MyAccountSubscriptionsComponent } from '@app/+my-account/my-account-subscriptions/my-account-subscriptions.component' +import { MyAccountOwnershipComponent } from '@app/+my-account/my-account-ownership/my-account-ownership.component' const myAccountRoutes: Routes = [ { @@ -84,6 +85,15 @@ const myAccountRoutes: Routes = [ title: 'Account subscriptions' } } + }, + { + path: 'ownership', + component: MyAccountOwnershipComponent, + data: { + meta: { + title: 'Ownership changes' + } + } } ] } diff --git a/client/src/app/+my-account/my-account-videos/my-account-videos.component.html b/client/src/app/+my-account/my-account-videos/my-account-videos.component.html index 8a6cb5c32..276d01408 100644 --- a/client/src/app/+my-account/my-account-videos/my-account-videos.component.html +++ b/client/src/app/+my-account/my-account-videos/my-account-videos.component.html @@ -42,7 +42,15 @@ + + + + \ No newline at end of file diff --git a/client/src/app/+my-account/my-account-videos/my-account-videos.component.scss b/client/src/app/+my-account/my-account-videos/my-account-videos.component.scss index cd805be73..8d0dec07d 100644 --- a/client/src/app/+my-account/my-account-videos/my-account-videos.component.scss +++ b/client/src/app/+my-account/my-account-videos/my-account-videos.component.scss @@ -35,12 +35,6 @@ } } -/deep/ .action-button { - &.action-button-delete { - margin-right: 10px; - } -} - .video { @include row-blocks; @@ -96,6 +90,10 @@ .video-buttons { min-width: 190px; + + *:not(:last-child) { + margin-right: 10px; + } } } diff --git a/client/src/app/+my-account/my-account-videos/my-account-videos.component.ts b/client/src/app/+my-account/my-account-videos/my-account-videos.component.ts index 01e1ef1da..7560f0128 100644 --- a/client/src/app/+my-account/my-account-videos/my-account-videos.component.ts +++ b/client/src/app/+my-account/my-account-videos/my-account-videos.component.ts @@ -1,6 +1,6 @@ import { from as observableFrom, Observable } from 'rxjs' import { concatAll, tap } from 'rxjs/operators' -import { Component, OnDestroy, OnInit, Inject, LOCALE_ID } from '@angular/core' +import { Component, OnDestroy, OnInit, Inject, LOCALE_ID, ViewChild } from '@angular/core' import { ActivatedRoute, Router } from '@angular/router' import { Location } from '@angular/common' import { immutableAssign } from '@app/shared/misc/utils' @@ -14,6 +14,7 @@ import { VideoService } from '../../shared/video/video.service' import { I18n } from '@ngx-translate/i18n-polyfill' import { VideoPrivacy, VideoState } from '../../../../../shared/models/videos' import { ScreenService } from '@app/shared/misc/screen.service' +import { VideoChangeOwnershipComponent } from './video-change-ownership/video-change-ownership.component' @Component({ selector: 'my-account-videos', @@ -33,6 +34,8 @@ export class MyAccountVideosComponent extends AbstractVideoList implements OnIni protected baseVideoWidth = -1 protected baseVideoHeight = 155 + @ViewChild('videoChangeOwnershipModal') videoChangeOwnershipModal: VideoChangeOwnershipComponent + constructor ( protected router: Router, protected route: ActivatedRoute, @@ -133,6 +136,11 @@ export class MyAccountVideosComponent extends AbstractVideoList implements OnIni ) } + changeOwnership (event: Event, video: Video) { + event.preventDefault() + this.videoChangeOwnershipModal.show(video) + } + getStateLabel (video: Video) { let suffix: string diff --git a/client/src/app/+my-account/my-account-videos/video-change-ownership/video-change-ownership.component.html b/client/src/app/+my-account/my-account-videos/video-change-ownership/video-change-ownership.component.html new file mode 100644 index 000000000..69b198faa --- /dev/null +++ b/client/src/app/+my-account/my-account-videos/video-change-ownership/video-change-ownership.component.html @@ -0,0 +1,31 @@ + + + + + + + diff --git a/client/src/app/+my-account/my-account-videos/video-change-ownership/video-change-ownership.component.scss b/client/src/app/+my-account/my-account-videos/video-change-ownership/video-change-ownership.component.scss new file mode 100644 index 000000000..a79fec179 --- /dev/null +++ b/client/src/app/+my-account/my-account-videos/video-change-ownership/video-change-ownership.component.scss @@ -0,0 +1,10 @@ +@import '_variables'; +@import '_mixins'; + +p-autocomplete { + display: block; +} + +.form-group { + margin: 20px 0; +} \ No newline at end of file diff --git a/client/src/app/+my-account/my-account-videos/video-change-ownership/video-change-ownership.component.ts b/client/src/app/+my-account/my-account-videos/video-change-ownership/video-change-ownership.component.ts new file mode 100644 index 000000000..0aa4c32ee --- /dev/null +++ b/client/src/app/+my-account/my-account-videos/video-change-ownership/video-change-ownership.component.ts @@ -0,0 +1,75 @@ +import { Component, ElementRef, OnInit, ViewChild } from '@angular/core' +import { NotificationsService } from 'angular2-notifications' +import { NgbModal } from '@ng-bootstrap/ng-bootstrap' +import { FormReactive, UserService } from '../../../shared/index' +import { Video } from '@app/shared/video/video.model' +import { I18n } from '@ngx-translate/i18n-polyfill' +import { FormValidatorService, VideoChangeOwnershipValidatorsService } from '@app/shared' +import { VideoOwnershipService } from '@app/shared/video-ownership' + +@Component({ + selector: 'my-video-change-ownership', + templateUrl: './video-change-ownership.component.html', + styleUrls: [ './video-change-ownership.component.scss' ] +}) +export class VideoChangeOwnershipComponent extends FormReactive implements OnInit { + @ViewChild('modal') modal: ElementRef + + usernamePropositions: string[] + + error: string = null + + private video: Video | undefined = undefined + + constructor ( + protected formValidatorService: FormValidatorService, + private videoChangeOwnershipValidatorsService: VideoChangeOwnershipValidatorsService, + private videoOwnershipService: VideoOwnershipService, + private notificationsService: NotificationsService, + private userService: UserService, + private modalService: NgbModal, + private i18n: I18n + ) { + super() + } + + ngOnInit () { + this.buildForm({ + username: this.videoChangeOwnershipValidatorsService.USERNAME + }) + this.usernamePropositions = [] + } + + show (video: Video) { + this.video = video + this.modalService + .open(this.modal) + .result + .then(() => this.changeOwnership()) + .catch((_) => _) // Called when closing (cancel) the modal without validating, do nothing + } + + search (event) { + const query = event.query + this.userService.autocomplete(query) + .subscribe( + (usernames) => { + this.usernamePropositions = usernames + }, + + err => this.notificationsService.error('Error', err.message) + ) + } + + changeOwnership () { + const username = this.form.value['username'] + + this.videoOwnershipService + .changeOwnership(this.video.id, username) + .subscribe( + () => this.notificationsService.success(this.i18n('Success'), this.i18n('Ownership changed.')), + + err => this.notificationsService.error(this.i18n('Error'), err.message) + ) + } +} diff --git a/client/src/app/+my-account/my-account.component.html b/client/src/app/+my-account/my-account.component.html index 74742649c..b79e61bef 100644 --- a/client/src/app/+my-account/my-account.component.html +++ b/client/src/app/+my-account/my-account.component.html @@ -9,6 +9,8 @@ My subscriptions My imports + + Ownership changes
diff --git a/client/src/app/+my-account/my-account.module.ts b/client/src/app/+my-account/my-account.module.ts index c93f38d4b..ad21162a8 100644 --- a/client/src/app/+my-account/my-account.module.ts +++ b/client/src/app/+my-account/my-account.module.ts @@ -1,5 +1,6 @@ import { TableModule } from 'primeng/table' import { NgModule } from '@angular/core' +import { AutoCompleteModule } from 'primeng/autocomplete' import { SharedModule } from '../shared' import { MyAccountRoutingModule } from './my-account-routing.module' import { MyAccountChangePasswordComponent } from './my-account-settings/my-account-change-password/my-account-change-password.component' @@ -7,6 +8,9 @@ import { MyAccountVideoSettingsComponent } from './my-account-settings/my-accoun import { MyAccountSettingsComponent } from './my-account-settings/my-account-settings.component' import { MyAccountComponent } from './my-account.component' import { MyAccountVideosComponent } from './my-account-videos/my-account-videos.component' +import { VideoChangeOwnershipComponent } from './my-account-videos/video-change-ownership/video-change-ownership.component' +import { MyAccountOwnershipComponent } from './my-account-ownership/my-account-ownership.component' +import { MyAccountAcceptOwnershipComponent } from './my-account-ownership/my-account-accept-ownership/my-account-accept-ownership.component' import { MyAccountProfileComponent } from '@app/+my-account/my-account-settings/my-account-profile/my-account-profile.component' import { MyAccountVideoChannelsComponent } from '@app/+my-account/my-account-video-channels/my-account-video-channels.component' import { MyAccountVideoChannelCreateComponent } from '@app/+my-account/my-account-video-channels/my-account-video-channel-create.component' @@ -18,7 +22,9 @@ import { MyAccountSubscriptionsComponent } from '@app/+my-account/my-account-sub @NgModule({ imports: [ + TableModule, MyAccountRoutingModule, + AutoCompleteModule, SharedModule, TableModule ], @@ -30,6 +36,9 @@ import { MyAccountSubscriptionsComponent } from '@app/+my-account/my-account-sub MyAccountVideoSettingsComponent, MyAccountProfileComponent, MyAccountVideosComponent, + VideoChangeOwnershipComponent, + MyAccountOwnershipComponent, + MyAccountAcceptOwnershipComponent, MyAccountVideoChannelsComponent, MyAccountVideoChannelCreateComponent, MyAccountVideoChannelUpdateComponent, diff --git a/client/src/app/shared/buttons/button.component.html b/client/src/app/shared/buttons/button.component.html new file mode 100644 index 000000000..87a8daccf --- /dev/null +++ b/client/src/app/shared/buttons/button.component.html @@ -0,0 +1,4 @@ + + + {{ label }} + diff --git a/client/src/app/shared/buttons/button.component.scss b/client/src/app/shared/buttons/button.component.scss index 343aea207..168102f09 100644 --- a/client/src/app/shared/buttons/button.component.scss +++ b/client/src/app/shared/buttons/button.component.scss @@ -26,6 +26,18 @@ &.icon-delete-grey { background-image: url('../../../assets/images/global/delete-grey.svg'); } + + &.icon-im-with-her { + background-image: url('../../../assets/images/global/im-with-her.svg'); + } + + &.icon-tick { + background-image: url('../../../assets/images/global/tick.svg'); + } + + &.icon-cross { + background-image: url('../../../assets/images/global/cross.svg'); + } } } diff --git a/client/src/app/shared/buttons/button.component.ts b/client/src/app/shared/buttons/button.component.ts new file mode 100644 index 000000000..967cb1409 --- /dev/null +++ b/client/src/app/shared/buttons/button.component.ts @@ -0,0 +1,18 @@ +import { Component, Input } from '@angular/core' + +@Component({ + selector: 'my-button', + styleUrls: ['./button.component.scss'], + templateUrl: './button.component.html' +}) + +export class ButtonComponent { + @Input() label = '' + @Input() className = undefined + @Input() icon = undefined + @Input() title = undefined + + getTitle () { + return this.title || this.label + } +} diff --git a/client/src/app/shared/forms/form-validators/index.ts b/client/src/app/shared/forms/form-validators/index.ts index 9bc7615ca..74e385b3d 100644 --- a/client/src/app/shared/forms/form-validators/index.ts +++ b/client/src/app/shared/forms/form-validators/index.ts @@ -10,3 +10,5 @@ export * from './video-channel-validators.service' export * from './video-comment-validators.service' export * from './video-validators.service' export * from './video-captions-validators.service' +export * from './video-change-ownership-validators.service' +export * from './video-accept-ownership-validators.service' diff --git a/client/src/app/shared/forms/form-validators/video-accept-ownership-validators.service.ts b/client/src/app/shared/forms/form-validators/video-accept-ownership-validators.service.ts new file mode 100644 index 000000000..48c7054a4 --- /dev/null +++ b/client/src/app/shared/forms/form-validators/video-accept-ownership-validators.service.ts @@ -0,0 +1,18 @@ +import { I18n } from '@ngx-translate/i18n-polyfill' +import { Validators } from '@angular/forms' +import { Injectable } from '@angular/core' +import { BuildFormValidator } from '@app/shared' + +@Injectable() +export class VideoAcceptOwnershipValidatorsService { + readonly CHANNEL: BuildFormValidator + + constructor (private i18n: I18n) { + this.CHANNEL = { + VALIDATORS: [ Validators.required ], + MESSAGES: { + 'required': this.i18n('The channel is required.') + } + } + } +} diff --git a/client/src/app/shared/forms/form-validators/video-change-ownership-validators.service.ts b/client/src/app/shared/forms/form-validators/video-change-ownership-validators.service.ts new file mode 100644 index 000000000..087b80b44 --- /dev/null +++ b/client/src/app/shared/forms/form-validators/video-change-ownership-validators.service.ts @@ -0,0 +1,18 @@ +import { I18n } from '@ngx-translate/i18n-polyfill' +import { Validators } from '@angular/forms' +import { Injectable } from '@angular/core' +import { BuildFormValidator } from '@app/shared' + +@Injectable() +export class VideoChangeOwnershipValidatorsService { + readonly USERNAME: BuildFormValidator + + constructor (private i18n: I18n) { + this.USERNAME = { + VALIDATORS: [ Validators.required ], + MESSAGES: { + 'required': this.i18n('The username is required.') + } + } + } +} diff --git a/client/src/app/shared/shared.module.ts b/client/src/app/shared/shared.module.ts index b96a9aa41..1e71feb86 100644 --- a/client/src/app/shared/shared.module.ts +++ b/client/src/app/shared/shared.module.ts @@ -12,6 +12,7 @@ import { BytesPipe, KeysPipe, NgPipesModule } from 'ngx-pipes' import { SharedModule as PrimeSharedModule } from 'primeng/components/common/shared' import { AUTH_INTERCEPTOR_PROVIDER } from './auth' +import { ButtonComponent } from './buttons/button.component' import { DeleteButtonComponent } from './buttons/delete-button.component' import { EditButtonComponent } from './buttons/edit-button.component' import { FromNowPipe } from './misc/from-now.pipe' @@ -22,6 +23,7 @@ import { RestExtractor, RestService } from './rest' import { UserService } from './users' import { VideoAbuseService } from './video-abuse' import { VideoBlacklistService } from './video-blacklist' +import { VideoOwnershipService } from './video-ownership' import { VideoMiniatureComponent } from './video/video-miniature.component' import { VideoFeedComponent } from './video/video-feed.component' import { VideoThumbnailComponent } from './video/video-thumbnail.component' @@ -40,7 +42,8 @@ import { VideoBlacklistValidatorsService, VideoChannelValidatorsService, VideoCommentValidatorsService, - VideoValidatorsService + VideoValidatorsService, + VideoChangeOwnershipValidatorsService, VideoAcceptOwnershipValidatorsService } from '@app/shared/forms' import { I18nPrimengCalendarService } from '@app/shared/i18n/i18n-primeng-calendar' import { ScreenService } from '@app/shared/misc/screen.service' @@ -77,6 +80,7 @@ import { OverviewService } from '@app/shared/overview' VideoThumbnailComponent, VideoMiniatureComponent, VideoFeedComponent, + ButtonComponent, DeleteButtonComponent, EditButtonComponent, ActionDropdownComponent, @@ -113,6 +117,7 @@ import { OverviewService } from '@app/shared/overview' VideoThumbnailComponent, VideoMiniatureComponent, VideoFeedComponent, + ButtonComponent, DeleteButtonComponent, EditButtonComponent, ActionDropdownComponent, @@ -135,6 +140,7 @@ import { OverviewService } from '@app/shared/overview' RestService, VideoAbuseService, VideoBlacklistService, + VideoOwnershipService, UserService, VideoService, AccountService, @@ -156,6 +162,8 @@ import { OverviewService } from '@app/shared/overview' VideoCaptionsValidatorsService, VideoBlacklistValidatorsService, OverviewService, + VideoChangeOwnershipValidatorsService, + VideoAcceptOwnershipValidatorsService, I18nPrimengCalendarService, ScreenService, diff --git a/client/src/app/shared/users/user.service.ts b/client/src/app/shared/users/user.service.ts index 249c589b7..fad5b0980 100644 --- a/client/src/app/shared/users/user.service.ts +++ b/client/src/app/shared/users/user.service.ts @@ -1,5 +1,6 @@ +import { Observable } from 'rxjs' import { catchError, map } from 'rxjs/operators' -import { HttpClient } from '@angular/common/http' +import { HttpClient, HttpParams } from '@angular/common/http' import { Injectable } from '@angular/core' import { UserCreate, UserUpdateMe, UserVideoQuota } from '../../../../../shared' import { environment } from '../../../environments/environment' @@ -117,4 +118,13 @@ export class UserService { catchError(err => this.restExtractor.handleError(err)) ) } + + autocomplete (search: string): Observable { + const url = UserService.BASE_USERS_URL + 'autocomplete' + const params = new HttpParams().append('search', search) + + return this.authHttp + .get(url, { params }) + .pipe(catchError(res => this.restExtractor.handleError(res))) + } } diff --git a/client/src/app/shared/video-ownership/index.ts b/client/src/app/shared/video-ownership/index.ts new file mode 100644 index 000000000..fe8902ee2 --- /dev/null +++ b/client/src/app/shared/video-ownership/index.ts @@ -0,0 +1 @@ +export * from './video-ownership.service' diff --git a/client/src/app/shared/video-ownership/video-ownership.service.ts b/client/src/app/shared/video-ownership/video-ownership.service.ts new file mode 100644 index 000000000..aa9e4839a --- /dev/null +++ b/client/src/app/shared/video-ownership/video-ownership.service.ts @@ -0,0 +1,67 @@ +import { catchError, map } from 'rxjs/operators' +import { HttpClient, HttpParams } from '@angular/common/http' +import { Injectable } from '@angular/core' +import { environment } from '../../../environments/environment' +import { RestExtractor, RestService } from '../rest' +import { VideoChangeOwnershipCreate } from '../../../../../shared/models/videos' +import { Observable } from 'rxjs/index' +import { SortMeta } from 'primeng/components/common/sortmeta' +import { ResultList, VideoChangeOwnership } from '../../../../../shared' +import { RestPagination } from '@app/shared/rest' +import { VideoChangeOwnershipAccept } from '../../../../../shared/models/videos/video-change-ownership-accept.model' + +@Injectable() +export class VideoOwnershipService { + private static BASE_VIDEO_CHANGE_OWNERSHIP_URL = environment.apiUrl + '/api/v1/videos/' + + constructor ( + private authHttp: HttpClient, + private restService: RestService, + private restExtractor: RestExtractor + ) { + } + + changeOwnership (id: number, username: string) { + const url = VideoOwnershipService.BASE_VIDEO_CHANGE_OWNERSHIP_URL + id + '/give-ownership' + const body: VideoChangeOwnershipCreate = { + username + } + + return this.authHttp.post(url, body) + .pipe( + map(this.restExtractor.extractDataBool), + catchError(res => this.restExtractor.handleError(res)) + ) + } + + getOwnershipChanges (pagination: RestPagination, sort: SortMeta): Observable> { + const url = VideoOwnershipService.BASE_VIDEO_CHANGE_OWNERSHIP_URL + 'ownership' + + let params = new HttpParams() + params = this.restService.addRestGetParams(params, pagination, sort) + + return this.authHttp.get>(url, { params }) + .pipe( + map(res => this.restExtractor.convertResultListDateToHuman(res)), + catchError(res => this.restExtractor.handleError(res)) + ) + } + + acceptOwnership (id: number, input: VideoChangeOwnershipAccept) { + const url = VideoOwnershipService.BASE_VIDEO_CHANGE_OWNERSHIP_URL + 'ownership/' + id + '/accept' + return this.authHttp.post(url, input) + .pipe( + map(this.restExtractor.extractDataBool), + catchError(this.restExtractor.handleError) + ) + } + + refuseOwnership (id: number) { + const url = VideoOwnershipService.BASE_VIDEO_CHANGE_OWNERSHIP_URL + 'ownership/' + id + '/refuse' + return this.authHttp.post(url, {}) + .pipe( + map(this.restExtractor.extractDataBool), + catchError(this.restExtractor.handleError) + ) + } +} -- cgit v1.2.3