Remove groupIdToken from IdTokenInfo
All checks were successful
ci/woodpecker/push/docker Pipeline was successful
All checks were successful
ci/woodpecker/push/docker Pipeline was successful
This commit is contained in:
parent
7a6495b405
commit
d2243c4f0b
|
@ -28,11 +28,12 @@ class ChargePoint(cp):
|
||||||
db_chargepoint.last_seen = datetime.now(UTC)
|
db_chargepoint.last_seen = datetime.now(UTC)
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
async def __get_id_token_info(self, id_token) -> IdTokenInfoType:
|
async def __get_id_token_info(self, id_token):
|
||||||
|
owner_id = None
|
||||||
if id_token["type"] not in ["ISO14443", "ISO15693"]:
|
if id_token["type"] not in ["ISO14443", "ISO15693"]:
|
||||||
return IdTokenInfoType(
|
return IdTokenInfoType(
|
||||||
status=AuthorizationStatusType.invalid
|
status=AuthorizationStatusType.invalid
|
||||||
)
|
), owner_id
|
||||||
|
|
||||||
with SessionLocal() as db:
|
with SessionLocal() as db:
|
||||||
db_id_token = db.query(DbIdToken).filter(DbIdToken.token == id_token["id_token"]).first()
|
db_id_token = db.query(DbIdToken).filter(DbIdToken.token == id_token["id_token"]).first()
|
||||||
|
@ -52,29 +53,23 @@ class ChargePoint(cp):
|
||||||
db.add(db_id_token)
|
db.add(db_id_token)
|
||||||
|
|
||||||
id_token_info=IdTokenInfoType(
|
id_token_info=IdTokenInfoType(
|
||||||
status=AuthorizationStatusType.accepted#,
|
status=AuthorizationStatusType.accepted
|
||||||
#group_id_token=IdTokenType(
|
|
||||||
#type=IdTokenEnumType.central,
|
|
||||||
#id_token=str(db_id_token.owner_id)
|
|
||||||
#)
|
|
||||||
)
|
)
|
||||||
|
owner_id = db_id_token.owner_id
|
||||||
db_chargepoint.learn_user_id = None
|
db_chargepoint.learn_user_id = None
|
||||||
db_chargepoint.learn_until = None
|
db_chargepoint.learn_until = None
|
||||||
db.commit()
|
db.commit()
|
||||||
else:
|
else:
|
||||||
|
owner_id = db_id_token.owner_id
|
||||||
if db_id_token.is_active == False:
|
if db_id_token.is_active == False:
|
||||||
id_token_info=IdTokenInfoType(
|
id_token_info=IdTokenInfoType(
|
||||||
status=AuthorizationStatusType.blocked
|
status=AuthorizationStatusType.blocked
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
id_token_info=IdTokenInfoType(
|
id_token_info=IdTokenInfoType(
|
||||||
status=AuthorizationStatusType.accepted#,
|
status=AuthorizationStatusType.accepted
|
||||||
#group_id_token=IdTokenType(
|
|
||||||
#type=IdTokenEnumType.central,
|
|
||||||
#id_token=str(db_id_token.owner_id)
|
|
||||||
#)
|
|
||||||
)
|
)
|
||||||
return id_token_info
|
return id_token_info, owner_id
|
||||||
|
|
||||||
@on(Action.BootNotification)
|
@on(Action.BootNotification)
|
||||||
async def on_boot_notification(self, charging_station, **kwargs):
|
async def on_boot_notification(self, charging_station, **kwargs):
|
||||||
|
@ -142,7 +137,7 @@ class ChargePoint(cp):
|
||||||
@on(Action.Authorize)
|
@on(Action.Authorize)
|
||||||
async def on_authorize(self, id_token, **kwargs):
|
async def on_authorize(self, id_token, **kwargs):
|
||||||
await self.__update_last_seen()
|
await self.__update_last_seen()
|
||||||
id_token_info = await self.__get_id_token_info(id_token)
|
id_token_info, _ = await self.__get_id_token_info(id_token)
|
||||||
return call_result.AuthorizePayload(id_token_info)
|
return call_result.AuthorizePayload(id_token_info)
|
||||||
|
|
||||||
@on(Action.TransactionEvent)
|
@on(Action.TransactionEvent)
|
||||||
|
@ -157,7 +152,7 @@ class ChargePoint(cp):
|
||||||
**kwargs
|
**kwargs
|
||||||
):
|
):
|
||||||
if id_token != None:
|
if id_token != None:
|
||||||
id_token_info = await self.__get_id_token_info(id_token)
|
id_token_info, token_owner_id = await self.__get_id_token_info(id_token)
|
||||||
|
|
||||||
with SessionLocal() as db:
|
with SessionLocal() as db:
|
||||||
chargepoint = db.query(DbChargePoint).filter(DbChargePoint.identity == self.id).first()
|
chargepoint = db.query(DbChargePoint).filter(DbChargePoint.identity == self.id).first()
|
||||||
|
@ -183,7 +178,7 @@ class ChargePoint(cp):
|
||||||
)
|
)
|
||||||
if id_token != None:
|
if id_token != None:
|
||||||
if id_token_info.status == AuthorizationStatusType.accepted:
|
if id_token_info.status == AuthorizationStatusType.accepted:
|
||||||
transaction.user_id = UUID(id_token_info.group_id_token.id_token)
|
transaction.user_id = UUID(token_owner_id)
|
||||||
db.add(transaction)
|
db.add(transaction)
|
||||||
elif event_type == str(TransactionEventType.updated):
|
elif event_type == str(TransactionEventType.updated):
|
||||||
transaction = db.get(DbTransaction, transaction_info["transaction_id"])
|
transaction = db.get(DbTransaction, transaction_info["transaction_id"])
|
||||||
|
@ -209,7 +204,7 @@ class ChargePoint(cp):
|
||||||
db.add(db_meter_value)
|
db.add(db_meter_value)
|
||||||
if id_token != None:
|
if id_token != None:
|
||||||
if id_token_info.status == AuthorizationStatusType.accepted:
|
if id_token_info.status == AuthorizationStatusType.accepted:
|
||||||
transaction.user_id = UUID(id_token_info.group_id_token.id_token)
|
transaction.user_id = UUID(token_owner_id)
|
||||||
elif event_type == str(TransactionEventType.ended):
|
elif event_type == str(TransactionEventType.ended):
|
||||||
transaction = db.get(DbTransaction, transaction_info["transaction_id"])
|
transaction = db.get(DbTransaction, transaction_info["transaction_id"])
|
||||||
transaction.status = TransactionStatus.ENDED
|
transaction.status = TransactionStatus.ENDED
|
||||||
|
@ -227,7 +222,7 @@ class ChargePoint(cp):
|
||||||
transaction.meter_end = meter_end
|
transaction.meter_end = meter_end
|
||||||
if id_token != None:
|
if id_token != None:
|
||||||
if id_token_info.status == AuthorizationStatusType.accepted:
|
if id_token_info.status == AuthorizationStatusType.accepted:
|
||||||
transaction.user_id = UUID(id_token_info.group_id_token.id_token)
|
transaction.user_id = UUID(token_owner_id)
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
if id_token != None:
|
if id_token != None:
|
||||||
|
|
Loading…
Reference in a new issue