Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 18, 2025

What is being addressed

The get_*_by_id methods in repository classes return deleted resources, while list methods filter them out. This allows accessing deleted workspaces, workspace services, user resources, and shared services via direct URL after deletion.

How is this addressed

Added deploymentStatus != Status.Deleted filter to all get_by_id queries:

  • WorkspaceRepository.get_workspace_by_id()
  • WorkspaceServiceRepository.get_workspace_service_by_id()
  • UserResourceRepository.get_user_resource_by_id()
  • SharedServiceRepository.get_shared_service_by_id()

Query pattern:

query += ' AND c.deploymentStatus != @deletedStatus'
parameters.append({'name': '@deletedStatus', 'value': Status.Deleted})

Updated E2E tests to support the filtering changes:

  • Modified check_deployment() in e2e_tests/resources/deployment.py to treat 404 status as a valid deleted state
  • When a resource is deleted, the operations endpoint returns 404 (since deleted resources are filtered out), which is now correctly interpreted as successful deletion

Updated unit tests to verify deleted resources raise EntityDoesNotExist.

Updated CHANGELOG.md with bug fix entry.

Incremented API version to 0.25.12 in api_app/_version.py.

Original prompt

This section details on the original issue you should resolve

<issue_title>Deleted workspaces are still accessible via URL</issue_title>
<issue_description>Describe the bug
workspaces are still accessible via their URL after they are deleted
See also #4307 as this functionality may be required

Steps to reproduce

  1. Create a workspace
  2. copy the url
  3. delete the workspace
  4. re-visit the url

Azure TRE release version (e.g. v0.14.0 or main):
main
Deployed Azure TRE components - click the (i) in the UI:

Azure TRE
UI Version:
0.8.17
API Version:
0.25.2</issue_description>

Comments on the Issue (you are @copilot in this section)

@marrobi Ok, it looks like the get `X_by_id` methods are not filtering deleted out, but the list methods are.
Entity Type List Endpoint (filters deleted?) Get-by-ID (filters deleted?)
Workspace Yes No
Workspace Service Yes No
User Resource Yes No
Shared Service Yes No

So need something like:

async def get_workspace_by_id(self, workspace_id: str) -> Workspace:
    query = 'SELECT * FROM c WHERE c.resourceType = @resourceType AND c.id = @workspaceId AND c.deploymentStatus != @deletedStatus'
    parameters = [
        {'name': '@resourceType', 'value': ResourceType.Workspace},
        {'name': '@workspaceId', 'value': str(workspace_id)},
        {'name': '@deletedStatus', 'value': Status.Deleted}
    ]
    workspaces = await self.query(query=query, parameters=parameters)
    if not workspaces:
        raise EntityDoesNotExist
    return parse_obj_as(Workspace, workspaces[0])

There should also be unit tests to verify this.

@tamirkamara @jonnyry welcome your view on this, I don't think these endpoints should return deleted resources?

@jonnyry @marrobi Hmm I can't think of a reason why the current codebase would need Get-by-ID methods to return deleted entities.

There might be some possible use cases in future, perhaps an audit trail or those outlined in #4307, but for those cases you could an additional optional parameter to include deleted resources (with a default of false).</comment_new>


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

- Updated get_workspace_by_id to exclude deleted workspaces
- Updated get_workspace_service_by_id to exclude deleted services
- Updated get_user_resource_by_id to exclude deleted user resources
- Updated get_shared_service_by_id to exclude deleted shared services
- Added/updated unit tests to verify deleted resources are filtered
- Updated CHANGELOG.md with bug fix entry

Co-authored-by: marrobi <17089773+marrobi@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix access to deleted workspaces via URL Filter deleted resources in get_by_id repository methods Dec 18, 2025
@github-actions
Copy link

github-actions bot commented Dec 18, 2025

Unit Test Results

668 tests   668 ✅  7s ⏱️
  1 suites    0 💤
  1 files      0 ❌

