From 500994400628c1722eecc8287dd47cdfbc38e809 Mon Sep 17 00:00:00 2001 From: Darrick Date: Mon, 11 Nov 2024 15:10:31 +0100 Subject: [PATCH] [Email/RetPol] Harden retention policy for Email Inbox setup. (#2324) #### Summary During upgrade and data migration, for some environments, they are running into an error that the Email Inbox is not in the allowed list of tables. This PR fixes it by combining both upgrade functions into one, and exiting if the table is not in the list of allowed tables. #### Work Item(s) Fixes [AB#556484](https://dynamicssmb2.visualstudio.com/1fcb79e7-ab07-432a-a3c6-6cf5a88ba4a5/_workitems/edit/556484) --- .../App/Email/src/EmailInstaller.Codeunit.al | 29 ++++--------------- 1 file changed, 5 insertions(+), 24 deletions(-) diff --git a/src/System Application/App/Email/src/EmailInstaller.Codeunit.al b/src/System Application/App/Email/src/EmailInstaller.Codeunit.al index 42949a2979..692a12320f 100644 --- a/src/System Application/App/Email/src/EmailInstaller.Codeunit.al +++ b/src/System Application/App/Email/src/EmailInstaller.Codeunit.al @@ -31,7 +31,6 @@ codeunit 1596 "Email Installer" procedure AddRetentionPolicyAllowedTables() begin AddRetentionPolicyAllowedTables(false); - AddRetentionPolicyEmailInboxAllowedTable(false); CreateRetentionPolicySetup(false); end; @@ -53,26 +52,11 @@ codeunit 1596 "Email Installer" UpgradeTag.SetUpgradeTag(GetEmailTablesAddedToAllowedListUpgradeTag()); end; - procedure AddRetentionPolicyEmailInboxAllowedTable(ForceUpdate: Boolean) - var - Field: Record Field; - RetenPolAllowedTables: Codeunit "Reten. Pol. Allowed Tables"; - UpgradeTag: Codeunit "Upgrade Tag"; - IsInitialSetup: Boolean; - begin - IsInitialSetup := not UpgradeTag.HasUpgradeTag(GetEmailInboxAddedToAllowedListUpgradeTag()); - if not (IsInitialSetup or ForceUpdate) then - exit; - - RetenPolAllowedTables.AddAllowedTable(Database::"Email Inbox", Field.FieldNo(SystemCreatedAt), 2); - - if IsInitialSetup then - UpgradeTag.SetUpgradeTag(GetEmailInboxAddedToAllowedListUpgradeTag()); - end; - procedure CreateRetentionPolicySetup(ForceUpdate: Boolean) var + Field: Record Field; RetentionPolicySetup: Record "Retention Policy Setup"; + RetenPolAllowedTables: Codeunit "Reten. Pol. Allowed Tables"; RetentionPolicySetupCU: Codeunit "Retention Policy Setup"; UpgradeTag: Codeunit "Upgrade Tag"; DateFormula: DateFormula; @@ -82,6 +66,9 @@ codeunit 1596 "Email Installer" if not (IsInitialSetup or ForceUpdate) then exit; + if not RetenPolAllowedTables.AddAllowedTable(Database::"Email Inbox", Field.FieldNo(SystemCreatedAt), 2) then + exit; + RetentionPolicySetup.SetRange("Table Id", Database::"Email Inbox"); if not RetentionPolicySetup.IsEmpty() then exit; @@ -103,11 +90,6 @@ codeunit 1596 "Email Installer" exit('MS-373161-EmailLogEntryAdded-20201005'); end; - local procedure GetEmailInboxAddedToAllowedListUpgradeTag(): Code[250] - begin - exit('MS-539754-EmailInboxAdded-20240827'); - end; - local procedure GetEmailInboxPolicyAddedToAllowedListUpgradeTag(): Code[250] begin exit('MS-539754-EmailInboxPolicyAdded-20240827'); @@ -117,7 +99,6 @@ codeunit 1596 "Email Installer" local procedure AddAllowedTablesOnRefreshAllowedTables() begin AddRetentionPolicyAllowedTables(true); - AddRetentionPolicyEmailInboxAllowedTable(true); CreateRetentionPolicySetup(true); end;