Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
tank
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AURA
tank
Commits
35c39978
Verified
Commit
35c39978
authored
1 year ago
by
Ernesto Rico Schmidt
Browse files
Options
Downloads
Patches
Plain Diff
fix: don’t require showId for most playlist operations
Closes:
#69
parent
a864b27e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
api/v1/playlists.go
+24
-16
24 additions, 16 deletions
api/v1/playlists.go
store/playlists.go
+11
-0
11 additions, 0 deletions
store/playlists.go
with
35 additions
and
16 deletions
api/v1/playlists.go
+
24
−
16
View file @
35c39978
...
...
@@ -146,23 +146,30 @@ func (api *API) ReadPlaylistOfShow(c *gin.Context) {
// @Failure 500 {object} ErrorResponse
// @Router /api/v1/playlists/{id} [put]
func
(
api
*
API
)
UpdatePlaylistOfShow
(
c
*
gin
.
Context
)
{
playlist
:=
&
store
.
P
laylist
{}
if
err
:=
json
.
NewDecoder
(
c
.
Request
.
Body
)
.
Decode
(
playlist
);
err
!=
nil
{
c
.
JSON
(
http
.
StatusBadRequest
,
ErrorResponse
{
Error
:
"
error decoding
playlist: "
+
err
.
Error
()})
playlist
ID
,
err
:=
idFromString
(
c
.
Param
(
"p
laylist
-id"
))
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusBadRequest
,
ErrorResponse
{
Error
:
"
invalid
playlist
-id
: "
+
err
.
Error
()})
return
}
if
authorized
,
_
:=
authorizeRequestForShow
(
c
,
playlist
.
ShowID
);
!
authorized
{
// with this we are actively subverting the checks performed in api.store.UpdatePlaylist
showID
,
err
:=
api
.
store
.
GetPlaylistShowID
(
playlistID
)
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusBadRequest
,
ErrorResponse
{
Error
:
"wrong playlist-id: "
+
err
.
Error
()})
return
}
id
,
err
:=
idFromString
(
c
.
Param
(
"playlist-id"
))
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusBadRequest
,
ErrorResponse
{
Error
:
"invalid playlist-id: "
+
err
.
Error
()})
if
authorized
,
_
:=
authorizeRequestForShow
(
c
,
showID
);
!
authorized
{
return
}
playlist
:=
&
store
.
Playlist
{}
if
err
:=
json
.
NewDecoder
(
c
.
Request
.
Body
)
.
Decode
(
playlist
);
err
!=
nil
{
c
.
JSON
(
http
.
StatusBadRequest
,
ErrorResponse
{
Error
:
"error decoding playlist: "
+
err
.
Error
()})
return
}
if
playlist
,
err
=
api
.
store
.
UpdatePlaylist
(
playlist
.
ShowID
,
id
,
*
playlist
);
err
!=
nil
{
if
playlist
,
err
=
api
.
store
.
UpdatePlaylist
(
showID
,
playlistID
,
*
playlist
);
err
!=
nil
{
sendError
(
c
,
err
)
return
}
...
...
@@ -182,23 +189,24 @@ func (api *API) UpdatePlaylistOfShow(c *gin.Context) {
// @Failure 500 {object} ErrorResponse
// @Router /api/v1/playlists/{id} [delete]
func
(
api
*
API
)
DeletePlaylistOfShow
(
c
*
gin
.
Context
)
{
playlist
:=
&
store
.
P
laylist
{}
if
err
:=
json
.
NewDecoder
(
c
.
Request
.
Body
)
.
Decode
(
playlist
);
err
!=
nil
{
c
.
JSON
(
http
.
StatusBadRequest
,
ErrorResponse
{
Error
:
"
error decoding
playlist: "
+
err
.
Error
()})
playlist
ID
,
err
:=
idFromString
(
c
.
Param
(
"p
laylist
-id"
))
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusBadRequest
,
ErrorResponse
{
Error
:
"
invalid
playlist
-id
: "
+
err
.
Error
()})
return
}
if
authorized
,
_
:=
authorizeRequestForShow
(
c
,
playlist
.
ShowID
);
!
authorized
{
// with this we are actively subverting the checks performed in api.store.DeletePlaylist
showID
,
err
:=
api
.
store
.
GetPlaylistShowID
(
playlistID
)
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusBadRequest
,
ErrorResponse
{
Error
:
"wrong playlist-id: "
+
err
.
Error
()})
return
}
id
,
err
:=
idFromString
(
c
.
Param
(
"playlist-id"
))
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusBadRequest
,
ErrorResponse
{
Error
:
"invalid playlist-id: "
+
err
.
Error
()})
if
authorized
,
_
:=
authorizeRequestForShow
(
c
,
showID
);
!
authorized
{
return
}
if
err
=
api
.
store
.
DeletePlaylist
(
playlist
.
ShowID
,
id
);
err
!=
nil
{
if
err
=
api
.
store
.
DeletePlaylist
(
showID
,
playlistID
);
err
!=
nil
{
sendError
(
c
,
err
)
return
}
...
...
This diff is collapsed.
Click to expand it.
store/playlists.go
+
11
−
0
View file @
35c39978
...
...
@@ -212,3 +212,14 @@ func (st *Store) GetPlaylistAllShows(id uint64) (playlist *Playlist, err error)
})
.
Preload
(
"Entries.File"
)
.
First
(
playlist
,
id
)
.
Error
return
}
func
(
st
*
Store
)
GetPlaylistShowID
(
id
uint64
)
(
uint64
,
error
)
{
// WARNING: using this function subverts the checks performed in the other functions
playlist
:=
&
Playlist
{}
if
err
:=
st
.
db
.
First
(
playlist
,
"id = ?"
,
id
)
.
Error
;
err
!=
nil
{
return
0
,
err
}
return
playlist
.
ShowID
,
nil
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment