From 27a7f3cb893de6ceac42ff4661db9e3bde360292 Mon Sep 17 00:00:00 2001 From: Ernesto Rico Schmidt <ernesto@helsinki.at> Date: Wed, 6 Nov 2024 16:23:01 -0400 Subject: [PATCH] feat: remove unused functions --- api/v1/utils.go | 58 ------------------------------------------------- store/files.go | 8 ------- 2 files changed, 66 deletions(-) diff --git a/api/v1/utils.go b/api/v1/utils.go index 02a41e7..5b5135e 100644 --- a/api/v1/utils.go +++ b/api/v1/utils.go @@ -135,23 +135,6 @@ func isRequestReadOnly(c *gin.Context) bool { return false } -func authorizeRequestAllShows(c *gin.Context) (bool, *auth.Session) { - s := getAuthSession(c.Request) - if s.Privileged { - return true, s - } - if s.ReadOnly && !isRequestReadOnly(c) { - c.JSON(http.StatusForbidden, ErrorResponse{Error: "this session is read-only"}) - return false, s - } - if s.AllShows { - return true, s - } - - c.JSON(http.StatusForbidden, ErrorResponse{Error: "you are not allowed to access all shows"}) - return false, s -} - func authorizeRequestForShow(c *gin.Context, showID uint64) (bool, *auth.Session) { s := getAuthSession(c.Request) if s.Privileged { @@ -181,47 +164,6 @@ func authorizeRequestForShow(c *gin.Context, showID uint64) (bool, *auth.Session return false, s } -func authorizeRequestForPlaylist(c *gin.Context, playlistID uint64, api *API) (bool, *auth.Session) { - s := getAuthSession(c.Request) - - if s.Privileged { - return true, s - } - - if s.ReadOnly && !isRequestReadOnly(c) { - c.JSON(http.StatusForbidden, ErrorResponse{Error: "this session is read-only"}) - return false, s - } - - if s.AllShows { - return true, s - } - - // query the database to get the showId and check if it’s listed in the session - if showID, err := api.store.GetPlaylistShowID(playlistID); err != nil { - if slices.Contains(s.Shows, showID) { - return true, s - } - } - - c.JSON(http.StatusForbidden, ErrorResponse{Error: "you are not allowed to access playlist: " + strconv.FormatUint(playlistID, 10)}) - return false, s -} - -func authorizeRequest(c *gin.Context, api *API) (bool, *auth.Session) { - // showId is passed as query parameter - if showID, _ := idFromString(c.Query("showId")); showID != 0 { - return authorizeRequestForShow(c, showID) - } - - // playlist-id is passed as url parameter - if playlistID, _ := idFromString(c.Param("playlist-id")); playlistID != 0 { - return authorizeRequestForPlaylist(c, playlistID, api) - } - - return authorizeRequestAllShows(c) -} - func authorizeRequestPrivilegedOrEntitled(c *gin.Context) (bool, *auth.Session) { s := getAuthSession(c.Request) diff --git a/store/files.go b/store/files.go index 1a99272..32bfaaf 100644 --- a/store/files.go +++ b/store/files.go @@ -124,14 +124,6 @@ func (st *Store) UpdateFileMetadata(showID uint64, id uint64, metadata map[strin return } -func (st *Store) updateFile(showID uint64, id uint64, values ...interface{}) (file *File, err error) { - file = &File{ID: id} - if err = st.db.Model(&file).Where("show_id = ?", showID).Updates(values).Error; err != nil { - return nil, err - } - return file, nil -} - func (st *Store) updateImportState(showID uint64, id uint64, state ImportState) (file *File, err error) { file = &File{ID: id} -- GitLab