Repository navigation
Description
Problem
Every per-instance layout mutation in the widget dashboard depends on a single dashboard-wide flag: editMode. Removal, drag, resize, and the width menu are all-or-nothing (widget-layout-controls.tsx, dashboard-grid/index.tsx:664), and attribute editing is always available.
Part of #79231. Related: #81893.
Nothing can make a single instance non-removable (a mandatory widget on a curated dashboard) while the rest remain fully editable. And there is no seam where a host could later map user permissions into what each user may do to the layout.
Proposed solution
One policy concept: per-operation, per-instance permission, composed restrictively. Every layer can only narrow the answer (boolean AND); no layer re-grants what another denied.
Operation vocabulary, explicit and unbundled: remove, move, resize, edit (instance attribute values) per instance; insert (already covered by widgetDashboard.canInsertWidgetType, #81893) and reset at the dashboard level. editMode stays a UI mode, orthogonal to policy.
One source ships first; the others compose into the same resolution point later:
- Instance datum, serialized with the layout and seedable through the default layout:
interface DashboardWidget< Attributes = unknown > {
// existing fields...
lock?: {
remove?: boolean;
move?: boolean;
resize?: boolean;
edit?: boolean;
};
}true locks the operation; absent means unlocked. No tri-state: an instance cannot re-enable what policy denies.
- Host seam, where a host maps user permissions (for WordPress hosts,
canUser()and friends) without the engine ever learning about them:
type LayoutOperation = 'remove' | 'move' | 'resize' | 'edit' | 'insert' | 'reset';
canPerform?: ( operation: LayoutOperation, widget?: DashboardWidget ) => boolean;- Later, one extension filter consistent with the inserter one:
widgetDashboard.canPerformWidgetOperation.
A single resolution helper in the dashboard provider answers canPerformOperation( operation, widget ), and every surface reads the same answer: the removal button and width menu, per-tile drag and resize (the grid gains a per-item flag plumbed to its existing internal disabled state), and the attribute-editing surfaces.
Enforcement: the UI reflects policy, and the staging layer adds a backstop for remove (re-asserting instances locked against removal). Every mutation already funnels through one choke point (onLayoutChange in the provider), so the guard is cheap and has no bypass.
Deliberately out, informed by how the block editor's model grew (canRemoveBlock evaluates 9 ordered gates backed by 8 overlapping mechanisms): no lock cascades or inheritance, no templateLock-style operation bundles, no editing-mode maps, no per-type policy in widget.json (the manifest declares invariant self-facts, never permissions), and no lock UI for now.
Tasks
- Add
locktoDashboardWidgetand a single resolution helper in the dashboard provider - Gate removal, width menu, and per-tile drag/resize (grid: per-item flag mapped to the internal
disabled) - Staging guard re-asserting instances locked against removal
- Unit tests and docs (package README, dashboard architecture doc)
Future work
- The
canPerformhost policy seam; its transport (prop vs host provider) is decided alongside the host-seam unification work - Extension filter
widgetDashboard.canPerformWidgetOperation - Capability-resolved policies at the app layer, and server-side enforcement once layouts persist as shared entities
- Type-suggested lock defaults copied onto the instance at insertion
- A lock-editing UI, if a real case appears
Activity