@@ -35,7 +35,7 @@ func (c *Controller) ServeGetPlaylists(r *http.Request) *spec.Response {
35
35
if err != nil {
36
36
return spec .NewError (0 , "error reading playlist %q: %v" , path , err )
37
37
}
38
- if playlist .UserID != user .ID && ! playlist . IsPublic {
38
+ if ! playlist .CanRead ( user .ID ) {
39
39
continue
40
40
}
41
41
playlistID := playlistIDEncode (path )
@@ -82,7 +82,7 @@ func (c *Controller) ServeCreateOrUpdatePlaylist(r *http.Request) *spec.Response
82
82
}
83
83
}
84
84
85
- if playlist .UserID != 0 && playlist .UserID != user .ID {
85
+ if playlist .UserID != 0 && ! playlist .CanWrite ( user .ID ) {
86
86
return spec .NewError (50 , "you aren't allowed update that user's playlist" )
87
87
}
88
88
@@ -133,7 +133,7 @@ func (c *Controller) ServeUpdatePlaylist(r *http.Request) *spec.Response {
133
133
}
134
134
135
135
// update meta info
136
- if playlist . UserID != 0 && playlist .UserID != user .ID {
136
+ if ! playlist .CanWrite ( user .ID ) {
137
137
return spec .NewResponse ()
138
138
}
139
139
@@ -173,9 +173,21 @@ func (c *Controller) ServeUpdatePlaylist(r *http.Request) *spec.Response {
173
173
}
174
174
175
175
func (c * Controller ) ServeDeletePlaylist (r * http.Request ) * spec.Response {
176
+ user := r .Context ().Value (CtxUser ).(* db.User )
176
177
params := r .Context ().Value (CtxParams ).(params.Params )
178
+
177
179
playlistID := params .GetFirstOr ( /* default */ "" , "id" , "playlistId" )
178
- if err := c .playlistStore .Delete (playlistIDDecode (playlistID )); err != nil {
180
+ playlistPath := playlistIDDecode (playlistID )
181
+ playlist , err := c .playlistStore .Read (playlistPath )
182
+ if err != nil {
183
+ return spec .NewError (0 , "find playlist: %v" , err )
184
+ }
185
+
186
+ if ! playlist .CanDelete (user .ID ) {
187
+ return spec .NewError (0 , "you cannot delete playlists you do not own" )
188
+ }
189
+
190
+ if err := c .playlistStore .Delete (playlistPath ); err != nil {
179
191
return spec .NewError (0 , "delete playlist: %v" , err )
180
192
}
181
193
return spec .NewResponse ()
0 commit comments