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

feat: Allow adding public assets through the CLI #727

Merged
merged 15 commits into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion documentation/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
FlexMeasures Changelog
**********************

v0.14.0 | June XX, 2023
v0.14.0 | June 15, 2023
============================

New features
Expand All @@ -13,6 +13,7 @@ New features
* Allow setting multiple :abbr:`SoC (state of charge)` maxima and minima constraints for the `StorageScheduler`, using the new ``soc-minima`` and ``soc-maxima`` fields when calling `/sensors/<id>/schedules/trigger` (POST) through the API (within the ``flex-model`` field) [see `PR #680 <https://www.github.com/FlexMeasures/flexmeasures/pull/680>`_]
* New CLI command ``flexmeasures add report`` to calculate a custom report from sensor data and save the results to the database, with the option to export them to a CSV or Excel file [see `PR #659 <https://www.github.com/FlexMeasures/flexmeasures/pull/659>`_]
* New CLI commands ``flexmeasures show reporters`` and ``flexmeasures show schedulers`` to list available reporters and schedulers, respectively, including any defined in registered plugins [see `PR #686 <https://www.github.com/FlexMeasures/flexmeasures/pull/686>`_ and `PR #708 <https://github.com/FlexMeasures/flexmeasures/pull/708>`_]
* Allow creating public assets through the CLI, which are available to all users [see `PR #727 <https://github.com/FlexMeasures/flexmeasures/pull/727>`_]

Bugfixes
-----------
Expand Down
9 changes: 9 additions & 0 deletions documentation/cli/change_log.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
FlexMeasures CLI Changelog
**********************

since v0.14.0 | June 15, 2023
=================================

* Allow setting a storage efficiency using the new ``--storage-efficiency`` option to the ``flexmeasures add schedule for-storage`` CLI command.
* Add CLI command ``flexmeasures add report`` to calculate a custom report from sensor data and save the results to the database, with the option to export them to a CSV or Excel file.
* Add CLI command ``flexmeasures show reporters`` to list available reporters, including any defined in registered plugins.
* Add CLI command ``flexmeasures show schedulers`` to list available schedulers, including any defined in registered plugins.
* Make ``--account-id`` optional in ``flexmeasures add asset`` to support creating public assets, which are available to all users.

since v0.13.0 | May 1, 2023
=================================

Expand Down
14 changes: 12 additions & 2 deletions flexmeasures/cli/data_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,12 @@ def new_account(name: str, roles: str):
@with_appcontext
@click.option("--username", required=True)
@click.option("--email", required=True)
@click.option("--account-id", type=int, required=True)
@click.option(
"--account-id",
type=int,
required=True,
help="Add user to this account. Follow up with the account's ID.",
)
@click.option("--roles", help="e.g. anonymous,Prosumer,CPO")
@click.option(
"--timezone",
Expand Down Expand Up @@ -286,7 +291,12 @@ def add_asset_type(**args):
type=LongitudeField(),
help="Longitude of the asset's location",
)
@click.option("--account-id", type=int, required=True)
@click.option(
"--account-id",
type=int,
required=False,
help="Add asset to this account. Follow up with the account's ID. If not set, the asset will become public (which makes it accessible to all users).",
)
Flix6x marked this conversation as resolved.
Show resolved Hide resolved
@click.option(
"--asset-type-id",
"generic_asset_type_id",
Expand Down
8 changes: 7 additions & 1 deletion flexmeasures/data/schemas/generic_assets.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import json

from marshmallow import validates, validates_schema, ValidationError, fields
Expand Down Expand Up @@ -66,7 +68,11 @@ def validate_generic_asset_type(self, generic_asset_type_id: int):
)

@validates("account_id")
def validate_account(self, account_id: int):
def validate_account(self, account_id: int | None):
if account_id is None and (
running_as_cli() or user_has_admin_access(current_user, "update")
):
return
account = Account.query.get(account_id)
if not account:
raise ValidationError(f"Account with Id {account_id} doesn't exist.")
Expand Down
Loading