Fix activity log indirect permissions - #10346
Conversation
Allow human and agent roles to insert, reassign, and delete activity rows only through permission-bearing application code. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: d9178a5c-c5ff-43a4-b9cb-877ec18618fa
|
The new local procedure VerifyPermissionSetCanInsertActivity lowers the execution context with LibraryLowerPermissions.SetExactPermissionSet and only restores it afterward via SetOutsideO365Scope; Initialize() does not unconditionally reset permissions at the start of the run. If an assertion or the LogExpenseReportEvent call fails/errors between SetExactPermissionSet and SetOutsideO365Scope, the lowered permission set leaks into whatever test runs next in this codeunit, causing unrelated tests to fail for the wrong reason. The codebase's own established pattern for this (Expense Event Subs. Perm. Test.Initialize) calls RestoreFullPermissions()/SetOutsideO365Scope() unconditionally at the very start of Initialize(), before the IsInitialized early-exit, specifically to guard against this leak; ExpenseActivityLogTest.Initialize() was not updated to do the same when permission-lowering was introduced into this codeunit. Suggested fix (apply manually — could not be anchored as a one-click suggestion): local procedure Initialize()
begin
LibraryTestInitialize.OnTestInitialize(Codeunit::"Expense Activity Log Test");
LibraryLowerPermissions.SetOutsideO365Scope();
if IsInitialized then
exit;
LibraryExpense.SetupNumberSeriesInExpenseMgmt();
IsInitialized := true;
LibraryTestInitialize.OnAfterTestSuiteInitialize(Codeunit::"Expense Activity Log Test");
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.33.4 |
Keep functional activity tests permission-disabled and verify indirect entitlements in a dedicated restrictive codeunit. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: d9178a5c-c5ff-43a4-b9cb-877ec18618fa
Rename the existing permission test codeunit and include activity-log entitlement scenarios there. 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
|
The new deletion-guard helpers (CreateExpenseForDeletionGuard, CreateExpenseReportForDeletionGuard, CreatePostedExpenseReportForDeletionGuard) hand-roll Expense, Expense Report Header, and Posted Expense Report Header fixtures with Init/Insert and ad-hoc GUID-derived keys instead of using supported library-backed creation flows (e.g. Library - Expense). This bypasses table validation and prerequisite setup that production-valid records go through, so the permission tests may pass against record shapes that would never be reachable through normal application flows, weakening the guarantee the tests provide. Knowledge: Posting this finding as an issue comment because inline comment placement failed. 👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v1.33.4 |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: d9178a5c-c5ff-43a4-b9cb-877ec18618fa
Closed with RestoreFullPermissions(); |
Pull request was closed
|
The new deletion-guard fixtures hand-roll business records with Init(), invented primary keys, and Insert(false) instead of building them through the test library/domain helpers. That makes the permission tests brittle: they can pass on records that skipped normal validation and will start failing for setup reasons when these tables gain required fields or validation logic. Knowledge: Posting this finding as an issue comment because inline comment placement failed. 👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v1.34.4 |
Agentic PR Review - Round 1Recommendation: Accept with SuggestionsWhat this PR doesThis PR grants indirect write permissions on Expense Activity Log Entry to the Expense Management edit path and to the Expense Agent data role. The main insert path is correct: callers still do not get direct write access, and Expense Activity Log Mgt. already carries the SuggestionsS1 - Cover indirect modify and delete rights Risk assessment and necessityRisk: The direct write surface stays closed because the tests assert WritePermission() is false, and activity writes still go through Expense Activity Log Mgt.. The remaining risk is coverage: posting reassigns activity entries to posted reports, and delete triggers remove entries through the same table permissions. Necessity: The change is needed to fix entitlement failures for users who are allowed to create expense lifecycle activity entries. The scope is small and matches the existing permission hierarchy for D365 BASIC, Expense Management edit, and the Expense Agent role.
|
Summary
Fix SaaS entitlement failures when Expense Agent or Expense Management users create lifecycle activity entries.
Expense Mgmt. Editindirect insert/modify/delete permission onExpense Activity Log Entry.Expense Agent - Datadirect read plus indirect insert/modify/delete (Rimd).Expense Activity Log Mgt.; no caller receives direct insert, modify, or delete access.D365 BASIChuman user and the compositeExpense Agentrole.The existing permission hierarchy carries the fix to users who can create/edit/delete expense reports:
Expense Mgmt. AdminincludesExpense Mgmt. Edit.Expense Mgmt. Edit.Ronly.Issue
Fixes AB#647154
Validation
rimd).Expense Mgmt. Editwithout its Base Application role.