Skip to content

Commit

Permalink
[Email/RetPol] Harden retention policy for Email Inbox setup. (#2324)
Browse files Browse the repository at this point in the history
<!-- Thank you for submitting a Pull Request. If you're new to
contributing to BCApps please read our pull request guideline below
* https://github.com/microsoft/BCApps/Contributing.md
-->
#### Summary <!-- Provide a general summary of your changes -->
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) <!-- Add the issue number here after the #. The issue
needs to be open and approved. Submitting PRs with no linked issues or
unapproved issues is highly discouraged. -->
Fixes
[AB#556484](https://dynamicssmb2.visualstudio.com/1fcb79e7-ab07-432a-a3c6-6cf5a88ba4a5/_workitems/edit/556484)
  • Loading branch information
darjoo authored Nov 11, 2024
1 parent e53f919 commit 38942f4
Showing 1 changed file with 5 additions and 24 deletions.
29 changes: 5 additions & 24 deletions src/System Application/App/Email/src/EmailInstaller.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ codeunit 1596 "Email Installer"
procedure AddRetentionPolicyAllowedTables()
begin
AddRetentionPolicyAllowedTables(false);
AddRetentionPolicyEmailInboxAllowedTable(false);
CreateRetentionPolicySetup(false);
end;

Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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');
Expand All @@ -117,7 +99,6 @@ codeunit 1596 "Email Installer"
local procedure AddAllowedTablesOnRefreshAllowedTables()
begin
AddRetentionPolicyAllowedTables(true);
AddRetentionPolicyEmailInboxAllowedTable(true);
CreateRetentionPolicySetup(true);
end;

Expand Down

0 comments on commit 38942f4

Please sign in to comment.