Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(): add link org settings in user workspace #1707

Merged
merged 12 commits into from
Nov 22, 2024
49 changes: 29 additions & 20 deletions package-lock.json

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

48 changes: 47 additions & 1 deletion packages/common/src/users/_internal/UserUiSchemaSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { IArcGISContext } from "../../ArcGISContext";
import { IUiSchema, UiSchemaRuleEffects } from "../../core/schemas/types";
import { fetchOrg } from "../../org/fetch-org";
import { failSafe } from "../../utils/fail-safe";
import { getPortalSettings } from "@esri/arcgis-rest-portal";

/**
* @private
Expand Down Expand Up @@ -30,6 +31,16 @@ export const buildUiSchema = async (
target: "_blank",
},
];

// we have to make this xhr to fetch the portal settings to determine if
// the banner is enabled as it's only exposed in appSettings/ember
const portalSettings = await _getPortalSettings(context);
const bannerString = portalSettings.informationalBanner?.enabled
? `{{${i18nScope}.fields.infoBanner.helperText:translate}}`
: `{{${i18nScope}.fields.infoBanner.helperTextWhenDisabled:translate}}`;
const configureBannerString = `{{${i18nScope}.fields.infoBanner.goToBannerConfig:translate}}`;
const showInfoBannerLink = `<calcite-link href=${context.portalUrl}/home/organization.html?tab=security#settings target=\"_blank\" icon-end=\"launch\">${configureBannerString}</calcite-link>`;

/**
* If there is a community org relationship, or we are in a community
* org with an enterprise org relationship, show another action that
Expand Down Expand Up @@ -137,9 +148,33 @@ export const buildUiSchema = async (
control: "hub-field-input-switch",
layout: "inline-space-between",
helperText: {
labelKey: `${i18nScope}.fields.infoBanner.helperText`,
label: bannerString,
},
},
rules: [
{
effect: UiSchemaRuleEffects.DISABLE,
conditions: [!portalSettings.informationalBanner?.enabled],
},
],
},
{
type: "Control",
scope:
"/properties/hubOrgSettings/properties/showInformationalBanner",
options: {
control: "calcite-link",
layout: "inline-space-between",
helperText: {
label: showInfoBannerLink,
},
},
rules: [
{
effect: UiSchemaRuleEffects.SHOW,
conditions: [context.isOrgAdmin],
},
],
},
],
},
Expand Down Expand Up @@ -251,3 +286,14 @@ async function _getCommunityOrEnterpriseAGOUrl(
// return the url
return orgUrl;
}

export async function _getPortalSettings(
MarvinPerry marked this conversation as resolved.
Show resolved Hide resolved
context: IArcGISContext
): Promise<any> {
// Fail safe fetch the portal settings
const fsGetPortalSettings = failSafe(getPortalSettings, {});
const settings = await fsGetPortalSettings(context.portal.id, {
portal: context.sharingApiUrl,
});
return settings;
}
16 changes: 9 additions & 7 deletions packages/common/src/users/_internal/computeProps.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { getPortalUrl } from "@esri/arcgis-rest-portal";
import { getPortalUrl, getSelf } from "@esri/arcgis-rest-portal";
import { IUser } from "@esri/arcgis-rest-types";
import { IRequestOptions, request } from "@esri/arcgis-rest-request";
import { IArcGISContext } from "../../ArcGISContext";
import { getProp } from "../../objects/get-prop";
import { IHubUser } from "../../core/types";
import { failSafe } from "../../utils/fail-safe";

/**
* Given a model and a user, sets various computed properties that can't be directly mapped.
Expand All @@ -22,12 +22,14 @@ export async function computeProps(

// 2. compute any props for user's org settings
// TODO: only fetch this if the user has necessary privs (org admin)
const signinSettings = await getPortalSignInSettings(context);
const fsGetSignInSettings = failSafe(getPortalSignInSettings, {});
const signinSettings = await fsGetSignInSettings(context);

const fsGetSelf = failSafe(getSelf, {});
const _portalself = await fsGetSelf(context.requestOptions);
user.hubOrgSettings = {
showInformationalBanner: !!getProp(
context,
"portal.portalProperties.hub.settings.informationalBanner"
),
showInformationalBanner:
!!_portalself.portalProperties?.hub?.settings?.informationalBanner,
enableTermsAndConditions: !!signinSettings.termsAndConditions,
termsAndConditions: signinSettings.termsAndConditions,
enableSignupText: !!signinSettings.signupText,
Expand Down
Loading
Loading