Skip to content

[ui] Asset wipe permission cascade is duplicated between useWipeDialog and useWipeMaterializations #34001

Description

@damienmeur

Commit ecc8b1c ("Consolidate all the places we check asset wipe permissions to be consistent and correct") ended up writing the same three-tier permission cascade (deployment-wide -> code location -> per-asset) by hand in two sibling hooks rather than sharing it. Both copies are live on master:

js_modules/ui-core/src/assets/useWipeDialog.tsx (lines 28-31), single-asset boolean chain:

const hasWipePermission =
  unscopedPermissions.canWipeAssets?.enabled ||
  (opts?.locationName && locationPermissions[opts.locationName]?.canWipeAssets?.enabled) ||
  !!opts?.definitionHasWipePermission;

js_modules/ui-core/src/assets/useWipeMaterializations.tsx (lines 25-41), the same cascade as an .every() over the selection:

const hasWipePermission = useMemo(() => {
  if (selected.length === 0) {
    return false;
  }
  if (unscopedPermissions.canWipeAssets?.enabled) {
    return true;
  }
  return selected.every((a) => {
    if (a.locationName && locationPermissions[a.locationName]?.canWipeAssets?.enabled) {
      return true;
    }
    return !!a.definitionHasWipePermission;
  });
}, [selected, unscopedPermissions, locationPermissions]);

The two are semantically identical today, but any change to the wipe-permission rules now has to be made in both places, which is the kind of divergence that commit set out to eliminate.

Since the hooks serve different shapes (single asset vs. a selection), the fix is probably not to merge them but to extract a shared predicate, e.g. assetHasWipePermission(asset, unscopedPermissions, locationPermissions), with the multi-asset case being selected.every of it — in the spirit of the existing shared useAssetPermissions helper. Happy to send a PR if that sounds reasonable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions