-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix JukeboxRole logic in GetUser to respect AdminOnly setting #4170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…plication - 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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @deluan, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
Summary of Changes
Hello team, gemini-code-assist here to provide a summary of this pull request. This PR primarily addresses a bug in the GetUser
Subsonic endpoint where the jukeboxRole
was incorrectly set to true
for all users when the jukebox feature was enabled, regardless of the Jukebox.AdminOnly
configuration setting. It also includes a refactoring to consolidate user response logic and adds comprehensive tests to cover the fix and ensure consistency between GetUser
and GetUsers
endpoints.
Highlights
- Bug Fix: JukeboxRole Logic: Corrected the logic in the
GetUser
endpoint to properly respect theconf.Server.Jukebox.AdminOnly
setting when determining thejukeboxRole
for a user. The logic is now!conf.Server.Jukebox.AdminOnly || user.IsAdmin
. - Code Refactoring: Extracted the common logic for building a user response object into a new helper function
buildUserResponse
. BothGetUser
andGetUsers
now utilize this function, reducing code duplication. This refactoring also fixes an inconsistency whereGetUsers
was usingloggedUser.Name
instead ofloggedUser.UserName
. - Comprehensive Tests Added: Introduced a new test file (
server/subsonic/users_test.go
) with tests covering the happy path (consistency betweenGetUser
andGetUsers
) and specificDescribeTable
tests to validate theJukeboxRole
logic across all relevant configuration and user type scenarios.
Changelog
- server/subsonic/users.go
- Added new helper function
buildUserResponse
(lines 12-29) to centralize user response creation logic. - Updated
GetUser
(lines 32-42) to use the newbuildUserResponse
helper. - Updated
GetUsers
(lines 46-53) to use the newbuildUserResponse
helper, fixing theUsername
field inconsistency and applying the correctJukeboxRole
logic via the helper.
- Added new helper function
- server/subsonic/users_test.go
- Added a new test file (
users_test.go
) for the Subsonic users API. - Included a 'Happy path' test (lines 33-78) to verify consistency between
GetUser
andGetUsers
responses. - Added a
DescribeTable
test (lines 80-95) specifically for validating theJukeboxRole
logic under different configurations and user types.
- Added a new test file (
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
A bug did hide,
Jukebox role defied.
Refactor came,
Tests played the game,
Now logic's applied.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This is an excellent pull request that effectively addresses the JukeboxRole
bug and significantly improves code maintainability through refactoring. The introduction of the buildUserResponse
helper function is a great way to centralize user response logic and eliminate duplication. The fix for the username field inconsistency is also well-handled by this refactoring.
The added tests are comprehensive and very well-structured, particularly the use of DescribeTable
for testing various jukebox permission scenarios. This ensures the fix is robust and covers all relevant cases. The "Happy path" test also provides good confidence in the consistency between GetUser
and GetUsers
.
The code adheres to common Go best practices and is clear and easy to understand. The PR description itself is also very thorough and clearly outlines the changes and their rationale.
Overall, this is a high-quality contribution.
Summary of Findings
- Global Configuration Access in Helper Function: The
buildUserResponse
function directly accesses the globalconf.Server
variable (e.g.,conf.Server.Jukebox
,conf.Server.EnableDownloads
). While this is consistent with some existing patterns in the codebase and works correctly, an alternative approach for future consideration could be to pass the necessary configuration values as parameters tobuildUserResponse
. This would make the function more self-contained, improve its testability in complete isolation (without relying on global state setup likeconfigtest.SetupConfig()
), and make its dependencies more explicit. This is a minor point and considered low severity, thus no specific review comment was added per the review settings.
Merge Readiness
The pull request is in excellent shape. The bug fix is correct, the refactoring improves the codebase, and the tests are thorough. From my perspective, after considering the findings, the code is ready to be merged. As I am an AI assistant, I am not authorized to approve pull requests; please ensure it undergoes the standard review and approval process by project maintainers.
Description
Fixes the bug where
GetUser
was incorrectly settingjukeboxRole
totrue
for all users when jukebox was enabled, regardless of theJukebox.AdminOnly
configuration setting.This PR also refactors the code to eliminate duplication between
GetUser
andGetUsers
methods.Changes Made
🐛 Primary Fix: JukeboxRole Logic
GetUser
method to properly implement jukebox role logic:!conf.Server.Jukebox.AdminOnly || user.IsAdmin
JukeboxRole = conf.Server.Jukebox.Enabled
ignoring the AdminOnly setting🔄 Code Refactoring
buildUserResponse()
helper function to eliminate ~30 lines of duplicated code betweenGetUser
andGetUsers
GetUsers
was incorrectly usingloggedUser.Name
instead ofloggedUser.UserName
✅ Added Comprehensive Tests
DescribeTable
to cover all scenarios:jukeboxRole: false
jukeboxRole: true
(for all users)jukeboxRole: true
(admin only),jukeboxRole: false
(regular users)Testing
All existing tests pass, and new comprehensive tests cover the fixed functionality:
The new tests specifically validate that:
jukeboxRole: false
whenJukebox.AdminOnly = true
jukeboxRole: true
when jukebox is enabledGetUser
andGetUsers
return identical user data (consistency)Fixes
Closes #4160
Breaking Changes
None. This is a bug fix that corrects the behavior to match the expected specification.
Before this fix:
GetUser
ignoredJukebox.AdminOnly
settingjukeboxRole: true
whenJukebox.AdminOnly = true
After this fix:
GetUser
properly respectsJukebox.AdminOnly
settingjukeboxRole: false
whenJukebox.AdminOnly = true