зеркало из https://github.com/microsoft/AzureTRE.git
Migrate reviewDecision of Airlock Reviews (#3152)
* add migration for airlock reviewDecision value * add 'update_review_decision_values' to the migrations test * update PR number * match issue number to PR number * update changelog * fix wrong expected status in e2e
This commit is contained in:
Родитель
35b486b100
Коммит
3eca58407c
|
@ -35,6 +35,7 @@ ENHANCEMENTS:
|
|||
|
||||
BUG FIXES:
|
||||
* Reauth CLI if TRE endpoint has changed [#3137](https://github.com/microsoft/AzureTRE/pull/3137)
|
||||
* Added Migration for Airlock requests that were created prior to version 0.5.0 ([#3152](https://github.com/microsoft/AzureTRE/pull/3152))
|
||||
|
||||
COMPONENTS:
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
__version__ = "0.11.0"
|
||||
__version__ = "0.11.1"
|
||||
|
|
|
@ -73,7 +73,11 @@ async def migrate_database(resources_repo=Depends(get_repository(ResourceReposit
|
|||
|
||||
logging.info("PR 2883 - Support multiple reviewer VMs per Airlock request")
|
||||
num_updated = await airlock_migration.change_review_resources_to_dict()
|
||||
migrations.append(Migration(issueNumber="XXXX", status=f'Updated {num_updated} airlock requests with new reviewUserResources format'))
|
||||
migrations.append(Migration(issueNumber="2883", status=f'Updated {num_updated} airlock requests with new reviewUserResources format'))
|
||||
|
||||
logging.info("PR 3152 - Migrate reviewDecision of Airlock Reviews")
|
||||
num_updated = await airlock_migration.update_review_decision_values()
|
||||
migrations.append(Migration(issueNumber="3152", status=f'Updated {num_updated} airlock requests with new reviewDecision value'))
|
||||
|
||||
return MigrationOutList(migrations=migrations)
|
||||
except Exception as e:
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
from azure.cosmos.aio import CosmosClient
|
||||
from resources import strings
|
||||
from db.repositories.airlock_requests import AirlockRequestRepository
|
||||
|
||||
|
||||
|
@ -52,3 +53,28 @@ class AirlockMigration(AirlockRequestRepository):
|
|||
num_updated += 1
|
||||
|
||||
return num_updated
|
||||
|
||||
async def update_review_decision_values(self) -> int:
|
||||
num_updated = 0
|
||||
for request in await self.query('SELECT * FROM c WHERE ARRAY_LENGTH(c.reviews) > 0'):
|
||||
request_changed = False
|
||||
|
||||
for review in request['reviews']:
|
||||
old_decision = review['reviewDecision']
|
||||
new_decision = old_decision
|
||||
|
||||
if old_decision == 'approval_in_progress':
|
||||
new_decision = strings.AIRLOCK_REVIEW_DECISION_APPROVED
|
||||
|
||||
if old_decision == 'rejection_in_progress':
|
||||
new_decision = strings.AIRLOCK_REVIEW_DECISION_REJECTED
|
||||
|
||||
if new_decision != old_decision:
|
||||
request_changed = True
|
||||
review['reviewDecision'] = new_decision
|
||||
|
||||
if request_changed:
|
||||
await self.update_item_dict(request)
|
||||
num_updated += 1
|
||||
|
||||
return num_updated
|
||||
|
|
|
@ -44,7 +44,8 @@ class TestMigrationRoutesThatRequireAdminRights:
|
|||
@ patch("api.routes.migrations.AirlockMigration.add_created_by_and_rename_in_history")
|
||||
@ patch("api.routes.migrations.AirlockMigration.rename_field_name")
|
||||
@ patch("api.routes.migrations.AirlockMigration.change_review_resources_to_dict")
|
||||
async def test_post_migrations_returns_202_on_successful(self, change_review_resources_to_dict, airlock_rename_field, add_created_by_and_rename_in_history,
|
||||
@ patch("api.routes.migrations.AirlockMigration.update_review_decision_values")
|
||||
async def test_post_migrations_returns_202_on_successful(self, update_review_decision_values, change_review_resources_to_dict, airlock_rename_field, add_created_by_and_rename_in_history,
|
||||
check_min_firewall_version, workspace_migration, shared_services_migration,
|
||||
rename_field, add_deployment_field, archive_history, _, logging, client, app):
|
||||
response = await client.post(app.url_path_for(strings.API_MIGRATE_DATABASE))
|
||||
|
@ -57,6 +58,7 @@ class TestMigrationRoutesThatRequireAdminRights:
|
|||
add_created_by_and_rename_in_history.assert_called_once()
|
||||
airlock_rename_field.assert_called()
|
||||
change_review_resources_to_dict.assert_called_once()
|
||||
update_review_decision_values.assert_called_once()
|
||||
archive_history.assert_called_once()
|
||||
logging.assert_called()
|
||||
assert response.status_code == status.HTTP_202_ACCEPTED
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#!/bin/bash
|
||||
|
||||
# This script migrates the Cosmos database based on any breaking changes that have occurred.
|
||||
# Cosmos is behind a private network, so we call the /migrate endpoint of the API
|
||||
# Cosmos is behind a private network, so we call the /migrations endpoint of the API
|
||||
|
||||
set -o errexit
|
||||
set -o pipefail
|
||||
|
|
|
@ -17,7 +17,7 @@ async def get_resource(endpoint, access_token, verify):
|
|||
auth_headers = get_auth_header(access_token)
|
||||
|
||||
response = await client.get(full_endpoint, headers=auth_headers, timeout=TIMEOUT)
|
||||
assert_status(response, [status.HTTP_202_ACCEPTED], f"Failed to GET {full_endpoint}")
|
||||
assert_status(response, [status.HTTP_200_OK], f"Failed to GET {full_endpoint}")
|
||||
|
||||
return response.json()
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче