diff --git a/conftest.py b/conftest.py index deab5f97..a1aa9109 100644 --- a/conftest.py +++ b/conftest.py @@ -1,12 +1,12 @@ """Conftest.""" import os import shutil -from tests.spiffworkflow_backend.helpers.test_data import load_test_spec import pytest from flask.app import Flask from flask_bpmn.models.db import db from flask_bpmn.models.db import SpiffworkflowBaseDBModel +from tests.spiffworkflow_backend.helpers.test_data import load_test_spec from spiffworkflow_backend.helpers.fixture_data import find_or_create_user from spiffworkflow_backend.models.process_instance import ProcessInstanceModel diff --git a/src/spiffworkflow_backend/api.yml b/src/spiffworkflow_backend/api.yml index e2b1f847..1cbe6065 100755 --- a/src/spiffworkflow_backend/api.yml +++ b/src/spiffworkflow_backend/api.yml @@ -715,11 +715,17 @@ paths: $ref: "#/components/schemas/WorkflowSpecCategory" responses: "200": + description: One task + content: + application/json: + schema: + $ref: "#/components/schemas/Task" + "202": description: "ok: true" content: application/json: schema: - $ref: "#/components/schemas/OkTrue" + $ref: "#components/schemas/OkTrue" components: securitySchemes: diff --git a/src/spiffworkflow_backend/models/process_instance.py b/src/spiffworkflow_backend/models/process_instance.py index d9778557..c59156b1 100644 --- a/src/spiffworkflow_backend/models/process_instance.py +++ b/src/spiffworkflow_backend/models/process_instance.py @@ -2,8 +2,6 @@ from __future__ import annotations from dataclasses import dataclass -from SpiffWorkflow.navigation import NavItem # type: ignore -from SpiffWorkflow.util.deep_merge import DeepMerge # type: ignore from typing import Any from typing import cast @@ -13,6 +11,8 @@ from flask_bpmn.models.db import SpiffworkflowBaseDBModel from marshmallow import INCLUDE from marshmallow import Schema from marshmallow_enum import EnumField # type: ignore +from SpiffWorkflow.navigation import NavItem # type: ignore +from SpiffWorkflow.util.deep_merge import DeepMerge # type: ignore from sqlalchemy import ForeignKey from sqlalchemy.orm import deferred from sqlalchemy.orm import relationship diff --git a/src/spiffworkflow_backend/routes/process_api_blueprint.py b/src/spiffworkflow_backend/routes/process_api_blueprint.py index fd38455c..16ef5588 100644 --- a/src/spiffworkflow_backend/routes/process_api_blueprint.py +++ b/src/spiffworkflow_backend/routes/process_api_blueprint.py @@ -1,7 +1,6 @@ """APIs for dealing with process groups, process models, and process instances.""" import json import uuid -from SpiffWorkflow import TaskState # type: ignore from typing import Any from typing import Dict from typing import Optional @@ -17,6 +16,7 @@ from flask import request from flask.wrappers import Response from flask_bpmn.api.api_error import ApiError from flask_bpmn.models.db import db +from SpiffWorkflow import TaskState # type: ignore from sqlalchemy import desc from spiffworkflow_backend.exceptions.process_entity_not_found_error import ( @@ -553,11 +553,12 @@ def task_list_my_tasks(page: int = 1, per_page: int = 100) -> flask.wrappers.Res def task_show(task_id: int) -> flask.wrappers.Response: """Task_list_my_tasks.""" principal = find_principal_or_raise() + active_task_assigned_to_me = find_active_task_by_id_or_raise(task_id, principal.id) - process_instance = ProcessInstanceModel.query.filter_by( - id=active_task_assigned_to_me.process_instance_id - ).first() + process_instance = find_process_instance_by_id_or_raise( + active_task_assigned_to_me.process_instance_id + ) process_model = get_process_model( process_instance.process_model_identifier, process_instance.process_group_identifier, @@ -645,7 +646,13 @@ def task_submit_user_data( ProcessInstanceService.update_task_assignments(processor) - return Response(json.dumps({"ok": True}), status=200, mimetype="application/json") + next_active_task_assigned_to_me = ActiveTaskModel.query.filter_by( + assigned_principal_id=principal.id, process_instance_id=process_instance.id + ).first() + if next_active_task_assigned_to_me: + return make_response(jsonify(next_active_task_assigned_to_me), 200) + + return Response(json.dumps({"ok": True}), status=202, mimetype="application/json") def get_file_from_request() -> Any: diff --git a/src/spiffworkflow_backend/services/process_instance_processor.py b/src/spiffworkflow_backend/services/process_instance_processor.py index cfe3028b..c633d519 100644 --- a/src/spiffworkflow_backend/services/process_instance_processor.py +++ b/src/spiffworkflow_backend/services/process_instance_processor.py @@ -1,6 +1,16 @@ """Process_instance_processor.""" import json import time +from typing import Any +from typing import Dict +from typing import List +from typing import Optional +from typing import Union + +from flask import current_app +from flask_bpmn.api.api_error import ApiError +from flask_bpmn.models.db import db +from lxml import etree # type: ignore from SpiffWorkflow import Task as SpiffTask # type: ignore from SpiffWorkflow import TaskState from SpiffWorkflow import WorkflowException @@ -21,16 +31,6 @@ from SpiffWorkflow.specs import WorkflowSpec # type: ignore from SpiffWorkflow.spiff.parser.process import SpiffBpmnParser # type: ignore from SpiffWorkflow.spiff.serializer import UserTaskConverter # type: ignore from SpiffWorkflow.util.deep_merge import DeepMerge # type: ignore -from typing import Any -from typing import Dict -from typing import List -from typing import Optional -from typing import Union - -from flask import current_app -from flask_bpmn.api.api_error import ApiError -from flask_bpmn.models.db import db -from lxml import etree # type: ignore from spiffworkflow_backend.models.active_task import ActiveTaskModel from spiffworkflow_backend.models.file import File diff --git a/src/spiffworkflow_backend/services/process_instance_service.py b/src/spiffworkflow_backend/services/process_instance_service.py index 7592c985..cea76786 100644 --- a/src/spiffworkflow_backend/services/process_instance_service.py +++ b/src/spiffworkflow_backend/services/process_instance_service.py @@ -1,5 +1,13 @@ """Process_instance_service.""" import time +from typing import Any +from typing import Dict +from typing import List +from typing import Optional + +from flask import current_app +from flask_bpmn.api.api_error import ApiError +from flask_bpmn.models.db import db from SpiffWorkflow.bpmn.specs.events import EndEvent # type: ignore from SpiffWorkflow.bpmn.specs.events import StartEvent from SpiffWorkflow.bpmn.specs.ManualTask import ManualTask # type: ignore @@ -11,14 +19,6 @@ from SpiffWorkflow.specs import CancelTask # type: ignore from SpiffWorkflow.specs import StartTask from SpiffWorkflow.task import Task as SpiffTask # type: ignore from SpiffWorkflow.util.deep_merge import DeepMerge # type: ignore -from typing import Any -from typing import Dict -from typing import List -from typing import Optional - -from flask import current_app -from flask_bpmn.api.api_error import ApiError -from flask_bpmn.models.db import db from spiffworkflow_backend.models.process_instance import ProcessInstanceApi from spiffworkflow_backend.models.process_instance import ProcessInstanceModel diff --git a/src/spiffworkflow_backend/services/spec_file_service.py b/src/spiffworkflow_backend/services/spec_file_service.py index dc81d748..282df692 100644 --- a/src/spiffworkflow_backend/services/spec_file_service.py +++ b/src/spiffworkflow_backend/services/spec_file_service.py @@ -2,7 +2,6 @@ import os import shutil from datetime import datetime -from SpiffWorkflow.bpmn.parser.ValidationException import ValidationException # type: ignore from typing import List from typing import Optional from typing import Union @@ -11,6 +10,7 @@ from flask_bpmn.api.api_error import ApiError from lxml import etree # type: ignore from lxml.etree import _Element # type: ignore from lxml.etree import Element as EtreeElement +from SpiffWorkflow.bpmn.parser.ValidationException import ValidationException # type: ignore from spiffworkflow_backend.models.file import File from spiffworkflow_backend.models.file import FileType diff --git a/tests/spiffworkflow_backend/helpers/test_data.py b/tests/spiffworkflow_backend/helpers/test_data.py index 96fc7052..9afee257 100644 --- a/tests/spiffworkflow_backend/helpers/test_data.py +++ b/tests/spiffworkflow_backend/helpers/test_data.py @@ -1,8 +1,9 @@ """User.""" -from tests.spiffworkflow_backend.helpers.example_data import ExampleDataLoader from typing import Dict from typing import Optional +from tests.spiffworkflow_backend.helpers.example_data import ExampleDataLoader + from spiffworkflow_backend.exceptions.process_entity_not_found_error import ( ProcessEntityNotFoundError, ) diff --git a/tests/spiffworkflow_backend/integration/test_process_api.py b/tests/spiffworkflow_backend/integration/test_process_api.py index 64c8680e..1b06fb37 100644 --- a/tests/spiffworkflow_backend/integration/test_process_api.py +++ b/tests/spiffworkflow_backend/integration/test_process_api.py @@ -2,8 +2,6 @@ import io import json import time -from tests.spiffworkflow_backend.helpers.test_data import load_test_spec -from tests.spiffworkflow_backend.helpers.test_data import logged_in_headers from typing import Any from typing import Dict from typing import Optional @@ -12,6 +10,8 @@ import pytest from flask.app import Flask from flask.testing import FlaskClient from flask_bpmn.models.db import db +from tests.spiffworkflow_backend.helpers.test_data import load_test_spec +from tests.spiffworkflow_backend.helpers.test_data import logged_in_headers from werkzeug.test import TestResponse from spiffworkflow_backend.exceptions.process_entity_not_found_error import (