Skip to content

Fixes #38638: Gate memory edit and delete on the memory's own permission - #38676

Merged
Rohit0301 merged 1 commit into
open-metadata:mainfrom
Vamsi-klu:fix/38638-memory-owner-edit-delete
Nov 26, 2026
Merged

Rohit0301 merged 1 commit into
open-metadata:mainfrom
Vamsi-klu:fix/38638-memory-owner-edit-delete

Conversation

@Vamsi-klu

Copy link
Copy Markdown
Contributor

Describe your changes:

Fixes #38638

In Context Center, a memory's owner could not edit or delete their own memory. The page gated each memory's Edit and Delete on the resource-level contextMemory permission. Every user inherits OrganizationPolicy-Owner-Rule (All when isOwner()), and the server reports a conditional rule as conditionalAllow/conditionalDeny at resource level, because there is no memory to evaluate the condition against. The UI translates resource-level conditionals strictly (permissionPolicy.ts), so Edit and Delete were hidden for every non-admin owner. Every default install is affected: it needs no custom policy, only a non-admin user who owns a memory.

This PR gates each memory's Edit and Delete on that memory's own permission:

  • New hook useMemoryActionPermissions(memories, resourcePermission) (src/hooks/discovery/context-center/), built on useBulkEntityPermissions:
    • Non-admin: looks up GET /permissions/contextMemory/name/{fqn} only for the memories the user owns (one cached React Query per FQN, shared with useEntityPermissions).
    • Admin: uses the resource-level answer with no lookups. The authorizer allows every operation for an admin, so the answer is the same, and admin behaviour is identical to main.
    • Fails closed: while a lookup is loading, or when it fails, the memory has neither action. Answers are keyed by FQN, so a late answer can never attach to another memory.
    • Keeps the owner-or-admin rule (product feedback in Context center feedbacks 2 #28436, tested by Added permission for context center action buttons #29287): a non-owner never sees Edit/Delete, even with unconditional EditAll.
  • ContextCenterMemoriesPage passes the resolver to the list, and the open memory's own answer to the detail/edit modal (canEdit, canDelete). Create stays on the resource level (canCreate via getDerivedPermissionFlags, which also removes the raw permissions.Create/permissions.Delete reads).
  • src/test/browser/fixtures/personas.ts: servePersona's entity callback now receives the lookup ({ resource, id?, fqn? }), so a list page can answer each row against its own owners. The one existing caller (entityMatrix.ts) ignores the argument.

Not changed: CreateMemoryModal, ExtractedMemoriesCard, permissionPolicy.ts, locales, backend.

MemoriesView props changed — Collate question

MemoriesViewProps loses canEdit, canDelete, currentUserName and isAdminUser and gains getMemoryActions?: (memory) => MemoryActionPermissions (default: no actions). In OSS the page is its only importer. Maintainers: please confirm that openmetadata-collate does not render MemoriesView directly. If it does, I will keep the old props as optional and deprecated for one release (REVIEW.md, "Collate builds against OpenMetadata main").

Issue discussion

Plan, including the three flipped assertions, posted on the issue before implementation: #38638 (comment). harshach assigned the issue in reply; there is no reply yet on the assertion flips themselves. @Rohit0301, as the author of #29287, please confirm the flips match the intent.

Type of change:

  • Bug fix

High-level design:

  • Why per memory, not a policy flip: flipping resourceLevelConditionalAllow to 'attempt' would still deny conditionalDeny, changes every resource-level check in the app, and shows buttons the server then refuses. permissionPolicy.ts reserves the resource level for "places with no specific entity yet"; a memory row has one.
  • Why only owned memories are looked up: the page keeps Edit/Delete to the owner or an admin, so a lookup for anyone else's memory could never show a button. There is no bulk permission endpoint (PermissionsResource has only /{resource}, /{resource}/{id}, /{resource}/name/{name}), so this keeps the request count to the user's own memories on the page.
  • Why admins skip the lookup: DefaultAuthorizer answers ALLOW for every admin operation at both levels, so a lookup per row (up to the page size) would add requests for the same answer.
  • Rejected: lookup on menu open (Edit is an always-visible icon, it would pop in after the click); entity level only in the modal (row and modal would disagree); letting CreateMemoryModal fetch its own permission (changes a shared component's props and duplicates the page's fetch).
  • No ADR: this follows permissionPolicy.ts and ADR:2026-10-09-data-consumers-create-context-memories.

Tests:

Use cases covered

  • A non-admin owner whose Edit/Delete come only from isOwner() sees Edit and the manage menu on their own row, edits the memory from its detail view (PATCH sent, dialog closes) and deletes it from the row (DELETE sent, row gone).
  • The same owner when the resource level is conditionalDeny (a deny rule such as !isOwner() && !noOwner()).
  • A non-owned memory stays read-only (banner, no Edit/Delete) and is never looked up.
  • A failed lookup leaves the memory with no Edit/Delete.
  • An admin keeps Edit/Delete on every memory with zero per-memory lookups.
  • Create stays on the resource-level permission.

Unit tests

  • Jest, yarn test src/hooks/discovery/context-center/useMemoryActionPermissions.test.tsx src/components/ContextCenter/MemoriesView src/pages/ContextCenterPage/ContextCenterMemoriesPage src/components/ContextCenter/CreateMemoryModal: 6 suites, 113 tests passed.

    • New useMemoryActionPermissions.test.tsx (7 tests; only rest/permissionAPI is mocked, real React Query and app store): owner allowed from the entity level while the resource level says no; only owned memories looked up; admin answered from the resource level with no call; a 403 leaves no actions; a late answer for memory A never reaches memory B; a soft-deleted memory allows Delete but not Edit; a memory listed twice is looked up once.
    • MemoriesView.test.tsx: Edit/Delete render only on the rows getMemoryActions allows (fails on main), and none without a resolver.
    • ContextCenterMemoriesPage.test.tsx: removed the two tests that asserted the resource-level canEdit prop wiring that no longer exists; the hook is mocked (frontend-permissions rule).
  • Browser test (Vitest browser mode, real app, MSW), new ContextCenterMemoriesPage.browser.test.tsx: 7/7 pass.

    # Test On main
    1 an owner whose edit and delete come only from isOwner() can act on their memory's row (also: no lookup for the other memory, Add Memory visible) fails
    2 the owner edits their memory from its detail view (PATCH /answer, dialog closes) fails
    3 the owner deletes their memory from its row (DELETE ?hardDelete=true, row removed) fails
    4 the owner keeps edit and delete when the resource level is a conditional deny fails
    5 a failed lookup leaves the memory without edit or delete fails (main makes no lookup); fail-closed guard
    6 an admin keeps edit on every memory without a lookup per memory passes (no-regression guard)
    7 a memory someone else owns stays read-only passes (owner rule kept)
  • Every browser test that reaches servePersona (82 files through the entity-matrix and custom-property contracts), because personas.ts changed: not verified locally. In this worktree the entity-matrix tests cannot load their lazy route (Failed to fetch dynamically imported module: …/TableDetailsPageV1.tsx). EntityDataConsumer.Table.browser.test.tsx fails 12/12 the same way with origin/main's personas.ts, so the cause is the local environment, not this change. The change itself is additive: the callback gets an argument, and the one existing caller (() => server.current()) ignores it; tsc is clean for it. The impact-selected browser job on this PR runs them.

Static checks

  • yarn tsc:playwright: clean. yarn tsc:check: 34 errors, all in two files this PR does not touch (src/utils/SSOUtils.test.ts, src/utils/ChartDetailsUtils.test.tsx); they are on origin/main as well. None in the changed files.
  • yarn ui-checkstyle:changed <changed src files> (organize-imports, ESLint, Prettier, licence, i18n sync): no diff, 0 errors (the only warnings are the existing setCurrentPage exhaustive-deps ones in the page). yarn lint:playwright: 0 errors. Pre-commit hooks passed.

Backend integration tests

  • Not applicable (no backend change).

Playwright (UI) tests

  • playwright/e2e/Features/ContextCenterPermission.spec.ts, Memories Permissions:
    • New, the issue's exact repro: a user whose contextMemory rules are Create+ViewBasic unconditionally, ViewAll/EditAll/Delete if isOwner(), and All denied if !isOwner() && !noOwner(). Asserts the resource level reports EditAll as conditional, then in the UI: the row shows Edit, the detail view's Edit → Save returns PATCH 200 and an admin GET shows the new content, and the row's Delete returns 200, removes the row, and an admin GET returns 404. Fails on main (no Edit on the row).
    • Three existing assertions flipped. They were added in Added permission for context center action buttons #29287 (2026-06-25), before ADR:2026-10-09-data-consumers-create-context-memories, which records: "A memory's owner edits and deletes it through OrganizationPolicy-Owner-Rule." The Playwright setup keeps that rule (ORGANIZATION_POLICY_RULES in playwright/constant/permission.ts), and the backend already allows these operations; the tests pinned the UI bug, they are not loosened to make this PR pass:
      1. "user with view-only permission who owns a memory still cannot edit or delete it" → retitled "… can edit and delete it through the owner rule": the row shows Edit and the manage menu; the dialog shows Edit and Delete.
      2. "user with editAll permission … can edit and save their own memory": the edit dialog of their own memory now also shows Delete.
      3. "user with deleteAll permission … can delete their own memory from the modal": their own row and dialog now also show Edit.
    • Local run against this branch's Docker stack (commit 683b788f95, server bound to 127.0.0.1, Playwright setup project first for the CI policy baseline), PLAYWRIGHT_IS_OSS=true PW_PRESEEDED_STATE=true npx playwright test playwright/e2e/Features/ContextCenterPermission.spec.ts --project=chromium --workers=1 -g "Memories Permissions": 9 passed (the new test, the 3 flipped tests and the 5 unchanged ones).
    • RED for this layer is shown by browser tests 1-4 (they mock the same permission answers). The new Playwright test was not run against main.
  • Baseline: the add-memory-btn assertions for the view-only and editAll users are green on main. The Playwright setup replaces DataConsumerPolicy with DATA_CONSUMER_RULES, which has no Create on contextMemory, and removes the Organization's default roles. The last full nightly run with results (run 45313589314, 2026-11-24, 3cdf00c82c) passed all 9 Memories Permissions tests on the first attempt. (The 2026-11-25 nightly failed in plan-playwright before any test ran.)
  • Not run: make playwright_affected_run. make playwright_affected selects 33 specs: this one, 11 impact-mapped Context Center specs, and canaries such as Pages/Entity.spec.ts, the DomainIsolation suite and Flow/SearchRBAC.spec.ts; two of them (SystemCertificationTags, IntakeForm) also pull in the whole chromium project. That is too broad for this shared box; the merge queue runs the full suite.

Manual testing performed

  1. Built this branch (yarn build, mvn package -pl openmetadata-dist -am), started MySQL, Elasticsearch and the server in Docker, bound to 127.0.0.1; /api/v1/system/version reported revision 683b788f95.
  2. As admin, created a user whose only own grant is ViewAll, and a memory owned by that user.
  3. Signed in as that user, opened Context Center → Memories, and searched for the memory: the row shows Edit and the manage (⋯) menu. Opened the memory: the footer shows Delete and Edit and there is no read-only banner.
  4. Another user's memory in the same list shows neither action (covered by the Playwright suite above).

UI screen recording:

Not applicable — a bug fix, not a feature. After screenshots from the local stack (classic mode renders light only; dark exists only in AI mode and was not captured): the owner's row with Edit and the manage menu, and the detail modal's footer with Delete and Edit. Before: on main the same row shows only the copy-link button and the footer only Cancel (browser tests 1-2 fail on exactly these controls).

After: the owner's row (copy link, Edit, manage menu)

Owner row with Edit and the manage menu

After: the owner's detail modal (Delete and Edit in the footer, no read-only banner)

Owner detail modal footer with Delete and Edit

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR title is Fixes #38638: Gate memory edit and delete on the memory's own permission
  • My PR is linked to a GitHub issue via Fixes #38638 above.
  • I have commented on my code, particularly in hard-to-understand areas.
  • For JSON Schema changes: not applicable, no schema change.
  • For a UI feature or feature task: not applicable, this is a bug fix.
  • I have added tests (unit / integration / Playwright as applicable) and listed them above.
  • Self-review: I reviewed the final diff against REVIEW.md (the pr-checklist skill runs it) and fixed every 🔴 finding, or answered it on the line below.
    Fresh-context review against REVIEW.md (of the pre-amend 270cdc18b3; the final commit is 683b788f95): no 🔴. Fixed: the failed-lookup browser test now waits for the 403 to land (networkIdle()) before its absence checks, so a loading state can't satisfy it (amended into this commit). Answered:
    • The new Playwright test overlaps browser tests 1-3: kept on purpose. The browser test mocks the permission API, so only Playwright shows the server's real isOwner() evaluation (resource level conditional, entity level allow, PATCH/DELETE 200) reaching the UI. A Java IT for that permission contract would be a good addition, but this PR has no backend change.
    • setCustomRulePolicy leaves its policy, role and team behind: the same as every other user in this spec; the test deletes its user and memory in a finally.
    • Issue numbers in test comments: kept, as the template's bug-fix checklist asks.
    • Team owners and ExtractedMemoriesCard: pre-existing, listed under follow-ups.
  • Decision check: no new decision; this follows permissionPolicy.ts and ADR:2026-10-09-data-consumers-create-context-memories.
  • I have added a test that covers the exact scenario we are fixing (browser tests 1-4 and the new Playwright test reference Context Center: owner cannot edit or delete own memory in UI when EditAll/Delete are granted via isOwner() condition #38638).

Follow-ups (not in this PR)

  • Team-owned memories: the UI matches owners by user name, while the server's isOwner() also matches the user's teams (SubjectContext). A member of an owning team still sees no Edit/Delete.
  • ExtractedMemoriesCard opens the same CreateMemoryModal but gates Delete on owner-or-admin with no permission check and never passes canEdit (so no Edit there, even for an admin). It can reuse useMemoryActionPermissions.
  • The owner-only rule hides Edit/Delete from a non-owner who has unconditional EditAll/Delete, which re-encodes policy in the UI (REVIEW.md, "The UI consumes the API's semantics"). Dropping it is a product decision.

🤖 Generated with Claude Code

…s own permission

Every user inherits OrganizationPolicy-Owner-Rule (All when isOwner()),
which the server reports as conditional at resource level, so the
Context Center hid Edit and Delete from a non-admin owner of a memory.

The new useMemoryActionPermissions hook answers each memory from its own
permission through useBulkEntityPermissions: a non-admin's owned
memories are looked up by FQN, an admin keeps the resource-level answer
with no lookup, and a loading or failed lookup offers no action. The
owner-or-admin rule is kept. MemoriesView takes a getMemoryActions
resolver instead of page-wide canEdit/canDelete flags, and the detail
modal gets the open memory's own answer. Create stays resource level.

Three ContextCenterPermission.spec.ts assertions that expected an owner
without a role grant to have no Edit or Delete now expect them, per
ADR:2026-10-09-data-consumers-create-context-memories.
@Vamsi-klu
Vamsi-klu requested a review from a team as a code owner November 25, 2026 10:52
@github-actions

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically.

Maintainers can bypass this check by adding the skip-pr-checks label.

@gitar-bot

gitar-bot Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Code Review ✅ Approved 🔴 High risk

The UI now gates memory edits and deletes on per-memory permissions, changing authorization decisions; an incorrect result could expose actions contrary to policy.

Gates each memory's Edit and Delete in Context Center on that memory's own permission, so owners of a memory can act on it even when the resource-level contextMemory rule is conditional. Admin behavior is unchanged, and non-owners still see no Edit or Delete. No issues found.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@github-actions

Copy link
Copy Markdown
Contributor

UI browser tests

Ran: all test files (no impact map from main yet)

Result: ✅ 1079 passed · 154 skipped

Changed code executed by these browser tests: 30 / 31 lines (97%)

File Changed lines Executed %
src/components/ContextCenter/MemoriesView/MemoriesView.component.tsx 1 0 0%
src/hooks/discovery/context-center/useMemoryActionPermissions.ts 23 23 100%
src/pages/ContextCenterPage/ContextCenterMemoriesPage/ContextCenterMemoriesPage.tsx 7 7 100%
Changed files no browser test loads
  • src/components/ContextCenter/MemoriesView/MemoriesView.interface.ts

@Rohit0301 Rohit0301 added the To release Will cherry-pick this PR into the release branch label Nov 26, 2026
@Rohit0301
Rohit0301 merged commit 590ea15 into open-metadata:main Nov 26, 2026
50 of 51 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🤖 Backport to 2.1 is under way. It is built from openmetadata-collate, which holds the credentials needed to open a PR here, and it will comment again with the result — nothing is needed from you unless it reports otherwise.

@github-actions

Copy link
Copy Markdown
Contributor

🤖 Backport to 2.0 is under way. It is built from openmetadata-collate, which holds the credentials needed to open a PR here, and it will comment again with the result — nothing is needed from you unless it reports otherwise.

@gh-bot-collate

Copy link
Copy Markdown

🤖 Backport to 2.1 opened as #38771. Claude resolved a cherry-pick conflict to build it. It merges itself once the checks pass, so read the diff now if this change is a sensitive one.

@gh-bot-collate

Copy link
Copy Markdown

🤖 Backport to 2.0 failed. The conflict could not be resolved, so this change is not on that branch. Resolver run.

Rohit0301 pushed a commit that referenced this pull request Nov 26, 2026
…ion (#38676) (#38771)

Every user inherits OrganizationPolicy-Owner-Rule (All when isOwner()),
which the server reports as conditional at resource level, so the
Context Center hid Edit and Delete from a non-admin owner of a memory.

The new useMemoryActionPermissions hook answers each memory from its own
permission through useBulkEntityPermissions: a non-admin's owned
memories are looked up by FQN, an admin keeps the resource-level answer
with no lookup, and a loading or failed lookup offers no action. The
owner-or-admin rule is kept. MemoriesView takes a getMemoryActions
resolver instead of page-wide canEdit/canDelete flags, and the detail
modal gets the open memory's own answer. Create stays resource level.

Three ContextCenterPermission.spec.ts assertions that expected an owner
without a role grant to have no Edit or Delete now expect them, per
ADR:2026-10-09-data-consumers-create-context-memories.

(cherry picked from commit 590ea15)

Co-authored-by: deepinsight coder <32898216+Vamsi-klu@users.noreply.github.com>
Rohit0301 added a commit that referenced this pull request Nov 26, 2026
…ermission (#38773)

* Fixes #38638: Gate memory edit and delete on the memory's own permission (#38676)

Every user inherits OrganizationPolicy-Owner-Rule (All when isOwner()),
which the server reports as conditional at resource level, so the
Context Center hid Edit and Delete from a non-admin owner of a memory.

The new useMemoryActionPermissions hook answers each memory from its own
permission through useBulkEntityPermissions: a non-admin's owned
memories are looked up by FQN, an admin keeps the resource-level answer
with no lookup, and a loading or failed lookup offers no action. The
owner-or-admin rule is kept. MemoriesView takes a getMemoryActions
resolver instead of page-wide canEdit/canDelete flags, and the detail
modal gets the open memory's own answer. Create stays resource level.

Three ContextCenterPermission.spec.ts assertions that expected an owner
without a role grant to have no Edit or Delete now expect them, per
ADR:2026-10-09-data-consumers-create-context-memories.

(cherry picked from commit 590ea15)

Backport notes for 2.0: useBulkEntityPermissions, PermissionDerivation and
the Vitest browser-test harness are not on 2.0, so useMemoryActionPermissions
queries per-memory permissions with useQueries directly, and the
ContextCenterMemoriesPage browser/Jest tests and personas fixture are dropped.

* Fix 2.0 backport: import createMemoryViaApi in spec, cache memory permission lookups

The spec auto-merged but on 2.0 never imported createMemoryViaApi, so it
failed to compile. Memory permission queries now use main's 5 minute
staleTime instead of the 2.0 client default of 0.

---------

Co-authored-by: deepinsight coder <32898216+Vamsi-klu@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

To release Will cherry-pick this PR into the release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Context Center: owner cannot edit or delete own memory in UI when EditAll/Delete are granted via isOwner() condition

3 participants