[Expense Agent] Fix administrative recall history access - #10382
[Expense Agent] Fix administrative recall history access#10382Prangshuman Das (t-prda) wants to merge 13 commits into
Conversation
Classify recalls by non-submitters with unlimited expense approval as administrative actions and keep those actors outside submitter and approver history participation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: d9178a5c-c5ff-43a4-b9cb-877ec18618fa
This comment has been minimized.
This comment has been minimized.
Use field metadata in the recall authorization error and reject Administrator as an expense-user history filter role. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: d9178a5c-c5ff-43a4-b9cb-877ec18618fa
This comment has been minimized.
This comment has been minimized.
Append activity-history filters with the correct query separator so API tests work with multi-tenant URLs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: d9178a5c-c5ff-43a4-b9cb-877ec18618fa
This comment has been minimized.
This comment has been minimized.
Move multi-tenant-aware query parameter composition into the Expense Agent test library for reuse by API tests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: d9178a5c-c5ff-43a4-b9cb-877ec18618fa
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: d9178a5c-c5ff-43a4-b9cb-877ec18618fa
Grant the required User Setup read permission, validate history roles by enum value, and strengthen recall authorization tests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: d9178a5c-c5ff-43a4-b9cb-877ec18618fa
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Prevent the audit API from exposing activity rows from transactions that may still roll back. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: d9178a5c-c5ff-43a4-b9cb-877ec18618fa
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Remove review-driven activity API changes and retain separate coverage for ordinary and unlimited submitter recalls. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: d9178a5c-c5ff-43a4-b9cb-877ec18618fa
Agentic PR Review - Round 2Recommendation: AcceptWhat this PR doesThe new commits improve localization and add explicit coverage for submitters who do and do not have Unlimited Expense Approval. The final code keeps submitter identity ahead of administrator capability and preserves the original authorization and actor-attribution fix. Status of previous suggestions
New observations (commits since round 1)None. Risk assessment and necessityRisk: The change remains limited to pending-report recall authorization and activity attribution. Authorization runs before mutation, administrative events cannot grant Expense User history participation, and the added tests cover mixed submitter and administrator capabilities. Necessity: The fix prevents administrative recall from being blocked or incorrectly recorded as a submitter action. The current scope and regression coverage are appropriate.
|
Use the shared document-approval library for current-user setup creation in recall authorization tests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: d9178a5c-c5ff-43a4-b9cb-877ec18618fa
Avoid the new AA0139 warning when passing the current user ID to the shared approval fixture helper. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: d9178a5c-c5ff-43a4-b9cb-877ec18618fa
Avoid the Windows SID lookup in Library Document Approvals, which can select a different user and attempt to insert duplicate ADMIN setup records in localized test environments. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: d9178a5c-c5ff-43a4-b9cb-877ec18618fa
| var | ||
| UserSetup: Record "User Setup"; | ||
| begin | ||
| if ExpenseReportHeader."Submitter Expense User Id" = UserId() then |
There was a problem hiding this comment.
GetRecallActorRole() authorizes the original submitter by comparing ExpenseReportHeader."Submitter Expense User ID" (a Code[50] snapshot of the BC user name taken at Submit time) with UserId(). If the BC user is later renamed, the stored snapshot no longer matches UserId(), so the original submitter can no longer recall their own report as "Submitter" and falls through to the "Unlimited Expense Approval" administrator check (or is denied outright). This mirrors an existing pattern elsewhere in the codeunit, but it is exercised directly by this new authorization gate, so a user rename between submission and recall silently changes who is allowed to self-recall a report. Consider keying the comparison off an immutable identifier (e.g. the BC User's SystemId/User Security ID) captured at submission time instead of the mutable user name.
Agent judgement — not directly backed by a BCQuality knowledge article.
👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v1.34.4
|
SetCurrentUserUnlimitedExpenseApproval hand-rolls a "User Setup" fixture with Init/Insert instead of using the existing test-library helpers. The Expense Agent test app already depends on Tests-TestLibraries, which ships codeunit 131352 "Library - Document Approvals" with CreateOrFindUserSetup(var UserSetup; UserName), and LibraryExpense.Codeunit.al (in this same test project) already has SetUnlimitedExpenseApprovalLimits/SetLimitedExpenseApprovalLimits(var UserSetup). Hand-rolling Init/Insert bypasses that library-owned setup and will silently break if the User Setup table gains a new mandatory field. Suggested fix (apply manually — could not be anchored as a one-click suggestion): local procedure SetCurrentUserUnlimitedExpenseApproval(UnlimitedExpenseApproval: Boolean)
var
UserSetup: Record "User Setup";
LibraryDocumentApprovals: Codeunit "Library - Document Approvals";
begin
LibraryDocumentApprovals.CreateOrFindUserSetup(UserSetup, UserId());
if UnlimitedExpenseApproval then
LibraryExpense.SetUnlimitedExpenseApprovalLimits(UserSetup)
else
LibraryExpense.SetLimitedExpenseApprovalLimits(UserSetup);
end;Knowledge: Line mapping was unavailable, so this was posted as an issue comment. 👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v1.34.4 |
Agentic PR Review - Round 1Recommendation: AcceptWhat this PR doesThis PR tightens recall of pending expense reports. A pending report can now be recalled by the captured submitter, or by a user with Unlimited Expense Approval. Administrative recalls are logged as BC User activity with the new Administrator actor role. The change checks the actor before changing the report status, so an unauthorized recall errors before status or history is updated. The submitter path still logs the captured submitter, while the administrator path uses the BC User record and does not satisfy submitter or approver history filters. The added tests cover submitter precedence, mapped and unmapped administrators, and unauthorized recall. SuggestionsNone. Risk assessment and necessityRisk: The touched area affects expense approval history and access to activity records. The codeunit and enum are internal, and the behavior change is limited to pending-report recall. App build checks were successful at review time; the GitHub unit-test matrix was still running. Necessity: The linked bug is valid because a non-submitter recall could grant incorrect submitter history access. The scope is right: it changes recall authorization and history attribution without changing posting or approval amount logic.
|
Summary
Validation
Fixes AB#647041