Skip to content

Add repository RLS scopes with context support#1

Open
bnlucas wants to merge 1 commit intomainfrom
codex/add-class-level-rls-scope-configuration
Open

Add repository RLS scopes with context support#1
bnlucas wants to merge 1 commit intomainfrom
codex/add-class-level-rls-scope-configuration

Conversation

@bnlucas
Copy link
Owner

@bnlucas bnlucas commented Dec 25, 2025

Motivation

  • Introduce repository-level row-level security (RLS) support so repository queries can be constrained by tenant/user context.
  • Ensure all delegated ActiveRecord-like methods are routed through a configurable base relation so RLS enforcement is centralized.
  • Provide a simple API to pass context into repository queries, enabling with_context usage or per-call context:.
  • Document usage and add specs to prevent regressions and clarify the intended behavior.

Description

  • Add rls_scope(&block) class method to store a repository-level scope block and base_relation(context:) to return either model or the executed scope using instance_exec.
  • Change delegate_common_model_methods to call base_relation(context:) and accept a context: keyword for delegated methods so queries go through the RLS layer.
  • Add with_context(context) and a ContextProxy class that forwards common AR methods while injecting the provided context into delegated calls.
  • Update README.md with an example using rls_scope and with_context, and add specs in spec/gaskit/repository_spec.rb covering default model behavior, applied RLS scopes, and context passing.

Testing

  • Added and updated spec/gaskit/repository_spec.rb with tests for default behavior, applying the RLS scope, and passing context into the scope block.
  • Attempted to run bundle exec rspec spec/gaskit/repository_spec.rb but the run failed because the environment lacks the Bundler/rspec executables.
  • No automated tests were executed successfully in this environment due to the missing test dependencies.
  • Local/CI environments with bundle install should be able to run the updated specs to confirm behavior.

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant