Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Guard Admin API Admin Users endpoint for host app issues with json co… (#14159)

Damian Legawiec825cb86d7351
diff --git a/spree/api/app/controllers/spree/api/v3/admin/admin_users_controller.rb b/spree/api/app/controllers/spree/api/v3/admin/admin_users_controller.rb
index 67d502a928..55db497d16 100644
--- a/spree/api/app/controllers/spree/api/v3/admin/admin_users_controller.rb
+++ b/spree/api/app/controllers/spree/api/v3/admin/admin_users_controller.rb
@@ -61,12 +61,18 @@ module Spree
end
# Restrict to users with a role assignment on the current store.
- # `accessible_by` enforces CanCanCan on top.
+ # `accessible_by` enforces CanCanCan on top. Deduplication happens via
+ # an ID subquery rather than `SELECT DISTINCT *` — the users table is
+ # host-app-defined and may contain `json` columns, which Postgres
+ # cannot compare for equality.
def scope
- model_class.
+ staff_ids = model_class.
joins(:role_users).
- where(spree_role_users: { resource: current_store }).
- distinct.
+ where(Spree::RoleUser.table_name => { resource: current_store }).
+ select(:id)
+
+ model_class.
+ where(id: staff_ids).
accessible_by(current_ability, :show)
end