-
Notifications
You must be signed in to change notification settings - Fork 442
[Agent Archiving] Payables and Expense agent implementation for IAgentArchiving #10460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
77e7e9c
43e74c7
a0b08e5
2d90809
83116b9
1ad61a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // ------------------------------------------------------------------------------------------------ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. See License.txt in the project root for license information. | ||
| // ------------------------------------------------------------------------------------------------ | ||
|
|
||
| namespace Microsoft.ExpenseAgent; | ||
|
|
||
| using System.Agents; | ||
|
|
||
| codeunit 7104 "EA Agent Archiving" implements IAgentArchiving | ||
| { | ||
| Access = Internal; | ||
| InherentEntitlements = X; | ||
| InherentPermissions = X; | ||
|
|
||
| procedure IsArchivingSupported(): Boolean | ||
| begin | ||
| exit(false); | ||
| end; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // ------------------------------------------------------------------------------------------------ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. See License.txt in the project root for license information. | ||
| // ------------------------------------------------------------------------------------------------ | ||
|
|
||
| namespace Microsoft.Agent.PayablesAgent; | ||
|
|
||
| using System.Agents; | ||
|
|
||
| codeunit 3319 "PA Agent Archiving" implements IAgentArchiving | ||
| { | ||
| Access = Internal; | ||
| InherentEntitlements = X; | ||
| InherentPermissions = X; | ||
|
|
||
| procedure IsArchivingSupported(): Boolean | ||
| begin | ||
| exit(false); | ||
| end; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,13 +67,37 @@ codeunit 4301 "Agent Impl." | |
| if Agent.Substate = Agent.Substate::Archived then | ||
| exit; // Archiving is terminal; idempotent no-op avoids the platform "archived agent cannot be modified" error on re-archive. | ||
|
|
||
| if not IsArchivingSupported(Agent) then | ||
|
krupybalu marked this conversation as resolved.
|
||
| Error(ArchivingNotSupportedErr, Agent."Agent Metadata Provider"); | ||
|
|
||
| if Agent.State <> Agent.State::Disabled then | ||
| Error(DeactivateBeforeArchivingErr); | ||
|
|
||
| Agent.Substate := Agent.Substate::Archived; | ||
| Agent.Modify(true); | ||
| end; | ||
|
|
||
| procedure IsArchivingSupported(AgentUserSecurityID: Guid): Boolean | ||
| var | ||
| Agent: Record Agent; | ||
| begin | ||
| GetAgent(Agent, AgentUserSecurityID); | ||
|
|
||
| exit(IsArchivingSupported(Agent)); | ||
| end; | ||
|
|
||
| local procedure IsArchivingSupported(Agent: Record Agent): Boolean | ||
|
krupybalu marked this conversation as resolved.
|
||
| var | ||
| AgentArchiving: Interface IAgentArchiving; | ||
| begin | ||
| if IsNullGuid(Agent."User Security ID") then | ||
| exit(false); | ||
|
|
||
| AgentArchiving := Agent."Agent Metadata Provider"; | ||
|
krupybalu marked this conversation as resolved.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AgentImpl.IsArchivingSupported(Agent) (local overload) does Agent judgement — not directly backed by a BCQuality knowledge article. 👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v1.35.4 |
||
|
|
||
| exit(AgentArchiving.IsArchivingSupported()); | ||
| end; | ||
|
|
||
| procedure IsArchived(AgentUserSecurityID: Guid): Boolean | ||
| var | ||
| Agent: Record Agent; | ||
|
|
@@ -644,6 +668,7 @@ codeunit 4301 "Agent Impl." | |
| AgentDoesNotExistErr: Label 'Agent does not exist.'; | ||
| AgentArchivedCannotBeModifiedErr: Label 'The agent is archived and cannot be modified.'; | ||
| DeactivateBeforeArchivingErr: Label 'Deactivate the agent before archiving it.'; | ||
| ArchivingNotSupportedErr: Label 'Archiving agents of type ''%1'' is not supported.', Comment = '%1 = the type of the agent.'; | ||
| AutoLbl: Label 'Auto'; | ||
| NoActiveAgentsErr: Label 'There are no active agents setup on the system.'; | ||
| NoAgentsAvailableNotificationLbl: Label 'Business Central agents are currently not available in your country.'; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ codeunit 133961 "Agent Test" | |
| LibraryVariableStorage: Codeunit "Library - Variable Storage"; | ||
| DeactivateBeforeArchivingErr: Label 'Deactivate the agent before archiving it.', Locked = true; | ||
| AgentArchivedCannotBeModifiedErr: Label 'The agent is archived and cannot be modified.', Locked = true; | ||
| ArchivingNotSupportedErr: Label 'is not supported', Locked = true; | ||
|
|
||
| local procedure Initialize() | ||
| begin | ||
|
|
@@ -993,6 +994,7 @@ codeunit 133961 "Agent Test" | |
|
|
||
| Agent.Deactivate(AgentId); | ||
| Assert.IsFalse(Agent.IsArchived(AgentId), 'Agent should not be archived initially'); | ||
| Assert.IsTrue(Agent.IsArchivingSupported(AgentId), 'Archiving should be supported for a type that does not opt out'); | ||
|
|
||
| // [WHEN] Archiving the agent | ||
| Agent.Archive(AgentId); | ||
|
|
@@ -1005,6 +1007,37 @@ codeunit 133961 "Agent Test" | |
| Assert.AreEqual(AgentRecord.Substate::Archived, AgentRecord.Substate, 'Agent substate should be Archived'); | ||
| end; | ||
|
|
||
| [Test] | ||
| procedure ArchiveAgentOfUnsupportedTypeErrors() | ||
| var | ||
| AgentRecord: Record Agent; | ||
| TempAgentAccessControl: Record "Agent Access Control" temporary; | ||
| Any: Codeunit Any; | ||
| AgentId: Guid; | ||
| AgentUserName: Code[50]; | ||
| begin | ||
| Initialize(); | ||
|
|
||
| // [SCENARIO] Archiving an agent whose type opts out of archiving is rejected | ||
|
|
||
| // [GIVEN] An agent of a type that reports archiving as unsupported | ||
| AgentUserName := CopyStr(Any.AlphanumericText(MaxStrLen(AgentRecord."User Name")), 1, MaxStrLen(AgentRecord."User Name")); | ||
| AgentId := Agent.Create( | ||
| "Agent Metadata Provider"::"SDK Mock Agent No Archiving", | ||
| AgentUserName, | ||
| CopyStr(Any.AlphanumericText(80), 1, 80), | ||
| TempAgentAccessControl); | ||
|
|
||
| // [THEN] Archiving is reported as unsupported for that agent | ||
| Assert.IsFalse(Agent.IsArchivingSupported(AgentId), 'Archiving should not be supported for this agent type'); | ||
|
|
||
| // [WHEN] Archiving the agent | ||
| // [THEN] An error is raised and the agent is not archived | ||
| asserterror Agent.Archive(AgentId); | ||
| Assert.ExpectedError(ArchivingNotSupportedErr); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This negative test follows Knowledge: 👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v1.35.4 |
||
| Assert.IsFalse(Agent.IsArchived(AgentId), 'Agent should not be archived'); | ||
| end; | ||
|
|
||
| [Test] | ||
| procedure ArchiveActiveAgentErrors() | ||
| var | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.