Skip to content

ADded function to disable key by key type - #9877

Open
ehenriksen9 wants to merge 2 commits into
mainfrom
bugs/add-disable-bykeyinfo
Open

ADded function to disable key by key type#9877
ehenriksen9 wants to merge 2 commits into
mainfrom
bugs/add-disable-bykeyinfo

Conversation

@ehenriksen9

@ehenriksen9 ehenriksen9 commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

What & why

Linked work

Fixes #

How I validated this

  • I read the full diff and it contains only changes I intended.
  • I built the affected app(s) locally with no new analyzer warnings.
  • I ran the change in Business Central and confirmed it behaves as expected.
  • I added or updated tests for the new behavior, or explained below why none are needed.

What I tested and the outcome (required — be specific: scenarios, commands, screenshots for UI changes)

Risk & compatibility

@ehenriksen9
ehenriksen9 requested a review from a team July 31, 2026 14:30
@github-actions github-actions Bot added AL: System Application Integration GitHub request for Integration area labels Jul 31, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Could not find a linked ADO work item. Please link one by using the pattern 'AB#' followed by the relevant work item number. You may use the 'Fixes' keyword to automatically resolve the work item when the pull request is merged. E.g. 'Fixes AB#1234'

InherentEntitlements = X;
InherentPermissions = X;

procedure Disable(IndexKey: KeyRef)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$\textbf{🟡\ Medium\ Severity\ —\ Error\ Handling}$

Table Key Impl.Disable(IndexKey) calls Database.AlterKey(IndexKey, false) directly with no precondition validation and no success/failure signaling, unlike the sibling AlterAll local procedure it sits next to, which validates the table (skips system tables and non-Normal table types) and lets DisableAll/EnableAll return a Boolean so callers can handle unsupported input gracefully. For a key on an unsupported table (system table, non-SQL table, clustered/unique/SIFT key, etc. — all called out as unsupported in this procedure's own XML doc remarks), the new Disable will let Database.AlterKey raise an unhandled runtime error instead of failing gracefully. Recommend validating the key/table upfront (reusing the same checks as AlterAll) and exposing a Boolean or TryFunction-based result so callers get the same predictable failure contract as the existing table-level operations.

👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v1.26.4

/// Clustered keys, unique keys, SIFT keys, Nonclustered Columnstore Indexes are not supported for this operation.
/// The key is automatically re-enabled when a Commit() is called, or at the end of AL code execution.
/// </remarks>
procedure Disable(IndexKey: KeyRef)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$\textbf{🟠\ High\ Severity\ —\ Security}$

The new public Table Key.Disable(IndexKey: KeyRef) procedure is a new entry point on a public System Application codeunit that forwards a caller-supplied KeyRef straight into Table Key Impl.Disable, which calls Database.AlterKey(IndexKey, false) under Access = Internal / InherentEntitlements = X / InherentPermissions = X. Unlike this, internal access does not authorize a runtime caller; it only relies on the internal-implementation boundary, which is not a security boundary. Compounding this, the sibling table-level operations DisableAll/EnableAll in the same codeunit are marked [Scope('OnPrem')] and validate preconditions (skip system tables where TableNo > 2000000000, skip non-Normal table types) before altering any key, while the new Disable(KeyRef) has neither the [Scope('OnPrem')] attribute nor any equivalent validation. As shipped, any extension (including SaaS/AppSource extensions, since the OnPrem restriction is absent) that can obtain a KeyRef can disable an arbitrary key — including ones the documented remarks say are unsupported — without an explicit authorization or allow-list check. Align the new API with its siblings: either restrict it to OnPrem like DisableAll/EnableAll, or add the same system-table/table-type validation and explicit authorization before calling Database.AlterKey.

Knowledge:

👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v1.26.4

/// Clustered keys, unique keys, SIFT keys, Nonclustered Columnstore Indexes are not supported for this operation.
/// The key is automatically re-enabled when a Commit() is called, or at the end of AL code execution.
/// </remarks>
procedure Disable(KeyToDisable: KeyRef)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$\textbf{🟠\ High\ Severity\ —\ Breaking\ Changes}$

The new Table Key.Disable(KeyToDisable: KeyRef) procedure is declared public with no [Scope('OnPrem')] attribute, while its sibling bulk operations in the same codeunit — DisableAll and EnableAll — are both deliberately restricted with [Scope('OnPrem')]. Per BCQuality's access-modifier guidance, dropping or omitting [Scope('OnPrem')] widens the supported contract and should be a deliberate decision, not an inconsistency between sibling members of the same public surface. If single-key disable is intentionally meant to be callable from SaaS/cloud extensions (unlike the bulk variants), that asymmetry should be called out explicitly (e.g., in the XML doc remarks) and confirmed as an intended product decision; otherwise add [Scope('OnPrem')] to match DisableAll/EnableAll and avoid an unreviewed capability expansion.

Knowledge:

👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v1.26.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AL: System Application Integration GitHub request for Integration area

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant