diff --git a/app/MindWork AI Studio/Assistants/DocumentAnalysis/DocumentAnalysisAssistant.razor.cs b/app/MindWork AI Studio/Assistants/DocumentAnalysis/DocumentAnalysisAssistant.razor.cs index c87d6800..a6ef3bab 100644 --- a/app/MindWork AI Studio/Assistants/DocumentAnalysis/DocumentAnalysisAssistant.razor.cs +++ b/app/MindWork AI Studio/Assistants/DocumentAnalysis/DocumentAnalysisAssistant.razor.cs @@ -286,7 +286,7 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore + /// Whether the given policy may take over an edit of one of its protected fields right now. + /// + /// + /// The handlers which write their value straight into the policy have to ask this themselves. + /// ApplyFormToPolicy asks the same question, but it never gets to judge their fields: they have + /// already brought policy and form in line, so nothing is left for it to compare. The markup + /// disables those controls for a protected policy and an enterprise policy is always a protected + /// one, which is why nobody should ever reach a handler that way -- this keeps the rule in the + /// code as well, where the next handler will look for it. The form value counts alongside the + /// stored one, because the protection switch is flipped before the store which writes it has run. + /// + private bool AcceptsProtectedFieldEdits(DataDocumentAnalysisPolicy policy) => policy is { IsEnterpriseConfiguration: false, IsProtected: false } && !this.policyIsProtected; + private DataDocumentAnalysisPolicy? selectedPolicy; private bool policyIsProtected; private bool policyHidePolicyDefinition; @@ -630,19 +644,19 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore allowedToolIds) { this.policyAllowedToolIds = allowedToolIds; - if (this.selectedPolicy is null) + if (this.selectedPolicy is not { } policy || !this.AcceptsProtectedFieldEdits(policy)) return; - this.selectedPolicy.AllowedToolIds = [..allowedToolIds]; + policy.AllowedToolIds = [..allowedToolIds]; this.policyStorePending = true; } private void PolicyMinimumConfidenceWasChanged(ConfidenceLevel level) { this.policyMinimumProviderConfidence = level; - if (this.selectedPolicy is not null) + if (this.selectedPolicy is { } policy && this.AcceptsProtectedFieldEdits(policy)) { - this.selectedPolicy.MinimumProviderConfidence = level; + policy.MinimumProviderConfidence = level; this.policyStorePending = true; } @@ -651,11 +665,11 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore