acts_as_tenant icon indicating copy to clipboard operation
acts_as_tenant copied to clipboard

Fix global record validations with existing scope

Open mikecmpbll opened this issue 2 years ago • 1 comments

Due to how the args object was being (man)handled, we were leaking the tenant scope into the global scope validation where it shouldn't have been. This only happened when there was a scope argument supplied to validates_uniquness_to_tenant.

mikecmpbll avatar Aug 18 '22 09:08 mikecmpbll

to expand on this a little; the # if tenant is set (instance is not global) and records can be global - validating within records with blank tenant validation query was:

SELECT 1 AS one
FROM "projects"
WHERE "projects"."name" = ?
  AND "projects"."user_defined_scope" = ?
  AND "projects"."account_id" = ?
  AND "projects"."account_id" IS NULL
LIMIT ?

the account_id = <tenant_id> portion of the query doesn't belong there, and was leaking into args[:scope] from how validation_args was being built for the main validation.

mikecmpbll avatar Aug 18 '22 09:08 mikecmpbll