fix: inject scope on joins when root is unscoped#16
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Currently, scoped join protection is only applied when the root table in
from(table)is itself scoped. If a query starts from an unscoped table (e.g.userswhich has no scoping rules) and joins a protected/scoped table (e.g.projects), the query builder returned by.from(users)is the raw, unwrapped Drizzle query builder. This means that subsequent calls to.leftJoinor.innerJoinbypass the scoped join wrapper entirely, and scope predicates are never injected for the joined table.Fix
from(table)in thecreateScopedFromBuilderwrapper, even when the root table has no scoping rules (rootRule === undefined).assertWhereAllowedandscopeConditionto support an optional/undefinedruleparameter. When undefined,assertWhereAllowedis a no-op andscopeConditionpasses the condition through unmodified..leftJoin()or.innerJoin()is intercepted, and table-specific scope rules are safely injected into the join condition usingscopeJoinCondition.then(), ifrootRuleis undefined and no scope predicate needs to be injected, we pass the raw builder through directly rather than calling.where(undefined).Validation