aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+manage/video-channel-edit/video-channel-update.component.ts
diff options
context:
space:
mode:
authorkontrollanten <6680299+kontrollanten@users.noreply.github.com>2021-12-13 15:29:13 +0100
committerGitHub <noreply@github.com>2021-12-13 15:29:13 +0100
commita37e9e74ff07b057370d1ed6c0b391a02be8a6d2 (patch)
tree30d59e12518149a309bbd10bee1485f8be523c75 /client/src/app/+manage/video-channel-edit/video-channel-update.component.ts
parent11e520b50d791a0dd48cbb2d0fc681b25eb7cd53 (diff)
downloadPeerTube-a37e9e74ff07b057370d1ed6c0b391a02be8a6d2.tar.gz
PeerTube-a37e9e74ff07b057370d1ed6c0b391a02be8a6d2.tar.zst
PeerTube-a37e9e74ff07b057370d1ed6c0b391a02be8a6d2.zip
Give moderators access to edit channels (#4608)
* give admins access to edit all channels closes #4598 * test(channels): +admin update another users channel * Fix tests * fix(server): delete another users channel Since the channel owner isn't necessary the auth user we need to check the right account whether it's the last video or not. * REMOVE_ANY_VIDEO_CHANNEL > MANAGE_ANY_VIDEO_CHANNEL Merge REMOVE_ANY_VIDEO_CHANNEL and MANY_VIDEO_CHANNELS to MANAGE_ANY_VIDEO_CHANNEL. * user-right: moderator can't manage admins channel * client: MyVideoChannelCreateComponent > VideoChannelCreateComponent * client: MyVideoChannelEdit > VideoChannelEdit * Revert "user-right: moderator can't manage admins channel" This reverts commit 2c627c154e2bfe6af2e0f45efb27faf4117572f3. * server: clean dupl validator functionality * fix ensureUserCanManageChannel usage It's not async anymore. * server: merge channel validator middleares ensureAuthUserOwnsChannelValidator & ensureUserCanManageChannel gets merged into one middleware. * client(VideoChannelEdit): redirect to prev route * fix(VideoChannels): handle anon users * client: new routes for create/update channel * Refactor channel validators Co-authored-by: Chocobozzz <me@florianbigard.com>
Diffstat (limited to 'client/src/app/+manage/video-channel-edit/video-channel-update.component.ts')
-rw-r--r--client/src/app/+manage/video-channel-edit/video-channel-update.component.ts189
1 files changed, 189 insertions, 0 deletions
diff --git a/client/src/app/+manage/video-channel-edit/video-channel-update.component.ts b/client/src/app/+manage/video-channel-edit/video-channel-update.component.ts
new file mode 100644
index 000000000..21b6167b2
--- /dev/null
+++ b/client/src/app/+manage/video-channel-edit/video-channel-update.component.ts
@@ -0,0 +1,189 @@
1import { Subscription } from 'rxjs'
2import { HttpErrorResponse } from '@angular/common/http'
3import { Component, OnDestroy, OnInit } from '@angular/core'
4import { ActivatedRoute, Router } from '@angular/router'
5import { AuthService, Notifier, RedirectService, ServerService } from '@app/core'
6import { genericUploadErrorHandler } from '@app/helpers'
7import {
8 VIDEO_CHANNEL_DESCRIPTION_VALIDATOR,
9 VIDEO_CHANNEL_DISPLAY_NAME_VALIDATOR,
10 VIDEO_CHANNEL_SUPPORT_VALIDATOR
11} from '@app/shared/form-validators/video-channel-validators'
12import { FormValidatorService } from '@app/shared/shared-forms'
13import { VideoChannel, VideoChannelService } from '@app/shared/shared-main'
14import { HTMLServerConfig, VideoChannelUpdate } from '@shared/models'
15import { VideoChannelEdit } from './video-channel-edit'
16
17@Component({
18 selector: 'my-video-channel-update',
19 templateUrl: './video-channel-edit.component.html',
20 styleUrls: [ './video-channel-edit.component.scss' ]
21})
22export class VideoChannelUpdateComponent extends VideoChannelEdit implements OnInit, OnDestroy {
23 error: string
24 videoChannel: VideoChannel
25
26 private paramsSub: Subscription
27 private oldSupportField: string
28 private serverConfig: HTMLServerConfig
29
30 constructor (
31 protected formValidatorService: FormValidatorService,
32 private authService: AuthService,
33 private notifier: Notifier,
34 private router: Router,
35 private route: ActivatedRoute,
36 private videoChannelService: VideoChannelService,
37 private serverService: ServerService,
38 private redirectService: RedirectService
39 ) {
40 super()
41 }
42
43 ngOnInit () {
44 this.serverConfig = this.serverService.getHTMLConfig()
45
46 this.buildForm({
47 'display-name': VIDEO_CHANNEL_DISPLAY_NAME_VALIDATOR,
48 description: VIDEO_CHANNEL_DESCRIPTION_VALIDATOR,
49 support: VIDEO_CHANNEL_SUPPORT_VALIDATOR,
50 bulkVideosSupportUpdate: null
51 })
52
53 this.paramsSub = this.route.params.subscribe(routeParams => {
54 const videoChannelName = routeParams['videoChannelName']
55
56 this.videoChannelService.getVideoChannel(videoChannelName)
57 .subscribe({
58 next: videoChannelToUpdate => {
59 this.videoChannel = videoChannelToUpdate
60
61 this.oldSupportField = videoChannelToUpdate.support
62
63 this.form.patchValue({
64 'display-name': videoChannelToUpdate.displayName,
65 description: videoChannelToUpdate.description,
66 support: videoChannelToUpdate.support
67 })
68 },
69
70 error: err => {
71 this.error = err.message
72 }
73 })
74 })
75 }
76
77 ngOnDestroy () {
78 if (this.paramsSub) this.paramsSub.unsubscribe()
79 }
80
81 formValidated () {
82 this.error = undefined
83
84 const body = this.form.value
85 const videoChannelUpdate: VideoChannelUpdate = {
86 displayName: body['display-name'],
87 description: body.description || null,
88 support: body.support || null,
89 bulkVideosSupportUpdate: body.bulkVideosSupportUpdate || false
90 }
91
92 this.videoChannelService.updateVideoChannel(this.videoChannel.name, videoChannelUpdate)
93 .subscribe({
94 next: () => {
95 this.authService.refreshUserInformation()
96
97 this.notifier.success($localize`Video channel ${videoChannelUpdate.displayName} updated.`)
98
99 this.redirectService.redirectToPreviousRoute([ '/c', this.videoChannel.name ])
100 },
101
102 error: err => {
103 this.error = err.message
104 }
105 })
106 }
107
108 onAvatarChange (formData: FormData) {
109 this.videoChannelService.changeVideoChannelImage(this.videoChannel.name, formData, 'avatar')
110 .subscribe({
111 next: data => {
112 this.notifier.success($localize`Avatar changed.`)
113
114 this.videoChannel.updateAvatar(data.avatar)
115 },
116
117 error: (err: HttpErrorResponse) => genericUploadErrorHandler({
118 err,
119 name: $localize`avatar`,
120 notifier: this.notifier
121 })
122 })
123 }
124
125 onAvatarDelete () {
126 this.videoChannelService.deleteVideoChannelImage(this.videoChannel.name, 'avatar')
127 .subscribe({
128 next: () => {
129 this.notifier.success($localize`Avatar deleted.`)
130
131 this.videoChannel.resetAvatar()
132 },
133
134 error: err => this.notifier.error(err.message)
135 })
136 }
137
138 onBannerChange (formData: FormData) {
139 this.videoChannelService.changeVideoChannelImage(this.videoChannel.name, formData, 'banner')
140 .subscribe({
141 next: data => {
142 this.notifier.success($localize`Banner changed.`)
143
144 this.videoChannel.updateBanner(data.banner)
145 },
146
147 error: (err: HttpErrorResponse) => genericUploadErrorHandler({
148 err,
149 name: $localize`banner`,
150 notifier: this.notifier
151 })
152 })
153 }
154
155 onBannerDelete () {
156 this.videoChannelService.deleteVideoChannelImage(this.videoChannel.name, 'banner')
157 .subscribe({
158 next: () => {
159 this.notifier.success($localize`Banner deleted.`)
160
161 this.videoChannel.resetBanner()
162 },
163
164 error: err => this.notifier.error(err.message)
165 })
166 }
167
168 get maxAvatarSize () {
169 return this.serverConfig.avatar.file.size.max
170 }
171
172 get avatarExtensions () {
173 return this.serverConfig.avatar.file.extensions.join(',')
174 }
175
176 isCreation () {
177 return false
178 }
179
180 getFormButtonTitle () {
181 return $localize`Update`
182 }
183
184 isBulkUpdateVideosDisplayed () {
185 if (this.oldSupportField === undefined) return false
186
187 return this.oldSupportField !== this.form.value['support']
188 }
189}