From 907adee4b090319407c9e0171c183eef08c0b30e Mon Sep 17 00:00:00 2001 From: Kirill Lakhov Date: Mon, 21 Aug 2023 17:11:10 +0300 Subject: [PATCH] Fixed switching from organization to sandbox while getting a resource (#6689) ### Motivation and context Resolves #6390 ### How has this been tested? ### Checklist - [x] I submit my changes into the `develop` branch - [x] I have added a description of my changes into the [CHANGELOG](https://github.com/opencv/cvat/blob/develop/CHANGELOG.md) file - [ ] ~~I have updated the documentation accordingly~~ - [ ] ~~I have added tests to cover my changes~~ - [x] I have linked related issues (see [GitHub docs]( https://help.github.com/en/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword)) - [x] I have increased versions of npm packages if it is necessary ([cvat-canvas](https://github.com/opencv/cvat/tree/develop/cvat-canvas#versioning), [cvat-core](https://github.com/opencv/cvat/tree/develop/cvat-core#versioning), [cvat-data](https://github.com/opencv/cvat/tree/develop/cvat-data#versioning) and [cvat-ui](https://github.com/opencv/cvat/tree/develop/cvat-ui#versioning)) ### License - [x] I submit _my code changes_ under the same [MIT License]( https://github.com/opencv/cvat/blob/develop/LICENSE) that covers the project. Feel free to contact the maintainers if that's a concern. --------- Co-authored-by: Boris Sekachev --- CHANGELOG.md | 2 +- cvat-core/src/server-proxy.ts | 8 +++++--- cvat-ui/package.json | 2 +- .../src/components/watchers/organization-watcher.tsx | 10 ++++++---- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 27692a58d4af..4046439bbb50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,7 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed -- TBD +- Fixed switching from organization to sandbox while getting a resource () ### Security diff --git a/cvat-core/src/server-proxy.ts b/cvat-core/src/server-proxy.ts index 0fabf6ffb20b..0cde101924d3 100644 --- a/cvat-core/src/server-proxy.ts +++ b/cvat-core/src/server-proxy.ts @@ -279,9 +279,11 @@ Axios.interceptors.request.use((reqConfig) => { }); Axios.interceptors.response.use((response) => { - if (isResourceURL(response.config.url)) { - const newOrg = response.data.organization; - if (newOrg && config.organization.organizationID !== newOrg) { + if (isResourceURL(response.config.url) && + 'organization' in (response.data || {}) + ) { + const newOrg: number | null = response.data.organization; + if (config.organization.organizationID !== newOrg) { config?.onOrganizationChange(newOrg); } } diff --git a/cvat-ui/package.json b/cvat-ui/package.json index faff5db8a9c5..7e5f886c46f1 100644 --- a/cvat-ui/package.json +++ b/cvat-ui/package.json @@ -1,6 +1,6 @@ { "name": "cvat-ui", - "version": "1.55.1", + "version": "1.55.2", "description": "CVAT single-page application", "main": "src/index.tsx", "scripts": { diff --git a/cvat-ui/src/components/watchers/organization-watcher.tsx b/cvat-ui/src/components/watchers/organization-watcher.tsx index 8f5717cc552f..63dc733acdd1 100644 --- a/cvat-ui/src/components/watchers/organization-watcher.tsx +++ b/cvat-ui/src/components/watchers/organization-watcher.tsx @@ -13,12 +13,14 @@ function OrganizationWatcher(): JSX.Element { const organizationList = useSelector((state: CombinedState) => state.organizations.list); useEffect(() => { - core.config.onOrganizationChange = (newOrgId: number) => { - const newOrganization = organizationList.find((org) => org.id === newOrgId); - if (newOrganization) { + core.config.onOrganizationChange = (newOrgId: number | null) => { + if (newOrgId === null) { + localStorage.removeItem('currentOrganization'); + } else { + const newOrganization = organizationList.find((org) => org.id === newOrgId); localStorage.setItem('currentOrganization', newOrganization.slug); - window.location.reload(); } + window.location.reload(); }; }, []);