Fix/restrict org id filtering#333
Conversation
…ypes to keep region endpoints unaffected
…ronment configuration
| ) | ||
|
|
||
| router = APIRouter(tags=[pathlib.Path(__file__).parent.stem.capitalize()]) | ||
| SITE_OBSERVER_NAME = "site_api" |
There was a problem hiding this comment.
The observer is called "site_api"? Does this mean every user writes their data to the same observer? I wonder if we're not better off with an observer per user...
There was a problem hiding this comment.
Yes, I discussed this with @peterdudfield . One of the main challenges was determining the observer name for a location when the user comes through the API endpoint. As a solution, we set it to site-api.
For debugging and audit purposes, we always have the auth data available, so we can determine who accessed the endpoint or performed the write operation based on that information.
That said, your suggestion makes sense, and I'm open to discussing a better approach if we think there's a more suitable solution.
There was a problem hiding this comment.
I think for adani for this route, this should keep it simple
Pull Request
Description
This PR fixes regional forecast and generation queries by resolving region names to location objects before querying the database, and restricts organization filtering strictly to
SITEandSUBSTATIONlocation types to keep regional endpoints unaffected.Context
Prior to this change:
/solar/ruvnl/generationand/solar/ruvnl/forecast) passed the region name string directly where location UUIDs were expected, causing database query failures.Key Changes
client.py):SITEandSUBSTATIONlocation types inget_locations._check_user_accesschecks toSITElocation types inget_actual_generationandput_actual_generation, preventing regional queries from being filtered or blocked.router.py):SITE_OBSERVER_NAME = "site_api"constant._resolve_regionto resolve a region name to its location object, raising a clean 404 Not Found if the region doesn't exist.get_historic_timeseries_route,get_forecast_timeseries_route, andget_forecast_csvto use the helper.SITE_OBSERVER_NAMEinget_actual_generationfor regional endpoints to resolve the missing observer error.How Has This Been Tested?
1. Automated Tests
Added a new unit test suite specifically for the regions router:
src/quartz_api/internal/service/regions/test_router.pyRun the router tests using:
All 28 tests passed successfully.
2. Manual Verification
Verified API responses locally:
/solar/regions: Returns valid regions (200 OK)./solar/ruvnl_solar/generation: Returns actual values (200 OK)./solar/ruvnl_solar/forecast: Returns forecast values (200 OK)./solar/invalid_region/forecast: Returns clean404 Not Foundwith{"detail": "Region or GSP 'invalid_region' not found."}.Checklist: