Skip to content

Commit

Permalink
Fixes from DevOps
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremyVyska committed Mar 2, 2023
1 parent 5a5bd74 commit 25423b4
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 17 deletions.
1 change: 1 addition & 0 deletions src/.permissions/SPBPLLicensing.PermissionSet.al
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ permissionset 71033 "SPBPL Licensing"
codeunit "SPBPL LemonSqueezy Comm." = X,
codeunit "SPBPL License Utilities" = X,
codeunit "SPBPL Licensing Install" = X,
codeunit "SPBPL Telemetry" = X,
codeunit "SPBPL Upgrade" = X,
codeunit "SPBPL Version Check" = X,
page "SPBPL Extension Licenses" = X,
Expand Down
1 change: 1 addition & 0 deletions src/.permissions/SPBPLLicensingRO.PermissionSet.al
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ permissionset 71034 "SPBPL Licensing RO"
codeunit "SPBPL LemonSqueezy Comm." = X,
codeunit "SPBPL License Utilities" = X,
codeunit "SPBPL Licensing Install" = X,
codeunit "SPBPL Telemetry" = X,
codeunit "SPBPL Upgrade" = X,
codeunit "SPBPL Version Check" = X,
page "SPBPL Extension Licenses" = X,
Expand Down
17 changes: 13 additions & 4 deletions src/Callables/SPBPLCheckActive.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@ codeunit 71042 "SPBPL Check Active"
procedure CheckBasic(SubscriptionId: Guid; InactiveShowError: Boolean) IsActive: Boolean
var
SPBExtensionLicense: Record "SPBPL Extension License";
SPBEvents: Codeunit "SPBPL Events";
NoSubFoundErr: Label 'No License was found in the Licenses list for SubscriptionId: %1', Comment = '%1 is the ID of the App.';
begin
SPBExtensionLicense.SetRange("Extension App Id");
SPBExtensionLicense.SetRange("Extension App Id", SubscriptionId);
//If using this function signature, the Submodule functionality should NOT be considered.
SPBExtensionLicense.SetRange("Submodule Name", '');
if not SPBExtensionLicense.FindFirst() then
if GuiAllowed() then
Error(NoSubFoundErr, SubscriptionId);
Error(NoSubFoundErr, SubscriptionId)
else
SPBEvents.OnAfterCheckActiveBasicFailure(SubscriptionId, '', StrSubstNo(FailureToFindSubscriptionTok, SPBExtensionLicense.GetFilters()));

IsActive := DoCheckBasic(SPBExtensionLicense, InactiveShowError);
end;
Expand All @@ -35,13 +38,16 @@ codeunit 71042 "SPBPL Check Active"
procedure CheckBasicSubmodule(SubscriptionId: Guid; SubmoduleName: Text[100]; InactiveShowError: Boolean) IsActive: Boolean
var
SPBExtensionLicense: Record "SPBPL Extension License";
SPBEvents: Codeunit "SPBPL Events";
NoSubscriptionFoundErr: Label 'No License was found in the Licenses list for SubscriptionId: %1 with Submodule name: %2', Comment = '%1 is the ID of the App. %2 is the Submodule.';
begin
SPBExtensionLicense.SetRange("Extension App Id");
SPBExtensionLicense.SetRange("Extension App Id", SubscriptionId);
SPBExtensionLicense.SetRange("Submodule Name", SubmoduleName);
if not SPBExtensionLicense.FindFirst() then
if GuiAllowed() then
Error(NoSubscriptionFoundErr, SubscriptionId, SubmoduleName);
Error(NoSubscriptionFoundErr, SubscriptionId, SubmoduleName)
else
SPBEvents.OnAfterCheckActiveBasicFailure(SubscriptionId, SubmoduleName, StrSubstNo(FailureToFindSubscriptionTok, SPBExtensionLicense.GetFilters()));

IsActive := DoCheckBasic(SPBExtensionLicense, InactiveShowError);
end;
Expand All @@ -58,4 +64,7 @@ codeunit 71042 "SPBPL Check Active"
Error(SubscriptionInactiveErr, SPBExtensionLicense."Extension Name");
exit(IsActive);
end;

var
FailureToFindSubscriptionTok: Label 'Unable to find Subscription Entry (Filters %1)', Locked = true;
}
2 changes: 1 addition & 1 deletion src/Callables/SPBPLExtensionRegistration.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ codeunit 71034 "SPBPL Extension Registration"
Error(VersionUpdateRequiredErr, AppInfo.Name, minVersion);
end;

