Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix registration of templates with no required or authorizedRoles defined. #3849

Merged
merged 14 commits into from
Feb 27, 2024
Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ BUG FIXES:
* Fix issue with connect button showing when no uri([#3820](https://github.com/microsoft/AzureTRE/issues/3820))
* Fix user resource upgrade validation: use the parent_service_template_name instead of the parent_resource_id. ([#3824](https://github.com/microsoft/AzureTRE/issues/3824))
* Airlock: Creating an import/export request causes a routing error ([#3830](https://github.com/microsoft/AzureTRE/issues/3830))
* Fix registration of templates with no 'authorizedRoles' or 'required' defined ([#3849](https://github.com/microsoft/AzureTRE/pull/3849))

COMPONENTS:

Expand Down
2 changes: 1 addition & 1 deletion api_app/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.18.3"
__version__ = "0.18.4"
4 changes: 2 additions & 2 deletions api_app/db/repositories/resource_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ async def create_template(self, template_input: ResourceTemplateInCreate, resour
"version": template_input.version,
"resourceType": resource_type,
"current": template_input.current,
"required": template_input.json_schema["required"],
"authorizedRoles": template_input.json_schema["authorizedRoles"] if "authorizedRoles" in template_input.json_schema else [],
"required": template_input.json_schema.get("required", []),
"authorizedRoles": template_input.json_schema.get("authorizedRoles", []),
"properties": template_input.json_schema["properties"],
"customActions": template_input.customActions
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from db.errors import EntityDoesNotExist, InvalidInput
from models.domain.resource import ResourceType
from models.domain.resource_template import ResourceTemplate
from models.schemas.workspace_template import WorkspaceTemplateInCreate


pytestmark = pytest.mark.asyncio
Expand All @@ -33,6 +34,46 @@ def sample_resource_template_as_dict(name: str, version: str = "1.0", resource_t
).dict()


@patch('db.repositories.resource_templates.ResourceTemplateRepository.save_item')
@patch('uuid.uuid4')
async def test_create_workspace_template_succeeds_without_required(uuid_mock, save_item_mock, resource_template_repo):
uuid_mock.return_value = "1234"
expected_type = ResourceType.Workspace
input_workspace_template = WorkspaceTemplateInCreate(
name="my-tre-workspace",
version="0.0.1",
current=True,
json_schema={
"title": "My Workspace Template",
"description": "This is a test workspace template schema.",
"properties": {
"updateable_property": {
"type": "string",
"title": "Test updateable property",
"updateable": True,
},
},
},
customActions=[],
)
returned_template = await resource_template_repo.create_template(input_workspace_template, expected_type)
expected_resource_template = ResourceTemplate(
id="1234",
name=input_workspace_template.name,
title=input_workspace_template.json_schema["title"],
description=input_workspace_template.json_schema["description"],
version=input_workspace_template.version,
resourceType=expected_type,
properties=input_workspace_template.json_schema["properties"],
customActions=input_workspace_template.customActions,
required=[],
authorizedRoles=[],
current=input_workspace_template.current
)
save_item_mock.assert_called_once_with(expected_resource_template)
assert expected_resource_template == returned_template


@patch('db.repositories.resource_templates.ResourceTemplateRepository.query')
async def test_get_by_name_and_version_queries_db(query_mock, resource_template_repo):
expected_query = 'SELECT * FROM c WHERE c.resourceType = "workspace" AND c.name = "test" AND c.version = "1.0"'
Expand Down
Loading