-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable exporting reports and events as CSV (#160)
* [WIP]Add site report exporting * Update go modules * Update frontend dependencies * Add report and event exports * Update frontend dependencies * Add tests for export downloads
- Loading branch information
Showing
39 changed files
with
1,355 additions
and
537 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,8 +15,9 @@ jobs: | |
|
||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 19.6.0 | ||
node-version: 19.7.0 | ||
|
||
# TODO: Delete this step when https://github.com/reviewdog/action-eslint/issues/152 is resolved. | ||
- name: Install custom npm version | ||
run: npm i -g [email protected] | ||
|
||
|
@@ -41,14 +42,6 @@ jobs: | |
- name: Setup reviewdog | ||
uses: reviewdog/action-setup@v1 | ||
|
||
# TODO: Delete this step when https://github.com/reviewdog/action-eslint/issues/152 is resolved. | ||
- name: Install custom npm version | ||
run: npm i -g [email protected] | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
working-directory: frontend | ||
|
||
- env: | ||
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
name: Run tsc | ||
|
@@ -125,7 +118,7 @@ jobs: | |
|
||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 19.6.0 | ||
node-version: 19.7.0 | ||
|
||
- id: restore-npm-cache | ||
name: Restore npm cache | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"yaml.schemas": { | ||
"https://json.schemastore.org/github-workflow.json": "file:///Users/th0th/Workspace/poeticmetric/.github/workflows/deploy.yaml" | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
92 changes: 92 additions & 0 deletions
92
backend/pkg/restapi/middleware/authentication/user_access_token_form_auth.go
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package authentication | ||
|
||
import ( | ||
"errors" | ||
"log" | ||
"strconv" | ||
"time" | ||
|
||
"github.com/getsentry/sentry-go" | ||
"github.com/gofiber/contrib/fibersentry" | ||
"github.com/gofiber/fiber/v2" | ||
"github.com/th0th/poeticmetric/backend/pkg/depot" | ||
"github.com/th0th/poeticmetric/backend/pkg/model" | ||
"github.com/th0th/poeticmetric/backend/pkg/pointer" | ||
dm "github.com/th0th/poeticmetric/backend/pkg/restapi/middleware/depot" | ||
"gorm.io/gorm" | ||
) | ||
|
||
func NewUserAccessTokenFormAuth() fiber.Handler { | ||
return func(c *fiber.Ctx) error { | ||
dateTime := time.Now() | ||
|
||
dp := dm.Get(c) | ||
|
||
userAccessToken := c.FormValue("user-access-token") | ||
|
||
if userAccessToken == "" { | ||
return c.Next() | ||
} | ||
|
||
modelUserAccessToken := &model.UserAccessToken{} | ||
|
||
err := dp.Postgres(). | ||
Model(&model.UserAccessToken{}). | ||
Where("token = ?", userAccessToken). | ||
First(modelUserAccessToken). | ||
Error | ||
if err != nil { | ||
if errors.Is(err, gorm.ErrRecordNotFound) { | ||
return fiber.ErrUnauthorized | ||
} | ||
|
||
return err | ||
} | ||
|
||
modelUser := &model.User{} | ||
|
||
err = dp.Postgres(). | ||
Model(&model.User{}). | ||
Where("is_active is true"). | ||
Where("id = ?", modelUserAccessToken.UserId). | ||
First(modelUser). | ||
Error | ||
if err != nil { | ||
return err | ||
} | ||
|
||
modelOrganization := &model.Organization{} | ||
|
||
err = dp.Postgres(). | ||
Model(&model.Organization{}). | ||
Joins("Plan"). | ||
Where("organizations.id = ?", modelUser.OrganizationId). | ||
First(modelOrganization). | ||
Error | ||
if err != nil { | ||
return err | ||
} | ||
|
||
c.Locals("auth", &Auth{ | ||
Kind: pointer.Get(AuthKindRestApiUserAccessToken), | ||
Organization: modelOrganization, | ||
User: modelUser, | ||
UserAccessToken: modelUserAccessToken, | ||
}) | ||
|
||
fibersentry.GetHubFromContext(c).Scope().SetUser(sentry.User{ | ||
Email: modelUser.Email, | ||
ID: strconv.Itoa(int(modelUser.Id)), | ||
}) | ||
|
||
err = dp.Redis(). | ||
Set(depot.Ctx, modelUserAccessToken.LastUsedAtRedisKey(), dateTime.Unix(), time.Hour). | ||
Err() | ||
if err != nil { | ||
// TODO: handle the error better | ||
log.Println(err) | ||
} | ||
|
||
return c.Next() | ||
} | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package sitereport | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/gofiber/fiber/v2" | ||
dm "github.com/th0th/poeticmetric/backend/pkg/restapi/middleware/depot" | ||
export2 "github.com/th0th/poeticmetric/backend/pkg/service/sitereport/export" | ||
) | ||
|
||
func exportEvents(c *fiber.Ctx) error { | ||
dp := dm.Get(c) | ||
|
||
filters := getFilters(c) | ||
|
||
zipFileName, zipFileContent, err := export2.Events(dp, filters) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
c.Set(fiber.HeaderContentDisposition, fmt.Sprintf(`attachment; filename="%s.zip"`, *zipFileName)) | ||
|
||
return c.Send(zipFileContent.Bytes()) | ||
} |
Oops, something went wrong.