-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Snapshots api #3833
Snapshots api #3833
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3833 +/- ##
==========================================
+ Coverage 79.16% 79.22% +0.05%
==========================================
Files 279 281 +2
Lines 12567 12660 +93
Branches 2792 2813 +21
==========================================
+ Hits 9949 10030 +81
- Misses 2618 2630 +12
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One minor tweak to the permissions descriptions to clarify the difference between the two - will self merge.
closes #3828
Description
This PR lays foundation for exporting device snapshots (part of #3617) for visualising snapshots (part of #3798) and goes some way to squaring up the snapshot vue pages differences as part of #3815 by providing a means to export a device snapshot
Details
A new API with 4 routes are added creating a top-level Snapshots API. The routes are:
GET
/snapshots/:id
- returns only the meta data of a snapshotGET
/snapshots/:id/full
- returns the full data of a snapshot (without credentials)DELETE
/snapshots/:id
- deletes a snapshotPOST
/snapshots/:id/export
- exports a snapshotThe pre-handler for these routes check if the user has the necessary RBAC permissions to perform the operations. These are:
snapshot:meta
- 'View a Snapshot' -Viewer
snapshot:full
- 'Export a Snapshot' -Member
snapshot:export
- 'Export a Snapshot' -Member
snapshot:delete
- 'Delete a Snapshot' -Owner
Tests are added to cover the new routes and the permissions they require. (see below)
A new controller
Snapshots
is added to handle these routes. Controller methods include:getSnapshot
- returns only the meta data of a snapshotgetFullSnapshot
- returns the full data of a snapshotdeleteSnapshot
- deletes a snapshotSchemas in the ProjectSnapshot view are updated to support the new API:
SnapshotSummary
SnapshotSummary
Snapshot
Snapshot
SnapshotSummary
instead of duplicating fieldsSnapshotAndSettings
FullSnapshot
andExportedSnapshot
FullSnapshot
SnapshotAndSettings
and addsflows
ExportedSnapshot
ExportedSnapshot
SnapshotAndSettings
but addsflows
andcredentials
SnapshotAndSettings
Existing calls to export snapshot and delete snapshot updated to utelise the new snapshot controller as a single source of truth.
NOTE WORTHY
This PR includes a minor pattern change to how
forge/db/views/ProjectSnapshot.js
is exported/imported.In essence, the module now exports the functions and has a new
init
routine to setup theapp
object.This new pattern is a first step in improving type inference and ultimately DX
throughout our codebase. Essentially, the start of some technical debt cleanup.
Most importantly, this is NOT a breaking change and can be done incrementally.
It is my hope this is accepted and adopted to all views eventually.
Amongst the benefits, it provides accurate function signatures (no app object), better code
completion, instant code navigation (by CTRL+clicking on the function), code peeking (on hover), and more.
For now, this is a first step in the right direction. Local variables can be decorated with JSDoc
to provide accurate typings. e.g.
/** @type {import('path-to-view.js')} */ const snapshotView = app.db.views.Snapshot
.Eventually, we will be able to properly decorate the
app
and theapp.db.views
objects so that offersthe dev accurate typings & completions to reduces context switching (no need to hunt down the function
when its signature is accurately offered as a suggestion).
Once all views are updated to this pattern, I want to apply the same pattern to the controllers.
The eventual goal is to have a reference-able objects that can be used to provide better
static analysis & simple refactoring possibilities.
Missing tests added (opportunistic/working in that area/quick wins)
Tests Added
Related Issue(s)
#3828
Checklist
flowforge.yml
?FlowFuse/helm
to update ConfigMap TemplateFlowFuse/CloudProject
to update values for Staging/ProductionLabels
area:migration
label