Merge remote-tracking branch 'origin/main' into feature/permissions

This commit is contained in:
jasquat 2022-10-11 10:31:22 -04:00
commit f652f3e56f
16 changed files with 118 additions and 108 deletions

4
poetry.lock generated
View File

@ -639,7 +639,7 @@ werkzeug = "*"
type = "git"
url = "https://github.com/sartography/flask-bpmn"
reference = "main"
resolved_reference = "b33362f2d62bbb4c1d1a1c992f6b057c8e71431c"
resolved_reference = "2e4b592fa36406423d69cd24018f720a4c041d8a"
[[package]]
name = "Flask-Cors"
@ -1866,7 +1866,7 @@ pytz = "*"
type = "git"
url = "https://github.com/sartography/SpiffWorkflow"
reference = "main"
resolved_reference = "804889ce3b993c909ea795047dd18ea0ed6e5a99"
resolved_reference = "f30221dc6bb52753952369fc3bc5ee55ceef762f"
[[package]]
name = "SQLAlchemy"

View File

@ -51,7 +51,7 @@ class UserModel(SpiffworkflowBaseDBModel):
ap_value: str = ap_type.value
return ap_value
raise ApiError(
code="invalid_service",
error_code="invalid_service",
message=f"Could not validate service with value: {value}",
)

View File

