insights: add http handler for exporting data for one code insight#46662
Conversation
|
Codenotify: Notifying subscribers in CODENOTIFY files for diff 4338f05...5a6c9c7.
|
|
@leonore was this tested against an unauthed user, and a user that doesn't have access to the insight? |
yes, it returns "Private mode requires authentication"
good catch, we don't assert on dashboard permissions. will fix that |
coury-clark
left a comment
There was a problem hiding this comment.
A few things that need to be addressed, but overall good work!
|
@coury-clark I've pushed some fixes for your requests. FYI I am planning on cleaning up all the repo regex loading stuff and commonising some things there as I just pulled it out the resolvers (plan is to move it out to |
| var orgIds []int | ||
| currentActor := actor.FromContext(ctx) | ||
| if !currentActor.IsAuthenticated() { | ||
| return nil, nil, errors.New("user is unauthenticated") |
There was a problem hiding this comment.
Ideally this returns 401, but there may be a middleware that does that already. I'd suggest giving it a quick test. I'm also wondering if we should move this check up to the API handler explicitly, just for clarity and to ensure we don't ever accidentally refactor this into the wrong place.
There was a problem hiding this comment.
yeah so if you try and hit the API without an authorization header it will already return 401 (with Private mode requires authentication). if you try it with a wrong token it does the same. I didn't pinpoint where exactly this was happening in the middleware. I've moved this a way up to be more explicit though.
closes #45746
This adds a new external api endpoint (
httpapi)./api/insights/export/{id}for exporting code insight data for an insight view. {id} corresponds to the id we use at the moment on the frontend, e.g. https://sourcegraph.sourcegraph.com/insights/aW5zaWdodF92aWV3OiIyQmRnV2VFYktwWGF2UjlGcXpuVDA1cld0c2siThe export store function adds empty rows for times we have no data for, and does some joining on tables to get all the metadata for a user
Some nitty things to consider in your review
./api/insights/export/{id}Test plan
Unit tests for basic store behaviour and repo permissions
Tested with
Search insight
Capture group insight
Compute type insight
Ensured insights with archived values had the archived values.
Ensured default filters were taken into account
Tested authorization
Ran the curl against
oss: returns "code insights data export handler is only available in enterprise"Ran the curl against
enterprise: returns "code insights data export handler is only available in enterprise"makeNotFoundHandlerCurl this was tested with
curl \ -H 'Authorization: token {token}' https://sourcegraph.test:3443/.api/insights/export/aW5zaWdodF92aWV3OiIySEx0R0plUVJxS05kS3IyRG1SdmU3ZjNjbXoi -O -J -v-O makes it output it into the file it defines and -J uses the header filename rather than the {id} name.