mirror of
https://github.com/navidrome/navidrome.git
synced 2025-07-14 15:41:18 +03:00
- Fix GetUser JukeboxRole to properly respect AdminOnly setting - Extract buildUserResponse helper to eliminate duplication between GetUser and GetUsers - Fix username field inconsistency (GetUsers was using loggedUser.Name instead of UserName) - Add comprehensive tests covering jukebox role permissions and consistency between methods Fixes #4160
55 lines
1.5 KiB
Go
55 lines
1.5 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"
|
|
)
|
|
|
|
// 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,
|
|
}
|
|
|
|
if conf.Server.Jukebox.Enabled {
|
|
userResponse.JukeboxRole = !conf.Server.Jukebox.AdminOnly || user.IsAdmin
|
|
}
|
|
|
|
return userResponse
|
|
}
|
|
|
|
// TODO This is a placeholder. The real one has to read this info from a config file or the database
|
|
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
|
|
}
|