Results for commit f73fac4.

♻️ This comment has been updated with latest results.

Copilot AI requested a review from marrobi December 18, 2025 13:03
@marrobi marrobi marked this pull request as ready for review December 18, 2025 13:03
@marrobi marrobi requested a review from a team as a code owner December 18, 2025 13:03
@marrobi
Copy link
Member

marrobi commented Dec 18, 2025

@copilot update the API version

Incremented API version from 0.25.6 to 0.25.7 for bug fix release.
Added version update entry to CHANGELOG.md COMPONENTS section.

Co-authored-by: marrobi <17089773+marrobi@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 18, 2025

@copilot update the API version

Updated API version to 0.25.7 in commit 2e4d7e8

@JC-wk
Copy link
Collaborator

JC-wk commented Jan 8, 2026

api version will need upping again

Copy link
Collaborator

@JC-wk JC-wk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tested this and deleted workspaces are no longer visible @marrobi

@marrobi
Copy link
Member

marrobi commented Jan 12, 2026

@tamirkamara are you able to look at this one? Thanks.

Copy link
Collaborator

@tamirkamara tamirkamara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marrobi I believe something not right here as the E2E consistently fail to delete workspaces.

@marrobi
Copy link
Member

marrobi commented Jan 18, 2026

Ah, I know what it is. The operation is giving 404 as the service no longer exists. The tests need updating to accept a 404 as its been deleted.

I thought had fixed this. Maybe not pushed.

@marrobi
Copy link
Member

marrobi commented Jan 19, 2026

@copilot The e2e tests in this pr fail as the operations endpoint returns 404. Once the workspace services and user resource are deleted it cannot be accessed. 404 should be a valid response that the resource has been deleted. Please fix this.

When checking operation status, if the parent resource has been deleted,
the operations endpoint will return 404 (due to the get_by_id filtering).
This is now treated as a valid deleted state rather than an error.

Also incremented API version to 0.25.12.

Co-authored-by: marrobi <17089773+marrobi@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 19, 2026

@copilot The e2e tests in this pr fail as the operations endpoint returns 404. Once the workspace services and user resource are deleted it cannot be accessed. 404 should be a valid response that the ...

Fixed in commit ba01e4a. The check_deployment function in e2e_tests now treats 404 responses as a valid deleted state, since deleted resources are filtered out by the get_by_id methods and their operations endpoints will return 404.

api version will need upping again

Updated API version to 0.25.12 in commit ba01e4a

@marrobi
Copy link
Member

marrobi commented Jan 19, 2026

/test-extended ba01e4a

@github-actions
Copy link

🤖 pr-bot 🤖

🏃 Running extended tests: https://github.com/microsoft/AzureTRE/actions/runs/21144706377 (with refid 95c03b79)

(in response to this comment from @marrobi)

@marrobi
Copy link
Member

marrobi commented Jan 19, 2026

@tamirkamara can you take another look?

The COMPONENTS section is auto-generated during releases and should
not be manually updated in PRs per copilot-instructions.md.

Co-authored-by: tamirkamara <26870601+tamirkamara@users.noreply.github.com>
The E2E test fix is an implementation detail required to support the
main bug fix (filtering deleted resources), not a separate user-facing
bug fix.

Co-authored-by: tamirkamara <26870601+tamirkamara@users.noreply.github.com>
@tamirkamara
Copy link
Collaborator

/test-force-approve
my comments were about the changelog file and previous tests were successful

@github-actions
Copy link

🤖 pr-bot 🤖

✅ Marking tests as complete (for commit f73fac4)

(in response to this comment from @tamirkamara)

Copilot AI requested a review from tamirkamara January 20, 2026 07:41
@marrobi marrobi merged commit 786d1f8 into main Jan 20, 2026
15 checks passed
@marrobi marrobi deleted the copilot/fix-deleted-workspaces-url-access branch January 20, 2026 07:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deleted workspaces are still accessible via URL

4 participants