Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[24.x] Feature Management. Add an overload to IsEnabled procedure. (#1720) #1800

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ codeunit 2611 "Feature Management Facade"
exit(FeatureManagementImpl.IsEnabled(FeatureId));
end;

/// <summary>
/// Returns true if the feature is enabled and data update, if required, is complete.
/// </summary>
/// <param name="FeatureId">the feature id in the system table "Feature Key"</param>
/// <param name="AllowInsert">specifies if inserts are allowed while checking for feature being enabled</param>
/// <returns>if the feature is fully enabled</returns>
procedure IsEnabled(FeatureId: Text[50]; AllowInsert: Boolean): Boolean;
begin
exit(FeatureManagementImpl.IsEnabled(FeatureId, AllowInsert));
end;

/// <summary>
/// Updates the status in "Feature Data Update Status" records related to all companies.
/// Also sends the notification reminding user to sign in again after feature is enabled/disabled.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ codeunit 2610 "Feature Management Impl."
/// <summary>
/// Inserts record to "Feature Data Update Status" table to show the feature status per company.
/// </summary>
local procedure InitializeFeatureDataUpdateStatus(FeatureKey: Record "Feature Key"; var FeatureDataUpdateStatus: Record "Feature Data Update Status")
local procedure InitializeFeatureDataUpdateStatus(FeatureKey: Record "Feature Key"; var FeatureDataUpdateStatus: Record "Feature Data Update Status"; AllowInsert: Boolean)
var
FeatureManagementFacade: Codeunit "Feature Management Facade";
InitializeHandled: Boolean;
Expand All @@ -106,7 +106,8 @@ codeunit 2610 "Feature Management Impl."
end;
// If the table extension is not in sync during upgrade then Get() always returns False,
// so the following insert will fail if the record does exist.
if FeatureDataUpdateStatus.Insert() then;
if AllowInsert then
if FeatureDataUpdateStatus.Insert() then;
end;

/// <summary>
Expand Down Expand Up @@ -162,7 +163,7 @@ codeunit 2610 "Feature Management Impl."
if FeatureDataUpdateStatus."Background Task" then
UpdateBackgroundTaskStatus(FeatureDataUpdateStatus);
end else
InitializeFeatureDataUpdateStatus(FeatureKey, FeatureDataUpdateStatus);
InitializeFeatureDataUpdateStatus(FeatureKey, FeatureDataUpdateStatus, true);
end;

/// <summary>
Expand Down Expand Up @@ -322,15 +323,26 @@ codeunit 2610 "Feature Management Impl."
/// <summary>
/// Returns true if the feature is enabled and data update, if required, is complete.
/// </summary>
/// <param name="FeatureId">the feature id in the system table "Feature Key"</param>
/// <returns>if the feature is fully enabled</returns>
/// <param name="FeatureId">The feature id in the system table "Feature Key"</param>
/// <returns>If the feature is fully enabled</returns>
procedure IsEnabled(FeatureId: Text[50]): Boolean;
begin
exit(IsEnabled(FeatureId, true));
end;

/// <summary>
/// Returns true if the feature is enabled and data update, if required, is complete.
/// </summary>
/// <param name="FeatureId">The feature id in the system table "Feature Key"</param>
/// <param name="AllowInsert">Specifies if inserts are allowed while checking for feature being enabled</param>
/// <returns>If the feature is fully enabled</returns>
procedure IsEnabled(FeatureId: Text[50]; AllowInsert: Boolean): Boolean;
var
FeatureKey: Record "Feature Key";
FeatureDataUpdateStatus: Record "Feature Data Update Status";
begin
if FeatureKey.Get(FeatureId) then begin
InitializeFeatureDataUpdateStatus(FeatureKey, FeatureDataUpdateStatus);
InitializeFeatureDataUpdateStatus(FeatureKey, FeatureDataUpdateStatus, AllowInsert);
exit(FeatureDataUpdateStatus."Feature Status" in ["Feature Status"::Complete, "Feature Status"::Enabled])
end;
end;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,63 @@ codeunit 135003 "Feature Key Test"
asserterror error('') // roll back
end;

[Test]
procedure T108_IsEnabledAllowInsertTrue()
var
FeatureDataUpdateStatus: Record "Feature Data Update Status";
Enabled: Option "None","All Users";
ID: Text[50];
begin
PermissionsMock.Set('Feature Key Admin');
Initialize();
ID := 'SalesPrices';
// [GIVEN] Feature Key 'X', where "Enabled" is 'All Users' with data update required
SetFeatureEnabled(ID, Enabled::"All Users");

// [GIVEN] FeatureDataUpdateStatus for Company 'A' does not exist
FeatureDataUpdateStatus.DeleteAll();

// [WHEN] run IsEnabled() with AllowInsert = true
// [THEN] result is False, because it requires data update
Assert.IsFalse(FeatureManagementFacade.IsEnabled(ID, true), 'should be disabled');

// [THEN] FeatureDataUpdateStatus for Company 'A' is created
FeatureDataUpdateStatus.SetRange("Feature Key", ID);
FeatureDataUpdateStatus.SetRange("Company Name", CopyStr(CompanyName(), 1, MaxStrLen(FeatureDataUpdateStatus."Company Name")));
Assert.RecordIsNotEmpty(FeatureDataUpdateStatus);

asserterror Error('') // roll back
end;

[Test]
procedure T109_IsEnabledAllowInsertFalse()
var
FeatureDataUpdateStatus: Record "Feature Data Update Status";
Enabled: Option "None","All Users";
ID: Text[50];
begin
PermissionsMock.Set('Feature Key Admin');
Initialize();
ID := 'SalesPrices';
// [GIVEN] Feature Key 'X', where "Enabled" is 'All Users' with data update required
SetFeatureEnabled(ID, Enabled::"All Users");

// [GIVEN] FeatureDataUpdateStatus for Company 'A' does not exist
FeatureDataUpdateStatus.DeleteAll();

// [WHEN] run IsEnabled() with AllowInsert = false
// [THEN] result is False, because it requires data update
Assert.IsFalse(FeatureManagementFacade.IsEnabled(ID, false), 'should be disabled');

// [THEN] FeatureDataUpdateStatus for Company 'A' is not created
FeatureDataUpdateStatus.SetRange("Feature Key", ID);
FeatureDataUpdateStatus.SetRange("Company Name", CopyStr(CompanyName(), 1, MaxStrLen(FeatureDataUpdateStatus."Company Name")));
Assert.RecordIsEmpty(FeatureDataUpdateStatus);

asserterror Error('') // roll back
end;


local procedure Initialize()
begin
LibraryVariableStorage.Clear();
Expand All @@ -528,12 +585,9 @@ codeunit 135003 "Feature Key Test"

local procedure MockFeatureStatus(ID: Text[50]; Enabled: Option "None","All Users"; Status: Enum "Feature Status")
var
FeatureKey: Record "Feature Key";
FeatureDataUpdateStatus: Record "Feature Data Update Status";
begin
FeatureKey.Get(ID);
FeatureKey.Enabled := Enabled;
FeatureKey.Modify();
SetFeatureEnabled(ID, Enabled);

FeatureDataUpdateStatus.DeleteAll();
FeatureDataUpdateStatus."Feature Key" := ID;
Expand All @@ -543,6 +597,15 @@ codeunit 135003 "Feature Key Test"
FeatureDataUpdateStatus.Insert();
end;

local procedure SetFeatureEnabled(ID: Text[50]; Enabled: Option "None","All Users")
var
FeatureKey: Record "Feature Key";
begin
FeatureKey.Get(ID);
FeatureKey.Enabled := Enabled;
FeatureKey.Modify();
end;

local procedure MockStatusInAnotherCompany(ID: Text[50]; DataUpdateRequired: Boolean; FeatureStatus: Enum "Feature Status") Name: Text[30]
var
FeatureDataUpdateStatus: Record "Feature Data Update Status";
Expand Down
Loading