Skip to content

[Expense Agent] Fix administrative recall history access - #10382

Open
Prangshuman Das (t-prda) wants to merge 13 commits into
mainfrom
fix/647041-administrative-recall-history-access
Open

[Expense Agent] Fix administrative recall history access#10382
Prangshuman Das (t-prda) wants to merge 13 commits into
mainfrom
fix/647041-administrative-recall-history-access

Conversation

@t-prda

@t-prda Prangshuman Das (t-prda) commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Summary

  • authorize pending expense report recall only for the captured submitter or a user with Unlimited Expense Approval
  • record non-submitter recalls as BC User activity with the Administrator role
  • keep administrative activity outside submitter and approver history participation
  • cover genuine submitter, mapped and unmapped administrator, and unauthorized recall scenarios

Validation

  • Expense Agent activity log tests passed after manual publication

Fixes AB#647041

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
@t-prda
Prangshuman Das (t-prda) requested a review from a team August 19, 2026 11:38
@t-prda
Prangshuman Das (t-prda) requested a review from a team as a code owner August 19, 2026 11:38
@github-actions github-actions Bot added AL: Apps (W1) Add-on apps for W1 Integration GitHub request for Integration area labels Aug 19, 2026
@github-actions github-actions Bot added this to the Version 29.0 milestone Aug 19, 2026
@t-prda Prangshuman Das (t-prda) added Ownership: Manual Preserve the manually selected team ownership and removed Integration GitHub request for Integration area labels Aug 19, 2026
@github-actions github-actions Bot added the Ownership: Needs Review Ownership is Other, low confidence, or needs manual correction label Aug 19, 2026
@t-prda

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
@t-prda

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
@github-actions

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
Comment thread src/Apps/W1/ExpenseAgent/test/src/ActivityLog/ExpenseActivityLogTest.Codeunit.al Outdated
Comment thread src/Apps/W1/ExpenseAgent/app/src/APIs/ActivityLog/ExpenseActivityLogAPI.Page.al Outdated
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
@t-prda

This comment has been minimized.

@github-actions

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
@t-prda

This comment has been minimized.

Comment thread src/Apps/W1/ExpenseAgent/app/src/APIs/ActivityLog/ExpenseActivityLogAPI.Page.al Outdated
@github-actions

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
@t-prda

Copy link
Copy Markdown
Contributor Author

Agentic PR Review - Round 2

Recommendation: Accept

What this PR does

The 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
ID Title Status Author response
S1 Keep administrator out of history filters Disputed The role filter is already combined with the scoped Expense User identity. Administrator events use a BC User actor, so this filter safely returns no matches.
New observations (commits since round 1)

None.

Risk assessment and necessity

Risk: 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.


[AI-PR-REVIEW] version=1 promptVersion=1 system=github pr=10382 round=2 by=t-prda at=2026-08-19T14:10:18.5573284Z lastSha=a49e7870000f17f02d1194a5768f0d558e9c2c26 reviewKey=9e40eb965e48f9be373a4d9fff0456c0ffeafa8f2f332d0566c76852970adf04 suggestions=S1@0dbcbc18:disputed parentRound=1

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
encimita
encimita previously approved these changes Aug 19, 2026
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
@t-prda
Prangshuman Das (t-prda) requested a review from a team as a code owner August 19, 2026 15:14
@t-prda Prangshuman Das (t-prda) removed the Ownership: Manual Preserve the manually selected team ownership label Aug 19, 2026
@t-prda Prangshuman Das (t-prda) added the Ownership: Manual Preserve the manually selected team ownership label Aug 19, 2026
@t-prda Prangshuman Das (t-prda) removed Ownership: Manual Preserve the manually selected team ownership Ownership: Needs Review Ownership is Other, low confidence, or needs manual correction labels Aug 19, 2026
@t-prda Prangshuman Das (t-prda) added the Ownership: Manual Preserve the manually selected team ownership label Aug 19, 2026
@github-actions github-actions Bot added the Ownership: Needs Review Ownership is Other, low confidence, or needs manual correction label Aug 19, 2026
@t-prda Prangshuman Das (t-prda) added the Finance GitHub request for Finance area label Aug 19, 2026
@github-actions github-actions Bot removed the Ownership: Needs Review Ownership is Other, low confidence, or needs manual correction label Aug 19, 2026
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$\textbf{🟡\ Medium\ Severity\ —\ Data\ Modeling}$

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

@github-actions

Copy link
Copy Markdown
Contributor

$\textbf{🟡\ Medium\ Severity\ —\ Testing}$

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

@alexei-dobriansky

Copy link
Copy Markdown
Contributor

Agentic PR Review - Round 1

Recommendation: Accept

What this PR does

This 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.

Suggestions

None.

Risk assessment and necessity

Risk: 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.


[AI-PR-REVIEW] version=1 promptVersion=2 system=github pr=10382 round=1 by=alexei-dobriansky at=2026-08-19T19:14:23Z lastSha=c5f317f0273ae3c5f2bca1340654bb69b77d5f78 reviewKey=4f910e678871fdfa1c2376774cf5438c2d11bd4a784195c2bca3a924466e201a suggestions=none

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

Labels

AL: Apps (W1) Add-on apps for W1 Finance GitHub request for Finance area Ownership: Manual Preserve the manually selected team ownership

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants