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

Restructure Airlock requests & add createdBy field #2779

Merged
merged 16 commits into from
Oct 26, 2022
Merged
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!-- markdownlint-disable MD041 -->
<!-- line format short be: change short description (#pr_numer) -->
## 0.7.0 (Unreleased)
## 0.6.1 (Unreleased)

**BREAKING CHANGES & MIGRATIONS**:

Expand All @@ -11,6 +11,7 @@ FEATURES:
ENHANCEMENTS:

BUG FIXES:
* Show the correct initiator of airlock requests in UI and in API queries ([#2779](https://github.com/microsoft/AzureTRE/pull/2779))

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.5.1"
__version__ = "0.5.2"
4 changes: 2 additions & 2 deletions api_app/api/routes/airlock.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ async def get_all_airlock_requests_by_workspace(
airlock_request_repo=Depends(get_repository(AirlockRequestRepository)),
workspace=Depends(get_deployed_workspace_by_id_from_path),
user=Depends(get_current_workspace_owner_or_researcher_user_or_airlock_manager),
creator_user_id: str = None, requestType: AirlockRequestType = None, status: AirlockRequestStatus = None,
initiator_user_id: str = None, requestType: AirlockRequestType = None, status: AirlockRequestStatus = None,
order_by: str = None, order_ascending: bool = True) -> AirlockRequestWithAllowedUserActionsInList:
try:
airlock_requests = get_airlock_requests_by_user_and_workspace(user=user, workspace=workspace, airlock_request_repo=airlock_request_repo,
creator_user_id=creator_user_id, type=requestType, status=status,
initiator_user_id=initiator_user_id, type=requestType, status=status,
order_by=order_by, order_ascending=order_ascending)
airlock_requests_with_allowed_user_actions = enrich_requests_with_allowed_actions(airlock_requests, user, airlock_request_repo)
except (ValidationError, ValueError) as e:
Expand Down
4 changes: 2 additions & 2 deletions api_app/api/routes/airlock_resource_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ def check_email_exists(role_assignment_details: defaultdict(list)):


def get_airlock_requests_by_user_and_workspace(user: User, workspace: Workspace, airlock_request_repo: AirlockRequestRepository,
creator_user_id: str = None, type: AirlockRequestType = None, status: AirlockRequestStatus = None,
initiator_user_id: str = None, type: AirlockRequestType = None, status: AirlockRequestStatus = None,
order_by: str = None, order_ascending=True) -> List[AirlockRequest]:
return airlock_request_repo.get_airlock_requests(workspace_id=workspace.id, user_id=creator_user_id, type=type, status=status,
return airlock_request_repo.get_airlock_requests(workspace_id=workspace.id, initiator_user_id=initiator_user_id, type=type, status=status,
order_by=order_by, order_ascending=order_ascending)


Expand Down
11 changes: 6 additions & 5 deletions api_app/db/repositories/airlock_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,13 @@ def create_airlock_request_item(self, airlock_request_input: AirlockRequestInCre

return airlock_request

def get_airlock_requests(self, workspace_id: str, user_id: str = None, type: AirlockRequestType = None, status: AirlockRequestStatus = None, order_by: str = None, order_ascending=True) -> List[AirlockRequest]:
query = self.airlock_requests_query() + f' where c.workspaceId = "{workspace_id}"'
def get_airlock_requests(self, workspace_id: str, initiator_user_id: str = None, type: AirlockRequestType = None, status: AirlockRequestStatus = None, order_by: str = None, order_ascending=True) -> List[AirlockRequest]:
query = self.airlock_requests_query() + f' WHERE c.workspaceId = "{workspace_id}"'

# optional filters
if user_id:
query += ' AND c.user.id=@user_id'
if initiator_user_id:
# If the resource has history, get the first user object (initiator)
query += ' AND (ARRAY_LENGTH(c.history) > 0? c.history[0].user.id=@user_id: c.user.id=@user_id)'
jjgriff93 marked this conversation as resolved.
Show resolved Hide resolved
if status:
query += ' AND c.status=@status'
if type:
Expand All @@ -120,7 +121,7 @@ def get_airlock_requests(self, workspace_id: str, user_id: str = None, type: Air
query += ' ASC' if order_ascending else ' DESC'

parameters = [
{"name": "@user_id", "value": user_id},
{"name": "@user_id", "value": initiator_user_id},
{"name": "@status", "value": status},
{"name": "@type", "value": type},
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ async def test_get_airlock_requests_by_user_and_workspace_with_status_filter_cal
get_airlock_requests_by_user_and_workspace(user=user, workspace=workspace, airlock_request_repo=airlock_request_repo_mock,
status=AirlockRequestStatus.InReview)

airlock_request_repo_mock.get_airlock_requests.assert_called_once_with(workspace_id=workspace.id, user_id=None, type=None,
airlock_request_repo_mock.get_airlock_requests.assert_called_once_with(workspace_id=workspace.id, initiator_user_id=None, type=None,
status=AirlockRequestStatus.InReview, order_by=None, order_ascending=True)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def test_update_airlock_request_should_retry_update_when_etag_is_not_up_to_date(

def test_get_airlock_requests_queries_db(airlock_request_repo):
airlock_request_repo.container.query_items = MagicMock()
expected_query = airlock_request_repo.airlock_requests_query() + f' where c.workspaceId = "{WORKSPACE_ID}"'
expected_query = airlock_request_repo.airlock_requests_query() + f' WHERE c.workspaceId = "{WORKSPACE_ID}"'
expected_parameters = [
{"name": "@user_id", "value": None},
{"name": "@status", "value": None},
Expand Down
13 changes: 8 additions & 5 deletions ui/app/src/components/shared/airlock/Airlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,18 @@ export const Airlock: React.FunctionComponent = () => {
fieldName: 'requestTitle'
},
{
key: 'creator_user_id',
key: 'initiator',
name: 'Initiator',
ariaLabel: 'Creator of the airlock request',
minWidth: 150,
maxWidth: 200,
isResizable: true,
fieldName: 'initiator',
onRender: (request: AirlockRequest) => <Persona size={ PersonaSize.size24 } text={ request.user?.name } />,
isFiltered: filters.has('creator_user_id')
onRender: (request: AirlockRequest) => <Persona size={ PersonaSize.size24 } text={
request.history?.length > 0
? request.history[0].user.name
: request.user.name
} />,
isFiltered: filters.has('initiator_user_id')
},
{
key: 'requestType',
Expand Down Expand Up @@ -275,7 +278,7 @@ export const Airlock: React.FunctionComponent = () => {
iconProps: { iconName: 'EditContact' },
onClick: () => {
const userId = account.localAccountId.split('.')[0];
setFilters(new Map([['creator_user_id', userId]]));
setFilters(new Map([['initiator_user_id', userId]]));
}
});
}
Expand Down
6 changes: 5 additions & 1 deletion ui/app/src/components/shared/airlock/AirlockViewRequest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,11 @@ export const AirlockViewRequest: React.FunctionComponent<AirlockViewRequestProps
<b>Initiator</b>
</Stack.Item>
<Stack.Item styles={stackItemStyles}>
<Persona text={request.user.name} size={PersonaSize.size32} />
<Persona size={PersonaSize.size32} text={
request.history?.length > 0
? request.history[0].user.name
: request.user.name
} />
</Stack.Item>
</Stack>

Expand Down