[Obsolete('Use new Events in SPBPL Events codeunit.')]
[Obsolete('Use SPB Check Active method codeunit instead.')]
procedure CheckIfActive(SubscriptionId: Guid; InactiveShowError: Boolean): Boolean
begin
end;
Expand Down
2 changes: 1 addition & 1 deletion src/EngineLogic/SPBPLActivateMeth.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ codeunit 71045 "SPBPL Activate Meth"
AppInfo: ModuleInfo;
begin
LicensePlatform := SPBExtensionLicense."License Platform";
LicensePlatformV2 := SPBExtensionLicense."License Platform";
LicensePlatformV2 := SPBExtensionLicense."License Platform";
// We'll want the App info for events / errors:
NavApp.GetModuleInfo(SPBExtensionLicense."Extension App Id", AppInfo);

Expand Down
35 changes: 27 additions & 8 deletions src/EngineLogic/SPBPLCheckActiveMeth.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ codeunit 71043 "SPBPL Check Active Meth"
var
EnvironmentInformation: Codeunit "Environment Information";
SPBIsoStoreManager: Codeunit "SPBPL IsoStore Manager";
SPBEvents: Codeunit "SPBPL Events";
SPBPLTelemetry: Codeunit "SPBPL Telemetry";
SPBPLVersionCheck: Codeunit "SPBPL Version Check";
IsoActive: Boolean;
Expand All @@ -41,13 +42,19 @@ codeunit 71043 "SPBPL Check Active Meth"
DaysGraceTok: Label '<+%1D>', Comment = '%1 is the number of days';
GraceExpiringMsg: Label 'Today is the last trial day for %1. Please purchase a License Key and Activate the subscription to continue use.', Comment = '%1 is the name of the Extension';
ResponseBody: Text;
IsoStorageValue: Text;
GracePeriodExpiredTok: Label 'Grace Period (End Date %1) Expired', Locked = true;
SubscriptionExpiredTok: Label 'Subscription Period (Ended %1) Expired', Locked = true;
IsoStorageTamperingTok: Label 'The IsoStorage and License record are different, which MAY indicate tampering or defects in the Platform.', Locked = true;
begin
LicensePlatform := SPBExtensionLicense."License Platform";

// if the subscription isn't active, check if we're in the 'grace' preinstall window, which always includes the first day of use
if not SPBExtensionLicense.Activated then begin
Evaluate(InstallDateTime, SPBIsoStoreManager.GetAppValue(SPBExtensionLicense, 'installDate'));
Evaluate(IsoNumber, SPBIsoStoreManager.GetAppValue(SPBExtensionLicense, 'preactivationDays'));
if SPBIsoStoreManager.GetAppValue(SPBExtensionLicense, 'installDate', IsoStorageValue) then
Evaluate(InstallDateTime, IsoStorageValue);
if SPBIsoStoreManager.GetAppValue(SPBExtensionLicense, 'preactivationDays', IsoStorageValue) then
Evaluate(IsoNumber, IsoStorageValue);
if IsoNumber > 0 then
GraceEndDate := CalcDate(StrSubstNo(DaysGraceTok, IsoNumber), DT2Date(InstallDateTime))
else
Expand All @@ -58,10 +65,15 @@ codeunit 71043 "SPBPL Check Active Meth"
GraceEndDate := Today;
if (GraceEndDate = Today) and GuiAllowed then
Message(GraceExpiringMsg, SPBExtensionLicense."Extension Name");
exit(GraceEndDate > Today);

// if the subscription isn't active, and we're not in the grace period, then we're not Active
if GraceEndDate < Today then
SPBEvents.OnAfterCheckActiveFailure(SPBExtensionLicense, false, StrSubstNo(GracePeriodExpiredTok, GraceEndDate));
exit(GraceEndDate >= Today);
end;

Evaluate(LastCheckDateTime, SPBIsoStoreManager.GetAppValue(SPBExtensionLicense, 'lastCheckDate'));
if SPBIsoStoreManager.GetAppValue(SPBExtensionLicense, 'lastCheckDate', IsoStorageValue) then
Evaluate(LastCheckDateTime, IsoStorageValue);
if ((Today() - DT2Date(LastCheckDateTime)) > 0) then begin
if LicensePlatform.CallAPIForVerification(SPBExtensionLicense, ResponseBody, false) then begin
// This may update the End Dates - note: may or may not call .Modify
Expand All @@ -75,24 +87,31 @@ codeunit 71043 "SPBPL Check Active Meth"
// if the subscription ran out
if (SPBExtensionLicense."Subscription End Date" < CurrentDateTime) and
(SPBExtensionLicense."Subscription End Date" <> 0DT)
then
then begin
SPBEvents.OnAfterCheckActiveFailure(SPBExtensionLicense, false, StrSubstNo(SubscriptionExpiredTok, SPBExtensionLicense."Subscription End Date"));
exit(false);

