Deluan 94d2696c84 feat(subsonic): populate Folder field with user's accessible library IDs
Added functionality to populate the Folder field in GetUser and GetUsers API responses
with the library IDs that the user has access to. This allows Subsonic API clients
to understand which music folders (libraries) a user can access for proper
content filtering and UI presentation.

Signed-off-by: Deluan <deluan@navidrome.org>
2025-07-29 18:00:33 -04:00

56 lines
1.6 KiB
Go

package subsonic
import (
"net/http"
"github.com/navidrome/navidrome/conf"
"github.com/navidrome/navidrome/model"
"github.com/navidrome/navidrome/model/request"
"github.com/navidrome/navidrome/server/subsonic/responses"
"github.com/navidrome/navidrome/utils/slice"
)
// buildUserResponse creates a User response object from a User model
func buildUserResponse(user model.User) responses.User {
userResponse := responses.User{
Username: user.UserName,
AdminRole: user.IsAdmin,
Email: user.Email,
StreamRole: true,
ScrobblingEnabled: true,
DownloadRole: conf.Server.EnableDownloads,
ShareRole: conf.Server.EnableSharing,
Folder: slice.Map(user.Libraries, func(lib model.Library) int32 { return int32(lib.ID) }),
}
if conf.Server.Jukebox.Enabled {
userResponse.JukeboxRole = !conf.Server.Jukebox.AdminOnly || user.IsAdmin
}
return userResponse
}
func (api *Router) GetUser(r *http.Request) (*responses.Subsonic, error) {
loggedUser, ok := request.UserFrom(r.Context())
if !ok {
return nil, newError(responses.ErrorGeneric, "Internal error")
}
response := newResponse()
user := buildUserResponse(loggedUser)
response.User = &user
return response, nil
}
func (api *Router) GetUsers(r *http.Request) (*responses.Subsonic, error) {
loggedUser, ok := request.UserFrom(r.Context())
if !ok {
return nil, newError(responses.ErrorGeneric, "Internal error")
}
user := buildUserResponse(loggedUser)
response := newResponse()
response.Users = &responses.Users{User: []responses.User{user}}
return response, nil
}