Skip to content

fix: gate org inventory UI and fetch on can_view_org_inventory (ISSUE-163)#166

Merged
GitAddRemote merged 6 commits into
mainfrom
feature/ISSUE-163
May 17, 2026
Merged

fix: gate org inventory UI and fetch on can_view_org_inventory (ISSUE-163)#166
GitAddRemote merged 6 commits into
mainfrom
feature/ISSUE-163

Conversation

@GitAddRemote
Copy link
Copy Markdown
Owner

Summary

  • Adds canViewOrgInventory memo that correctly reflects the permission hierarchy (can_view OR can_edit OR can_admin all imply view access)
  • Skips GET /api/orgs/:orgId/inventory entirely when permissions are still loading or the user lacks can_view_org_inventory — no 403 errors are surfaced
  • After permissions resolve without view access, silently reverts the selector to personal mode (no error, no disabled state — the org section simply doesn't exist for that user)
  • Uses a permissionsFetchedForOrgId ref to ensure the revert only fires after a real fetch completes, not on initial render before the fetch has started
  • Removes the misleading "no permission to add items" info alert — showAddButton already hides the add control for users without edit/admin access

Test plan

  • Log in as a user with can_view_org_inventory: false — selecting the org in the View dropdown should immediately return to "My Inventory" with no error banner and no inventory API call fired
  • Log in as a user with can_view_org_inventory: true and can_edit_org_inventory: false — org inventory loads and displays, but no Add button visible
  • Log in as a user with can_edit_org_inventory: true — full org inventory with Add button visible and functional
  • Confirm no red error banners appear for any permission level
  • Confirm GET /api/orgs/:orgId/inventory is not called when user lacks view permission (check Network tab)

Closes #163

…-163)

- Add canViewOrgInventory memo (view|edit|admin implies view access)
- Skip getOrgInventory fetch when permissions loading or user lacks can_view_org_inventory — no 403 surfaced
- Revert to personal mode silently after permissions resolve without view access
- Use permissionsFetchedForOrgId ref to avoid premature revert before fetch completes
- Remove misleading "no permission to add" info alert; showAddButton already gates the add action
Copilot AI review requested due to automatic review settings May 17, 2026 06:13
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the inventory page to gate organization inventory loading and UI behavior on resolved organization inventory permissions, avoiding unnecessary 403 errors for users without view access.

Changes:

  • Adds canViewOrgInventory based on view/edit/admin permission hierarchy.
  • Skips organization inventory fetches while permissions are loading or view access is absent.
  • Reverts back to personal inventory after permissions resolve without org inventory view access and removes the no-add-permission info alert.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread frontend/src/pages/Inventory.tsx
Copilot AI review requested due to automatic review settings May 17, 2026 06:39
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment thread frontend/src/pages/Inventory.tsx Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.

Comment thread frontend/src/pages/Inventory.tsx
Comment thread frontend/src/pages/Inventory.tsx
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

Comment thread frontend/src/pages/Inventory.tsx Outdated
Comment thread frontend/src/pages/Inventory.tsx
Comment thread frontend/src/pages/Inventory.editor-mode.test.tsx
…gsLoaded

- Add allOrgOptions (unfiltered) for the share dialog so members can
  share to any org they belong to, regardless of inventory view perms
- orgOptions (view-filtered) remains the source for the View selector only
- Add orgsLoaded ref; validation effect now only runs after fetchOrganizations
  completes, preventing premature reset of a valid sessionStorage org selection
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@GitAddRemote GitAddRemote merged commit cfd8901 into main May 17, 2026
11 checks passed
@GitAddRemote GitAddRemote deleted the feature/ISSUE-163 branch May 17, 2026 23:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: org inventory UI visible to users lacking can_view_org_inventory permission

2 participants