-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cache information for OnAddCommonCustomDimensions telemetry subscriber (
#567) <!-- 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 --> `AzureADGraph.GetTenantDetail(TenantInfo);` is called everytime and the information returned is the exact same. Cache the information for each session that runs this. #### 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#499449](https://dynamicssmb2.visualstudio.com/1fcb79e7-ab07-432a-a3c6-6cf5a88ba4a5/_workitems/edit/499449)
- Loading branch information
Showing
3 changed files
with
74 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,6 +110,10 @@ | |
{ | ||
"from": 9029, | ||
"to": 9029 | ||
}, | ||
{ | ||
"from": 9034, | ||
"to": 9034 | ||
} | ||
], | ||
"internalsVisibleTo": [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/System Application/App/Azure AD User Management/src/AzureADUserSubscribers.Codeunit.al
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |