Fix for updating xero token in the background (#60)

This commit is contained in:
jbirddog 2022-11-23 15:49:43 -05:00 committed by GitHub
parent 1c9cee4081
commit a3aa4fb543
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -65,7 +65,7 @@ class SecretService:
def update_secret( def update_secret(
key: str, key: str,
value: str, value: str,
user_id: int, user_id: Optional[int] = None,
create_if_not_exists: Optional[bool] = False, create_if_not_exists: Optional[bool] = False,
) -> None: ) -> None:
"""Does this pass pre commit?""" """Does this pass pre commit?"""
@ -79,6 +79,12 @@ class SecretService:
db.session.rollback() db.session.rollback()
raise e raise e
elif create_if_not_exists: elif create_if_not_exists:
if user_id is None:
raise ApiError(
error_code="update_secret_error_no_user_id",
message=f"Cannot update secret with key: {key}. Missing user id.",
status_code=404,
)
SecretService.add_secret(key=key, value=value, user_id=user_id) SecretService.add_secret(key=key, value=value, user_id=user_id)
else: else:
raise ApiError( raise ApiError(

View File

@ -8,6 +8,7 @@ from flask import g
from spiffworkflow_backend.services.file_system_service import FileSystemService from spiffworkflow_backend.services.file_system_service import FileSystemService
from spiffworkflow_backend.services.secret_service import SecretService from spiffworkflow_backend.services.secret_service import SecretService
from spiffworkflow_backend.services.user_service import UserService
class ConnectorProxyError(Exception): class ConnectorProxyError(Exception):
@ -65,7 +66,8 @@ class ServiceTaskDelegate:
secret_key = parsed_response["auth"] secret_key = parsed_response["auth"]
refreshed_token_set = json.dumps(parsed_response["refreshed_token_set"]) refreshed_token_set = json.dumps(parsed_response["refreshed_token_set"])
SecretService().update_secret(secret_key, refreshed_token_set, g.user.id) user_id = g.user.id if UserService.has_user() else None
SecretService().update_secret(secret_key, refreshed_token_set, user_id)
return json.dumps(parsed_response["api_response"]) return json.dumps(parsed_response["api_response"])