Skip to content

Commit

Permalink
feat(hub-common): upgradeCatalogSchema handles "orgId" field in legac…
Browse files Browse the repository at this point in the history
…y catalogs (#1299)

affects: @esri/hub-common
  • Loading branch information
sonofflynn89 authored Oct 25, 2023
1 parent bbce039 commit 8e85c47
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/common/src/search/upgradeCatalogSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}
}
11 changes: 11 additions & 0 deletions packages/common/test/search/upgradeCatalogSchema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 8e85c47

Please sign in to comment.