From 3d7299c93fafa753b746b464c375b66de71fa7d8 Mon Sep 17 00:00:00 2001 From: Darrick Joo Date: Sun, 25 Aug 2024 15:50:59 +0200 Subject: [PATCH 1/2] Add GetAllV2Accounts API --- .../src/Account/EmailAccount.Codeunit.al | 25 +++++++++-- .../src/Account/EmailAccountImpl.Codeunit.al | 31 ++++++++----- .../Email/src/EmailAccountsTest.Codeunit.al | 43 +++++++++++++++++++ 3 files changed, 86 insertions(+), 13 deletions(-) diff --git a/src/System Application/App/Email/src/Account/EmailAccount.Codeunit.al b/src/System Application/App/Email/src/Account/EmailAccount.Codeunit.al index 72a10bc6ad..776b5c0b52 100644 --- a/src/System Application/App/Email/src/Account/EmailAccount.Codeunit.al +++ b/src/System Application/App/Email/src/Account/EmailAccount.Codeunit.al @@ -12,6 +12,24 @@ codeunit 8894 "Email Account" { Access = Public; + /// + /// Gets all of the email accounts registered in Business Central. + /// + /// Out parameter holding the email accounts. + procedure GetAllAccounts(var TempEmailAccount: Record "Email Account" temporary) + begin + EmailAccountImpl.GetAllAccounts(false, TempEmailAccount); + end; + + /// + /// Gets all of the email accounts which implement the v2 interface registered in Business Central. + /// + /// Out parameter holding the email accounts. + procedure GetAllV2Accounts(var TempEmailAccount: Record "Email Account" temporary) + begin + EmailAccountImpl.GetAllV2Accounts(false, TempEmailAccount); + end; + /// /// Gets all of the email accounts registered in Business Central. /// @@ -23,12 +41,13 @@ codeunit 8894 "Email Account" end; /// - /// Gets all of the email accounts registered in Business Central. + /// Gets all of the email accounts which implement the v2 interface registered in Business Central. /// + /// Flag, used to determine whether to load the logos for the accounts. /// Out parameter holding the email accounts. - procedure GetAllAccounts(var TempEmailAccount: Record "Email Account" temporary) + procedure GetAllV2Accounts(LoadLogos: Boolean; var TempEmailAccount: Record "Email Account" temporary) begin - EmailAccountImpl.GetAllAccounts(false, TempEmailAccount); + EmailAccountImpl.GetAllV2Accounts(LoadLogos, TempEmailAccount); end; /// diff --git a/src/System Application/App/Email/src/Account/EmailAccountImpl.Codeunit.al b/src/System Application/App/Email/src/Account/EmailAccountImpl.Codeunit.al index 63bc7aa1f9..1888cca01f 100644 --- a/src/System Application/App/Email/src/Account/EmailAccountImpl.Codeunit.al +++ b/src/System Application/App/Email/src/Account/EmailAccountImpl.Codeunit.al @@ -26,6 +26,16 @@ codeunit 8889 "Email Account Impl." CannotManageSetupErr: Label 'Your user account does not give you permission to set up email. Please contact your administrator.'; procedure GetAllAccounts(LoadLogos: Boolean; var TempEmailAccount: Record "Email Account" temporary) + begin + GetAllAccounts(LoadLogos, false, TempEmailAccount); + end; + + procedure GetAllV2Accounts(LoadLogos: Boolean; var TempEmailAccount: Record "Email Account" temporary) + begin + GetAllAccounts(LoadLogos, true, TempEmailAccount); + end; + + local procedure GetAllAccounts(LoadLogos: Boolean; LoadV2Only: Boolean; var TempEmailAccount: Record "Email Account" temporary) var EmailAccounts: Record "Email Account"; Connector: Enum "Email Connector"; @@ -40,18 +50,19 @@ codeunit 8889 "Email Account Impl." EmailAccounts.DeleteAll(); IEmailConnector.GetAccounts(EmailAccounts); - if EmailAccounts.FindSet() then - repeat - TempEmailAccount := EmailAccounts; - TempEmailAccount.Connector := Connector; + if (not LoadV2Only) or (LoadV2Only and IEmailConnector is "Email Connector v2") then + if EmailAccounts.FindSet() then + repeat + TempEmailAccount := EmailAccounts; + TempEmailAccount.Connector := Connector; - if LoadLogos then begin - ImportLogo(TempEmailAccount, Connector); - ImportLogoBlob(TempEmailAccount, Connector); - end; + if LoadLogos then begin + ImportLogo(TempEmailAccount, Connector); + ImportLogoBlob(TempEmailAccount, Connector); + end; - if not TempEmailAccount.Insert() then; - until EmailAccounts.Next() = 0; + if not TempEmailAccount.Insert() then; + until EmailAccounts.Next() = 0; end; // Sort by account name diff --git a/src/System Application/Test/Email/src/EmailAccountsTest.Codeunit.al b/src/System Application/Test/Email/src/EmailAccountsTest.Codeunit.al index cdb62a58a2..5a7d4f5c25 100644 --- a/src/System Application/Test/Email/src/EmailAccountsTest.Codeunit.al +++ b/src/System Application/Test/Email/src/EmailAccountsTest.Codeunit.al @@ -261,6 +261,49 @@ codeunit 134686 "Email Accounts Test" Assert.AreEqual(EmailAccountBuffer."Email Address", EmailAccounts."Email Address", 'Wrong account email address'); end; + [Test] + procedure GetAllV2AccountsTest() + var + EmailAccountBuffer, EmailAccounts : Record "Email Account"; + ConnectorMock: Codeunit "Connector Mock"; + EmailAccount: Codeunit "Email Account"; + begin + // [SCENARIO] GetAllV2Accounts retrieves all the registered accounts that implement the v2 interface + + // [GIVEN] A connector is installed and no account is added + ConnectorMock.Initialize(); + + PermissionsMock.Set('Email Edit'); + + // [WHEN] GetAllAccounts is called + EmailAccount.GetAllV2Accounts(EmailAccounts); + + // [THEN] The returned record is empty (there are no registered accounts) + Assert.IsTrue(EmailAccounts.IsEmpty(), 'Record should be empty'); + + // [GIVEN] An account is added to the connector + ConnectorMock.AddAccount(EmailAccountBuffer); + // [GIVEN] A v2 account is added to the connector + ConnectorMock.AddAccount(EmailAccountBuffer, Enum::"Email Connector"::"Test Email Connector v2"); + + // [WHEN] GetAllAccounts is called + EmailAccount.GetAllAccounts(EmailAccounts); + + // [THEN] The returned record is not empty and the values are as expected + Assert.AreEqual(2, EmailAccounts.Count(), 'Record should not be empty'); + + // [WHEN] GetAllV2Accounts is called + EmailAccount.GetAllV2Accounts(EmailAccounts); + + // [THEN] The returned record is not empty and the values are as expected + Assert.AreEqual(1, EmailAccounts.Count(), 'Record should not be empty'); + EmailAccounts.FindFirst(); + Assert.AreEqual(EmailAccountBuffer."Account Id", EmailAccounts."Account Id", 'Wrong account ID'); + Assert.AreEqual(Enum::"Email Connector"::"Test Email Connector v2", EmailAccounts.Connector, 'Wrong connector'); + Assert.AreEqual(EmailAccountBuffer.Name, EmailAccounts.Name, 'Wrong account name'); + Assert.AreEqual(EmailAccountBuffer."Email Address", EmailAccounts."Email Address", 'Wrong account email address'); + end; + [Test] procedure IsAnyAccountRegisteredTest() var From 815b2b82de628c47d9c45b091d80359342783af2 Mon Sep 17 00:00:00 2001 From: Darrick Joo Date: Mon, 26 Aug 2024 15:16:03 +0200 Subject: [PATCH 2/2] Remove unneeded API addition --- .../Email/src/Account/EmailAccount.Codeunit.al | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/src/System Application/App/Email/src/Account/EmailAccount.Codeunit.al b/src/System Application/App/Email/src/Account/EmailAccount.Codeunit.al index 776b5c0b52..a676a8b2fe 100644 --- a/src/System Application/App/Email/src/Account/EmailAccount.Codeunit.al +++ b/src/System Application/App/Email/src/Account/EmailAccount.Codeunit.al @@ -12,24 +12,6 @@ codeunit 8894 "Email Account" { Access = Public; - /// - /// Gets all of the email accounts registered in Business Central. - /// - /// Out parameter holding the email accounts. - procedure GetAllAccounts(var TempEmailAccount: Record "Email Account" temporary) - begin - EmailAccountImpl.GetAllAccounts(false, TempEmailAccount); - end; - - /// - /// Gets all of the email accounts which implement the v2 interface registered in Business Central. - /// - /// Out parameter holding the email accounts. - procedure GetAllV2Accounts(var TempEmailAccount: Record "Email Account" temporary) - begin - EmailAccountImpl.GetAllV2Accounts(false, TempEmailAccount); - end; - /// /// Gets all of the email accounts registered in Business Central. ///