CRUD for automations in the API and UI - #2294
Draft
Flix6x wants to merge 6 commits into
Draft
Conversation
- New endpoints on assets: POST /automations (create, validating parameters by automation type), PATCH /automations/<id> (name, cron string, activation status) and DELETE /automations/<id>. Managing automations requires the same principals that may delete the asset (account admins and consultants). - The UI automations page gets a 'New automation' modal and per-row (de)activate and delete actions, shown to users with management rights. - Creation, update and deletion logic (incl. audit log records) moved into the automations service, shared by the CLI commands and the API endpoints. Part of #2288 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Rbix8k1JfeUWNXEmHEZVpX
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Rbix8k1JfeUWNXEmHEZVpX
Documentation build overview
21 files changed ·
|
…elves Context: - Review of #2290 asked that automations administered through the UI (and hence the API) may only involve sensors the creating user has access to; account admin rights on the asset should not grant access to another account's sensors Change: - Work out the sensors an automation would read from and write to (forecasts: the sensor to forecast plus its regressors, and the sensor to save to; schedules: the flex-model's device sensors, and whatever the parameters refer to) - Require read access to the former and create-children (the permission for recording data through the API) on the latter, when creating via the API - The CLI creates automations without a user, and stays unrestricted Signed-off-by: F.N. Claessen <felix@seita.nl>
Context: - The endpoint description now states the sensor access rule Change: - Regenerated the specs Signed-off-by: F.N. Claessen <felix@seita.nl>
Context: - The sensor access rule for created automations needs regression coverage Change: - An account admin creating an automation on another account's sensor gets a 403 naming that sensor, and no automation is created; the same request on their own sensor still succeeds (verified to fail without the check) Signed-off-by: F.N. Claessen <felix@seita.nl>
Context: - The sensor access rule is user-facing Change: - Documented it in the forecasting feature docs, the changelog entry of #2294 and the API change log Signed-off-by: F.N. Claessen <felix@seita.nl>
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
Milestone 3 of #2288 (stacked on #2293, which is stacked on #2290): automations can now be created, edited and deleted through the API and the UI.
POST /assets/<id>/automations— create an automation; parameters are validated by the schema matching the automation type (forecast parameters or a schedule trigger message). Response includes any validation warnings.PATCH /assets/<id>/automations/<automation_id>— update name, cron string and/or activation status.DELETE /assets/<id>/automations/<automation_id>— delete (already-queued jobs are unaffected).flexmeasures/data/services/automations.py, shared by the CLI commands and the new endpoints (audit messages now say "via CLI" or "via API" consistently).How to test
As an account admin, open
/assets/<id>/automationsand use the New automation button, or:Tests:
pytest flexmeasures/api/v3_0/tests/test_automations_api.py flexmeasures/cli/tests/test_automations.py(permission matrix: plain member 403, account admin OK, other account 403).🤖 Generated with Claude Code
https://claude.ai/code/session_01Rbix8k1JfeUWNXEmHEZVpX
related issues
closes #2372