process group move api endpoint

This commit is contained in:
mike cullerton 2022-11-19 13:24:40 -05:00
parent 82388b66e5
commit 38dc4570de
4 changed files with 112 additions and 0 deletions

View File

@ -238,6 +238,33 @@ paths:
schema:
$ref: "#/components/schemas/ProcessModelCategory"
/process-groups/{modified_process_group_id}/move:
parameters:
- name: modified_process_group_id
in: path
required: true
description: The unique id of an existing process group.
schema:
type: string
- name: new_location
in: query
required: true
description: the new location, as an existing process group id
schema:
type: string
put:
operationId: spiffworkflow_backend.routes.process_api_blueprint.process_group_move
summary: returns the new group
tags:
- Process Groups
responses:
"200":
description: Process Group
content:
application/json:
schema:
$ref: "#/components/schemas/ProcessModelCategory"
/process-models:
parameters:
- name: process_group_identifier

View File

@ -234,6 +234,14 @@ def process_group_show(
return make_response(jsonify(process_group), 200)
def process_group_move(
modified_process_group_id: str, new_location: str
) -> flask.wrappers.Response:
original_process_group_id = un_modify_modified_process_model_id(modified_process_group_id)
new_process_group = ProcessModelService().process_group_move(original_process_group_id, new_location)
return make_response(jsonify(new_process_group), 201)
def process_model_create(
modified_process_group_id: str, body: Dict[str, Union[str, bool, int]]
) -> flask.wrappers.Response:

View File

@ -231,6 +231,19 @@ class ProcessModelService(FileSystemService):
self.write_json_file(json_path, serialized_process_group)
return process_group
def process_group_move(self, original_process_group_id, new_location) -> ProcessGroup:
original_group_path = self.process_group_path(original_process_group_id)
original_root, original_group_id = os.path.split(original_group_path)
new_root = f"{FileSystemService.root_path()}/{new_location}"
new_relative_path = f"{new_location}/{original_group_id}"
new_group_path = os.path.abspath(
os.path.join(FileSystemService.root_path(), new_root, original_group_id)
)
destination = shutil.move(original_group_path, new_group_path)
new_process_group = self.get_process_group(destination)
print("process_group_move")
return new_process_group
def __get_all_nested_models(self, group_path: str) -> list:
"""__get_all_nested_models."""
all_nested_models = []

View File

@ -2369,3 +2369,67 @@ class TestProcessApi(BaseTest):
)
print("test_script_unit_test_run")
def test_move_model(self):
...
def test_move_group(
self,
app: Flask,
client: FlaskClient,
with_db_and_bpmn_file_cleanup: None,
with_super_admin_user: UserModel,
) -> None:
groups = [
'group_a', 'group_b', 'group_b/group_bb'
]
# setup initial groups
for group in groups:
self.create_process_group(
client,
with_super_admin_user,
group,
display_name=group
)
# make sure initial groups exist
for group in groups:
persisted = ProcessModelService().get_process_group(group)
assert persisted is not None
assert persisted.id == group
# add sub group to `group_a`
sub_group_id = 'sub_group'
original_location = 'group_a'
original_sub_path = f"{original_location}/{sub_group_id}"
self.create_process_group(
client,
with_super_admin_user,
original_sub_path,
display_name=sub_group_id
)
# make sure original subgroup exists
persisted = ProcessModelService().get_process_group(original_sub_path)
assert persisted is not None
assert persisted.id == original_sub_path
# move sub_group to `group_b/group_bb`
new_location = 'group_b/group_bb'
new_sub_path = f"{new_location}/{sub_group_id}"
modified_original_process_group_id = original_sub_path.replace("/", ":")
response = client.put(
f"/v1.0/process-groups/{modified_original_process_group_id}/move?new_location={new_location}",
headers=self.logged_in_headers(with_super_admin_user),
)
assert response.status_code == 201
assert response.json['id'] == new_sub_path
# make sure the original subgroup does not exist
with pytest.raises(ProcessEntityNotFoundError) as e:
ProcessModelService().get_process_group(original_sub_path)
assert e.value.args[0] == 'process_group_not_found'
assert e.value.args[1] == f"Process Group Id: {original_sub_path}"
# make sure the new subgroup does exist
new_process_group = ProcessModelService().get_process_group(new_sub_path)
assert new_process_group.id == new_sub_path