Skip to content
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

Issue 247 generic asset crud #290

Merged
merged 35 commits into from Jan 5, 2022
Merged

Conversation

nhoening
Copy link
Contributor

@nhoening nhoening commented Dec 29, 2021

  • Add a new API for our new asset data model: generic assets. For now reachable at /api/dev, as the old API will stay for a bit.
  • Move the asset CRUD in the UI to use this new API.

Also:

  • Auth: Change "create" permission to "create-children", as you get the permission from the the ACL of the instance one level up in the hierarchy (and the highest objects, like accounts, are created by site-admins on CLI level)
  • Auth2: add another method for the permission-for-context endpoint decorator to define a context (with a Callable, useful for defaults, like current_user.account)
  • Auth3: Add ACLs for GenericAsset, Sensor, Account & User
  • Auth4: Fix a bug in parsing ACLs for the case that there are two possible ways to authorize for the same permission
  • Data model: add unique contraints: on GenericAssetType.name & on GenericAssets for name+account_id (the latter is also checked on the schema level, for nicer responses)

For testing: try if the UI Asset Crud is doing its job. It is using the generic asset API internally.

TODO:

  • make crud tests work
  • move API tests to new API & make work
  • check if UI can consistently show asset type icon
  • changelog entry (incl deprecation notice)

@nhoening nhoening changed the base branch from main to project-9 December 29, 2021 16:55
@nhoening nhoening requested a review from Flix6x January 1, 2022 22:24
Copy link
Contributor

@Flix6x Flix6x left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I request small changes mostly.

The bigger issue is that we need some sensor CRUD (at least the R) before we can update our documentation. In particular, we are missing a sensor listing where users can look up entity addresses, so they can actually use the data API.

flexmeasures/auth/tests/test_principal_matching.py Outdated Show resolved Hide resolved
flexmeasures/conftest.py Outdated Show resolved Hide resolved
flexmeasures/data/models/time_series.py Show resolved Hide resolved
flexmeasures/data/models/user.py Outdated Show resolved Hide resolved
flexmeasures/data/schemas/generic_assets.py Outdated Show resolved Hide resolved
@@ -17,6 +17,11 @@
from flexmeasures.api.common.responses import required_info_missing


"""
Deprecated. Use /api/dev/generic_assets.
TODO: Can/should we add a deprecation warning to responses?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. At the very least in the documentation of the relevant endpoints.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also discuss updating documentation before releasing.

documentation/changelog.rst Outdated Show resolved Hide resolved
documentation/changelog.rst Outdated Show resolved Hide resolved
flexmeasures/api/dev/tests/test_assets_api.py Outdated Show resolved Hide resolved
flexmeasures/ui/templates/crud/assets.html Outdated Show resolved Hide resolved
@nhoening
Copy link
Contributor Author

nhoening commented Jan 3, 2022

Maybe the easiest path towards releasing this is to a listing of sensors on each asset page.

Later, we can link from there to a sensor page where you can see a plot and find a link to edit its meta data or delete it. Those are less crucial for now.

@Flix6x
Copy link
Contributor

Flix6x commented Jan 3, 2022

Maybe the easiest path towards releasing this is to a listing of sensors on each asset page.

I agree.

Signed-off-by: Nicolas Höning <nicolas@seita.nl>
-e
Signed-off-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: Nicolas Höning <nicolas@seita.nl>
Flix6x and others added 4 commits January 4, 2022 12:37
Remove the entity addresses from the generic asset listing, and list the number of sensors instead.


* grammar

Signed-off-by: F.N. Claessen <felix@seita.nl>

* Update generic asset listing, replacing entity addresses with number of sensors

Signed-off-by: F.N. Claessen <felix@seita.nl>

* Avoid crashing on formatting None values

Signed-off-by: F.N. Claessen <felix@seita.nl>

* Fix wrong variable name

Signed-off-by: F.N. Claessen <felix@seita.nl>

* Fix incorrect type annotation

Signed-off-by: F.N. Claessen <felix@seita.nl>

* Partly revert cefe320

Signed-off-by: F.N. Claessen <felix@seita.nl>
Signed-off-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: Nicolas Höning <nicolas@seita.nl>
@nhoening nhoening requested a review from Flix6x January 4, 2022 12:30
Signed-off-by: F.N. Claessen <felix@seita.nl>
Signed-off-by: F.N. Claessen <felix@seita.nl>
Signed-off-by: F.N. Claessen <felix@seita.nl>
Signed-off-by: F.N. Claessen <felix@seita.nl>
Copy link
Contributor

@Flix6x Flix6x left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for all the help moving our asset crud over! It seems project 9 is about finished.

Signed-off-by: F.N. Claessen <felix@seita.nl>
Signed-off-by: F.N. Claessen <felix@seita.nl>
… to fm1 scheme.

Signed-off-by: F.N. Claessen <felix@seita.nl>
@nhoening nhoening merged commit 1bb2819 into project-9 Jan 5, 2022
@nhoening nhoening deleted the issue-247-GenericAsset-CRUD branch January 5, 2022 15:59
@Flix6x Flix6x linked an issue Jan 6, 2022 that may be closed by this pull request
@Flix6x Flix6x added this to the 0.8.0 milestone Jan 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement GenericAsset crud
2 participants