ThevinuJ opened a new pull request, #6798: URL: https://github.com/apache/fineract/pull/6798
## Description Follow-up to FINERACT-2639 (#6698), covering the remaining operations of [FINERACT-2982](https://issues.apache.org/jira/browse/FINERACT-2982). Account activation is handled in #6777 and capitalized income by another contributor, as agreed on the ticket, so neither is included here. Users could still post money-moving operations on accounts belonging to offices outside their hierarchy. This PR adds the same office-hierarchy check that #6698 introduced to the remaining write paths. The PR is split into one commit per area (loans, share accounts, working capital loans) for review. ### Summary of Changes * **Loans:** buy-down fee, re-age / undo, re-amortize / undo, and contract termination / loan withdrawal plus their undo (`LoanEarlyTerminationServiceImpl`) now load the loan with `assembleFromInUserScope`. Interest pause (create / update / delete, by id or external id) checks the loan's office in its shared `process*` methods, because it loads the loan by external id or without lazy collections. * **Share accounts:** new `ShareAccountRepositoryWrapper.findOneInUserScope`, which checks the client's office, used by every write operation on an existing account: approve, reject, undo approval, activate, apply / approve / reject additional shares, redeem, close, update. * **Working capital loans:** disbursal, undo disbursal, repayment, goodwill credit, payout refund, credit balance refund, discount fee and its adjustment, transaction undo / adjust / adjust-by-delta, charge add / adjust / waive, charge-off / undo, write-off / undo, and recovery payment now check the loan's office. The module has no repository wrapper, so the check is inline right after each load; happy to extract a helper if preferred. ### What Remains Unchanged * **Read and preview operations** (re-age and re-amortize previews, account reads). * **Scheduled jobs and COB**, such as share dividend posting and working capital loan COB steps. None of the changed methods is called from them; they are reached only through command handlers. * **Working capital loan operations that do not move money:** approve, undo approval, reject, modify, delete, mark as fraud, rate change, and delinquency / breach / near-breach actions. * **Share account notes**, which keep using `findOneWithNotFoundDetection`. ### Behaviour Change A non-head-office user can no longer perform these operations on accounts outside their office hierarchy and gets 403 instead. Users in the account's office or a parent office, including head-office users, are unaffected. This may be worth a line in the release notes. ### Testing * **Unit:** new `ShareAccountRepositoryWrapperTest`. Working capital loan service tests whose mocked loan had no office now stub `loan.getOffice()`. All working capital loan unit tests pass. * **Integration (PostgreSQL):** new `LoanOperationsOfficeHierarchyAccessIntegrationTest` (contract termination, buy-down fee, re-age, interest pause), `ShareAccountOfficeHierarchyAccessIntegrationTest` and `WorkingCapitalLoanOfficeHierarchyAccessIntegrationTest`. The sibling-office user is given the operation's permission, so the 403 comes from the office check; each test asserts the status, the `error.msg.not.authorized` code and the hierarchy message, then checks that a user from the account's office succeeds. The existing `LoanContractTerminationTest` also passes. * `:fineract-provider:cucumber`: 150/150 scenarios pass. ### Noticed While Testing (not changed here) The interest pause API checks the read permission `"UPDATE LOAN"` (`LoanInterestPauseApiResource`), which resolves to the code `READ_UPDATE LOAN`. No such permission exists, so only users with `ALL_FUNCTIONS_READ` can reach the endpoint; a role with just `CREATE_INTEREST_PAUSE` gets 403. The integration test grants `ALL_FUNCTIONS_READ` for that reason. Happy to raise a separate ticket. ## Checklist - [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 changes) - [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). - [ ] If merging this PR resolves a JIRA issue, I will mark that issue as resolved and set "Fix Version/s" appropriately. (FINERACT-2982 stays open until #6777 and the capitalized income PR are merged) - [x] I followed the [AI Policy](https://github.com/apache/fineract/blob/develop/CONTRIBUTING.md#ai-policy). -- 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]
