Skip to content

[5.4] API users/levels: Validate group IDs in PATCH/POST requests#47455

Open
adarshdubey03 wants to merge 4 commits intojoomla:5.4-devfrom
adarshdubey03:fix-46832-api-users-levels-validate-group-ids
Open

[5.4] API users/levels: Validate group IDs in PATCH/POST requests#47455
adarshdubey03 wants to merge 4 commits intojoomla:5.4-devfrom
adarshdubey03:fix-46832-api-users-levels-validate-group-ids

Conversation

@adarshdubey03
Copy link
Copy Markdown
Contributor

Pull Request resolves #46832 .

  • I read the Generative AI policy and my contribution is either not created with the help of AI or is compatible with the policy and GNU/GPL 2 or later.

Summary of Changes

Validates the rules field in the Users Access Levels API to ensure only existing user group IDs are accepted. Previously, invalid values were silently stored

Testing Instructions

follow #46832

Actual result BEFORE applying this Pull Request

Invalid values were accepted and written to the database, for eg invalid { "rules": [99999] } gets 200 ok
{
"links": {
"self": "http://localhost/joomla-cms/api/index.php/v1/users/levels/7"
},
"data": {
"type": "levels",
"id": "7",
"attributes": {
"id": 7,
"title": "API Test Level",
"rules": [
99999
]
}
}
}

Expected result AFTER applying this Pull Request

Invalid input is rejected with a validation error and only valid existing group ids are accepted, and the database remains consistent, for eg invalid invalid { "rules": [99999] } gets 400 bad request,
{
"errors": [
{
"title": "Invalid Group"
}
]
}

Link to documentations

Please select:

  • Documentation link for guide.joomla.org:

  • No documentation changes for guide.joomla.org needed

  • Pull Request link for manual.joomla.org:

  • No documentation changes for manual.joomla.org needed

@richard67
Copy link
Copy Markdown
Member

@adarshdubey03 Please check the result of the CI check actions on GitHub. Code style checks are failing, and system tests are failing, too.

@adarshdubey03
Copy link
Copy Markdown
Contributor Author

Hello @richard67 i implemented validation for the rules field following the documentation for the error handling https://manual.joomla.org/migrations/54-60/errorhandling/.

instead of deprecated $this->setError(), i implemented the documented based approach and that produces the correct API responses, but CI fails because of PHPStan
so what would be the correct way to deal with that?

@richard67
Copy link
Copy Markdown
Member

Hello @richard67 i implemented validation for the rules field following the documentation for the error handling https://manual.joomla.org/migrations/54-60/errorhandling/.

instead of deprecated $this->setError(), i implemented the documented based approach and that produces the correct API responses, but CI fails because of PHPStan so what would be the correct way to deal with that?

Maybe @Hackwar can advise if you should add exclusions to the phpstan baseline file (I could help with that if that’s the way to go) or if you should change error handling of your code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

API webservices: PATCH/POST users/levels does not check group IDs

3 participants