aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared
diff options
context:
space:
mode:
authorGaƫtan Rizio <gaetan@rizio.fr>2018-09-04 08:57:13 +0200
committerChocobozzz <me@florianbigard.com>2018-09-04 08:57:13 +0200
commit74d63469355bad731cdd32defdc85913df3cbd5c (patch)
tree5e7a9033a507fd69c554ddc7cc6ce3f7a6416ca1 /client/src/app/shared
parent2303a803aa19c2857efac9f2af2223ccae5757e2 (diff)
downloadPeerTube-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
Diffstat (limited to 'client/src/app/shared')
-rw-r--r--client/src/app/shared/buttons/button.component.html4
-rw-r--r--client/src/app/shared/buttons/button.component.scss12
-rw-r--r--client/src/app/shared/buttons/button.component.ts18
-rw-r--r--client/src/app/shared/forms/form-validators/index.ts2
-rw-r--r--client/src/app/shared/forms/form-validators/video-accept-ownership-validators.service.ts18
-rw-r--r--client/src/app/shared/forms/form-validators/video-change-ownership-validators.service.ts18
-rw-r--r--client/src/app/shared/shared.module.ts10
-rw-r--r--client/src/app/shared/users/user.service.ts12
-rw-r--r--client/src/app/shared/video-ownership/index.ts1
-rw-r--r--client/src/app/shared/video-ownership/video-ownership.service.ts67
10 files changed, 160 insertions, 2 deletions
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 @@
1import { Component, Input } from '@angular/core'
2
3@Component({
4 selector: 'my-button',
5 styleUrls: ['./button.component.scss'],
6 templateUrl: './button.component.html'
7})
8
9export 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'
10export * from './video-comment-validators.service' 10export * from './video-comment-validators.service'
11export * from './video-validators.service' 11export * from './video-validators.service'
12export * from './video-captions-validators.service' 12export * from './video-captions-validators.service'
13export * from './video-change-ownership-validators.service'
14export * 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 @@
1import { I18n } from '@ngx-translate/i18n-polyfill'
2import { Validators } from '@angular/forms'
3import { Injectable } from '@angular/core'
4import { BuildFormValidator } from '@app/shared'
5
6@Injectable()
7export 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 @@
1import { I18n } from '@ngx-translate/i18n-polyfill'
2import { Validators } from '@angular/forms'
3import { Injectable } from '@angular/core'
4import { BuildFormValidator } from '@app/shared'
5
6@Injectable()
7export 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'
12import { SharedModule as PrimeSharedModule } from 'primeng/components/common/shared' 12import { SharedModule as PrimeSharedModule } from 'primeng/components/common/shared'
13 13
14import { AUTH_INTERCEPTOR_PROVIDER } from './auth' 14import { AUTH_INTERCEPTOR_PROVIDER } from './auth'
15import { ButtonComponent } from './buttons/button.component'
15import { DeleteButtonComponent } from './buttons/delete-button.component' 16import { DeleteButtonComponent } from './buttons/delete-button.component'
16import { EditButtonComponent } from './buttons/edit-button.component' 17import { EditButtonComponent } from './buttons/edit-button.component'
17import { FromNowPipe } from './misc/from-now.pipe' 18import { FromNowPipe } from './misc/from-now.pipe'
@@ -22,6 +23,7 @@ import { RestExtractor, RestService } from './rest'
22import { UserService } from './users' 23import { UserService } from './users'
23import { VideoAbuseService } from './video-abuse' 24import { VideoAbuseService } from './video-abuse'
24import { VideoBlacklistService } from './video-blacklist' 25import { VideoBlacklistService } from './video-blacklist'
26import { VideoOwnershipService } from './video-ownership'
25import { VideoMiniatureComponent } from './video/video-miniature.component' 27import { VideoMiniatureComponent } from './video/video-miniature.component'
26import { VideoFeedComponent } from './video/video-feed.component' 28import { VideoFeedComponent } from './video/video-feed.component'
27import { VideoThumbnailComponent } from './video/video-thumbnail.component' 29import { 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'
45import { I18nPrimengCalendarService } from '@app/shared/i18n/i18n-primeng-calendar' 48import { I18nPrimengCalendarService } from '@app/shared/i18n/i18n-primeng-calendar'
46import { ScreenService } from '@app/shared/misc/screen.service' 49import { 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 @@
1import { Observable } from 'rxjs'
1import { catchError, map } from 'rxjs/operators' 2import { catchError, map } from 'rxjs/operators'
2import { HttpClient } from '@angular/common/http' 3import { HttpClient, HttpParams } from '@angular/common/http'
3import { Injectable } from '@angular/core' 4import { Injectable } from '@angular/core'
4import { UserCreate, UserUpdateMe, UserVideoQuota } from '../../../../../shared' 5import { UserCreate, UserUpdateMe, UserVideoQuota } from '../../../../../shared'
5import { environment } from '../../../environments/environment' 6import { 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 @@
1import { catchError, map } from 'rxjs/operators'
2import { HttpClient, HttpParams } from '@angular/common/http'
3import { Injectable } from '@angular/core'
4import { environment } from '../../../environments/environment'
5import { RestExtractor, RestService } from '../rest'
6import { VideoChangeOwnershipCreate } from '../../../../../shared/models/videos'
7import { Observable } from 'rxjs/index'
8import { SortMeta } from 'primeng/components/common/sortmeta'
9import { ResultList, VideoChangeOwnership } from '../../../../../shared'
10import { RestPagination } from '@app/shared/rest'
11import { VideoChangeOwnershipAccept } from '../../../../../shared/models/videos/video-change-ownership-accept.model'
12
13@Injectable()
14export 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}