Skip to content

Commit

Permalink
refactor: all_accessible sesnor logic revamp
Browse files Browse the repository at this point in the history
Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
  • Loading branch information
joshuaunity committed Oct 28, 2024
1 parent 90e2c77 commit 23ac6e2
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions flexmeasures/api/v3_0/sensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from flask import current_app, url_for
from flask_classful import FlaskView, route
from flask_json import as_json
from flask_security import auth_required
from flask_security import auth_required, current_user
from marshmallow import fields, ValidationError
import marshmallow.validate as validate
from rq.job import Job, NoSuchJobError
Expand Down Expand Up @@ -155,7 +155,6 @@ def index(
:status 422: UNPROCESSABLE_ENTITY
"""
account_ids: list = [account.id]
accounts: list = [account]

if asset is not None:
child_assets = (
Expand All @@ -170,10 +169,14 @@ def index(
filter_statement = GenericAsset.account_id.in_(account_ids)

if all_accessible:
consultancy_account_ids: list = [
acc.consultancy_account_id for acc in accounts
]
account_ids.extend(consultancy_account_ids)
if current_user.has_role("consultant"):
consultancy_accounts = (
db.session.query(Account)
.filter(Account.consultancy_account_id == account.id)
.all()
)
consultancy_account_ids: list = [acc.id for acc in consultancy_accounts]
account_ids.extend(consultancy_account_ids)

if asset and asset.account_id not in account_ids:
return {"message": "Asset does not belong to the account"}, 422
Expand Down

0 comments on commit 23ac6e2

Please sign in to comment.