move common script errors to script so it can keep the error messaging consistent across scripts
This commit is contained in:
parent
2bb3e09c0d
commit
fd5969d8ad
|
@ -7,7 +7,6 @@ from spiffworkflow_backend.models.process_model import ProcessModelInfo
|
|||
from spiffworkflow_backend.models.script_attributes_context import (
|
||||
ScriptAttributesContext,
|
||||
)
|
||||
from spiffworkflow_backend.scripts.script import ProcessModelIdentifierMissingError
|
||||
from spiffworkflow_backend.scripts.script import Script
|
||||
|
||||
|
||||
|
@ -38,10 +37,8 @@ class GetMarkdownFileDownloadLink(Script):
|
|||
label = parts[1].split("=")[1]
|
||||
process_model_identifier = script_attributes_context.process_model_identifier
|
||||
if process_model_identifier is None:
|
||||
raise ProcessModelIdentifierMissingError(
|
||||
"The process model identifier was not given to script"
|
||||
" 'markdown_file_download_link'. This script needs to be run from"
|
||||
" within the context of a process model."
|
||||
raise self.get_proces_model_identifier_is_missing_error(
|
||||
"markdown_file_download_link"
|
||||
)
|
||||
modified_process_model_identifier = (
|
||||
ProcessModelInfo.modify_process_identifier_for_path_param(
|
||||
|
@ -49,6 +46,10 @@ class GetMarkdownFileDownloadLink(Script):
|
|||
)
|
||||
)
|
||||
process_instance_id = script_attributes_context.process_instance_id
|
||||
if process_instance_id is None:
|
||||
raise self.get_proces_instance_id_is_missing_error(
|
||||
"save_process_instance_metadata"
|
||||
)
|
||||
url = current_app.config["SPIFFWORKFLOW_BACKEND_URL"]
|
||||
url += (
|
||||
f"/v1.0/process-data-file-download/{modified_process_model_identifier}/"
|
||||
|
|
|
@ -8,7 +8,6 @@ from spiffworkflow_backend.models.process_instance_metadata import (
|
|||
from spiffworkflow_backend.models.script_attributes_context import (
|
||||
ScriptAttributesContext,
|
||||
)
|
||||
from spiffworkflow_backend.scripts.script import ProcessInstanceIdMissingError
|
||||
from spiffworkflow_backend.scripts.script import Script
|
||||
|
||||
|
||||
|
@ -28,10 +27,8 @@ class SaveProcessInstanceMetadata(Script):
|
|||
"""Run."""
|
||||
metadata_dict = args[0]
|
||||
if script_attributes_context.process_instance_id is None:
|
||||
raise ProcessInstanceIdMissingError(
|
||||
"The process instance id was not given to script"
|
||||
" 'save_process_instance_metadata'. This script needs to be run from"
|
||||
" within the context of a process instance."
|
||||
raise self.get_proces_instance_id_is_missing_error(
|
||||
"save_process_instance_metadata"
|
||||
)
|
||||
for key, value in metadata_dict.items():
|
||||
pim = ProcessInstanceMetadataModel.query.filter_by(
|
||||
|
|
|
@ -57,6 +57,26 @@ class Script:
|
|||
+ "does not properly implement the run function.",
|
||||
)
|
||||
|
||||
def get_proces_instance_id_is_missing_error(
|
||||
self, script_name: str
|
||||
) -> ProcessInstanceIdMissingError:
|
||||
"""Return the error so we can raise it from the script and mypy will be happy."""
|
||||
raise ProcessInstanceIdMissingError(
|
||||
"The process instance id was not given to script"
|
||||
f" '{script_name}'. This script needs to be run from"
|
||||
" within the context of a process instance."
|
||||
)
|
||||
|
||||
def get_proces_model_identifier_is_missing_error(
|
||||
self, script_name: str
|
||||
) -> ProcessModelIdentifierMissingError:
|
||||
"""Return the error so we can raise it from the script and mypy will be happy."""
|
||||
return ProcessModelIdentifierMissingError(
|
||||
"The process model identifier was not given to script"
|
||||
f" '{script_name}'. This script needs to be run from"
|
||||
" within the context of a process model."
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def requires_privileged_permissions() -> bool:
|
||||
"""It seems safer to default to True and make safe functions opt in for any user to run them.
|
||||
|
|
Loading…
Reference in New Issue