From 8e85c47c39047d52464fbcba97a5515b29261c68 Mon Sep 17 00:00:00 2001 From: Caleb Pomar Date: Wed, 25 Oct 2023 11:10:53 -0600 Subject: [PATCH] feat(hub-common): upgradeCatalogSchema handles "orgId" field in legacy catalogs (#1299) affects: @esri/hub-common --- .../common/src/search/upgradeCatalogSchema.ts | 19 +++++++++++++++++++ .../test/search/upgradeCatalogSchema.test.ts | 11 +++++++++++ 2 files changed, 30 insertions(+) diff --git a/packages/common/src/search/upgradeCatalogSchema.ts b/packages/common/src/search/upgradeCatalogSchema.ts index 01c7055facf..3da81cf2fa8 100644 --- a/packages/common/src/search/upgradeCatalogSchema.ts +++ b/packages/common/src/search/upgradeCatalogSchema.ts @@ -43,6 +43,7 @@ function applyCatalogSchema(original: any): IHubCatalog { collections: [], }; + // Handle legacy group structure const rawGroups = getProp(original, "groups"); let groups = []; if (Array.isArray(rawGroups) && rawGroups.length) { @@ -57,6 +58,24 @@ function applyCatalogSchema(original: any): IHubCatalog { }); } + // Handle legacy orgId value, which should only be present + // for org-level home sites (e.g., "my-org.hub.arcgis.com") + const orgId = getProp(original, "orgId"); + if (orgId) { + catalog.scopes.item.filters.push({ + predicates: [ + // Portal uses `orgid` instead of `orgId`, so we comply. + // While `orgid` is valid field for search, it does not count + // towards Portal's requirement of needing at least one filter. + { orgid: [orgId] }, + // Hack to force Portal to think that at least one filter has + // been provided. 'Code Attachment' is an old AGO type that has + // been defunct for some time, so the results won't be affected. + { type: { not: ["Code Attachment"] } }, + ], + }); + } + return catalog; } } diff --git a/packages/common/test/search/upgradeCatalogSchema.test.ts b/packages/common/test/search/upgradeCatalogSchema.test.ts index 35ea658e82a..55d287fa620 100644 --- a/packages/common/test/search/upgradeCatalogSchema.test.ts +++ b/packages/common/test/search/upgradeCatalogSchema.test.ts @@ -41,6 +41,17 @@ describe("upgradeCatalogSchema", () => { ]); }); + it("handles org-level home site legacy catalogs", () => { + const chk = upgradeCatalogSchema({ orgId: "a3g" }); + expect(chk.title).toBe("Default Catalog"); + expect(chk.scopes).toBeDefined(); + expect(chk.scopes?.item?.filters.length).toBe(1); + expect(chk.scopes?.item?.filters[0].predicates[0].orgid).toEqual(["a3g"]); + expect(chk.scopes?.item?.filters[0].predicates[1].type).toEqual({ + not: ["Code Attachment"], + }); + }); + it("skips upgrade if on the same version", () => { const cat = { schemaVersion: 1.0 }; const chk = upgradeCatalogSchema(cat);