Skip to content

Scope organization, partner user, and attachment lookups to the current organization - #5761

Open
awwaiid wants to merge 1 commit into
mainfrom
fix-cross-organization-access
Open

awwaiid wants to merge 1 commit into
mainfrom
fix-cross-organization-access

Conversation

@awwaiid

@awwaiid awwaiid commented Nov 1, 2026

Copy link
Copy Markdown
Collaborator

Description

Bugfixes for lookups that weren't scoped to the current organization:

  • ApplicationController#current_organization: the organization_id param fallback is meant for super admins (whose role has no organization). It now applies only to super admins; partner-role users get nil, so bank screens redirect them to the partner dashboard.
  • OrganizationsController#invite_user: invites to current_organization instead of the org form param. The modal's hidden field is renamed org → organization_id, so super admins can still pick the organization.
  • OrganizationsController#resend_user_invitation: only finds users of the current organization.
  • PartnerUsersController: set_partner now finds the partner within the current organization and runs for every action (it was skipped for reset_password). destroy, resend_invitation and reset_password find the user within that partner.
  • AttachmentsController#destroy: only deletes documents of the current organization's partners, which is the only thing the UI uses it for. Anything else is a 404.

Spec setup changes that came with this:

  • users_requests_spec (partner_user_reset_password): a let!(:user) was shadowing the signed-in bank user with a partner user. It's renamed partner_user, so the spec signs in as a bank user as intended.
  • partner_users_requests_spec and attachments_requests_spec created partners in a different organization from the signed-in user. They now use the user's organization.

Not changed here (already broken before this PR): on the admin organization page, the reinvite/promote/remove buttons don't pass organization_id, so they redirect super admins. Could be a follow-up.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • New request specs per controller (dashboard, organizations, partner users, attachments) plus current_organization controller specs. Against the old app code, 13 of them fail; with this change, all pass.
  • Full non-system suite passes locally, as do the organization, partner, admin, and partner-portal system specs.
  • rubocop is clean on changed files.

🤖 Generated with Claude Code

https://claude.ai/code/session_01UCzWYsxjKeDD9EVVp6L2eS

…nt organization

Bugfixes:
- current_organization only uses the organization_id param for super
  admins; other roles without an organization get nil.
- invite_user invites to current_organization instead of a form param
  (hidden field renamed to organization_id so super admins can still
  choose the organization).
- resend_user_invitation only finds users of the current organization.
- PartnerUsersController finds the partner within the current
  organization, and users within that partner, for every action
  (including reset_password).
- AttachmentsController only deletes documents of the current
  organization's partners.

Specs that relied on the old lookups now set up records in the
signed-in user's organization.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UCzWYsxjKeDD9EVVp6L2eS

This branch has not been deployed

No deployments
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.

1 participant