Skip to content

Commit

Permalink
feat: add community as a facet && update context with isCommunityOrg
Browse files Browse the repository at this point in the history
  • Loading branch information
benstoltz committed May 20, 2024
1 parent 625c9a8 commit 7858826
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions packages/common/src/ArcGISContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,11 @@ export interface IArcGISContext {
*/
survey123Url: string;

/**
* Is the current users org type a community org?
*/
isCommunityOrg: boolean;

/**
* Return the token for a given app, if defined
* @param app
Expand Down Expand Up @@ -801,6 +806,21 @@ export class ArcGISContext implements IArcGISContext {
return this._trustedOrgs;
}

/**
* Returns whether the current user's org type is a community org
*/
public get isCommunityOrg(): boolean {
let result = false;
if (this._portalSelf) {
const orgType = getProp(
this._portalSelf,
"portalProperties.hub.settings.orgType"
);
result = orgType === "community";
}
return result;
}

/**
* Return the whole array of user resource tokens
*/
Expand Down
16 changes: 13 additions & 3 deletions packages/common/src/associations/wellKnownAssociationCatalogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,25 +160,35 @@ export const getAvailableToRequestAssociationCatalogs = (
entity,
associationType
)?.filters;
// Get Community org id. If the current org is a community org, use the first trusted org id, otherwise fall back to the communityOrgId
const communityOrgId = context?.isCommunityOrg
? context?.trustedOrgIds[0]
: context?.communityOrgId;
// Get trusted orgs that aren't the current user's org or the community org
const trustedOrgIds =
context.trustedOrgIds &&
context?.trustedOrgIds.filter((orgId) => {
context?.trustedOrgIds?.filter((orgId) => {
return (
orgId !== context?.currentUser?.orgId &&
orgId !== context?.communityOrgId
);
});
}) || [];
// Default catalogs to include
const catalogNames: WellKnownCatalog[] = ["myContent", "organization"];
// If there are trusted orgs, include the partners catalog
if (trustedOrgIds && trustedOrgIds.length > 0) {
catalogNames.push("partners");
}
// If there is a community org id, include the community catalog
if (communityOrgId) {
catalogNames.push("community");
}
return catalogNames.map((name: WellKnownCatalog) => {
const options: IGetWellKnownCatalogOptions = {
user: context.currentUser,
filters,
collectionNames: [associationType as WellKnownCollection],
trustedOrgIds,
communityOrgId,
};
return getWellKnownCatalog(i18nScope, name, "item", options);
});
Expand Down
18 changes: 17 additions & 1 deletion packages/common/src/search/wellKnownCatalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export type WellKnownCatalog =
| "editGroups"
| "viewGroups"
| "allGroups"
| "partners";
| "partners"
| "community";

/**
* This is used to determine what IHubCollection definition JSON object
Expand All @@ -43,6 +44,8 @@ export interface IGetWellKnownCatalogOptions {
filters?: IFilter[];
/** partnered org ids that catalog might need */
trustedOrgIds?: string[];
/** community org id that catalog might need */
communityOrgId?: string;
}

/**
Expand Down Expand Up @@ -171,6 +174,19 @@ function getWellknownItemCatalog(
"item"
);
break;
case "community":
validateUserExistence(catalogName, options);
catalog = buildCatalog(
i18nScope,
catalogName,
[
{ predicates: [{ orgid: options.communityOrgId }] },
...additionalFilters,
],
collections,
"item"
);
break;
case "world":
catalog = buildCatalog(
i18nScope,
Expand Down

0 comments on commit 7858826

Please sign in to comment.