Improve permissions checking#1696
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR tightens authorization by scoping record lookups to the current user (or the current book/team) instead of fetching by raw :id, reducing the chance of unauthorized access via ID guessing.
Changes:
- Scope
Team,ApiKey,Judgement, andQueryDocPairlookups throughcurrent_user/@book. - Scope API “share” endpoints to cases/scorers the current user is involved with, returning
404when inaccessible. - Add/adjust tests to cover the new authorization behavior and reduce noisy output/flaky external LLM behavior.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| test/services/llm_service_test.rb | Removes debug output; makes the Ollama test conditional on reachability and ensures WebMock is restored. |
| test/controllers/teams_controller_test.rb | Switches fixture user and adds coverage for non-member access/rename attempts. |
| test/controllers/api_keys_controller_test.rb | Adds integration tests ensuring users can only delete their own API keys. |
| test/controllers/api/v1/team_scorers_controller_test.rb | Adds a not-found test when sharing an inaccessible scorer. |
| test/controllers/api/v1/team_cases_controller_test.rb | Adds a not-found test when sharing an inaccessible case. |
| app/controllers/teams_controller.rb | Scopes set_team to current_user.teams. |
| app/controllers/query_doc_pairs_controller.rb | Reorders callbacks and scopes query-doc-pair lookup via @book. |
| app/controllers/judgements_controller.rb | Reorders callbacks and scopes judgement lookup via @book. |
| app/controllers/api_keys_controller.rb | Scopes API key deletion via current_user.api_keys. |
| app/controllers/api/v1/team_scorers_controller.rb | Scopes scorer lookup via current_user.scorers_involved_with. |
| app/controllers/api/v1/team_cases_controller.rb | Scopes case lookup via current_user.cases_involved_with (with includes). |
| app/controllers/ai_judges_controller.rb | Scopes team and AI-judge lookups through current_user.teams and @team.members.only_ai_judges. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
6
to
8
| before_action :set_book | ||
| before_action :set_query_doc_pair, only: [ :show, :edit, :update, :destroy ] | ||
|
|
Comment on lines
6
to
8
| before_action :set_book | ||
| before_action :set_judgement, only: [ :show, :edit, :update, :destroy ] | ||
|
|
davidshq
approved these changes
May 11, 2026
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.
Description
We need to scope lookups for data to who owns it instead of using
:iddirectly.Motivation and Context
Better security
How Has This Been Tested?
manual and tests
Types of changes