From 2c35049badc1d637a688e27aeafdf26f625e85d8 Mon Sep 17 00:00:00 2001 From: Onat Buyukakkus <55088871+onbuyuka@users.noreply.github.com> Date: Mon, 10 Nov 2025 14:44:04 +0100 Subject: [PATCH] Disabling modify setting does not apply for already added tools --- .../MCPConfigImplementation.Codeunit.al | 17 +++++++++++ .../Configuration/Pages/MCPConfigCard.Page.al | 2 ++ .../Test/MCP/src/MCPConfigTest.Codeunit.al | 29 +++++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/src/System Application/App/MCP/src/Configuration/Codeunits/MCPConfigImplementation.Codeunit.al b/src/System Application/App/MCP/src/Configuration/Codeunits/MCPConfigImplementation.Codeunit.al index c2f4e0e20d..4a748d2855 100644 --- a/src/System Application/App/MCP/src/Configuration/Codeunits/MCPConfigImplementation.Codeunit.al +++ b/src/System Application/App/MCP/src/Configuration/Codeunits/MCPConfigImplementation.Codeunit.al @@ -78,11 +78,28 @@ codeunit 8351 "MCP Config Implementation" if not MCPConfiguration.GetBySystemId(ConfigId) then exit; + if not Allow then + DisableCreateUpdateDeleteToolsInConfig(ConfigId); + MCPConfiguration.AllowProdChanges := Allow; MCPConfiguration.Modify(); Session.LogMessage('0000QEA', StrSubstNo(SettingConfigurationAllowProdChangesLbl, ConfigId, Allow), Verbosity::Normal, DataClassification::SystemMetadata, TelemetryScope::ExtensionPublisher, 'Category', GetTelemetryCategory()); end; + internal procedure DisableCreateUpdateDeleteToolsInConfig(ConfigId: Guid) + var + MCPConfigurationTool: Record "MCP Configuration Tool"; + begin + MCPConfigurationTool.SetRange(ID, ConfigId); + if MCPConfigurationTool.IsEmpty() then + exit; + + MCPConfigurationTool.ModifyAll("Allow Create", false); + MCPConfigurationTool.ModifyAll("Allow Modify", false); + MCPConfigurationTool.ModifyAll("Allow Delete", false); + MCPConfigurationTool.ModifyAll("Allow Bound Actions", false); + end; + internal procedure DeleteConfiguration(ConfigId: Guid) var MCPConfiguration: Record "MCP Configuration"; diff --git a/src/System Application/App/MCP/src/Configuration/Pages/MCPConfigCard.Page.al b/src/System Application/App/MCP/src/Configuration/Pages/MCPConfigCard.Page.al index 5cc9fc5ea5..da564c4a59 100644 --- a/src/System Application/App/MCP/src/Configuration/Pages/MCPConfigCard.Page.al +++ b/src/System Application/App/MCP/src/Configuration/Pages/MCPConfigCard.Page.al @@ -76,6 +76,8 @@ page 8351 "MCP Config Card" trigger OnValidate() begin + if not Rec.AllowProdChanges then + MCPConfigImplementation.DisableCreateUpdateDeleteToolsInConfig(Rec.SystemId); CurrPage.Update(); Session.LogMessage('0000QE8', StrSubstNo(SettingConfigurationAllowProdChangesLbl, Rec.SystemId, Rec.AllowProdChanges), Verbosity::Normal, DataClassification::SystemMetadata, TelemetryScope::ExtensionPublisher, 'Category', MCPConfigImplementation.GetTelemetryCategory()); end; diff --git a/src/System Application/Test/MCP/src/MCPConfigTest.Codeunit.al b/src/System Application/Test/MCP/src/MCPConfigTest.Codeunit.al index 4bdd2b56ee..dd7f0b16d0 100644 --- a/src/System Application/Test/MCP/src/MCPConfigTest.Codeunit.al +++ b/src/System Application/Test/MCP/src/MCPConfigTest.Codeunit.al @@ -549,6 +549,35 @@ codeunit 130130 "MCP Config Test" Assert.AreEqual('mcp', APIGroup, 'APIGroup mismatch'); end; + [Test] + procedure TestDisableCreateUpdateDeleteToolsDisablesAllowCreate() + var + MCPConfigurationTool: Record "MCP Configuration Tool"; + ConfigId: Guid; + ToolId: Guid; + begin + // [GIVEN] Configuration and tool is created + ConfigId := CreateMCPConfig(false, false, true, false); + ToolId := CreateMCPConfigTool(ConfigId); + Commit(); + + // [GIVEN] Create, update and delete tools are enabled + MCPConfig.AllowCreate(ToolId, true); + MCPConfig.AllowModify(ToolId, true); + MCPConfig.AllowDelete(ToolId, true); + MCPConfig.AllowBoundActions(ToolId, true); + + // [WHEN] Disable create, update and delete tools is called + MCPConfig.AllowCreateUpdateDeleteTools(ConfigId, false); + + // [THEN] Allow create, modify, delete and bound actions are set to false + MCPConfigurationTool.GetBySystemId(ToolId); + Assert.IsFalse(MCPConfigurationTool."Allow Create", 'Allow Create is not false'); + Assert.IsFalse(MCPConfigurationTool."Allow Modify", 'Allow Modify is not false'); + Assert.IsFalse(MCPConfigurationTool."Allow Delete", 'Allow Delete is not false'); + Assert.IsFalse(MCPConfigurationTool."Allow Bound Actions", 'Allow Bound Actions is not false'); + end; + local procedure CreateMCPConfig(Active: Boolean; DynamicToolMode: Boolean; AllowCreateUpdateDeleteTools: Boolean; DiscoverReadOnlyObjects: Boolean): Guid var MCPConfiguration: Record "MCP Configuration";