Skip to content
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

[Bug]: Creating new user incorrectly generates warning for tag access control #3358

Closed
nichwall opened this issue Sep 2, 2024 · 2 comments
Closed
Labels
bug Something isn't working

Comments

@nichwall
Copy link
Contributor

nichwall commented Sep 2, 2024

What happened?

Created a new user with or without access control by tags. A warning is incorrectly logged, but access control is correctly applied.

Investigating in the code, looks like this is specifically due to line 162 because the selectedTagNotAccessible is an array and handled before the loop over the request keys. Note that this only applies for tags, access control by libraries does not generate this warning.

let reqItemTagsSelected = req.body.itemTagsSelected || req.body.permissions?.itemTagsSelected
if (reqItemTagsSelected && (!Array.isArray(reqItemTagsSelected) || reqItemTagsSelected.some((tagId) => typeof tagId !== 'string'))) {
Logger.warn(`[UserController] create: Invalid itemTagsSelected value: ${reqItemTagsSelected}`)
reqItemTagsSelected = null
}
if (req.body.permissions?.itemTagsSelected || req.body.permissions?.librariesAccessible) {
delete req.body.permissions.itemTagsSelected
delete req.body.permissions.librariesAccessible
}
// Map permissions
const permissions = Database.userModel.getDefaultPermissionsForUserType(userType)
if (req.body.permissions && typeof req.body.permissions === 'object') {
for (const key in req.body.permissions) {
if (permissions[key] !== undefined) {
if (typeof req.body.permissions[key] !== 'boolean') {
Logger.warn(`[UserController] create: Invalid permission value for key ${key}. Should be boolean`)
} else {
permissions[key] = req.body.permissions[key]
}
} else {
Logger.warn(`[UserController] create: Invalid permission key: ${key}`)
}
}
}
permissions.itemTagsSelected = reqItemTagsSelected || []
permissions.librariesAccessible = reqLibrariesAccessible || []

What did you expect to happen?

No warning for creating/updating a user with tag access control.

Steps to reproduce the issue

  1. Create new user and disable "User can access all tags"

Audiobookshelf version

v2.13.2

How are you running audiobookshelf?

Docker

What OS is your Audiobookshelf server hosted from?

Other (list in "Additional Notes" box)

If the issue is being seen in the UI, what browsers are you seeing the problem on?

None

Logs

[UserController] create: Invalid permission key: selectedTagsNotAccessible

Additional Notes

Synology NAS

@nichwall nichwall added the bug Something isn't working label Sep 2, 2024
@nichwall nichwall changed the title [Bug]: [UserController] create: Invalid permission key: selectedTagsNotAccessible [Bug]: Creating new user incorrectly generates warning for tag access control Sep 2, 2024
@nichwall
Copy link
Contributor Author

nichwall commented Sep 2, 2024

Update, the "tag invert" is not stored correctly. Related to #3365

@nichwall
Copy link
Contributor Author

nichwall commented Sep 2, 2024

Well, I went on a wild goose chase because I misunderstood the error.
Duplicate of #3365

@nichwall nichwall closed this as not planned Won't fix, can't repro, duplicate, stale Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant