move helpers where they belong
This commit is contained in:
parent
ff18aa77bc
commit
a763c54d64
|
@ -13,14 +13,10 @@ from flask import request
|
||||||
from flask.wrappers import Response
|
from flask.wrappers import Response
|
||||||
from flask_bpmn.api.api_error import ApiError
|
from flask_bpmn.api.api_error import ApiError
|
||||||
from flask_bpmn.models.db import db
|
from flask_bpmn.models.db import db
|
||||||
from sqlalchemy import and_
|
|
||||||
from sqlalchemy import or_
|
|
||||||
|
|
||||||
from spiffworkflow_backend.exceptions.process_entity_not_found_error import (
|
from spiffworkflow_backend.exceptions.process_entity_not_found_error import (
|
||||||
ProcessEntityNotFoundError,
|
ProcessEntityNotFoundError,
|
||||||
)
|
)
|
||||||
from spiffworkflow_backend.models.human_task import HumanTaskModel
|
|
||||||
from spiffworkflow_backend.models.human_task_user import HumanTaskUserModel
|
|
||||||
from spiffworkflow_backend.models.principal import PrincipalModel
|
from spiffworkflow_backend.models.principal import PrincipalModel
|
||||||
from spiffworkflow_backend.models.process_instance import ProcessInstanceModel
|
from spiffworkflow_backend.models.process_instance import ProcessInstanceModel
|
||||||
from spiffworkflow_backend.models.process_instance import ProcessInstanceModelSchema
|
from spiffworkflow_backend.models.process_instance import ProcessInstanceModelSchema
|
||||||
|
@ -208,41 +204,6 @@ def _commit_and_push_to_git(message: str) -> None:
|
||||||
current_app.logger.info("Git commit on save is disabled")
|
current_app.logger.info("Git commit on save is disabled")
|
||||||
|
|
||||||
|
|
||||||
def _find_process_instance_for_me_or_raise(
|
|
||||||
process_instance_id: int,
|
|
||||||
) -> ProcessInstanceModel:
|
|
||||||
"""_find_process_instance_for_me_or_raise."""
|
|
||||||
process_instance: ProcessInstanceModel = (
|
|
||||||
ProcessInstanceModel.query.filter_by(id=process_instance_id)
|
|
||||||
.outerjoin(HumanTaskModel)
|
|
||||||
.outerjoin(
|
|
||||||
HumanTaskUserModel,
|
|
||||||
and_(
|
|
||||||
HumanTaskModel.id == HumanTaskUserModel.human_task_id,
|
|
||||||
HumanTaskUserModel.user_id == g.user.id,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.filter(
|
|
||||||
or_(
|
|
||||||
HumanTaskUserModel.id.is_not(None),
|
|
||||||
ProcessInstanceModel.process_initiator_id == g.user.id,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.first()
|
|
||||||
)
|
|
||||||
|
|
||||||
if process_instance is None:
|
|
||||||
raise (
|
|
||||||
ApiError(
|
|
||||||
error_code="process_instance_cannot_be_found",
|
|
||||||
message=f"Process instance with id {process_instance_id} cannot be found that is associated with you.",
|
|
||||||
status_code=400,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
return process_instance
|
|
||||||
|
|
||||||
|
|
||||||
def _un_modify_modified_process_model_id(modified_process_model_identifier: str) -> str:
|
def _un_modify_modified_process_model_id(modified_process_model_identifier: str) -> str:
|
||||||
"""Un_modify_modified_process_model_id."""
|
"""Un_modify_modified_process_model_id."""
|
||||||
return modified_process_model_identifier.replace(":", "/")
|
return modified_process_model_identifier.replace(":", "/")
|
||||||
|
|
|
@ -14,7 +14,11 @@ from flask.wrappers import Response
|
||||||
from flask_bpmn.api.api_error import ApiError
|
from flask_bpmn.api.api_error import ApiError
|
||||||
from flask_bpmn.models.db import db
|
from flask_bpmn.models.db import db
|
||||||
from SpiffWorkflow.task import TaskState # type: ignore
|
from SpiffWorkflow.task import TaskState # type: ignore
|
||||||
|
from sqlalchemy import and_
|
||||||
|
from sqlalchemy import or_
|
||||||
|
|
||||||
|
from spiffworkflow_backend.models.human_task import HumanTaskModel
|
||||||
|
from spiffworkflow_backend.models.human_task_user import HumanTaskUserModel
|
||||||
from spiffworkflow_backend.models.process_instance import ProcessInstanceApiSchema
|
from spiffworkflow_backend.models.process_instance import ProcessInstanceApiSchema
|
||||||
from spiffworkflow_backend.models.process_instance import (
|
from spiffworkflow_backend.models.process_instance import (
|
||||||
ProcessInstanceCannotBeDeletedError,
|
ProcessInstanceCannotBeDeletedError,
|
||||||
|
@ -35,9 +39,6 @@ from spiffworkflow_backend.models.user import UserModel
|
||||||
from spiffworkflow_backend.routes.process_api_blueprint import (
|
from spiffworkflow_backend.routes.process_api_blueprint import (
|
||||||
_find_process_instance_by_id_or_raise,
|
_find_process_instance_by_id_or_raise,
|
||||||
)
|
)
|
||||||
from spiffworkflow_backend.routes.process_api_blueprint import (
|
|
||||||
_find_process_instance_for_me_or_raise,
|
|
||||||
)
|
|
||||||
from spiffworkflow_backend.routes.process_api_blueprint import _get_process_model
|
from spiffworkflow_backend.routes.process_api_blueprint import _get_process_model
|
||||||
from spiffworkflow_backend.routes.process_api_blueprint import (
|
from spiffworkflow_backend.routes.process_api_blueprint import (
|
||||||
_un_modify_modified_process_model_id,
|
_un_modify_modified_process_model_id,
|
||||||
|
@ -608,3 +609,38 @@ def _get_process_instance(
|
||||||
process_instance.bpmn_xml_file_contents = bpmn_xml_file_contents
|
process_instance.bpmn_xml_file_contents = bpmn_xml_file_contents
|
||||||
|
|
||||||
return make_response(jsonify(process_instance), 200)
|
return make_response(jsonify(process_instance), 200)
|
||||||
|
|
||||||
|
|
||||||
|
def _find_process_instance_for_me_or_raise(
|
||||||
|
process_instance_id: int,
|
||||||
|
) -> ProcessInstanceModel:
|
||||||
|
"""_find_process_instance_for_me_or_raise."""
|
||||||
|
process_instance: ProcessInstanceModel = (
|
||||||
|
ProcessInstanceModel.query.filter_by(id=process_instance_id)
|
||||||
|
.outerjoin(HumanTaskModel)
|
||||||
|
.outerjoin(
|
||||||
|
HumanTaskUserModel,
|
||||||
|
and_(
|
||||||
|
HumanTaskModel.id == HumanTaskUserModel.human_task_id,
|
||||||
|
HumanTaskUserModel.user_id == g.user.id,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.filter(
|
||||||
|
or_(
|
||||||
|
HumanTaskUserModel.id.is_not(None),
|
||||||
|
ProcessInstanceModel.process_initiator_id == g.user.id,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.first()
|
||||||
|
)
|
||||||
|
|
||||||
|
if process_instance is None:
|
||||||
|
raise (
|
||||||
|
ApiError(
|
||||||
|
error_code="process_instance_cannot_be_found",
|
||||||
|
message=f"Process instance with id {process_instance_id} cannot be found that is associated with you.",
|
||||||
|
status_code=400,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
return process_instance
|
||||||
|
|
|
@ -7,7 +7,6 @@ from typing import Union
|
||||||
|
|
||||||
import flask.wrappers
|
import flask.wrappers
|
||||||
from flask import current_app
|
from flask import current_app
|
||||||
from flask import g
|
|
||||||
from flask import jsonify
|
from flask import jsonify
|
||||||
from flask import make_response
|
from flask import make_response
|
||||||
from flask.wrappers import Response
|
from flask.wrappers import Response
|
||||||
|
@ -15,7 +14,6 @@ from flask_bpmn.api.api_error import ApiError
|
||||||
from lxml import etree # type: ignore
|
from lxml import etree # type: ignore
|
||||||
from lxml.builder import ElementMaker # type: ignore
|
from lxml.builder import ElementMaker # type: ignore
|
||||||
|
|
||||||
from spiffworkflow_backend.models.principal import PrincipalModel
|
|
||||||
from spiffworkflow_backend.routes.process_api_blueprint import _get_process_model
|
from spiffworkflow_backend.routes.process_api_blueprint import _get_process_model
|
||||||
from spiffworkflow_backend.routes.process_api_blueprint import (
|
from spiffworkflow_backend.routes.process_api_blueprint import (
|
||||||
_get_required_parameter_or_raise,
|
_get_required_parameter_or_raise,
|
||||||
|
@ -131,17 +129,3 @@ def script_unit_test_run(
|
||||||
python_script, input_json, expected_output_json
|
python_script, input_json, expected_output_json
|
||||||
)
|
)
|
||||||
return make_response(jsonify(result), 200)
|
return make_response(jsonify(result), 200)
|
||||||
|
|
||||||
|
|
||||||
def _find_principal_or_raise() -> PrincipalModel:
|
|
||||||
"""Find_principal_or_raise."""
|
|
||||||
principal = PrincipalModel.query.filter_by(user_id=g.user.id).first()
|
|
||||||
if principal is None:
|
|
||||||
raise (
|
|
||||||
ApiError(
|
|
||||||
error_code="principal_not_found",
|
|
||||||
message=f"Principal not found from user id: {g.user.id}",
|
|
||||||
status_code=400,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
return principal # type: ignore
|
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
"""APIs for dealing with process groups, process models, and process instances."""
|
"""APIs for dealing with process groups, process models, and process instances."""
|
||||||
import json
|
import json
|
||||||
from spiffworkflow_backend.routes.user import verify_token
|
|
||||||
from flask import redirect
|
import flask.wrappers
|
||||||
from flask import request
|
|
||||||
import werkzeug
|
import werkzeug
|
||||||
from flask import current_app
|
from flask import current_app
|
||||||
import flask.wrappers
|
|
||||||
from spiffworkflow_backend.services.service_task_service import ServiceTaskService
|
|
||||||
|
|
||||||
from flask import g
|
from flask import g
|
||||||
|
from flask import redirect
|
||||||
|
from flask import request
|
||||||
from flask.wrappers import Response
|
from flask.wrappers import Response
|
||||||
|
|
||||||
|
from spiffworkflow_backend.routes.user import verify_token
|
||||||
from spiffworkflow_backend.services.secret_service import SecretService
|
from spiffworkflow_backend.services.secret_service import SecretService
|
||||||
|
from spiffworkflow_backend.services.service_task_service import ServiceTaskService
|
||||||
|
|
||||||
|
|
||||||
def service_task_list() -> flask.wrappers.Response:
|
def service_task_list() -> flask.wrappers.Response:
|
||||||
|
|
Loading…
Reference in New Issue