diff options
author | Gaƫtan Rizio <gaetan@rizio.fr> | 2018-09-04 08:57:13 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-09-04 08:57:13 +0200 |
commit | 74d63469355bad731cdd32defdc85913df3cbd5c (patch) | |
tree | 5e7a9033a507fd69c554ddc7cc6ce3f7a6416ca1 | |
parent | 2303a803aa19c2857efac9f2af2223ccae5757e2 (diff) | |
download | PeerTube-74d63469355bad731cdd32defdc85913df3cbd5c.tar.gz PeerTube-74d63469355bad731cdd32defdc85913df3cbd5c.tar.zst PeerTube-74d63469355bad731cdd32defdc85913df3cbd5c.zip |
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
44 files changed, 1332 insertions, 17 deletions
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 @@ | |||
17 | } | 17 | } |
18 | 18 | ||
19 | .moderation-expanded { | 19 | .moderation-expanded { |
20 | word-wrap: break-word; | 20 | word-wrap: break-word; |
21 | overflow: visible !important; | 21 | overflow: visible !important; |
22 | text-overflow: unset !important; | 22 | text-overflow: unset !important; |
23 | white-space: unset !important; | 23 | white-space: unset !important; |
24 | } | 24 | } |
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 @@ | |||
1 | <ng-template #modal let-close="close" let-dismiss="dismiss"> | ||
2 | <div class="modal-header"> | ||
3 | <h4 i18n class="modal-title">Accept ownership</h4> | ||
4 | <span class="close" aria-label="Close" role="button" (click)="dismiss()"></span> | ||
5 | </div> | ||
6 | |||
7 | <div class="modal-body" [formGroup]="form"> | ||
8 | <div class="form-group"> | ||
9 | <label i18n for="channel">Select the target channel</label> | ||
10 | <select formControlName="channel" id="channel" class="peertube-select-container"> | ||
11 | <option></option> | ||
12 | <option *ngFor="let channel of videoChannels" [value]="channel.id">{{ channel.displayName }} | ||
13 | </option> | ||
14 | </select> | ||
15 | <div *ngIf="formErrors.channel" class="form-error"> | ||
16 | {{ formErrors.channel }} | ||
17 | </div> | ||
18 | </div> | ||
19 | </div> | ||
20 | |||
21 | <div class="modal-footer inputs"> | ||
22 | <div class="form-group inputs"> | ||
23 | <span i18n class="action-button action-button-cancel" (click)="dismiss()"> | ||
24 | Cancel | ||
25 | </span> | ||
26 | |||
27 | <input | ||
28 | type="submit" i18n-value value="Submit" class="action-button-submit" | ||
29 | [disabled]="!form.valid" | ||
30 | (click)="close()" | ||
31 | > | ||
32 | </div> | ||
33 | </div> | ||
34 | </ng-template> | ||
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 @@ | |||
1 | @import '_variables'; | ||
2 | @import '_mixins'; | ||
3 | |||
4 | select { | ||
5 | display: block; | ||
6 | } | ||
7 | |||
8 | .form-group { | ||
9 | margin: 20px 0; | ||
10 | } \ 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 @@ | |||
1 | import { Component, ElementRef, EventEmitter, OnInit, Output, ViewChild } from '@angular/core' | ||
2 | import { NotificationsService } from 'angular2-notifications' | ||
3 | import { FormReactive } from '@app/shared' | ||
4 | import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' | ||
5 | import { VideoOwnershipService } from '@app/shared/video-ownership' | ||
6 | import { VideoChangeOwnership } from '../../../../../../shared/models/videos' | ||
7 | import { VideoAcceptOwnershipValidatorsService } from '@app/shared/forms/form-validators' | ||
8 | import { VideoChannel } from '@app/shared/video-channel/video-channel.model' | ||
9 | import { VideoChannelService } from '@app/shared/video-channel/video-channel.service' | ||
10 | import { I18n } from '@ngx-translate/i18n-polyfill' | ||
11 | import { AuthService } from '@app/core' | ||
12 | import { NgbModal } from '@ng-bootstrap/ng-bootstrap' | ||
13 | |||
14 | @Component({ | ||
15 | selector: 'my-account-accept-ownership', | ||
16 | templateUrl: './my-account-accept-ownership.component.html', | ||
17 | styleUrls: [ './my-account-accept-ownership.component.scss' ] | ||
18 | }) | ||
19 | export class MyAccountAcceptOwnershipComponent extends FormReactive implements OnInit { | ||
20 | @Output() accepted = new EventEmitter<void>() | ||
21 | |||
22 | @ViewChild('modal') modal: ElementRef | ||
23 | |||
24 | videoChangeOwnership: VideoChangeOwnership | undefined = undefined | ||
25 | |||
26 | videoChannels: VideoChannel[] | ||
27 | |||
28 | error: string = null | ||
29 | |||
30 | constructor ( | ||
31 | protected formValidatorService: FormValidatorService, | ||
32 | private videoChangeOwnershipValidatorsService: VideoAcceptOwnershipValidatorsService, | ||
33 | private videoOwnershipService: VideoOwnershipService, | ||
34 | private notificationsService: NotificationsService, | ||
35 | private authService: AuthService, | ||
36 | private videoChannelService: VideoChannelService, | ||
37 | private modalService: NgbModal, | ||
38 | private i18n: I18n | ||
39 | ) { | ||
40 | super() | ||
41 | } | ||
42 | |||
43 | ngOnInit () { | ||
44 | this.videoChannels = [] | ||
45 | |||
46 | this.videoChannelService.listAccountVideoChannels(this.authService.getUser().account) | ||
47 | .subscribe(videoChannels => this.videoChannels = videoChannels.data) | ||
48 | |||
49 | this.buildForm({ | ||
50 | channel: this.videoChangeOwnershipValidatorsService.CHANNEL | ||
51 | }) | ||
52 | } | ||
53 | |||
54 | show (videoChangeOwnership: VideoChangeOwnership) { | ||
55 | this.videoChangeOwnership = videoChangeOwnership | ||
56 | this.modalService | ||
57 | .open(this.modal) | ||
58 | .result | ||
59 | .then(() => this.acceptOwnership()) | ||
60 | .catch(() => this.videoChangeOwnership = undefined) | ||
61 | } | ||
62 | |||
63 | acceptOwnership () { | ||
64 | const channel = this.form.value['channel'] | ||
65 | |||
66 | const videoChangeOwnership = this.videoChangeOwnership | ||
67 | this.videoOwnershipService | ||
68 | .acceptOwnership(videoChangeOwnership.id, { channelId: channel }) | ||
69 | .subscribe( | ||
70 | () => { | ||
71 | this.notificationsService.success(this.i18n('Success'), this.i18n('Ownership accepted')) | ||
72 | if (this.accepted) this.accepted.emit() | ||
73 | this.videoChangeOwnership = undefined | ||
74 | }, | ||
75 | |||
76 | err => this.notificationsService.error(this.i18n('Error'), err.message) | ||
77 | ) | ||
78 | } | ||
79 | } | ||
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 @@ | |||
1 | <p-table | ||
2 | [value]="videoChangeOwnerships" | ||
3 | [lazy]="true" | ||
4 | [paginator]="true" | ||
5 | [totalRecords]="totalRecords" | ||
6 | [rows]="rowsPerPage" | ||
7 | [sortField]="sort.field" | ||
8 | [sortOrder]="sort.order" | ||
9 | (onLazyLoad)="loadLazy($event)" | ||
10 | > | ||
11 | <ng-template pTemplate="header"> | ||
12 | <tr> | ||
13 | <th i18n>Initiator</th> | ||
14 | <th i18n>Video</th> | ||
15 | <th i18n pSortableColumn="createdAt"> | ||
16 | Created | ||
17 | <p-sortIcon field="createdAt"></p-sortIcon> | ||
18 | </th> | ||
19 | <th i18n>Status</th> | ||
20 | <th i18n>Action</th> | ||
21 | </tr> | ||
22 | </ng-template> | ||
23 | |||
24 | <ng-template pTemplate="body" let-videoChangeOwnership> | ||
25 | <tr> | ||
26 | <td> | ||
27 | <a [href]="videoChangeOwnership.initiatorAccount.url" i18n-title title="Go to the account" | ||
28 | target="_blank" rel="noopener noreferrer"> | ||
29 | {{ createByString(videoChangeOwnership.initiatorAccount) }} | ||
30 | </a> | ||
31 | </td> | ||
32 | <td> | ||
33 | <a [href]="videoChangeOwnership.video.url" i18n-title title="Go to the video" target="_blank" | ||
34 | rel="noopener noreferrer"> | ||
35 | {{ videoChangeOwnership.video.name }} | ||
36 | </a> | ||
37 | </td> | ||
38 | <td>{{ videoChangeOwnership.createdAt }}</td> | ||
39 | <td i18n>{{ videoChangeOwnership.status }}</td> | ||
40 | <td class="action-cell"> | ||
41 | <ng-container *ngIf="videoChangeOwnership.status === 'WAITING'"> | ||
42 | <my-button i18n label="Accept" | ||
43 | icon="icon-tick" | ||
44 | (click)="openAcceptModal(videoChangeOwnership)"></my-button> | ||
45 | <my-button i18n label="Refuse" | ||
46 | icon="icon-cross" | ||
47 | (click)="refuse(videoChangeOwnership)">Refuse</my-button> | ||
48 | </ng-container> | ||
49 | </td> | ||
50 | </tr> | ||
51 | </ng-template> | ||
52 | </p-table> | ||
53 | |||
54 | <my-account-accept-ownership #myAccountAcceptOwnershipComponent (accepted)="accepted()"></my-account-accept-ownership> \ 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 @@ | |||
1 | import { Component, OnInit, ViewChild } from '@angular/core' | ||
2 | import { NotificationsService } from 'angular2-notifications' | ||
3 | import { I18n } from '@ngx-translate/i18n-polyfill' | ||
4 | import { RestPagination, RestTable } from '@app/shared' | ||
5 | import { SortMeta } from 'primeng/components/common/sortmeta' | ||
6 | import { VideoChangeOwnership } from '../../../../../shared' | ||
7 | import { VideoOwnershipService } from '@app/shared/video-ownership' | ||
8 | import { Account } from '@app/shared/account/account.model' | ||
9 | import { MyAccountAcceptOwnershipComponent } | ||
10 | from '@app/+my-account/my-account-ownership/my-account-accept-ownership/my-account-accept-ownership.component' | ||
11 | |||
12 | @Component({ | ||
13 | selector: 'my-account-ownership', | ||
14 | templateUrl: './my-account-ownership.component.html' | ||
15 | }) | ||
16 | export class MyAccountOwnershipComponent extends RestTable implements OnInit { | ||
17 | videoChangeOwnerships: VideoChangeOwnership[] = [] | ||
18 | totalRecords = 0 | ||
19 | rowsPerPage = 10 | ||
20 | sort: SortMeta = { field: 'createdAt', order: -1 } | ||
21 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } | ||
22 | |||
23 | @ViewChild('myAccountAcceptOwnershipComponent') myAccountAcceptOwnershipComponent: MyAccountAcceptOwnershipComponent | ||
24 | |||
25 | constructor ( | ||
26 | private notificationsService: NotificationsService, | ||
27 | private videoOwnershipService: VideoOwnershipService, | ||
28 | private i18n: I18n | ||
29 | ) { | ||
30 | super() | ||
31 | } | ||
32 | |||
33 | ngOnInit () { | ||
34 | this.loadSort() | ||
35 | } | ||
36 | |||
37 | protected loadData () { | ||
38 | return this.videoOwnershipService.getOwnershipChanges(this.pagination, this.sort) | ||
39 | .subscribe( | ||
40 | resultList => { | ||
41 | this.videoChangeOwnerships = resultList.data | ||
42 | this.totalRecords = resultList.total | ||
43 | }, | ||
44 | |||
45 | err => this.notificationsService.error(this.i18n('Error'), err.message) | ||
46 | ) | ||
47 | } | ||
48 | |||
49 | createByString (account: Account) { | ||
50 | return Account.CREATE_BY_STRING(account.name, account.host) | ||
51 | } | ||
52 | |||
53 | openAcceptModal (videoChangeOwnership: VideoChangeOwnership) { | ||
54 | this.myAccountAcceptOwnershipComponent.show(videoChangeOwnership) | ||
55 | } | ||
56 | |||
57 | accepted () { | ||
58 | this.loadData() | ||
59 | } | ||
60 | |||
61 | refuse (videoChangeOwnership: VideoChangeOwnership) { | ||
62 | this.videoOwnershipService.refuseOwnership(videoChangeOwnership.id) | ||
63 | .subscribe( | ||
64 | () => this.loadData(), | ||
65 | err => this.notificationsService.error(this.i18n('Error'), err.message) | ||
66 | ) | ||
67 | } | ||
68 | } | ||
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 | |||
10 | import { MyAccountVideoChannelUpdateComponent } from '@app/+my-account/my-account-video-channels/my-account-video-channel-update.component' | 10 | import { MyAccountVideoChannelUpdateComponent } from '@app/+my-account/my-account-video-channels/my-account-video-channel-update.component' |
11 | import { MyAccountVideoImportsComponent } from '@app/+my-account/my-account-video-imports/my-account-video-imports.component' | 11 | import { MyAccountVideoImportsComponent } from '@app/+my-account/my-account-video-imports/my-account-video-imports.component' |
12 | import { MyAccountSubscriptionsComponent } from '@app/+my-account/my-account-subscriptions/my-account-subscriptions.component' | 12 | import { MyAccountSubscriptionsComponent } from '@app/+my-account/my-account-subscriptions/my-account-subscriptions.component' |
13 | import { MyAccountOwnershipComponent } from '@app/+my-account/my-account-ownership/my-account-ownership.component' | ||
13 | 14 | ||
14 | const myAccountRoutes: Routes = [ | 15 | const myAccountRoutes: Routes = [ |
15 | { | 16 | { |
@@ -84,6 +85,15 @@ const myAccountRoutes: Routes = [ | |||
84 | title: 'Account subscriptions' | 85 | title: 'Account subscriptions' |
85 | } | 86 | } |
86 | } | 87 | } |
88 | }, | ||
89 | { | ||
90 | path: 'ownership', | ||
91 | component: MyAccountOwnershipComponent, | ||
92 | data: { | ||
93 | meta: { | ||
94 | title: 'Ownership changes' | ||
95 | } | ||
96 | } | ||
87 | } | 97 | } |
88 | ] | 98 | ] |
89 | } | 99 | } |
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 @@ | |||
42 | <my-delete-button (click)="deleteVideo(video)"></my-delete-button> | 42 | <my-delete-button (click)="deleteVideo(video)"></my-delete-button> |
43 | 43 | ||
44 | <my-edit-button [routerLink]="[ '/videos', 'update', video.uuid ]"></my-edit-button> | 44 | <my-edit-button [routerLink]="[ '/videos', 'update', video.uuid ]"></my-edit-button> |
45 | |||
46 | <my-button i18n label="Change ownership" | ||
47 | className="action-button-change-ownership" | ||
48 | icon="icon-im-with-her" | ||
49 | (click)="changeOwnership($event, video)" | ||
50 | ></my-button> | ||
45 | </div> | 51 | </div> |
46 | </div> | 52 | </div> |
47 | </div> | 53 | </div> |
48 | </div> | 54 | </div> |
55 | |||
56 | <my-video-change-ownership #videoChangeOwnershipModal></my-video-change-ownership> \ 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 @@ | |||
35 | } | 35 | } |
36 | } | 36 | } |
37 | 37 | ||
38 | /deep/ .action-button { | ||
39 | &.action-button-delete { | ||
40 | margin-right: 10px; | ||
41 | } | ||
42 | } | ||
43 | |||
44 | .video { | 38 | .video { |
45 | @include row-blocks; | 39 | @include row-blocks; |
46 | 40 | ||
@@ -96,6 +90,10 @@ | |||
96 | 90 | ||
97 | .video-buttons { | 91 | .video-buttons { |
98 | min-width: 190px; | 92 | min-width: 190px; |
93 | |||
94 | *:not(:last-child) { | ||
95 | margin-right: 10px; | ||
96 | } | ||
99 | } | 97 | } |
100 | } | 98 | } |
101 | 99 | ||
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 @@ | |||
1 | import { from as observableFrom, Observable } from 'rxjs' | 1 | import { from as observableFrom, Observable } from 'rxjs' |
2 | import { concatAll, tap } from 'rxjs/operators' | 2 | import { concatAll, tap } from 'rxjs/operators' |
3 | import { Component, OnDestroy, OnInit, Inject, LOCALE_ID } from '@angular/core' | 3 | import { Component, OnDestroy, OnInit, Inject, LOCALE_ID, ViewChild } from '@angular/core' |
4 | import { ActivatedRoute, Router } from '@angular/router' | 4 | import { ActivatedRoute, Router } from '@angular/router' |
5 | import { Location } from '@angular/common' | 5 | import { Location } from '@angular/common' |
6 | import { immutableAssign } from '@app/shared/misc/utils' | 6 | import { immutableAssign } from '@app/shared/misc/utils' |
@@ -14,6 +14,7 @@ import { VideoService } from '../../shared/video/video.service' | |||
14 | import { I18n } from '@ngx-translate/i18n-polyfill' | 14 | import { I18n } from '@ngx-translate/i18n-polyfill' |
15 | import { VideoPrivacy, VideoState } from '../../../../../shared/models/videos' | 15 | import { VideoPrivacy, VideoState } from '../../../../../shared/models/videos' |
16 | import { ScreenService } from '@app/shared/misc/screen.service' | 16 | import { ScreenService } from '@app/shared/misc/screen.service' |
17 | import { VideoChangeOwnershipComponent } from './video-change-ownership/video-change-ownership.component' | ||
17 | 18 | ||
18 | @Component({ | 19 | @Component({ |
19 | selector: 'my-account-videos', | 20 | selector: 'my-account-videos', |
@@ -33,6 +34,8 @@ export class MyAccountVideosComponent extends AbstractVideoList implements OnIni | |||
33 | protected baseVideoWidth = -1 | 34 | protected baseVideoWidth = -1 |
34 | protected baseVideoHeight = 155 | 35 | protected baseVideoHeight = 155 |
35 | 36 | ||
37 | @ViewChild('videoChangeOwnershipModal') videoChangeOwnershipModal: VideoChangeOwnershipComponent | ||
38 | |||
36 | constructor ( | 39 | constructor ( |
37 | protected router: Router, | 40 | protected router: Router, |
38 | protected route: ActivatedRoute, | 41 | protected route: ActivatedRoute, |
@@ -133,6 +136,11 @@ export class MyAccountVideosComponent extends AbstractVideoList implements OnIni | |||
133 | ) | 136 | ) |
134 | } | 137 | } |
135 | 138 | ||
139 | changeOwnership (event: Event, video: Video) { | ||
140 | event.preventDefault() | ||
141 | this.videoChangeOwnershipModal.show(video) | ||
142 | } | ||
143 | |||
136 | getStateLabel (video: Video) { | 144 | getStateLabel (video: Video) { |
137 | let suffix: string | 145 | let suffix: string |
138 | 146 | ||
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 @@ | |||
1 | <ng-template #modal let-close="close" let-dismiss="dismiss"> | ||
2 | <div class="modal-header"> | ||
3 | <h4 i18n class="modal-title">Change ownership</h4> | ||
4 | <span class="close" aria-label="Close" role="button" (click)="dismiss()"></span> | ||
5 | </div> | ||
6 | |||
7 | <div class="modal-body" [formGroup]="form"> | ||
8 | <div class="form-group"> | ||
9 | <label i18n for="next-ownership-username">Select the next owner</label> | ||
10 | <p-autoComplete formControlName="username" [suggestions]="usernamePropositions" | ||
11 | (completeMethod)="search($event)" id="next-ownership-username"></p-autoComplete> | ||
12 | <div *ngIf="formErrors.username" class="form-error"> | ||
13 | {{ formErrors.username }} | ||
14 | </div> | ||
15 | </div> | ||
16 | </div> | ||
17 | |||
18 | <div class="modal-footer inputs"> | ||
19 | <div class="form-group inputs"> | ||
20 | <span i18n class="action-button action-button-cancel" (click)="dismiss()"> | ||
21 | Cancel | ||
22 | </span> | ||
23 | |||
24 | <input | ||
25 | type="submit" i18n-value value="Submit" class="action-button-submit" | ||
26 | [disabled]="!form.valid" | ||
27 | (click)="close()" | ||
28 | /> | ||
29 | </div> | ||
30 | </div> | ||
31 | </ng-template> | ||
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 @@ | |||
1 | @import '_variables'; | ||
2 | @import '_mixins'; | ||
3 | |||
4 | p-autocomplete { | ||
5 | display: block; | ||
6 | } | ||
7 | |||
8 | .form-group { | ||
9 | margin: 20px 0; | ||
10 | } \ 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 @@ | |||
1 | import { Component, ElementRef, OnInit, ViewChild } from '@angular/core' | ||
2 | import { NotificationsService } from 'angular2-notifications' | ||
3 | import { NgbModal } from '@ng-bootstrap/ng-bootstrap' | ||
4 | import { FormReactive, UserService } from '../../../shared/index' | ||
5 | import { Video } from '@app/shared/video/video.model' | ||
6 | import { I18n } from '@ngx-translate/i18n-polyfill' | ||
7 | import { FormValidatorService, VideoChangeOwnershipValidatorsService } from '@app/shared' | ||
8 | import { VideoOwnershipService } from '@app/shared/video-ownership' | ||
9 | |||
10 | @Component({ | ||
11 | selector: 'my-video-change-ownership', | ||
12 | templateUrl: './video-change-ownership.component.html', | ||
13 | styleUrls: [ './video-change-ownership.component.scss' ] | ||
14 | }) | ||
15 | export class VideoChangeOwnershipComponent extends FormReactive implements OnInit { | ||
16 | @ViewChild('modal') modal: ElementRef | ||
17 | |||
18 | usernamePropositions: string[] | ||
19 | |||
20 | error: string = null | ||
21 | |||
22 | private video: Video | undefined = undefined | ||
23 | |||
24 | constructor ( | ||
25 | protected formValidatorService: FormValidatorService, | ||
26 | private videoChangeOwnershipValidatorsService: VideoChangeOwnershipValidatorsService, | ||
27 | private videoOwnershipService: VideoOwnershipService, | ||
28 | private notificationsService: NotificationsService, | ||
29 | private userService: UserService, | ||
30 | private modalService: NgbModal, | ||
31 | private i18n: I18n | ||
32 | ) { | ||
33 | super() | ||
34 | } | ||
35 | |||
36 | ngOnInit () { | ||
37 | this.buildForm({ | ||
38 | username: this.videoChangeOwnershipValidatorsService.USERNAME | ||
39 | }) | ||
40 | this.usernamePropositions = [] | ||
41 | } | ||
42 | |||
43 | show (video: Video) { | ||
44 | this.video = video | ||
45 | this.modalService | ||
46 | .open(this.modal) | ||
47 | .result | ||
48 | .then(() => this.changeOwnership()) | ||
49 | .catch((_) => _) // Called when closing (cancel) the modal without validating, do nothing | ||
50 | } | ||
51 | |||
52 | search (event) { | ||
53 | const query = event.query | ||
54 | this.userService.autocomplete(query) | ||
55 | .subscribe( | ||
56 | (usernames) => { | ||
57 | this.usernamePropositions = usernames | ||
58 | }, | ||
59 | |||
60 | err => this.notificationsService.error('Error', err.message) | ||
61 | ) | ||
62 | } | ||
63 | |||
64 | changeOwnership () { | ||
65 | const username = this.form.value['username'] | ||
66 | |||
67 | this.videoOwnershipService | ||
68 | .changeOwnership(this.video.id, username) | ||
69 | .subscribe( | ||
70 | () => this.notificationsService.success(this.i18n('Success'), this.i18n('Ownership changed.')), | ||
71 | |||
72 | err => this.notificationsService.error(this.i18n('Error'), err.message) | ||
73 | ) | ||
74 | } | ||
75 | } | ||
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 @@ | |||
9 | <a i18n routerLink="/my-account/subscriptions" routerLinkActive="active" class="title-page">My subscriptions</a> | 9 | <a i18n routerLink="/my-account/subscriptions" routerLinkActive="active" class="title-page">My subscriptions</a> |
10 | 10 | ||
11 | <a *ngIf="isVideoImportEnabled()" i18n routerLink="/my-account/video-imports" routerLinkActive="active" class="title-page">My imports</a> | 11 | <a *ngIf="isVideoImportEnabled()" i18n routerLink="/my-account/video-imports" routerLinkActive="active" class="title-page">My imports</a> |
12 | |||
13 | <a i18n routerLink="/my-account/ownership" routerLinkActive="active" class="title-page">Ownership changes</a> | ||
12 | </div> | 14 | </div> |
13 | 15 | ||
14 | <div class="margin-content"> | 16 | <div class="margin-content"> |
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 @@ | |||
1 | import { TableModule } from 'primeng/table' | 1 | import { TableModule } from 'primeng/table' |
2 | import { NgModule } from '@angular/core' | 2 | import { NgModule } from '@angular/core' |
3 | import { AutoCompleteModule } from 'primeng/autocomplete' | ||
3 | import { SharedModule } from '../shared' | 4 | import { SharedModule } from '../shared' |
4 | import { MyAccountRoutingModule } from './my-account-routing.module' | 5 | import { MyAccountRoutingModule } from './my-account-routing.module' |
5 | import { MyAccountChangePasswordComponent } from './my-account-settings/my-account-change-password/my-account-change-password.component' | 6 | 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 | |||
7 | import { MyAccountSettingsComponent } from './my-account-settings/my-account-settings.component' | 8 | import { MyAccountSettingsComponent } from './my-account-settings/my-account-settings.component' |
8 | import { MyAccountComponent } from './my-account.component' | 9 | import { MyAccountComponent } from './my-account.component' |
9 | import { MyAccountVideosComponent } from './my-account-videos/my-account-videos.component' | 10 | import { MyAccountVideosComponent } from './my-account-videos/my-account-videos.component' |
11 | import { VideoChangeOwnershipComponent } from './my-account-videos/video-change-ownership/video-change-ownership.component' | ||
12 | import { MyAccountOwnershipComponent } from './my-account-ownership/my-account-ownership.component' | ||
13 | import { MyAccountAcceptOwnershipComponent } from './my-account-ownership/my-account-accept-ownership/my-account-accept-ownership.component' | ||
10 | import { MyAccountProfileComponent } from '@app/+my-account/my-account-settings/my-account-profile/my-account-profile.component' | 14 | import { MyAccountProfileComponent } from '@app/+my-account/my-account-settings/my-account-profile/my-account-profile.component' |
11 | import { MyAccountVideoChannelsComponent } from '@app/+my-account/my-account-video-channels/my-account-video-channels.component' | 15 | import { MyAccountVideoChannelsComponent } from '@app/+my-account/my-account-video-channels/my-account-video-channels.component' |
12 | import { MyAccountVideoChannelCreateComponent } from '@app/+my-account/my-account-video-channels/my-account-video-channel-create.component' | 16 | 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 | |||
18 | 22 | ||
19 | @NgModule({ | 23 | @NgModule({ |
20 | imports: [ | 24 | imports: [ |
25 | TableModule, | ||
21 | MyAccountRoutingModule, | 26 | MyAccountRoutingModule, |
27 | AutoCompleteModule, | ||
22 | SharedModule, | 28 | SharedModule, |
23 | TableModule | 29 | TableModule |
24 | ], | 30 | ], |
@@ -30,6 +36,9 @@ import { MyAccountSubscriptionsComponent } from '@app/+my-account/my-account-sub | |||
30 | MyAccountVideoSettingsComponent, | 36 | MyAccountVideoSettingsComponent, |
31 | MyAccountProfileComponent, | 37 | MyAccountProfileComponent, |
32 | MyAccountVideosComponent, | 38 | MyAccountVideosComponent, |
39 | VideoChangeOwnershipComponent, | ||
40 | MyAccountOwnershipComponent, | ||
41 | MyAccountAcceptOwnershipComponent, | ||
33 | MyAccountVideoChannelsComponent, | 42 | MyAccountVideoChannelsComponent, |
34 | MyAccountVideoChannelCreateComponent, | 43 | MyAccountVideoChannelCreateComponent, |
35 | MyAccountVideoChannelUpdateComponent, | 44 | 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 @@ | |||
1 | <span class="action-button" [ngClass]="className" [title]="getTitle()"> | ||
2 | <span class="icon" [ngClass]="icon"></span> | ||
3 | <span class="button-label">{{ label }}</span> | ||
4 | </span> | ||
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 @@ | |||
26 | &.icon-delete-grey { | 26 | &.icon-delete-grey { |
27 | background-image: url('../../../assets/images/global/delete-grey.svg'); | 27 | background-image: url('../../../assets/images/global/delete-grey.svg'); |
28 | } | 28 | } |
29 | |||
30 | &.icon-im-with-her { | ||
31 | background-image: url('../../../assets/images/global/im-with-her.svg'); | ||
32 | } | ||
33 | |||
34 | &.icon-tick { | ||
35 | background-image: url('../../../assets/images/global/tick.svg'); | ||
36 | } | ||
37 | |||
38 | &.icon-cross { | ||
39 | background-image: url('../../../assets/images/global/cross.svg'); | ||
40 | } | ||
29 | } | 41 | } |
30 | } | 42 | } |
31 | 43 | ||
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 @@ | |||
1 | import { Component, Input } from '@angular/core' | ||
2 | |||
3 | @Component({ | ||
4 | selector: 'my-button', | ||
5 | styleUrls: ['./button.component.scss'], | ||
6 | templateUrl: './button.component.html' | ||
7 | }) | ||
8 | |||
9 | export class ButtonComponent { | ||
10 | @Input() label = '' | ||
11 | @Input() className = undefined | ||
12 | @Input() icon = undefined | ||
13 | @Input() title = undefined | ||
14 | |||
15 | getTitle () { | ||
16 | return this.title || this.label | ||
17 | } | ||
18 | } | ||
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' | |||
10 | export * from './video-comment-validators.service' | 10 | export * from './video-comment-validators.service' |
11 | export * from './video-validators.service' | 11 | export * from './video-validators.service' |
12 | export * from './video-captions-validators.service' | 12 | export * from './video-captions-validators.service' |
13 | export * from './video-change-ownership-validators.service' | ||
14 | 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 @@ | |||
1 | import { I18n } from '@ngx-translate/i18n-polyfill' | ||
2 | import { Validators } from '@angular/forms' | ||
3 | import { Injectable } from '@angular/core' | ||
4 | import { BuildFormValidator } from '@app/shared' | ||
5 | |||
6 | @Injectable() | ||
7 | export class VideoAcceptOwnershipValidatorsService { | ||
8 | readonly CHANNEL: BuildFormValidator | ||
9 | |||
10 | constructor (private i18n: I18n) { | ||
11 | this.CHANNEL = { | ||
12 | VALIDATORS: [ Validators.required ], | ||
13 | MESSAGES: { | ||
14 | 'required': this.i18n('The channel is required.') | ||
15 | } | ||
16 | } | ||
17 | } | ||
18 | } | ||
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 @@ | |||
1 | import { I18n } from '@ngx-translate/i18n-polyfill' | ||
2 | import { Validators } from '@angular/forms' | ||
3 | import { Injectable } from '@angular/core' | ||
4 | import { BuildFormValidator } from '@app/shared' | ||
5 | |||
6 | @Injectable() | ||
7 | export class VideoChangeOwnershipValidatorsService { | ||
8 | readonly USERNAME: BuildFormValidator | ||
9 | |||
10 | constructor (private i18n: I18n) { | ||
11 | this.USERNAME = { | ||
12 | VALIDATORS: [ Validators.required ], | ||
13 | MESSAGES: { | ||
14 | 'required': this.i18n('The username is required.') | ||
15 | } | ||
16 | } | ||
17 | } | ||
18 | } | ||
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' | |||
12 | import { SharedModule as PrimeSharedModule } from 'primeng/components/common/shared' | 12 | import { SharedModule as PrimeSharedModule } from 'primeng/components/common/shared' |
13 | 13 | ||
14 | import { AUTH_INTERCEPTOR_PROVIDER } from './auth' | 14 | import { AUTH_INTERCEPTOR_PROVIDER } from './auth' |
15 | import { ButtonComponent } from './buttons/button.component' | ||
15 | import { DeleteButtonComponent } from './buttons/delete-button.component' | 16 | import { DeleteButtonComponent } from './buttons/delete-button.component' |
16 | import { EditButtonComponent } from './buttons/edit-button.component' | 17 | import { EditButtonComponent } from './buttons/edit-button.component' |
17 | import { FromNowPipe } from './misc/from-now.pipe' | 18 | import { FromNowPipe } from './misc/from-now.pipe' |
@@ -22,6 +23,7 @@ import { RestExtractor, RestService } from './rest' | |||
22 | import { UserService } from './users' | 23 | import { UserService } from './users' |
23 | import { VideoAbuseService } from './video-abuse' | 24 | import { VideoAbuseService } from './video-abuse' |
24 | import { VideoBlacklistService } from './video-blacklist' | 25 | import { VideoBlacklistService } from './video-blacklist' |
26 | import { VideoOwnershipService } from './video-ownership' | ||
25 | import { VideoMiniatureComponent } from './video/video-miniature.component' | 27 | import { VideoMiniatureComponent } from './video/video-miniature.component' |
26 | import { VideoFeedComponent } from './video/video-feed.component' | 28 | import { VideoFeedComponent } from './video/video-feed.component' |
27 | import { VideoThumbnailComponent } from './video/video-thumbnail.component' | 29 | import { VideoThumbnailComponent } from './video/video-thumbnail.component' |
@@ -40,7 +42,8 @@ import { | |||
40 | VideoBlacklistValidatorsService, | 42 | VideoBlacklistValidatorsService, |
41 | VideoChannelValidatorsService, | 43 | VideoChannelValidatorsService, |
42 | VideoCommentValidatorsService, | 44 | VideoCommentValidatorsService, |
43 | VideoValidatorsService | 45 | VideoValidatorsService, |
46 | VideoChangeOwnershipValidatorsService, VideoAcceptOwnershipValidatorsService | ||
44 | } from '@app/shared/forms' | 47 | } from '@app/shared/forms' |
45 | import { I18nPrimengCalendarService } from '@app/shared/i18n/i18n-primeng-calendar' | 48 | import { I18nPrimengCalendarService } from '@app/shared/i18n/i18n-primeng-calendar' |
46 | import { ScreenService } from '@app/shared/misc/screen.service' | 49 | import { ScreenService } from '@app/shared/misc/screen.service' |
@@ -77,6 +80,7 @@ import { OverviewService } from '@app/shared/overview' | |||
77 | VideoThumbnailComponent, | 80 | VideoThumbnailComponent, |
78 | VideoMiniatureComponent, | 81 | VideoMiniatureComponent, |
79 | VideoFeedComponent, | 82 | VideoFeedComponent, |
83 | ButtonComponent, | ||
80 | DeleteButtonComponent, | 84 | DeleteButtonComponent, |
81 | EditButtonComponent, | 85 | EditButtonComponent, |
82 | ActionDropdownComponent, | 86 | ActionDropdownComponent, |
@@ -113,6 +117,7 @@ import { OverviewService } from '@app/shared/overview' | |||
113 | VideoThumbnailComponent, | 117 | VideoThumbnailComponent, |
114 | VideoMiniatureComponent, | 118 | VideoMiniatureComponent, |
115 | VideoFeedComponent, | 119 | VideoFeedComponent, |
120 | ButtonComponent, | ||
116 | DeleteButtonComponent, | 121 | DeleteButtonComponent, |
117 | EditButtonComponent, | 122 | EditButtonComponent, |
118 | ActionDropdownComponent, | 123 | ActionDropdownComponent, |
@@ -135,6 +140,7 @@ import { OverviewService } from '@app/shared/overview' | |||
135 | RestService, | 140 | RestService, |
136 | VideoAbuseService, | 141 | VideoAbuseService, |
137 | VideoBlacklistService, | 142 | VideoBlacklistService, |
143 | VideoOwnershipService, | ||
138 | UserService, | 144 | UserService, |
139 | VideoService, | 145 | VideoService, |
140 | AccountService, | 146 | AccountService, |
@@ -156,6 +162,8 @@ import { OverviewService } from '@app/shared/overview' | |||
156 | VideoCaptionsValidatorsService, | 162 | VideoCaptionsValidatorsService, |
157 | VideoBlacklistValidatorsService, | 163 | VideoBlacklistValidatorsService, |
158 | OverviewService, | 164 | OverviewService, |
165 | VideoChangeOwnershipValidatorsService, | ||
166 | VideoAcceptOwnershipValidatorsService, | ||
159 | 167 | ||
160 | I18nPrimengCalendarService, | 168 | I18nPrimengCalendarService, |
161 | ScreenService, | 169 | 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 @@ | |||
1 | import { Observable } from 'rxjs' | ||
1 | import { catchError, map } from 'rxjs/operators' | 2 | import { catchError, map } from 'rxjs/operators' |
2 | import { HttpClient } from '@angular/common/http' | 3 | import { HttpClient, HttpParams } from '@angular/common/http' |
3 | import { Injectable } from '@angular/core' | 4 | import { Injectable } from '@angular/core' |
4 | import { UserCreate, UserUpdateMe, UserVideoQuota } from '../../../../../shared' | 5 | import { UserCreate, UserUpdateMe, UserVideoQuota } from '../../../../../shared' |
5 | import { environment } from '../../../environments/environment' | 6 | import { environment } from '../../../environments/environment' |
@@ -117,4 +118,13 @@ export class UserService { | |||
117 | catchError(err => this.restExtractor.handleError(err)) | 118 | catchError(err => this.restExtractor.handleError(err)) |
118 | ) | 119 | ) |
119 | } | 120 | } |
121 | |||
122 | autocomplete (search: string): Observable<string[]> { | ||
123 | const url = UserService.BASE_USERS_URL + 'autocomplete' | ||
124 | const params = new HttpParams().append('search', search) | ||
125 | |||
126 | return this.authHttp | ||
127 | .get<string[]>(url, { params }) | ||
128 | .pipe(catchError(res => this.restExtractor.handleError(res))) | ||
129 | } | ||
120 | } | 130 | } |
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 @@ | |||
1 | import { catchError, map } from 'rxjs/operators' | ||
2 | import { HttpClient, HttpParams } from '@angular/common/http' | ||
3 | import { Injectable } from '@angular/core' | ||
4 | import { environment } from '../../../environments/environment' | ||
5 | import { RestExtractor, RestService } from '../rest' | ||
6 | import { VideoChangeOwnershipCreate } from '../../../../../shared/models/videos' | ||
7 | import { Observable } from 'rxjs/index' | ||
8 | import { SortMeta } from 'primeng/components/common/sortmeta' | ||
9 | import { ResultList, VideoChangeOwnership } from '../../../../../shared' | ||
10 | import { RestPagination } from '@app/shared/rest' | ||
11 | import { VideoChangeOwnershipAccept } from '../../../../../shared/models/videos/video-change-ownership-accept.model' | ||
12 | |||
13 | @Injectable() | ||
14 | export class VideoOwnershipService { | ||
15 | private static BASE_VIDEO_CHANGE_OWNERSHIP_URL = environment.apiUrl + '/api/v1/videos/' | ||
16 | |||
17 | constructor ( | ||
18 | private authHttp: HttpClient, | ||
19 | private restService: RestService, | ||
20 | private restExtractor: RestExtractor | ||
21 | ) { | ||
22 | } | ||
23 | |||
24 | changeOwnership (id: number, username: string) { | ||
25 | const url = VideoOwnershipService.BASE_VIDEO_CHANGE_OWNERSHIP_URL + id + '/give-ownership' | ||
26 | const body: VideoChangeOwnershipCreate = { | ||
27 | username | ||
28 | } | ||
29 | |||
30 | return this.authHttp.post(url, body) | ||
31 | .pipe( | ||
32 | map(this.restExtractor.extractDataBool), | ||
33 | catchError(res => this.restExtractor.handleError(res)) | ||
34 | ) | ||
35 | } | ||
36 | |||
37 | getOwnershipChanges (pagination: RestPagination, sort: SortMeta): Observable<ResultList<VideoChangeOwnership>> { | ||
38 | const url = VideoOwnershipService.BASE_VIDEO_CHANGE_OWNERSHIP_URL + 'ownership' | ||
39 | |||
40 | let params = new HttpParams() | ||
41 | params = this.restService.addRestGetParams(params, pagination, sort) | ||
42 | |||
43 | return this.authHttp.get<ResultList<VideoChangeOwnership>>(url, { params }) | ||
44 | .pipe( | ||
45 | map(res => this.restExtractor.convertResultListDateToHuman(res)), | ||
46 | catchError(res => this.restExtractor.handleError(res)) | ||
47 | ) | ||
48 | } | ||
49 | |||
50 | acceptOwnership (id: number, input: VideoChangeOwnershipAccept) { | ||
51 | const url = VideoOwnershipService.BASE_VIDEO_CHANGE_OWNERSHIP_URL + 'ownership/' + id + '/accept' | ||
52 | return this.authHttp.post(url, input) | ||
53 | .pipe( | ||
54 | map(this.restExtractor.extractDataBool), | ||
55 | catchError(this.restExtractor.handleError) | ||
56 | ) | ||
57 | } | ||
58 | |||
59 | refuseOwnership (id: number) { | ||
60 | const url = VideoOwnershipService.BASE_VIDEO_CHANGE_OWNERSHIP_URL + 'ownership/' + id + '/refuse' | ||
61 | return this.authHttp.post(url, {}) | ||
62 | .pipe( | ||
63 | map(this.restExtractor.extractDataBool), | ||
64 | catchError(this.restExtractor.handleError) | ||
65 | ) | ||
66 | } | ||
67 | } | ||
diff --git a/client/src/assets/images/global/im-with-her.svg b/client/src/assets/images/global/im-with-her.svg new file mode 100644 index 000000000..31d4754fd --- /dev/null +++ b/client/src/assets/images/global/im-with-her.svg | |||
@@ -0,0 +1,15 @@ | |||
1 | <?xml version="1.0" encoding="UTF-8"?> | ||
2 | <svg width="24px" height="24px" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> | ||
3 | <!-- Generator: Sketch 43.2 (39069) - http://www.bohemiancoding.com/sketch --> | ||
4 | <title>im-with-her</title> | ||
5 | <desc>Created with Sketch.</desc> | ||
6 | <defs></defs> | ||
7 | <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"> | ||
8 | <g id="Artboard-4" transform="translate(-708.000000, -467.000000)"> | ||
9 | <g id="176" transform="translate(708.000000, 467.000000)"> | ||
10 | <path d="M8,9 L8,3.99339768 C8,3.44494629 7.55641359,3 7.00922203,3 L2.99077797,3 C2.45097518,3 2,3.44475929 2,3.99339768 L2,20.0066023 C2,20.5550537 2.44358641,21 2.99077797,21 L7.00922203,21 C7.54902482,21 8,20.5552407 8,20.0066023 L8,15 L14,15 L14,20.0066023 C14,20.5550537 14.4435864,21 14.990778,21 L19.009222,21 C19.5490248,21 20,20.5564587 20,20.0093228 L20,15.0006104 L23,12 L20,8.99267578 L20,4.00303919 C20,3.45042467 19.5564136,3 19.009222,3 L14.990778,3 C14.4509752,3 14,3.44475929 14,3.99339768 L14,9 L8,9 Z" id="Combined-Shape" fill="#333333" opacity="0.5"></path> | ||
11 | <path d="M2,9 L14,9 L14,3.99077797 C14,3.44358641 14.3203148,3.32031476 14.7062149,3.7062149 L23,12 L14.7062149,20.2937851 C14.3161832,20.6838168 14,20.5490248 14,20.009222 L14,15 L2,15 L2,9 Z" id="Rectangle-121" fill-opacity="0.5" fill="#000000"></path> | ||
12 | </g> | ||
13 | </g> | ||
14 | </g> | ||
15 | </svg> \ No newline at end of file | ||
diff --git a/client/src/sass/include/_mixins.scss b/client/src/sass/include/_mixins.scss index 99225e4e5..547f03caa 100644 --- a/client/src/sass/include/_mixins.scss +++ b/client/src/sass/include/_mixins.scss | |||
@@ -23,7 +23,7 @@ | |||
23 | * @param $line-height line-height property | 23 | * @param $line-height line-height property |
24 | * @param $lines-to-show amount of lines to show | 24 | * @param $lines-to-show amount of lines to show |
25 | */ | 25 | */ |
26 | @mixin ellipsis-multiline($font-size: 1rem, $line-height: 1, $lines-to-show: 2) { | 26 | @mixin ellipsis-multiline($font-size: 1rem, $line-height: 1, $lines-to-show: 2) { |
27 | display: block; | 27 | display: block; |
28 | /* Fallback for non-webkit */ | 28 | /* Fallback for non-webkit */ |
29 | display: -webkit-box; | 29 | display: -webkit-box; |
diff --git a/server/controllers/api/users/index.ts b/server/controllers/api/users/index.ts index 01ee73a53..faba7e208 100644 --- a/server/controllers/api/users/index.ts +++ b/server/controllers/api/users/index.ts | |||
@@ -18,6 +18,7 @@ import { | |||
18 | setDefaultPagination, | 18 | setDefaultPagination, |
19 | setDefaultSort, | 19 | setDefaultSort, |
20 | token, | 20 | token, |
21 | userAutocompleteValidator, | ||
21 | usersAddValidator, | 22 | usersAddValidator, |
22 | usersGetValidator, | 23 | usersGetValidator, |
23 | usersRegisterValidator, | 24 | usersRegisterValidator, |
@@ -51,6 +52,11 @@ const askSendEmailLimiter = new RateLimit({ | |||
51 | const usersRouter = express.Router() | 52 | const usersRouter = express.Router() |
52 | usersRouter.use('/', meRouter) | 53 | usersRouter.use('/', meRouter) |
53 | 54 | ||
55 | usersRouter.get('/autocomplete', | ||
56 | userAutocompleteValidator, | ||
57 | asyncMiddleware(autocompleteUsers) | ||
58 | ) | ||
59 | |||
54 | usersRouter.get('/', | 60 | usersRouter.get('/', |
55 | authenticate, | 61 | authenticate, |
56 | ensureUserHasRight(UserRight.MANAGE_USERS), | 62 | ensureUserHasRight(UserRight.MANAGE_USERS), |
@@ -222,6 +228,12 @@ function getUser (req: express.Request, res: express.Response, next: express.Nex | |||
222 | return res.json((res.locals.user as UserModel).toFormattedJSON()) | 228 | return res.json((res.locals.user as UserModel).toFormattedJSON()) |
223 | } | 229 | } |
224 | 230 | ||
231 | async function autocompleteUsers (req: express.Request, res: express.Response, next: express.NextFunction) { | ||
232 | const resultList = await UserModel.autocomplete(req.query.search as string) | ||
233 | |||
234 | return res.json(resultList) | ||
235 | } | ||
236 | |||
225 | async function listUsers (req: express.Request, res: express.Response, next: express.NextFunction) { | 237 | async function listUsers (req: express.Request, res: express.Response, next: express.NextFunction) { |
226 | const resultList = await UserModel.listForApi(req.query.start, req.query.count, req.query.sort) | 238 | const resultList = await UserModel.listForApi(req.query.start, req.query.count, req.query.sort) |
227 | 239 | ||
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index be803490b..0c9e6c2d1 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts | |||
@@ -49,6 +49,7 @@ import { abuseVideoRouter } from './abuse' | |||
49 | import { blacklistRouter } from './blacklist' | 49 | import { blacklistRouter } from './blacklist' |
50 | import { videoCommentRouter } from './comment' | 50 | import { videoCommentRouter } from './comment' |
51 | import { rateVideoRouter } from './rate' | 51 | import { rateVideoRouter } from './rate' |
52 | import { ownershipVideoRouter } from './ownership' | ||
52 | import { VideoFilter } from '../../../../shared/models/videos/video-query.type' | 53 | import { VideoFilter } from '../../../../shared/models/videos/video-query.type' |
53 | import { buildNSFWFilter, createReqFiles } from '../../../helpers/express-utils' | 54 | import { buildNSFWFilter, createReqFiles } from '../../../helpers/express-utils' |
54 | import { ScheduleVideoUpdateModel } from '../../../models/video/schedule-video-update' | 55 | import { ScheduleVideoUpdateModel } from '../../../models/video/schedule-video-update' |
@@ -84,6 +85,7 @@ videosRouter.use('/', rateVideoRouter) | |||
84 | videosRouter.use('/', videoCommentRouter) | 85 | videosRouter.use('/', videoCommentRouter) |
85 | videosRouter.use('/', videoCaptionsRouter) | 86 | videosRouter.use('/', videoCaptionsRouter) |
86 | videosRouter.use('/', videoImportsRouter) | 87 | videosRouter.use('/', videoImportsRouter) |
88 | videosRouter.use('/', ownershipVideoRouter) | ||
87 | 89 | ||
88 | videosRouter.get('/categories', listVideoCategories) | 90 | videosRouter.get('/categories', listVideoCategories) |
89 | videosRouter.get('/licences', listVideoLicences) | 91 | videosRouter.get('/licences', listVideoLicences) |
diff --git a/server/controllers/api/videos/ownership.ts b/server/controllers/api/videos/ownership.ts new file mode 100644 index 000000000..fc42f5fff --- /dev/null +++ b/server/controllers/api/videos/ownership.ts | |||
@@ -0,0 +1,117 @@ | |||
1 | import * as express from 'express' | ||
2 | import { logger } from '../../../helpers/logger' | ||
3 | import { sequelizeTypescript } from '../../../initializers' | ||
4 | import { | ||
5 | asyncMiddleware, | ||
6 | asyncRetryTransactionMiddleware, | ||
7 | authenticate, | ||
8 | paginationValidator, | ||
9 | setDefaultPagination, | ||
10 | videosAcceptChangeOwnershipValidator, | ||
11 | videosChangeOwnershipValidator, | ||
12 | videosTerminateChangeOwnershipValidator | ||
13 | } from '../../../middlewares' | ||
14 | import { AccountModel } from '../../../models/account/account' | ||
15 | import { VideoModel } from '../../../models/video/video' | ||
16 | import { VideoChangeOwnershipModel } from '../../../models/video/video-change-ownership' | ||
17 | import { VideoChangeOwnershipStatus } from '../../../../shared/models/videos' | ||
18 | import { VideoChannelModel } from '../../../models/video/video-channel' | ||
19 | import { getFormattedObjects } from '../../../helpers/utils' | ||
20 | |||
21 | const ownershipVideoRouter = express.Router() | ||
22 | |||
23 | ownershipVideoRouter.post('/:videoId/give-ownership', | ||
24 | authenticate, | ||
25 | asyncMiddleware(videosChangeOwnershipValidator), | ||
26 | asyncRetryTransactionMiddleware(giveVideoOwnership) | ||
27 | ) | ||
28 | |||
29 | ownershipVideoRouter.get('/ownership', | ||
30 | authenticate, | ||
31 | paginationValidator, | ||
32 | setDefaultPagination, | ||
33 | asyncRetryTransactionMiddleware(listVideoOwnership) | ||
34 | ) | ||
35 | |||
36 | ownershipVideoRouter.post('/ownership/:id/accept', | ||
37 | authenticate, | ||
38 | asyncMiddleware(videosTerminateChangeOwnershipValidator), | ||
39 | asyncMiddleware(videosAcceptChangeOwnershipValidator), | ||
40 | asyncRetryTransactionMiddleware(acceptOwnership) | ||
41 | ) | ||
42 | |||
43 | ownershipVideoRouter.post('/ownership/:id/refuse', | ||
44 | authenticate, | ||
45 | asyncMiddleware(videosTerminateChangeOwnershipValidator), | ||
46 | asyncRetryTransactionMiddleware(refuseOwnership) | ||
47 | ) | ||
48 | |||
49 | // --------------------------------------------------------------------------- | ||
50 | |||
51 | export { | ||
52 | ownershipVideoRouter | ||
53 | } | ||
54 | |||
55 | // --------------------------------------------------------------------------- | ||
56 | |||
57 | async function giveVideoOwnership (req: express.Request, res: express.Response) { | ||
58 | const videoInstance = res.locals.video as VideoModel | ||
59 | const initiatorAccount = res.locals.oauth.token.User.Account as AccountModel | ||
60 | const nextOwner = res.locals.nextOwner as AccountModel | ||
61 | |||
62 | await sequelizeTypescript.transaction(async t => { | ||
63 | await VideoChangeOwnershipModel.findOrCreate({ | ||
64 | where: { | ||
65 | initiatorAccountId: initiatorAccount.id, | ||
66 | nextOwnerAccountId: nextOwner.id, | ||
67 | videoId: videoInstance.id, | ||
68 | status: VideoChangeOwnershipStatus.WAITING | ||
69 | }, | ||
70 | defaults: { | ||
71 | initiatorAccountId: initiatorAccount.id, | ||
72 | nextOwnerAccountId: nextOwner.id, | ||
73 | videoId: videoInstance.id, | ||
74 | status: VideoChangeOwnershipStatus.WAITING | ||
75 | } | ||
76 | }) | ||
77 | logger.info('Ownership change for video %s created.', videoInstance.name) | ||
78 | return res.type('json').status(204).end() | ||
79 | }) | ||
80 | } | ||
81 | |||
82 | async function listVideoOwnership (req: express.Request, res: express.Response) { | ||
83 | const currentAccount = res.locals.oauth.token.User.Account as AccountModel | ||
84 | const resultList = await VideoChangeOwnershipModel.listForApi( | ||
85 | currentAccount.id, | ||
86 | req.query.start || 0, | ||
87 | req.query.count || 10, | ||
88 | req.query.sort || 'createdAt' | ||
89 | ) | ||
90 | |||
91 | return res.json(getFormattedObjects(resultList.data, resultList.total)) | ||
92 | } | ||
93 | |||
94 | async function acceptOwnership (req: express.Request, res: express.Response) { | ||
95 | return sequelizeTypescript.transaction(async t => { | ||
96 | const videoChangeOwnership = res.locals.videoChangeOwnership as VideoChangeOwnershipModel | ||
97 | const targetVideo = videoChangeOwnership.Video | ||
98 | const channel = res.locals.videoChannel as VideoChannelModel | ||
99 | |||
100 | targetVideo.set('channelId', channel.id) | ||
101 | |||
102 | await targetVideo.save() | ||
103 | videoChangeOwnership.set('status', VideoChangeOwnershipStatus.ACCEPTED) | ||
104 | await videoChangeOwnership.save() | ||
105 | |||
106 | return res.sendStatus(204) | ||
107 | }) | ||
108 | } | ||
109 | |||
110 | async function refuseOwnership (req: express.Request, res: express.Response) { | ||
111 | return sequelizeTypescript.transaction(async t => { | ||
112 | const videoChangeOwnership = res.locals.videoChangeOwnership as VideoChangeOwnershipModel | ||
113 | videoChangeOwnership.set('status', VideoChangeOwnershipStatus.REFUSED) | ||
114 | await videoChangeOwnership.save() | ||
115 | return res.sendStatus(204) | ||
116 | }) | ||
117 | } | ||
diff --git a/server/helpers/custom-validators/video-ownership.ts b/server/helpers/custom-validators/video-ownership.ts new file mode 100644 index 000000000..aaa0c736b --- /dev/null +++ b/server/helpers/custom-validators/video-ownership.ts | |||
@@ -0,0 +1,42 @@ | |||
1 | import { Response } from 'express' | ||
2 | import * as validator from 'validator' | ||
3 | import { VideoChangeOwnershipModel } from '../../models/video/video-change-ownership' | ||
4 | import { UserModel } from '../../models/account/user' | ||
5 | |||
6 | export async function doesChangeVideoOwnershipExist (id: string, res: Response): Promise<boolean> { | ||
7 | const videoChangeOwnership = await loadVideoChangeOwnership(id) | ||
8 | |||
9 | if (!videoChangeOwnership) { | ||
10 | res.status(404) | ||
11 | .json({ error: 'Video change ownership not found' }) | ||
12 | .end() | ||
13 | |||
14 | return false | ||
15 | } | ||
16 | |||
17 | res.locals.videoChangeOwnership = videoChangeOwnership | ||
18 | return true | ||
19 | } | ||
20 | |||
21 | async function loadVideoChangeOwnership (id: string): Promise<VideoChangeOwnershipModel | undefined> { | ||
22 | if (validator.isInt(id)) { | ||
23 | return VideoChangeOwnershipModel.load(parseInt(id, 10)) | ||
24 | } | ||
25 | |||
26 | return undefined | ||
27 | } | ||
28 | |||
29 | export function checkUserCanTerminateOwnershipChange ( | ||
30 | user: UserModel, | ||
31 | videoChangeOwnership: VideoChangeOwnershipModel, | ||
32 | res: Response | ||
33 | ): boolean { | ||
34 | if (videoChangeOwnership.NextOwner.userId === user.Account.userId) { | ||
35 | return true | ||
36 | } | ||
37 | |||
38 | res.status(403) | ||
39 | .json({ error: 'Cannot terminate an ownership change of another user' }) | ||
40 | .end() | ||
41 | return false | ||
42 | } | ||
diff --git a/server/initializers/database.ts b/server/initializers/database.ts index 78bc8101c..b68e1a882 100644 --- a/server/initializers/database.ts +++ b/server/initializers/database.ts | |||
@@ -26,6 +26,7 @@ import { ScheduleVideoUpdateModel } from '../models/video/schedule-video-update' | |||
26 | import { VideoCaptionModel } from '../models/video/video-caption' | 26 | import { VideoCaptionModel } from '../models/video/video-caption' |
27 | import { VideoImportModel } from '../models/video/video-import' | 27 | import { VideoImportModel } from '../models/video/video-import' |
28 | import { VideoViewModel } from '../models/video/video-views' | 28 | import { VideoViewModel } from '../models/video/video-views' |
29 | import { VideoChangeOwnershipModel } from '../models/video/video-change-ownership' | ||
29 | 30 | ||
30 | require('pg').defaults.parseInt8 = true // Avoid BIGINT to be converted to string | 31 | require('pg').defaults.parseInt8 = true // Avoid BIGINT to be converted to string |
31 | 32 | ||
@@ -75,6 +76,7 @@ async function initDatabaseModels (silent: boolean) { | |||
75 | AccountVideoRateModel, | 76 | AccountVideoRateModel, |
76 | UserModel, | 77 | UserModel, |
77 | VideoAbuseModel, | 78 | VideoAbuseModel, |
79 | VideoChangeOwnershipModel, | ||
78 | VideoChannelModel, | 80 | VideoChannelModel, |
79 | VideoShareModel, | 81 | VideoShareModel, |
80 | VideoFileModel, | 82 | VideoFileModel, |
diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts index a595c39ec..d13c50c84 100644 --- a/server/middlewares/validators/users.ts +++ b/server/middlewares/validators/users.ts | |||
@@ -290,6 +290,10 @@ const usersVerifyEmailValidator = [ | |||
290 | } | 290 | } |
291 | ] | 291 | ] |
292 | 292 | ||
293 | const userAutocompleteValidator = [ | ||
294 | param('search').isString().not().isEmpty().withMessage('Should have a search parameter') | ||
295 | ] | ||
296 | |||
293 | // --------------------------------------------------------------------------- | 297 | // --------------------------------------------------------------------------- |
294 | 298 | ||
295 | export { | 299 | export { |
@@ -307,7 +311,8 @@ export { | |||
307 | usersAskResetPasswordValidator, | 311 | usersAskResetPasswordValidator, |
308 | usersResetPasswordValidator, | 312 | usersResetPasswordValidator, |
309 | usersAskSendVerifyEmailValidator, | 313 | usersAskSendVerifyEmailValidator, |
310 | usersVerifyEmailValidator | 314 | usersVerifyEmailValidator, |
315 | userAutocompleteValidator | ||
311 | } | 316 | } |
312 | 317 | ||
313 | // --------------------------------------------------------------------------- | 318 | // --------------------------------------------------------------------------- |
diff --git a/server/middlewares/validators/videos.ts b/server/middlewares/validators/videos.ts index a2c866152..9befbc9ee 100644 --- a/server/middlewares/validators/videos.ts +++ b/server/middlewares/validators/videos.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import 'express-validator' | 2 | import 'express-validator' |
3 | import { body, param, ValidationChain } from 'express-validator/check' | 3 | import { body, param, ValidationChain } from 'express-validator/check' |
4 | import { UserRight, VideoPrivacy } from '../../../shared' | 4 | import { UserRight, VideoChangeOwnershipStatus, VideoPrivacy } from '../../../shared' |
5 | import { | 5 | import { |
6 | isBooleanValid, | 6 | isBooleanValid, |
7 | isDateValid, | 7 | isDateValid, |
@@ -37,6 +37,10 @@ import { areValidationErrors } from './utils' | |||
37 | import { cleanUpReqFiles } from '../../helpers/express-utils' | 37 | import { cleanUpReqFiles } from '../../helpers/express-utils' |
38 | import { VideoModel } from '../../models/video/video' | 38 | import { VideoModel } from '../../models/video/video' |
39 | import { UserModel } from '../../models/account/user' | 39 | import { UserModel } from '../../models/account/user' |
40 | import { checkUserCanTerminateOwnershipChange, doesChangeVideoOwnershipExist } from '../../helpers/custom-validators/video-ownership' | ||
41 | import { VideoChangeOwnershipAccept } from '../../../shared/models/videos/video-change-ownership-accept.model' | ||
42 | import { VideoChangeOwnershipModel } from '../../models/video/video-change-ownership' | ||
43 | import { AccountModel } from '../../models/account/account' | ||
40 | 44 | ||
41 | const videosAddValidator = getCommonVideoAttributes().concat([ | 45 | const videosAddValidator = getCommonVideoAttributes().concat([ |
42 | body('videofile') | 46 | body('videofile') |
@@ -217,6 +221,78 @@ const videosShareValidator = [ | |||
217 | } | 221 | } |
218 | ] | 222 | ] |
219 | 223 | ||
224 | const videosChangeOwnershipValidator = [ | ||
225 | param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), | ||
226 | |||
227 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
228 | logger.debug('Checking changeOwnership parameters', { parameters: req.params }) | ||
229 | |||
230 | if (areValidationErrors(req, res)) return | ||
231 | if (!await isVideoExist(req.params.videoId, res)) return | ||
232 | |||
233 | // Check if the user who did the request is able to change the ownership of the video | ||
234 | if (!checkUserCanManageVideo(res.locals.oauth.token.User, res.locals.video, UserRight.CHANGE_VIDEO_OWNERSHIP, res)) return | ||
235 | |||
236 | const nextOwner = await AccountModel.loadLocalByName(req.body.username) | ||
237 | if (!nextOwner) { | ||
238 | res.status(400) | ||
239 | .type('json') | ||
240 | .end() | ||
241 | return | ||
242 | } | ||
243 | res.locals.nextOwner = nextOwner | ||
244 | |||
245 | return next() | ||
246 | } | ||
247 | ] | ||
248 | |||
249 | const videosTerminateChangeOwnershipValidator = [ | ||
250 | param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), | ||
251 | |||
252 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
253 | logger.debug('Checking changeOwnership parameters', { parameters: req.params }) | ||
254 | |||
255 | if (areValidationErrors(req, res)) return | ||
256 | if (!await doesChangeVideoOwnershipExist(req.params.id, res)) return | ||
257 | |||
258 | // Check if the user who did the request is able to change the ownership of the video | ||
259 | if (!checkUserCanTerminateOwnershipChange(res.locals.oauth.token.User, res.locals.videoChangeOwnership, res)) return | ||
260 | |||
261 | return next() | ||
262 | }, | ||
263 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
264 | const videoChangeOwnership = res.locals.videoChangeOwnership as VideoChangeOwnershipModel | ||
265 | |||
266 | if (videoChangeOwnership.status === VideoChangeOwnershipStatus.WAITING) { | ||
267 | return next() | ||
268 | } else { | ||
269 | res.status(403) | ||
270 | .json({ error: 'Ownership already accepted or refused' }) | ||
271 | .end() | ||
272 | return | ||
273 | } | ||
274 | } | ||
275 | ] | ||
276 | |||
277 | const videosAcceptChangeOwnershipValidator = [ | ||
278 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
279 | const body = req.body as VideoChangeOwnershipAccept | ||
280 | if (!await isVideoChannelOfAccountExist(body.channelId, res.locals.oauth.token.User, res)) return | ||
281 | |||
282 | const user = res.locals.oauth.token.User | ||
283 | const videoChangeOwnership = res.locals.videoChangeOwnership as VideoChangeOwnershipModel | ||
284 | const isAble = await user.isAbleToUploadVideo(videoChangeOwnership.Video.getOriginalFile()) | ||
285 | if (isAble === false) { | ||
286 | res.status(403) | ||
287 | .json({ error: 'The user video quota is exceeded with this video.' }) | ||
288 | .end() | ||
289 | return | ||
290 | } | ||
291 | |||
292 | return next() | ||
293 | } | ||
294 | ] | ||
295 | |||
220 | function getCommonVideoAttributes () { | 296 | function getCommonVideoAttributes () { |
221 | return [ | 297 | return [ |
222 | body('thumbnailfile') | 298 | body('thumbnailfile') |
@@ -295,6 +371,10 @@ export { | |||
295 | 371 | ||
296 | videoRateValidator, | 372 | videoRateValidator, |
297 | 373 | ||
374 | videosChangeOwnershipValidator, | ||
375 | videosTerminateChangeOwnershipValidator, | ||
376 | videosAcceptChangeOwnershipValidator, | ||
377 | |||
298 | getCommonVideoAttributes | 378 | getCommonVideoAttributes |
299 | } | 379 | } |
300 | 380 | ||
diff --git a/server/models/account/user.ts b/server/models/account/user.ts index 89265774b..4b13e47a0 100644 --- a/server/models/account/user.ts +++ b/server/models/account/user.ts | |||
@@ -39,6 +39,7 @@ import { AccountModel } from './account' | |||
39 | import { NSFWPolicyType } from '../../../shared/models/videos/nsfw-policy.type' | 39 | import { NSFWPolicyType } from '../../../shared/models/videos/nsfw-policy.type' |
40 | import { values } from 'lodash' | 40 | import { values } from 'lodash' |
41 | import { NSFW_POLICY_TYPES } from '../../initializers' | 41 | import { NSFW_POLICY_TYPES } from '../../initializers' |
42 | import { VideoFileModel } from '../video/video-file' | ||
42 | 43 | ||
43 | enum ScopeNames { | 44 | enum ScopeNames { |
44 | WITH_VIDEO_CHANNEL = 'WITH_VIDEO_CHANNEL' | 45 | WITH_VIDEO_CHANNEL = 'WITH_VIDEO_CHANNEL' |
@@ -393,4 +394,15 @@ export class UserModel extends Model<UserModel> { | |||
393 | return parseInt(total, 10) | 394 | return parseInt(total, 10) |
394 | }) | 395 | }) |
395 | } | 396 | } |
397 | |||
398 | static autocomplete (search: string) { | ||
399 | return UserModel.findAll({ | ||
400 | where: { | ||
401 | username: { | ||
402 | [Sequelize.Op.like]: `%${search}%` | ||
403 | } | ||
404 | } | ||
405 | }) | ||
406 | .then(u => u.map(u => u.username)) | ||
407 | } | ||
396 | } | 408 | } |
diff --git a/server/models/video/video-change-ownership.ts b/server/models/video/video-change-ownership.ts new file mode 100644 index 000000000..c9cff5054 --- /dev/null +++ b/server/models/video/video-change-ownership.ts | |||
@@ -0,0 +1,127 @@ | |||
1 | import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' | ||
2 | import { AccountModel } from '../account/account' | ||
3 | import { VideoModel } from './video' | ||
4 | import { VideoChangeOwnership, VideoChangeOwnershipStatus } from '../../../shared/models/videos' | ||
5 | import { getSort } from '../utils' | ||
6 | import { VideoFileModel } from './video-file' | ||
7 | |||
8 | enum ScopeNames { | ||
9 | FULL = 'FULL' | ||
10 | } | ||
11 | |||
12 | @Table({ | ||
13 | tableName: 'videoChangeOwnership', | ||
14 | indexes: [ | ||
15 | { | ||
16 | fields: ['videoId'] | ||
17 | }, | ||
18 | { | ||
19 | fields: ['initiatorAccountId'] | ||
20 | }, | ||
21 | { | ||
22 | fields: ['nextOwnerAccountId'] | ||
23 | } | ||
24 | ] | ||
25 | }) | ||
26 | @Scopes({ | ||
27 | [ScopeNames.FULL]: { | ||
28 | include: [ | ||
29 | { | ||
30 | model: () => AccountModel, | ||
31 | as: 'Initiator', | ||
32 | required: true | ||
33 | }, | ||
34 | { | ||
35 | model: () => AccountModel, | ||
36 | as: 'NextOwner', | ||
37 | required: true | ||
38 | }, | ||
39 | { | ||
40 | model: () => VideoModel, | ||
41 | required: true, | ||
42 | include: [{ model: () => VideoFileModel }] | ||
43 | } | ||
44 | ] | ||
45 | } | ||
46 | }) | ||
47 | export class VideoChangeOwnershipModel extends Model<VideoChangeOwnershipModel> { | ||
48 | @CreatedAt | ||
49 | createdAt: Date | ||
50 | |||
51 | @UpdatedAt | ||
52 | updatedAt: Date | ||
53 | |||
54 | @AllowNull(false) | ||
55 | @Column | ||
56 | status: VideoChangeOwnershipStatus | ||
57 | |||
58 | @ForeignKey(() => AccountModel) | ||
59 | @Column | ||
60 | initiatorAccountId: number | ||
61 | |||
62 | @BelongsTo(() => AccountModel, { | ||
63 | foreignKey: { | ||
64 | name: 'initiatorAccountId', | ||
65 | allowNull: false | ||
66 | }, | ||
67 | onDelete: 'cascade' | ||
68 | }) | ||
69 | Initiator: AccountModel | ||
70 | |||
71 | @ForeignKey(() => AccountModel) | ||
72 | @Column | ||
73 | nextOwnerAccountId: number | ||
74 | |||
75 | @BelongsTo(() => AccountModel, { | ||
76 | foreignKey: { | ||
77 | name: 'nextOwnerAccountId', | ||
78 | allowNull: false | ||
79 | }, | ||
80 | onDelete: 'cascade' | ||
81 | }) | ||
82 | NextOwner: AccountModel | ||
83 | |||
84 | @ForeignKey(() => VideoModel) | ||
85 | @Column | ||
86 | videoId: number | ||
87 | |||
88 | @BelongsTo(() => VideoModel, { | ||
89 | foreignKey: { | ||
90 | allowNull: false | ||
91 | }, | ||
92 | onDelete: 'cascade' | ||
93 | }) | ||
94 | Video: VideoModel | ||
95 | |||
96 | static listForApi (nextOwnerId: number, start: number, count: number, sort: string) { | ||
97 | return VideoChangeOwnershipModel.scope(ScopeNames.FULL).findAndCountAll({ | ||
98 | offset: start, | ||
99 | limit: count, | ||
100 | order: getSort(sort), | ||
101 | where: { | ||
102 | nextOwnerAccountId: nextOwnerId | ||
103 | } | ||
104 | }) | ||
105 | .then(({ rows, count }) => ({ total: count, data: rows })) | ||
106 | } | ||
107 | |||
108 | static load (id: number) { | ||
109 | return VideoChangeOwnershipModel.scope(ScopeNames.FULL).findById(id) | ||
110 | } | ||
111 | |||
112 | toFormattedJSON (): VideoChangeOwnership { | ||
113 | return { | ||
114 | id: this.id, | ||
115 | status: this.status, | ||
116 | initiatorAccount: this.Initiator.toFormattedJSON(), | ||
117 | nextOwnerAccount: this.NextOwner.toFormattedJSON(), | ||
118 | video: { | ||
119 | id: this.Video.id, | ||
120 | uuid: this.Video.uuid, | ||
121 | url: this.Video.url, | ||
122 | name: this.Video.name | ||
123 | }, | ||
124 | createdAt: this.createdAt | ||
125 | } | ||
126 | } | ||
127 | } | ||
diff --git a/server/tests/api/videos/video-change-ownership.ts b/server/tests/api/videos/video-change-ownership.ts new file mode 100644 index 000000000..275be40be --- /dev/null +++ b/server/tests/api/videos/video-change-ownership.ts | |||
@@ -0,0 +1,262 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import * as chai from 'chai' | ||
4 | import 'mocha' | ||
5 | import { | ||
6 | acceptChangeOwnership, | ||
7 | changeVideoOwnership, | ||
8 | createUser, | ||
9 | flushTests, | ||
10 | getMyUserInformation, | ||
11 | getVideoChangeOwnershipList, | ||
12 | getVideosList, | ||
13 | killallServers, | ||
14 | refuseChangeOwnership, | ||
15 | runServer, | ||
16 | ServerInfo, | ||
17 | setAccessTokensToServers, | ||
18 | uploadVideo, | ||
19 | userLogin | ||
20 | } from '../../utils' | ||
21 | import { waitJobs } from '../../utils/server/jobs' | ||
22 | import { User } from '../../../../shared/models/users' | ||
23 | |||
24 | const expect = chai.expect | ||
25 | |||
26 | describe('Test video change ownership - nominal', function () { | ||
27 | let server: ServerInfo = undefined | ||
28 | const firstUser = { | ||
29 | username: 'first', | ||
30 | password: 'My great password' | ||
31 | } | ||
32 | const secondUser = { | ||
33 | username: 'second', | ||
34 | password: 'My other password' | ||
35 | } | ||
36 | let firstUserAccessToken = '' | ||
37 | let secondUserAccessToken = '' | ||
38 | let lastRequestChangeOwnershipId = undefined | ||
39 | |||
40 | before(async function () { | ||
41 | this.timeout(50000) | ||
42 | |||
43 | // Run one server | ||
44 | await flushTests() | ||
45 | server = await runServer(1) | ||
46 | await setAccessTokensToServers([server]) | ||
47 | |||
48 | const videoQuota = 42000000 | ||
49 | await createUser(server.url, server.accessToken, firstUser.username, firstUser.password, videoQuota) | ||
50 | await createUser(server.url, server.accessToken, secondUser.username, secondUser.password, videoQuota) | ||
51 | |||
52 | firstUserAccessToken = await userLogin(server, firstUser) | ||
53 | secondUserAccessToken = await userLogin(server, secondUser) | ||
54 | |||
55 | // Upload some videos on the server | ||
56 | const video1Attributes = { | ||
57 | name: 'my super name', | ||
58 | description: 'my super description' | ||
59 | } | ||
60 | await uploadVideo(server.url, firstUserAccessToken, video1Attributes) | ||
61 | |||
62 | await waitJobs(server) | ||
63 | |||
64 | const res = await getVideosList(server.url) | ||
65 | const videos = res.body.data | ||
66 | |||
67 | expect(videos.length).to.equal(1) | ||
68 | |||
69 | server.video = videos.find(video => video.name === 'my super name') | ||
70 | }) | ||
71 | |||
72 | it('Should not have video change ownership', async function () { | ||
73 | const resFirstUser = await getVideoChangeOwnershipList(server.url, firstUserAccessToken) | ||
74 | |||
75 | expect(resFirstUser.body.total).to.equal(0) | ||
76 | expect(resFirstUser.body.data).to.be.an('array') | ||
77 | expect(resFirstUser.body.data.length).to.equal(0) | ||
78 | |||
79 | const resSecondUser = await getVideoChangeOwnershipList(server.url, secondUserAccessToken) | ||
80 | |||
81 | expect(resSecondUser.body.total).to.equal(0) | ||
82 | expect(resSecondUser.body.data).to.be.an('array') | ||
83 | expect(resSecondUser.body.data.length).to.equal(0) | ||
84 | }) | ||
85 | |||
86 | it('Should send a request to change ownership of a video', async function () { | ||
87 | this.timeout(15000) | ||
88 | |||
89 | await changeVideoOwnership(server.url, firstUserAccessToken, server.video.id, secondUser.username) | ||
90 | }) | ||
91 | |||
92 | it('Should only return a request to change ownership for the second user', async function () { | ||
93 | const resFirstUser = await getVideoChangeOwnershipList(server.url, firstUserAccessToken) | ||
94 | |||
95 | expect(resFirstUser.body.total).to.equal(0) | ||
96 | expect(resFirstUser.body.data).to.be.an('array') | ||
97 | expect(resFirstUser.body.data.length).to.equal(0) | ||
98 | |||
99 | const resSecondUser = await getVideoChangeOwnershipList(server.url, secondUserAccessToken) | ||
100 | |||
101 | expect(resSecondUser.body.total).to.equal(1) | ||
102 | expect(resSecondUser.body.data).to.be.an('array') | ||
103 | expect(resSecondUser.body.data.length).to.equal(1) | ||
104 | |||
105 | lastRequestChangeOwnershipId = resSecondUser.body.data[0].id | ||
106 | }) | ||
107 | |||
108 | it('Should accept the same change ownership request without crashing', async function () { | ||
109 | this.timeout(10000) | ||
110 | |||
111 | await changeVideoOwnership(server.url, firstUserAccessToken, server.video.id, secondUser.username) | ||
112 | }) | ||
113 | |||
114 | it('Should not create multiple change ownership requests while one is waiting', async function () { | ||
115 | this.timeout(10000) | ||
116 | |||
117 | const resSecondUser = await getVideoChangeOwnershipList(server.url, secondUserAccessToken) | ||
118 | |||
119 | expect(resSecondUser.body.total).to.equal(1) | ||
120 | expect(resSecondUser.body.data).to.be.an('array') | ||
121 | expect(resSecondUser.body.data.length).to.equal(1) | ||
122 | }) | ||
123 | |||
124 | it('Should not be possible to refuse the change of ownership from first user', async function () { | ||
125 | this.timeout(10000) | ||
126 | |||
127 | await refuseChangeOwnership(server.url, firstUserAccessToken, lastRequestChangeOwnershipId, 403) | ||
128 | }) | ||
129 | |||
130 | it('Should be possible to refuse the change of ownership from second user', async function () { | ||
131 | this.timeout(10000) | ||
132 | |||
133 | await refuseChangeOwnership(server.url, secondUserAccessToken, lastRequestChangeOwnershipId) | ||
134 | }) | ||
135 | |||
136 | it('Should send a new request to change ownership of a video', async function () { | ||
137 | this.timeout(15000) | ||
138 | |||
139 | await changeVideoOwnership(server.url, firstUserAccessToken, server.video.id, secondUser.username) | ||
140 | }) | ||
141 | |||
142 | it('Should return two requests to change ownership for the second user', async function () { | ||
143 | const resFirstUser = await getVideoChangeOwnershipList(server.url, firstUserAccessToken) | ||
144 | |||
145 | expect(resFirstUser.body.total).to.equal(0) | ||
146 | expect(resFirstUser.body.data).to.be.an('array') | ||
147 | expect(resFirstUser.body.data.length).to.equal(0) | ||
148 | |||
149 | const resSecondUser = await getVideoChangeOwnershipList(server.url, secondUserAccessToken) | ||
150 | |||
151 | expect(resSecondUser.body.total).to.equal(2) | ||
152 | expect(resSecondUser.body.data).to.be.an('array') | ||
153 | expect(resSecondUser.body.data.length).to.equal(2) | ||
154 | |||
155 | lastRequestChangeOwnershipId = resSecondUser.body.data[0].id | ||
156 | }) | ||
157 | |||
158 | it('Should not be possible to accept the change of ownership from first user', async function () { | ||
159 | this.timeout(10000) | ||
160 | |||
161 | const secondUserInformationResponse = await getMyUserInformation(server.url, secondUserAccessToken) | ||
162 | const secondUserInformation: User = secondUserInformationResponse.body | ||
163 | const channelId = secondUserInformation.videoChannels[0].id | ||
164 | await acceptChangeOwnership(server.url, firstUserAccessToken, lastRequestChangeOwnershipId, channelId, 403) | ||
165 | }) | ||
166 | |||
167 | it('Should be possible to accept the change of ownership from second user', async function () { | ||
168 | this.timeout(10000) | ||
169 | |||
170 | const secondUserInformationResponse = await getMyUserInformation(server.url, secondUserAccessToken) | ||
171 | const secondUserInformation: User = secondUserInformationResponse.body | ||
172 | const channelId = secondUserInformation.videoChannels[0].id | ||
173 | await acceptChangeOwnership(server.url, secondUserAccessToken, lastRequestChangeOwnershipId, channelId) | ||
174 | }) | ||
175 | |||
176 | after(async function () { | ||
177 | killallServers([server]) | ||
178 | }) | ||
179 | }) | ||
180 | |||
181 | describe('Test video change ownership - quota too small', function () { | ||
182 | let server: ServerInfo = undefined | ||
183 | const firstUser = { | ||
184 | username: 'first', | ||
185 | password: 'My great password' | ||
186 | } | ||
187 | const secondUser = { | ||
188 | username: 'second', | ||
189 | password: 'My other password' | ||
190 | } | ||
191 | let firstUserAccessToken = '' | ||
192 | let secondUserAccessToken = '' | ||
193 | let lastRequestChangeOwnershipId = undefined | ||
194 | |||
195 | before(async function () { | ||
196 | this.timeout(50000) | ||
197 | |||
198 | // Run one server | ||
199 | await flushTests() | ||
200 | server = await runServer(1) | ||
201 | await setAccessTokensToServers([server]) | ||
202 | |||
203 | const videoQuota = 42000000 | ||
204 | const limitedVideoQuota = 10 | ||
205 | await createUser(server.url, server.accessToken, firstUser.username, firstUser.password, videoQuota) | ||
206 | await createUser(server.url, server.accessToken, secondUser.username, secondUser.password, limitedVideoQuota) | ||
207 | |||
208 | firstUserAccessToken = await userLogin(server, firstUser) | ||
209 | secondUserAccessToken = await userLogin(server, secondUser) | ||
210 | |||
211 | // Upload some videos on the server | ||
212 | const video1Attributes = { | ||
213 | name: 'my super name', | ||
214 | description: 'my super description' | ||
215 | } | ||
216 | await uploadVideo(server.url, firstUserAccessToken, video1Attributes) | ||
217 | |||
218 | await waitJobs(server) | ||
219 | |||
220 | const res = await getVideosList(server.url) | ||
221 | const videos = res.body.data | ||
222 | |||
223 | expect(videos.length).to.equal(1) | ||
224 | |||
225 | server.video = videos.find(video => video.name === 'my super name') | ||
226 | }) | ||
227 | |||
228 | it('Should send a request to change ownership of a video', async function () { | ||
229 | this.timeout(15000) | ||
230 | |||
231 | await changeVideoOwnership(server.url, firstUserAccessToken, server.video.id, secondUser.username) | ||
232 | }) | ||
233 | |||
234 | it('Should only return a request to change ownership for the second user', async function () { | ||
235 | const resFirstUser = await getVideoChangeOwnershipList(server.url, firstUserAccessToken) | ||
236 | |||
237 | expect(resFirstUser.body.total).to.equal(0) | ||
238 | expect(resFirstUser.body.data).to.be.an('array') | ||
239 | expect(resFirstUser.body.data.length).to.equal(0) | ||
240 | |||
241 | const resSecondUser = await getVideoChangeOwnershipList(server.url, secondUserAccessToken) | ||
242 | |||
243 | expect(resSecondUser.body.total).to.equal(1) | ||
244 | expect(resSecondUser.body.data).to.be.an('array') | ||
245 | expect(resSecondUser.body.data.length).to.equal(1) | ||
246 | |||
247 | lastRequestChangeOwnershipId = resSecondUser.body.data[0].id | ||
248 | }) | ||
249 | |||
250 | it('Should not be possible to accept the change of ownership from second user because of exceeded quota', async function () { | ||
251 | this.timeout(10000) | ||
252 | |||
253 | const secondUserInformationResponse = await getMyUserInformation(server.url, secondUserAccessToken) | ||
254 | const secondUserInformation: User = secondUserInformationResponse.body | ||
255 | const channelId = secondUserInformation.videoChannels[0].id | ||
256 | await acceptChangeOwnership(server.url, secondUserAccessToken, lastRequestChangeOwnershipId, channelId, 403) | ||
257 | }) | ||
258 | |||
259 | after(async function () { | ||
260 | killallServers([server]) | ||
261 | }) | ||
262 | }) | ||
diff --git a/server/tests/utils/index.ts b/server/tests/utils/index.ts index 391db18cf..897389824 100644 --- a/server/tests/utils/index.ts +++ b/server/tests/utils/index.ts | |||
@@ -13,5 +13,6 @@ export * from './videos/video-abuses' | |||
13 | export * from './videos/video-blacklist' | 13 | export * from './videos/video-blacklist' |
14 | export * from './videos/video-channels' | 14 | export * from './videos/video-channels' |
15 | export * from './videos/videos' | 15 | export * from './videos/videos' |
16 | export * from './videos/video-change-ownership' | ||
16 | export * from './feeds/feeds' | 17 | export * from './feeds/feeds' |
17 | export * from './search/videos' | 18 | export * from './search/videos' |
diff --git a/server/tests/utils/videos/video-change-ownership.ts b/server/tests/utils/videos/video-change-ownership.ts new file mode 100644 index 000000000..f288692ea --- /dev/null +++ b/server/tests/utils/videos/video-change-ownership.ts | |||
@@ -0,0 +1,54 @@ | |||
1 | import * as request from 'supertest' | ||
2 | |||
3 | function changeVideoOwnership (url: string, token: string, videoId: number | string, username) { | ||
4 | const path = '/api/v1/videos/' + videoId + '/give-ownership' | ||
5 | |||
6 | return request(url) | ||
7 | .post(path) | ||
8 | .set('Accept', 'application/json') | ||
9 | .set('Authorization', 'Bearer ' + token) | ||
10 | .send({ username }) | ||
11 | .expect(204) | ||
12 | } | ||
13 | |||
14 | function getVideoChangeOwnershipList (url: string, token: string) { | ||
15 | const path = '/api/v1/videos/ownership' | ||
16 | |||
17 | return request(url) | ||
18 | .get(path) | ||
19 | .query({ sort: '-createdAt' }) | ||
20 | .set('Accept', 'application/json') | ||
21 | .set('Authorization', 'Bearer ' + token) | ||
22 | .expect(200) | ||
23 | .expect('Content-Type', /json/) | ||
24 | } | ||
25 | |||
26 | function acceptChangeOwnership (url: string, token: string, ownershipId: string, channelId: number, expectedStatus = 204) { | ||
27 | const path = '/api/v1/videos/ownership/' + ownershipId + '/accept' | ||
28 | |||
29 | return request(url) | ||
30 | .post(path) | ||
31 | .set('Accept', 'application/json') | ||
32 | .set('Authorization', 'Bearer ' + token) | ||
33 | .send({ channelId }) | ||
34 | .expect(expectedStatus) | ||
35 | } | ||
36 | |||
37 | function refuseChangeOwnership (url: string, token: string, ownershipId: string, expectedStatus = 204) { | ||
38 | const path = '/api/v1/videos/ownership/' + ownershipId + '/refuse' | ||
39 | |||
40 | return request(url) | ||
41 | .post(path) | ||
42 | .set('Accept', 'application/json') | ||
43 | .set('Authorization', 'Bearer ' + token) | ||
44 | .expect(expectedStatus) | ||
45 | } | ||
46 | |||
47 | // --------------------------------------------------------------------------- | ||
48 | |||
49 | export { | ||
50 | changeVideoOwnership, | ||
51 | getVideoChangeOwnershipList, | ||
52 | acceptChangeOwnership, | ||
53 | refuseChangeOwnership | ||
54 | } | ||
diff --git a/shared/models/users/user-right.enum.ts b/shared/models/users/user-right.enum.ts index 142a0474b..64ad3e9b9 100644 --- a/shared/models/users/user-right.enum.ts +++ b/shared/models/users/user-right.enum.ts | |||
@@ -12,5 +12,6 @@ export enum UserRight { | |||
12 | REMOVE_ANY_VIDEO, | 12 | REMOVE_ANY_VIDEO, |
13 | REMOVE_ANY_VIDEO_CHANNEL, | 13 | REMOVE_ANY_VIDEO_CHANNEL, |
14 | REMOVE_ANY_VIDEO_COMMENT, | 14 | REMOVE_ANY_VIDEO_COMMENT, |
15 | UPDATE_ANY_VIDEO | 15 | UPDATE_ANY_VIDEO, |
16 | CHANGE_VIDEO_OWNERSHIP | ||
16 | } | 17 | } |
diff --git a/shared/models/videos/index.ts b/shared/models/videos/index.ts index f1a3d52e1..90a0e3053 100644 --- a/shared/models/videos/index.ts +++ b/shared/models/videos/index.ts | |||
@@ -11,6 +11,8 @@ export * from './blacklist/video-blacklist-update.model' | |||
11 | export * from './channel/video-channel-create.model' | 11 | export * from './channel/video-channel-create.model' |
12 | export * from './channel/video-channel-update.model' | 12 | export * from './channel/video-channel-update.model' |
13 | export * from './channel/video-channel.model' | 13 | export * from './channel/video-channel.model' |
14 | export * from './video-change-ownership.model' | ||
15 | export * from './video-change-ownership-create.model' | ||
14 | export * from './video-create.model' | 16 | export * from './video-create.model' |
15 | export * from './video-privacy.enum' | 17 | export * from './video-privacy.enum' |
16 | export * from './video-rate.type' | 18 | export * from './video-rate.type' |
diff --git a/shared/models/videos/video-change-ownership-accept.model.ts b/shared/models/videos/video-change-ownership-accept.model.ts new file mode 100644 index 000000000..f27247633 --- /dev/null +++ b/shared/models/videos/video-change-ownership-accept.model.ts | |||
@@ -0,0 +1,3 @@ | |||
1 | export interface VideoChangeOwnershipAccept { | ||
2 | channelId: number | ||
3 | } | ||
diff --git a/shared/models/videos/video-change-ownership-create.model.ts b/shared/models/videos/video-change-ownership-create.model.ts new file mode 100644 index 000000000..40fcca285 --- /dev/null +++ b/shared/models/videos/video-change-ownership-create.model.ts | |||
@@ -0,0 +1,3 @@ | |||
1 | export interface VideoChangeOwnershipCreate { | ||
2 | username: string | ||
3 | } | ||
diff --git a/shared/models/videos/video-change-ownership.model.ts b/shared/models/videos/video-change-ownership.model.ts new file mode 100644 index 000000000..0d735c798 --- /dev/null +++ b/shared/models/videos/video-change-ownership.model.ts | |||
@@ -0,0 +1,21 @@ | |||
1 | import { Account } from '../actors' | ||
2 | |||
3 | export interface VideoChangeOwnership { | ||
4 | id: number | ||
5 | status: VideoChangeOwnershipStatus | ||
6 | initiatorAccount: Account | ||
7 | nextOwnerAccount: Account | ||
8 | video: { | ||
9 | id: number | ||
10 | name: string | ||
11 | uuid: string | ||
12 | url: string | ||
13 | } | ||
14 | createdAt: Date | ||
15 | } | ||
16 | |||
17 | export enum VideoChangeOwnershipStatus { | ||
18 | WAITING = 'WAITING', | ||
19 | ACCEPTED = 'ACCEPTED', | ||
20 | REFUSED = 'REFUSED' | ||
21 | } | ||