diff --git a/src/System Application/App/Azure AD User Management/app.json b/src/System Application/App/Azure AD User Management/app.json index 0404b0ee90..e69c4db86b 100644 --- a/src/System Application/App/Azure AD User Management/app.json +++ b/src/System Application/App/Azure AD User Management/app.json @@ -110,6 +110,10 @@ { "from": 9029, "to": 9029 + }, + { + "from": 9034, + "to": 9034 } ], "internalsVisibleTo": [ diff --git a/src/System Application/App/Azure AD User Management/src/AzureADUserMgmtImpl.Codeunit.al b/src/System Application/App/Azure AD User Management/src/AzureADUserMgmtImpl.Codeunit.al index 7acf971200..0ded1dd885 100644 --- a/src/System Application/App/Azure AD User Management/src/AzureADUserMgmtImpl.Codeunit.al +++ b/src/System Application/App/Azure AD User Management/src/AzureADUserMgmtImpl.Codeunit.al @@ -8,8 +8,6 @@ namespace System.Azure.Identity; using System; using System.Security.User; using System.Environment; -using System.Telemetry; -using System.Globalization; using System.Security.AccessControl; using System.Environment.Configuration; @@ -312,37 +310,6 @@ codeunit 9017 "Azure AD User Mgmt. Impl." exit(AccessControl.Count() > TempAccessControlWithDefaultPermissions.Count()); end; - [EventSubscriber(ObjectType::Codeunit, Codeunit::"Telemetry Custom Dimensions", OnAddCommonCustomDimensions, '', true, true)] - local procedure OnAddCommonCustomDimensions(var Sender: Codeunit "Telemetry Custom Dimensions") - var - Language: Codeunit Language; - PlanIds: Codeunit "Plan Ids"; - UserAccountHelper: DotNet NavUserAccountHelper; - IsAdmin: Boolean; - CountryCode: Text; - begin - if not UserAccountHelper.IsAzure() then - exit; - - // Add IsAdmin - IsAdmin := AzureADGraphUser.IsUserDelegatedAdmin() or AzureADPlan.IsPlanAssignedToUser(PlanIds.GetGlobalAdminPlanId()) or AzureADPlan.IsPlanAssignedToUser(PlanIds.GetD365AdminPlanId()) or AzureADPlan.IsPlanAssignedToUser(PlanIds.GetBCAdminPlanId()); - Sender.AddCommonCustomDimension('IsAdmin', Language.ToDefaultLanguage(IsAdmin)); - - // Add CountryCode - if TryGetCountryCode(CountryCode) then - Sender.AddCommonCustomDimension('CountryCode', CountryCode); - end; - - [TryFunction] - local procedure TryGetCountryCode(var CountryCode: Text) - var - TenantInfo: DotNet TenantInfo; - begin - AzureADGraph.GetTenantDetail(TenantInfo); - if not IsNull(TenantInfo) then - CountryCode := TenantInfo.CountryLetterCode(); - end; - [InternalEvent(false)] local procedure OnIsUserTenantAdmin(var IsUserTenantAdmin: Boolean; var Handled: Boolean) begin diff --git a/src/System Application/App/Azure AD User Management/src/AzureADUserSubscribers.Codeunit.al b/src/System Application/App/Azure AD User Management/src/AzureADUserSubscribers.Codeunit.al new file mode 100644 index 0000000000..173d9b9929 --- /dev/null +++ b/src/System Application/App/Azure AD User Management/src/AzureADUserSubscribers.Codeunit.al @@ -0,0 +1,70 @@ +// ------------------------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// ------------------------------------------------------------------------------------------------ + +namespace System.Azure.Identity; + +using System; +using System.Globalization; +using System.Telemetry; + +codeunit 9034 "Azure AD User Subscribers" +{ + Access = Internal; + InherentEntitlements = X; + InherentPermissions = X; + SingleInstance = true; + + var + AzureADGraphUser: Codeunit "Azure AD Graph User"; + AzureADGraph: Codeunit "Azure AD Graph"; + AzureADPlan: Codeunit "Azure AD Plan"; + Initialized, IsAzure, IsAdmin : Boolean; + CountryCode: Text; + + local procedure GetInformation() + var + PlanIds: Codeunit "Plan Ids"; + UserAccountHelper: DotNet NavUserAccountHelper; + begin + if Initialized then + exit; + Initialized := true; + + IsAzure := UserAccountHelper.IsAzure(); + if not IsAzure then + exit; + + IsAdmin := AzureADGraphUser.IsUserDelegatedAdmin() or AzureADPlan.IsPlanAssignedToUser(PlanIds.GetGlobalAdminPlanId()) or AzureADPlan.IsPlanAssignedToUser(PlanIds.GetD365AdminPlanId()); + if TryGetCountryCode() then; + end; + + [TryFunction] + local procedure TryGetCountryCode() + var + TenantInfo: DotNet TenantInfo; + begin + AzureADGraph.GetTenantDetail(TenantInfo); + if not IsNull(TenantInfo) then + CountryCode := TenantInfo.CountryLetterCode(); + end; + + [EventSubscriber(ObjectType::Codeunit, Codeunit::"Telemetry Custom Dimensions", OnAddCommonCustomDimensions, '', true, true)] + local procedure OnAddCommonCustomDimensions(var Sender: Codeunit "Telemetry Custom Dimensions") + var + Language: Codeunit Language; + begin + GetInformation(); + + if not IsAzure then + exit; + + // Add IsAdmin + Sender.AddCommonCustomDimension('IsAdmin', Language.ToDefaultLanguage(IsAdmin)); + + // Add CountryCode + if CountryCode <> '' then + Sender.AddCommonCustomDimension('CountryCode', CountryCode); + end; +} \ No newline at end of file