rymghosn opened a new pull request, #6717:
URL: https://github.com/apache/fineract/pull/6717

   ## Description
   
   JIRA: [FINERACT-2983](https://issues.apache.org/jira/browse/FINERACT-2983)
   
   **Root cause.** A datatable registered under a name such as `group` creates 
the permissions `CREATE_group`, `READ_group`, `UPDATE_group` and `DELETE_group` 
(`DatatableWriteServiceImpl.registerPermissions` builds them from the raw 
datatable name), which differ from the core `CREATE_GROUP` etc. only by case. 
`RoleWritePlatformServiceJpaRepositoryImpl.findPermissionByCode` (`PUT 
/roles/{roleId}/permissions`) and 
`PermissionWritePlatformServiceJpaRepositoryImpl.findPermissionInCollectionByCode`
 (`PUT /permissions`, maker-checker) return the first permission in `findAll()` 
for which `Permission.hasCode` (`equalsIgnoreCase`) is true. Which of the two 
rows that is depends on the unordered `findAll()` result, so a request for one 
code can act on its twin, and the response still answers 200, listing the 
requested code as changed.
   
   **Fix.** Both lookups return the permission whose code matches exactly, and 
fall back to the first case-insensitive match only when no exact code exists, 
so clients that send a code in a different case keep working.
   
   **Tests.** `RoleWritePlatformServiceJpaRepositoryImplTest` and 
`PermissionWritePlatformServiceJpaRepositoryImplTest` (3 tests each, the 
datatable permission first in `findAll()`): on `develop` the `CREATE_GROUP` 
test of each class fails; with the fix all 6 pass, including the 
case-insensitive fallback. `spotlessJavaCheck` clean.
   
   **Live check on a local stock instance** (`develop` `71c39730e9`, 
PostgreSQL). Datatable `group` on `m_group` (`POST /datatables`), a new role. 
In this database the datatable's rows come after the core ones in `findAll()`, 
so on `develop` the defect shows in the other direction:
   
   | request | develop | with this PR |
   |---|---|---|
   | `PUT /roles/{id}/permissions {"CREATE_GROUP":true,"CREATE_group":true}` | 
200, `changes` lists only `CREATE_GROUP`; `CREATE_group` not granted | 200, 
both granted |
   | `PUT /roles/{id}/permissions {"CREATE_group":false}` | 200, `changes` says 
`CREATE_group:false`, but `CREATE_GROUP` is revoked | 200, only `CREATE_group` 
revoked |
   | `PUT /roles/{id}/permissions {"CREATE_GROUP":false}` (both granted) | 200, 
both end up revoked | 200, only `CREATE_GROUP` revoked |
   | `PUT /permissions {"CREATE_group":true}` | 200, maker-checker enabled on 
`CREATE_GROUP` | `CREATE_GROUP` untouched |
   
   No API change: same endpoints, same request and response shape.
   
   ## Checklist
   
   Please make sure these boxes are checked before submitting your pull request 
- thanks!
   
   - [x] Write the commit message as per [our 
guidelines](https://github.com/apache/fineract/blob/develop/CONTRIBUTING.md#pull-requests)
   - [x] Acknowledge that we will not review PRs that are not passing the build 
_("green")_ - it is your responsibility to get a proposed PR to pass the build, 
not primarily the project's maintainers.
   - [x] Create/update [unit or integration 
tests](https://fineract.apache.org/docs/current/#_testing) for verifying the 
changes made.
   - [x] Follow our [coding 
conventions](https://cwiki.apache.org/confluence/display/FINERACT/Coding+Conventions).
   - [ ] Add required Swagger annotation and update API documentation at 
fineract-provider/src/main/resources/static/legacy-docs/apiLive.htm with 
details of any API changes (no API change)
   - [x] [This PR must not be a "code 
dump"](https://cwiki.apache.org/confluence/display/FINERACT/Pull+Request+Size+Limit).
 Large changes can be made in a branch, with assistance. Ask for help on the 
[developer mailing list](https://fineract.apache.org/#contribute).
   - [x] If merging this PR resolves a JIRA issue, I will mark that issue as 
resolved and set "Fix Version/s" appropriately.
   - [x] I followed the [AI 
Policy](https://github.com/apache/fineract/blob/develop/CONTRIBUTING.md#ai-policy).
   
   Your assigned reviewer(s) will follow our [guidelines for code 
reviews](https://cwiki.apache.org/confluence/display/FINERACT/Code+Review+Guide).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to