end;

// if the record version IS active, then let's crosscheck against isolated storage
Evaluate(IsoActive, SPBIsoStoreManager.GetAppValue(SPBExtensionLicense, 'active'));
if SPBIsoStoreManager.GetAppValue(SPBExtensionLicense, 'active', IsoStorageValue) then
Evaluate(IsoActive, IsoStorageValue);
if not IsoActive then begin
LicensePlatform.ReportPossibleMisuse(SPBExtensionLicense);
SPBPLTelemetry.EventTagMisuseReport(SPBExtensionLicense);
SPBEvents.OnAfterCheckActiveFailure(SPBExtensionLicense, false, IsoStorageTamperingTok);
exit(false);
end;

// Check Record end date against IsoStorage end date
Evaluate(IsoDatetime, SPBIsoStoreManager.GetAppValue(SPBExtensionLicense, 'endDate'));
if SPBIsoStoreManager.GetAppValue(SPBExtensionLicense, 'endDate', IsoStorageValue) then
Evaluate(IsoDatetime, IsoStorageValue);
if IsoDatetime <> 0DT then
// Only checking at the date level in case of time zone nonsense
if DT2Date(IsoDatetime) <> DT2Date(SPBExtensionLicense."Subscription End Date") then begin
LicensePlatform.ReportPossibleMisuse(SPBExtensionLicense);
SPBPLTelemetry.EventTagMisuseReport(SPBExtensionLicense);
SPBEvents.OnAfterCheckActiveFailure(SPBExtensionLicense, false, IsoStorageTamperingTok);
exit(false);
end;

// Finally, all things checked out
Expand Down
10 changes: 10 additions & 0 deletions src/Extensibility/SPBPLEvents.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ codeunit 71041 "SPBPL Events"
internal procedure OnAfterCheckActiveBasic(var SPBExtensionLicense: Record "SPBPL Extension License"; IsActive: Boolean);
begin
end;

[IntegrationEvent(false, false)]
internal procedure OnAfterCheckActiveBasicFailure(SubscriptionId: Guid; SubmoduleName: Text[100]; FailureReason: Text);
begin
end;

[IntegrationEvent(false, false)]
internal procedure OnAfterCheckActiveFailure(var SPBExtensionLicense: Record "SPBPL Extension License"; IsActive: Boolean; FailureReason: Text);
begin
end;
#endregion ActiveCheckEvents

#region VersionEvents
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ codeunit 71035 "SPBPL Gumroad Communicator" implements "SPBPL ILicenseCommunicat
TempJsonBuffer.GetIntegerPropertyValue(LicenseUses, 'uses');
TempJsonBuffer.GetIntegerPropertyValue(LicenseCount, 'quantity');

exit(LicenseUses < LicenseCount);
exit(LicenseUses <= LicenseCount);
end;

procedure SampleKeyFormatText(): Text
Expand Down
4 changes: 2 additions & 2 deletions src/Storage/SPBPLIsoStoreManager.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ codeunit 71038 "SPBPL IsoStore Manager"
IsolatedStorage.Set(StrSubstNo(NameMapTok, SPBExtensionLicense."Entry Id", StoreName), StoreValue, DataScope::Module);
end;

internal procedure GetAppValue(SPBExtensionLicense: Record "SPBPL Extension License"; StoreName: Text) ReturnValue: Text
internal procedure GetAppValue(SPBExtensionLicense: Record "SPBPL Extension License"; StoreName: Text; ReturnValue: Text) Found: Boolean
begin
IsolatedStorage.Get(StrSubstNo(NameMapTok, SPBExtensionLicense."Entry Id", StoreName), DataScope::Module, ReturnValue);
Found := IsolatedStorage.Get(StrSubstNo(NameMapTok, SPBExtensionLicense."Entry Id", StoreName), DataScope::Module, ReturnValue);
if EnvironmentInformation.IsOnPrem() and CryptographyManagement.IsEncryptionEnabled() and CryptographyManagement.IsEncryptionPossible() then
ReturnValue := CryptographyManagement.Decrypt(ReturnValue);
end;
Expand Down

0 comments on commit 25423b4

Please sign in to comment.