@ -154,7 +154,7 @@ def process_group_show(
except ProcessEntityNotFoundError as exception:
raise (
ApiError(
code="process_group_cannot_be_found",
error_code="process_group_cannot_be_found",
message=f"Process group cannot be found: {process_group_id}",
status_code=400,
)
@ -169,7 +169,7 @@ def process_model_add(
process_model_info = ProcessModelInfoSchema().load(body)
if process_model_info is None:
raise ApiError(
code="process_model_could_not_be_created",
error_code="process_model_could_not_be_created",
message=f"Process Model could not be created from given body: {body}",
status_code=400,
)
@ -180,7 +180,7 @@ def process_model_add(
)
if process_group is None:
raise ApiError(
code="process_model_could_not_be_created",
error_code="process_model_could_not_be_created",
message=f"Process Model could not be created from given body because Process Group could not be found: {body}",
status_code=400,
)
@ -259,7 +259,7 @@ def get_file(process_group_id: str, process_model_id: str, file_name: str) -> An
files = SpecFileService.get_files(process_model, file_name)
if len(files) == 0:
raise ApiError(
code="unknown file",
error_code="unknown file",
message=f"No information exists for file {file_name}"
f" it does not exist in workflow {process_model_id}.",
status_code=404,
@ -283,7 +283,7 @@ def process_model_file_update(
request_file_contents = request_file.stream.read()
if not request_file_contents:
raise ApiError(
code="file_contents_empty",
error_code="file_contents_empty",
message="Given request file does not have any content",
status_code=400,
)
@ -311,7 +311,7 @@ def process_model_file_delete(
except FileNotFoundError as exception:
raise (
ApiError(
code="process_model_file_cannot_be_found",
error_code="process_model_file_cannot_be_found",
message=f"Process model file cannot be found: {file_name}",
status_code=400,
)
@ -326,7 +326,7 @@ def add_file(process_group_id: str, process_model_id: str) -> flask.wrappers.Res
request_file = get_file_from_request()
if not request_file.filename:
raise ApiError(
code="could_not_get_filename",
error_code="could_not_get_filename",
message="Could not get filename from request",
status_code=400,
)
@ -379,7 +379,7 @@ def process_instance_run(
ErrorHandlingService().handle_error(processor, e)
task = processor.bpmn_process_instance.last_task
raise ApiError.from_task(
code="unknown_exception",
error_code="unknown_exception",
message=f"An unknown error occurred. Original error: {e}",
status_code=400,
task=task,
@ -507,7 +507,7 @@ def message_start(
if message_model is None:
raise (
ApiError(
code="unknown_message",
error_code="unknown_message",
message=f"Could not find message with identifier: {message_identifier}",
status_code=404,
)
@ -516,7 +516,7 @@ def message_start(
if "payload" not in body:
raise (
ApiError(
code="missing_payload",
error_code="missing_payload",
message="Body is missing payload.",
status_code=400,
)
@ -538,7 +538,7 @@ def message_start(
if message_instance is None:
raise (
ApiError(
code="cannot_find_waiting_message",
error_code="cannot_find_waiting_message",
message=f"Could not find waiting message for identifier {message_identifier} "
f"and process instance {process_instance.id}",
status_code=400,
@ -558,7 +558,7 @@ def message_start(
if message_triggerable_process_model is None:
raise (
ApiError(
code="cannot_start_message",
error_code="cannot_start_message",
message=f"Message with identifier cannot be start with message: {message_identifier}",
status_code=400,
)
@ -607,7 +607,7 @@ def process_instance_list(
):
raise (
ApiError(
code="unexpected_condition",
error_code="unexpected_condition",
message="Something went very wrong",
status_code=500,
)
@ -730,7 +730,7 @@ def process_instance_report_update(
).first()
if process_instance_report is None:
raise ApiError(
code="unknown_process_instance_report",
error_code="unknown_process_instance_report",
message="Unknown process instance report",
status_code=404,
)
@ -754,7 +754,7 @@ def process_instance_report_delete(
).first()
if process_instance_report is None:
raise ApiError(
code="unknown_process_instance_report",
error_code="unknown_process_instance_report",
message="Unknown process instance report",
status_code=404,
)
@ -798,7 +798,7 @@ def process_instance_report_show(
).first()
if process_instance_report is None:
raise ApiError(
code="unknown_process_instance_report",
error_code="unknown_process_instance_report",
message="Unknown process instance report",
status_code=404,
)
@ -926,7 +926,7 @@ def task_show(process_instance_id: int, task_id: str) -> flask.wrappers.Response
if not form_schema_file_name:
raise (
ApiError(
code="missing_form_file",
error_code="missing_form_file",
message=f"Cannot find a form file for process_instance_id: {process_instance_id}, task_id: {task_id}",
status_code=500,
)
@ -987,7 +987,7 @@ def task_submit(
if spiff_task.state != TaskState.READY:
raise (
ApiError(
code="invalid_state",
error_code="invalid_state",
message="You may not update a task unless it is in the READY state.",
status_code=400,
)
@ -1041,7 +1041,7 @@ def script_unit_test_create(
file = SpecFileService.get_files(process_model, process_model.primary_file_name)[0]
if file is None:
raise ApiError(
code="cannot_find_file",
error_code="cannot_find_file",
message=f"Could not find the primary bpmn file for process_model: {process_model.id}",
status_code=404,
)
@ -1063,7 +1063,7 @@ def script_unit_test_create(
)
if len(script_task_elements) == 0:
raise ApiError(
code="missing_script_task",
error_code="missing_script_task",
message=f"Cannot find a script task with id: {bpmn_task_identifier}",
status_code=404,
)
@ -1139,7 +1139,7 @@ def get_file_from_request() -> Any:
request_file = connexion.request.files.get("file")
if not request_file:
raise ApiError(
code="no_file_given",
error_code="no_file_given",
message="Given request does not contain a file",
status_code=400,
)
@ -1156,7 +1156,7 @@ def get_process_model(process_model_id: str, process_group_id: str) -> ProcessMo
except ProcessEntityNotFoundError as exception:
raise (
ApiError(
code="process_model_cannot_be_found",
error_code="process_model_cannot_be_found",
message=f"Process model cannot be found: {process_model_id}",
status_code=400,
)
@ -1171,7 +1171,7 @@ def find_principal_or_raise() -> PrincipalModel:
if principal is None:
raise (
ApiError(
code="principal_not_found",
error_code="principal_not_found",
message=f"Principal not found from user id: {g.user.id}",
status_code=400,
)
@ -1195,7 +1195,7 @@ def find_active_task_by_id_or_raise(
)
raise (
ApiError(
code="task_not_found",
error_code="task_not_found",
message=message,
status_code=400,
)
@ -1213,7 +1213,7 @@ def find_process_instance_by_id_or_raise(
if process_instance is None:
raise (
ApiError(
code="process_instance_cannot_be_found",
error_code="process_instance_cannot_be_found",
message=f"Process instance cannot be found: {process_instance_id}",
status_code=400,
)
@ -1264,7 +1264,7 @@ def get_spiff_task_from_process_instance(
if spiff_task is None:
raise (
ApiError(
code="empty_task",
error_code="empty_task",
message="Processor failed to obtain task.",
status_code=500,
)
@ -1355,7 +1355,7 @@ def _get_required_parameter_or_raise(parameter: str, post_body: dict[str, Any])
if return_value is None or return_value == "":
raise (
ApiError(
code="missing_required_parameter",
error_code="missing_required_parameter",
message=f"Parameter is missing from json request body: {parameter}",
status_code=400,
)
@ -1386,7 +1386,7 @@ def _update_form_schema_with_task_data_as_needed(
if task_data_var not in task_data:
raise (
ApiError(
code="missing_task_data_var",
error_code="missing_task_data_var",
message=f"Task data is missing variable: {task_data_var}",
status_code=500,
)

View File

@ -66,7 +66,7 @@ def verify_token(token: Optional[str] = None) -> Dict[str, Optional[Union[str, i
except Exception as e:
current_app.logger.error(f"Exception raised in get_token: {e}")
raise ApiError(
code="fail_get_user_info",
error_code="fail_get_user_info",
message="Cannot get user info from token",
) from e
@ -80,14 +80,14 @@ def verify_token(token: Optional[str] = None) -> Dict[str, Optional[Union[str, i
)
if user_model is None:
raise ApiError(
code="invalid_user",
error_code="invalid_user",
message="Invalid user. Please log in.",
status_code=401,
)
# no user_info
else:
raise ApiError(
code="no_user_info", message="Cannot retrieve user info"
error_code="no_user_info", message="Cannot retrieve user info"
)
else:
@ -95,7 +95,7 @@ def verify_token(token: Optional[str] = None) -> Dict[str, Optional[Union[str, i
"token_type not in decode_token in verify_token"
)
raise ApiError(
code="invalid_token",
error_code="invalid_token",
message="Invalid token. Please log in.",
status_code=401,
)
@ -110,10 +110,10 @@ def verify_token(token: Optional[str] = None) -> Dict[str, Optional[Union[str, i
return {"uid": g.user.id, "sub": g.user.id, "scope": scope}
# return validate_scope(token, user_info, user_model)
else:
raise ApiError(code="no_user_id", message="Cannot get a user id")
raise ApiError(error_code="no_user_id", message="Cannot get a user id")
raise ApiError(
code="invalid_token", message="Cannot validate token.", status_code=401
error_code="invalid_token", message="Cannot validate token.", status_code=401
)
# no token -- do we ever get here?
# else:
@ -132,7 +132,7 @@ def verify_token(token: Optional[str] = None) -> Dict[str, Optional[Union[str, i
#
# else:
# raise ApiError(
# code="no_auth_token",
# error_code="no_auth_token",
# message="No authorization token was available.",
# status_code=401,
# )
@ -190,7 +190,7 @@ def encode_auth_token(sub: str, token_type: Optional[str] = None) -> str:
else:
current_app.logger.error("Missing SECRET_KEY in encode_auth_token")
raise ApiError(
code="encode_error", message="Missing SECRET_KEY in encode_auth_token"
error_code="encode_error", message="Missing SECRET_KEY in encode_auth_token"
)
return jwt.encode(
payload,
@ -258,14 +258,14 @@ def login_return(code: str, state: str, session_state: str) -> Optional[Response
return redirect(redirect_url)
raise ApiError(
code="invalid_login",
error_code="invalid_login",
message="Login failed. Please try again",
status_code=401,
)
else:
raise ApiError(
code="invalid_token",
error_code="invalid_token",
message="Login failed. Please try again",
status_code=401,
)
@ -317,7 +317,9 @@ def get_decoded_token(token: str) -> Optional[Dict]:
decoded_token = jwt.decode(token, options={"verify_signature": False})
except Exception as e:
print(f"Exception in get_token_type: {e}")
raise ApiError(code="invalid_token", message="Cannot decode token.") from e
raise ApiError(
error_code="invalid_token", message="Cannot decode token."
) from e
else:
if "token_type" in decoded_token or "iss" in decoded_token:
return decoded_token
@ -326,7 +328,8 @@ def get_decoded_token(token: str) -> Optional[Dict]:
f"Unknown token type in get_decoded_token: token: {token}"
)
raise ApiError(
code="unknown_token", message="Unknown token type in get_decoded_token"
error_code="unknown_token",
message="Unknown token type in get_decoded_token",
)
# try:
# # see if we have an open_id token

View File

@ -31,7 +31,7 @@ user_blueprint = Blueprint("main", __name__)
# if user is not None:
# raise (
# ApiError(
# code="user_already_exists",
# error_code="user_already_exists",
# message=f"User already exists: {username}",
# status_code=409,
# )
@ -45,7 +45,7 @@ user_blueprint = Blueprint("main", __name__)
# db.session.add(user)
# except IntegrityError as exception:
# raise (
# ApiError(code="integrity_error", message=repr(exception), status_code=500)
# ApiError(error_code="integrity_error", message=repr(exception), status_code=500)
# ) from exception
#
# try:
@ -68,7 +68,7 @@ def delete_user(username: str) -> flask.wrappers.Response:
if user is None:
raise (
ApiError(
code="user_cannot_be_found",
error_code="user_cannot_be_found",
message=f"User cannot be found: {username}",
status_code=400,
)
@ -87,7 +87,7 @@ def create_group(group_name: str) -> flask.wrappers.Response:
if group is not None:
raise (
ApiError(
code="group_already_exists",
error_code="group_already_exists",
message=f"Group already exists: {group_name}",
status_code=409,
)
@ -98,7 +98,9 @@ def create_group(group_name: str) -> flask.wrappers.Response:
db.session.add(group)
except IntegrityError as exception:
raise (
ApiError(code="integrity_error", message=repr(exception), status_code=500)
ApiError(
error_code="integrity_error", message=repr(exception), status_code=500
)
) from exception
db.session.commit()
@ -112,7 +114,7 @@ def delete_group(group_name: str) -> flask.wrappers.Response:
if group is None:
raise (
ApiError(
code="group_cannot_be_found",
error_code="group_cannot_be_found",
message=f"Group cannot be found: {group_name}",
status_code=400,
)
@ -136,7 +138,7 @@ def assign_user_to_group() -> flask.wrappers.Response:
if user_group_assignment is not None:
raise (
ApiError(
code="user_is_already_in_group",
error_code="user_is_already_in_group",
message=f"User ({user.id}) is already in group ({group.id})",
status_code=409,
)
@ -165,7 +167,7 @@ def remove_user_from_group() -> flask.wrappers.Response:
if user_group_assignment is None:
raise (
ApiError(
code="user_not_in_group",
error_code="user_not_in_group",
message=f"User ({user.id}) is not in group ({group.id})",
status_code=400,
)
@ -195,7 +197,7 @@ def get_user_from_request() -> Any:
if user_id is None:
raise (
ApiError(
code="user_id_is_required",
error_code="user_id_is_required",
message="Attribute user_id is required",
status_code=400,
)
@ -205,7 +207,7 @@ def get_user_from_request() -> Any:
if user is None:
raise (
ApiError(
code="user_cannot_be_found",
error_code="user_cannot_be_found",
message=f"User cannot be found: {user_id}",
status_code=400,
)
@ -220,7 +222,7 @@ def get_group_from_request() -> Any:
if group_id is None:
raise (
ApiError(
code="group_id_is_required",
error_code="group_id_is_required",
message="Attribute group_id is required",
status_code=400,
)
@ -230,7 +232,7 @@ def get_group_from_request() -> Any:
if group is None:
raise (
ApiError(
code="group_cannot_be_found",
error_code="group_cannot_be_found",
message=f"Group cannot be found: {group_id}",
status_code=400,
)

View File

@ -66,21 +66,21 @@ class PublicAuthenticationService:
except Exception as e:
current_app.logger.error(f"Exception in get_user_info_from_id_token: {e}")
raise ApiError(
code="token_error",
error_code="token_error",
message=f"Exception in get_user_info_from_id_token: {e}",
status_code=401,
) from e
if request_response.status_code == 401:
raise ApiError(
code="invalid_token", message="Please login", status_code=401
error_code="invalid_token", message="Please login", status_code=401
)
elif request_response.status_code == 200:
user_info: dict = json.loads(request_response.text)
return user_info
raise ApiError(
code="user_info_error",
error_code="user_info_error",
message="Cannot get user info in get_user_info_from_id_token",
status_code=401,
)
@ -180,7 +180,9 @@ class PublicAuthenticationService:
decoded_token = jwt.decode(id_token, options={"verify_signature": False})
except Exception as e:
raise ApiError(
code="bad_id_token", message="Cannot decode id_token", status_code=401
error_code="bad_id_token",
message="Cannot decode id_token",
status_code=401,
) from e
if decoded_token["iss"] != f"{open_id_server_url}/realms/{open_id_realm_name}":
valid = False
@ -203,7 +205,7 @@ class PublicAuthenticationService:
if now > decoded_token["exp"]:
raise ApiError(
code="invalid_token",
error_code="invalid_token",
message="Your token is expired. Please Login",
status_code=401,
)

View File

@ -108,4 +108,6 @@ class FailingService:
@staticmethod
def fail_as_service() -> None:
"""It fails."""
raise ApiError(code="failing_service", message="This is my failing service")
raise ApiError(
error_code="failing_service", message="This is my failing service"
)

View File

@ -315,7 +315,7 @@ class ProcessInstanceProcessor:
except MissingSpecError as ke:
raise ApiError(
code="unexpected_process_instance_structure",
error_code="unexpected_process_instance_structure",
message="Failed to deserialize process_instance"
" '%s' due to a mis-placed or missing task '%s'"
% (self.process_model_identifier, str(ke)),
@ -521,7 +521,7 @@ class ProcessInstanceProcessor:
if principal is None:
raise (
ApiError(
code="principal_not_found",
error_code="principal_not_found",
message=f"Principal not found from user id: {user_id}",
status_code=400,
)
@ -623,7 +623,7 @@ class ProcessInstanceProcessor:
if bpmn_file_full_path is None:
raise (
ApiError(
code="could_not_find_bpmn_process_identifier",
error_code="could_not_find_bpmn_process_identifier",
message="Could not find the the given bpmn process identifier from any sources: %s"
% bpmn_process_identifier,
)
@ -686,7 +686,7 @@ class ProcessInstanceProcessor:
):
raise (
ApiError(
code="no_primary_bpmn_error",
error_code="no_primary_bpmn_error",
message="There is no primary BPMN process id defined for process_model %s"
% process_model_info.id,
)
@ -704,7 +704,7 @@ class ProcessInstanceProcessor:
)
except ValidationException as ve:
raise ApiError(
code="process_instance_validation_error",
error_code="process_instance_validation_error",
message="Failed to parse the Workflow Specification. "
+ "Error is '%s.'" % str(ve),
file_name=ve.filename,

View File

@ -213,7 +213,7 @@ class ProcessInstanceService:
"""Get_users_assigned_to_task."""
if processor.process_instance_model.process_initiator_id is None:
raise ApiError.from_task(
code="invalid_workflow",
error_code="invalid_workflow",
message="A process instance must have a user_id.",
task=spiff_task,
)
@ -246,7 +246,7 @@ class ProcessInstanceService:
lane_uids.append(user["value"])
else:
raise ApiError.from_task(
code="task_lane_user_error",
error_code="task_lane_user_error",
message="Spiff Task %s lane user dict must have a key called 'value' with the user's uid in it."
% spiff_task.task_spec.name,
task=spiff_task,
@ -255,7 +255,7 @@ class ProcessInstanceService:
lane_uids.append(user)
else:
raise ApiError.from_task(
code="task_lane_user_error",
error_code="task_lane_user_error",
message="Spiff Task %s lane user is not a string or dict"
% spiff_task.task_spec.name,
task=spiff_task,

View File

@ -83,7 +83,7 @@ class ProcessModelService(FileSystemService):
).all()
if len(instances) > 0:
raise ApiError(
code="existing_instances",
error_code="existing_instances",
message=f"We cannot delete the model `{process_model_id}`, there are existing instances that depend on it.",
)
process_model = self.get_process_model(process_model_id)
@ -260,7 +260,7 @@ class ProcessModelService(FileSystemService):
process_group = ProcessGroup(**data)
if process_group is None:
raise ApiError(
code="process_group_could_not_be_loaded_from_disk",
error_code="process_group_could_not_be_loaded_from_disk",
message=f"We could not load the process_group from disk from: {dir_item}",
)
else:
@ -300,13 +300,13 @@ class ProcessModelService(FileSystemService):
spec = ProcessModelInfo(**data)
if spec is None:
raise ApiError(
code="process_model_could_not_be_loaded_from_disk",
error_code="process_model_could_not_be_loaded_from_disk",
message=f"We could not load the process_model from disk with data: {data}",
)
else:
if name is None:
raise ApiError(
code="missing_name_of_process_model",
error_code="missing_name_of_process_model",
message="Missing name of process model. It should be given",
)

View File

@ -47,7 +47,7 @@ class SecretService:
db.session.commit()
except Exception as e:
raise ApiError(
code="create_secret_error",
error_code="create_secret_error",
message=f"There was an error creating a secret with key: {key} and value ending with: {value[:-4]}. "
f"Original error is {e}",
) from e
@ -63,7 +63,7 @@ class SecretService:
return secret
else:
raise ApiError(
code="missing_secret_error",
error_code="missing_secret_error",
message=f"Unable to locate a secret with the name: {key}. ",
)
@ -83,18 +83,18 @@ class SecretService:
db.session.commit()
except Exception as e:
raise ApiError(
code="update_secret_error",
error_code="update_secret_error",
message=f"There was an error updating the secret with key: {key}, and value: {value}",
) from e
else:
raise ApiError(
code="update_secret_error",
error_code="update_secret_error",
message=f"User: {creator_user_id} cannot update the secret with key : {key}",
status_code=401,
)
else:
raise ApiError(
code="update_secret_error",
error_code="update_secret_error",
message=f"Cannot update secret with key: {key}. Resource does not exist.",
status_code=404,
)
@ -110,18 +110,18 @@ class SecretService:
db.session.commit()
except Exception as e:
raise ApiError(
code="delete_secret_error",
error_code="delete_secret_error",
message=f"Could not delete secret with key: {key}. Original error is: {e}",
) from e
else:
raise ApiError(
code="delete_secret_error",
error_code="delete_secret_error",
message=f"User: {user_id} cannot delete the secret with key : {key}",
status_code=401,
)
else:
raise ApiError(
code="delete_secret_error",
error_code="delete_secret_error",
message=f"Cannot delete secret with key: {key}. Resource does not exist.",
status_code=404,
)
@ -145,7 +145,7 @@ class SecretService:
except IntegrityError as ie:
db.session.rollback()
raise ApiError(
code="add_allowed_process_error",
error_code="add_allowed_process_error",
message=f"Error adding allowed_process with secret {secret_model.id}, "
f"and path: {allowed_relative_path}. Resource already exists. "
f"Original error is {ie}",
@ -155,7 +155,7 @@ class SecretService:
# TODO: should we call db.session.rollback() here?
# db.session.rollback()
raise ApiError(
code="add_allowed_process_error",
error_code="add_allowed_process_error",
message=f"Could not create an allowed process for secret with key: {secret_model.key} "
f"with path: {allowed_relative_path}. "
f"Original error is {e}",
@ -163,13 +163,13 @@ class SecretService:
return secret_process_model
else:
raise ApiError(
code="add_allowed_process_error",
error_code="add_allowed_process_error",
message=f"User: {user_id} cannot modify the secret with key : {secret_model.key}",
status_code=401,
)
else:
raise ApiError(
code="add_allowed_process_error",
error_code="add_allowed_process_error",
message=f"Cannot add allowed process to secret with key: {secret_id}. Resource does not exist.",
status_code=404,
)
@ -191,19 +191,19 @@ class SecretService:
db.session.commit()
except Exception as e:
raise ApiError(
code="delete_allowed_process_error",
error_code="delete_allowed_process_error",
message=f"There was an exception deleting allowed_process: {allowed_process_id}. "
f"Original error is: {e}",
) from e
else:
raise ApiError(
code="delete_allowed_process_error",
error_code="delete_allowed_process_error",
message=f"User: {user_id} cannot delete the allowed_process with id : {allowed_process_id}",
status_code=401,
)
else:
raise ApiError(
code="delete_allowed_process_error",
error_code="delete_allowed_process_error",
message=f"Cannot delete allowed_process: {allowed_process_id}. Resource does not exist.",
status_code=404,
)

View File

@ -217,12 +217,12 @@ class SpecFileService(FileSystemService):
except ValidationException as ve:
if ve.args[0].find("No executable process tag found") >= 0:
raise ApiError(
code="missing_executable_option",
error_code="missing_executable_option",
message="No executable process tag found. Please make sure the Executable option is set in the workflow.",
) from ve
else:
raise ApiError(
code="validation_error",
error_code="validation_error",
message=f"There was an error validating your workflow. Original message is: {ve}",
) from ve
else:

View File

@ -50,7 +50,8 @@ class UserService:
except Exception as e:
db.session.rollback()
raise ApiError(
code="add_user_error", message=f"Could not add user {username}"
error_code="add_user_error",
message=f"Could not add user {username}",
) from e
cls.create_principal(user_model.id)
return user_model
@ -61,7 +62,7 @@ class UserService:
# Don't really want to send service_id.
raise (
ApiError(
code="user_already_exists",
error_code="user_already_exists",
message=f"User already exists: {username}",
status_code=409,
)
@ -264,7 +265,7 @@ class UserService:
if principal:
return principal
raise ApiError(
code="no_principal_found",
error_code="no_principal_found",
message=f"No principal was found for user_id: {user_id}",
)
@ -283,7 +284,7 @@ class UserService:
db.session.rollback()
current_app.logger.error(f"Exception in create_principal: {e}")
raise ApiError(
code="add_principal_error",
error_code="add_principal_error",
message=f"Could not create principal {user_id}",
) from e
return principal

View File

@ -43,7 +43,8 @@ class BaseTest:
return user
raise ApiError(
code="create_user_error", message=f"Cannot find or create user: {username}"
error_code="create_user_error",
message=f"Cannot find or create user: {username}",
)
@staticmethod

View File

@ -164,7 +164,7 @@ class TestProcessApi(BaseTest):
# make sure we get an error in the response
assert response.status_code == 400
data = json.loads(response.get_data(as_text=True))
assert data["code"] == "existing_instances"
assert data["error_code"] == "existing_instances"
assert (
data["message"]
== "We cannot delete the model `sample`, there are existing instances that depend on it."
@ -459,7 +459,7 @@ class TestProcessApi(BaseTest):
assert response.status_code == 400
assert response.json is not None
assert response.json["code"] == "no_file_given"
assert response.json["error_code"] == "no_file_given"
def test_process_model_file_update_fails_if_contents_is_empty(
self, app: Flask, client: FlaskClient, with_db_and_bpmn_file_cleanup: None
@ -480,7 +480,7 @@ class TestProcessApi(BaseTest):
assert response.status_code == 400
assert response.json is not None
assert response.json["code"] == "file_contents_empty"
assert response.json["error_code"] == "file_contents_empty"
def test_process_model_file_update(
self, app: Flask, client: FlaskClient, with_db_and_bpmn_file_cleanup: None
@ -529,7 +529,7 @@ class TestProcessApi(BaseTest):
assert response.status_code == 400
assert response.json is not None
assert response.json["code"] == "process_model_cannot_be_found"
assert response.json["error_code"] == "process_model_cannot_be_found"
def test_process_model_file_delete_when_bad_file(
self, app: Flask, client: FlaskClient, with_db_and_bpmn_file_cleanup: None
@ -547,7 +547,7 @@ class TestProcessApi(BaseTest):
assert response.status_code == 400
assert response.json is not None
assert response.json["code"] == "process_model_file_cannot_be_found"
assert response.json["error_code"] == "process_model_file_cannot_be_found"
def test_process_model_file_delete(
self, app: Flask, client: FlaskClient, with_db_and_bpmn_file_cleanup: None
@ -682,7 +682,7 @@ class TestProcessApi(BaseTest):
)
assert response.status_code == 400
assert response.json is not None
assert response.json["code"] == "process_model_cannot_be_found"
assert response.json["error_code"] == "process_model_cannot_be_found"
def test_process_instance_create(
self, app: Flask, client: FlaskClient, with_db_and_bpmn_file_cleanup: None
@ -1332,7 +1332,7 @@ class TestProcessApi(BaseTest):
)
assert response.status_code == 404
data = json.loads(response.get_data(as_text=True))
assert data["code"] == "unknown_process_instance_report"
assert data["error_code"] == "unknown_process_instance_report"
def setup_testing_instance(
self,
@ -1377,9 +1377,9 @@ class TestProcessApi(BaseTest):
assert response.status_code == 400
api_error = json.loads(response.get_data(as_text=True))
assert api_error["code"] == "task_error"
assert api_error["error_code"] == "task_error"
assert (
'Activity_CauseError: TypeError:can only concatenate str (not "int") to str'
'TypeError:can only concatenate str (not "int") to str'
in api_error["message"]
)
@ -1460,8 +1460,7 @@ class TestProcessApi(BaseTest):
message = outbox[0]
assert message.subject == "Unexpected error in app"
assert (
message.body
== 'Activity_CauseError: TypeError:can only concatenate str (not "int") to str'
message.body == 'TypeError:can only concatenate str (not "int") to str'
)
assert message.recipients == process_model.exception_notification_addresses

View File

@ -95,7 +95,7 @@ class TestSecretService(SecretServiceTestHelpers):
self.add_test_secret(user)
with pytest.raises(ApiError) as ae:
self.add_test_secret(user)
assert ae.value.code == "create_secret_error"
assert ae.value.error_code == "create_secret_error"
def test_get_secret(self, app: Flask, with_db_and_bpmn_file_cleanup: None) -> None:
"""Test_get_secret."""
@ -154,7 +154,7 @@ class TestSecretService(SecretServiceTestHelpers):
with pytest.raises(ApiError) as ae:
SecretService.update_secret(secret.key + "x", "some_new_value", user.id)
assert "Resource does not exist" in ae.value.message
assert ae.value.code == "update_secret_error"
assert ae.value.error_code == "update_secret_error"
def test_delete_secret(
self, app: Flask, client: FlaskClient, with_db_and_bpmn_file_cleanup: None