From b73fe0450f7d84b918d5c6d482737d99d36a6352 Mon Sep 17 00:00:00 2001 From: klakhov Date: Wed, 16 Aug 2023 16:03:20 +0300 Subject: [PATCH 1/4] allowed `organization-watcher` to intercept `org=null` --- cvat-core/src/server-proxy.ts | 6 +++--- cvat-ui/src/components/watchers/organization-watcher.tsx | 8 +++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/cvat-core/src/server-proxy.ts b/cvat-core/src/server-proxy.ts index 0fabf6ffb20b..9a2b528fe8b1 100644 --- a/cvat-core/src/server-proxy.ts +++ b/cvat-core/src/server-proxy.ts @@ -279,9 +279,9 @@ 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/src/components/watchers/organization-watcher.tsx b/cvat-ui/src/components/watchers/organization-watcher.tsx index 8f5717cc552f..a00233ba4af7 100644 --- a/cvat-ui/src/components/watchers/organization-watcher.tsx +++ b/cvat-ui/src/components/watchers/organization-watcher.tsx @@ -13,7 +13,13 @@ function OrganizationWatcher(): JSX.Element { const organizationList = useSelector((state: CombinedState) => state.organizations.list); useEffect(() => { - core.config.onOrganizationChange = (newOrgId: number) => { + core.config.onOrganizationChange = (newOrgId: number | null) => { + if (newOrgId === null) { + localStorage.removeItem('currentOrganization'); + window.location.reload(); + return; + } + const newOrganization = organizationList.find((org) => org.id === newOrgId); if (newOrganization) { localStorage.setItem('currentOrganization', newOrganization.slug); From c1f774ef760de6583f56533930e0b39a07bbdb6c Mon Sep 17 00:00:00 2001 From: klakhov Date: Wed, 16 Aug 2023 16:07:22 +0300 Subject: [PATCH 2/4] updated version & changelog --- CHANGELOG.md | 2 +- cvat-core/package.json | 2 +- cvat-ui/package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f14e908d1d34..fa848ae55d86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,7 +24,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/package.json b/cvat-core/package.json index d9712f79ea66..b832b1da0673 100644 --- a/cvat-core/package.json +++ b/cvat-core/package.json @@ -1,6 +1,6 @@ { "name": "cvat-core", - "version": "11.0.0", + "version": "11.0.1", "description": "Part of Computer Vision Tool which presents an interface for client-side integration", "main": "src/api.ts", "scripts": { diff --git a/cvat-ui/package.json b/cvat-ui/package.json index 35d78bf9426d..0c476645ee1e 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": { From 52c7e7ddb695e25c024eeffbce2114f15af221e4 Mon Sep 17 00:00:00 2001 From: klakhov Date: Thu, 17 Aug 2023 11:06:08 +0300 Subject: [PATCH 3/4] added check for `response.data` --- cvat-core/src/server-proxy.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cvat-core/src/server-proxy.ts b/cvat-core/src/server-proxy.ts index 9a2b528fe8b1..623353904574 100644 --- a/cvat-core/src/server-proxy.ts +++ b/cvat-core/src/server-proxy.ts @@ -279,7 +279,10 @@ Axios.interceptors.request.use((reqConfig) => { }); Axios.interceptors.response.use((response) => { - if (isResourceURL(response.config.url) && 'organization' in response.data) { + if (isResourceURL(response.config.url) && + response.data && + 'organization' in response.data + ) { const newOrg: number | null = response.data.organization; if (config.organization.organizationID !== newOrg) { config?.onOrganizationChange(newOrg); From bddb54029eb024724c9b3e20ad7f3164bf821142 Mon Sep 17 00:00:00 2001 From: klakhov Date: Fri, 18 Aug 2023 16:06:31 +0300 Subject: [PATCH 4/4] applied comments --- cvat-core/src/server-proxy.ts | 3 +-- .../src/components/watchers/organization-watcher.tsx | 10 +++------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/cvat-core/src/server-proxy.ts b/cvat-core/src/server-proxy.ts index 623353904574..0cde101924d3 100644 --- a/cvat-core/src/server-proxy.ts +++ b/cvat-core/src/server-proxy.ts @@ -280,8 +280,7 @@ Axios.interceptors.request.use((reqConfig) => { Axios.interceptors.response.use((response) => { if (isResourceURL(response.config.url) && - response.data && - 'organization' in response.data + 'organization' in (response.data || {}) ) { const newOrg: number | null = response.data.organization; if (config.organization.organizationID !== newOrg) { diff --git a/cvat-ui/src/components/watchers/organization-watcher.tsx b/cvat-ui/src/components/watchers/organization-watcher.tsx index a00233ba4af7..63dc733acdd1 100644 --- a/cvat-ui/src/components/watchers/organization-watcher.tsx +++ b/cvat-ui/src/components/watchers/organization-watcher.tsx @@ -16,15 +16,11 @@ function OrganizationWatcher(): JSX.Element { core.config.onOrganizationChange = (newOrgId: number | null) => { if (newOrgId === null) { localStorage.removeItem('currentOrganization'); - window.location.reload(); - return; - } - - const newOrganization = organizationList.find((org) => org.id === newOrgId); - if (newOrganization) { + } else { + const newOrganization = organizationList.find((org) => org.id === newOrgId); localStorage.setItem('currentOrganization', newOrganization.slug); - window.location.reload(); } + window.location.reload(); }; }, []);