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: showInfoBanner for user org settings #1676

Merged
merged 4 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 18 additions & 30 deletions package-lock.json

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

11 changes: 10 additions & 1 deletion packages/common/src/users/HubUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { cloneObject } from "../util";
import { UserEditorType } from "./_internal/UserSchema";
import { DEFAULT_USER } from "./defaults";
import { updateCommunityOrgSettings } from "../utils/internal/updateCommunityOrgSettings";
import { updatePortalOrgSettings } from "../utils/internal/updatePortalOrgSettings";

export class HubUser implements IWithEditorBehavior {
protected context: IArcGISContext;
Expand Down Expand Up @@ -92,7 +93,15 @@ export class HubUser implements IWithEditorBehavior {
}

// 3. update portal settings
// TODO in later story
// User is org admin, we have org settings to send, and we have a banner to show
if (
this.context.isOrgAdmin &&
this.entity.hubOrgSettings &&
this.entity.hubOrgSettings.hasOwnProperty("showInformationalBanner")
) {
// update the portal settings
await updatePortalOrgSettings(this.entity.hubOrgSettings, this.context);
}

return;
}
Expand Down
20 changes: 20 additions & 0 deletions packages/common/src/users/_internal/UserUiSchemaSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,26 @@ export const buildUiSchema = async (
},
},
},
{
type: "Section",
labelKey: `${i18nScope}.sections.orgSettings.siteDefaults.label`,
elements: [
{
type: "Control",
scope:
"/properties/hubOrgSettings/properties/showInformationalBanner",
labelKey: `${i18nScope}.fields.infoBanner.label`,
options: {
type: "Control",
control: "hub-field-input-switch",
layout: "inline-space-between",
helperText: {
labelKey: `${i18nScope}.fields.infoBanner.helperText`,
},
},
},
],
},
{
type: "Section",
labelKey: `${i18nScope}.sections.orgSettings.signinSettings.label`,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { _isOrgAdmin, getPortalUrl } from "../..";
import { IArcGISContext } from "../../ArcGISContext";
import { IHubUserOrgSettings } from "../../core/types/IHubUser";
import { request } from "@esri/arcgis-rest-request";
Expand Down
44 changes: 44 additions & 0 deletions packages/common/src/utils/internal/updatePortalOrgSettings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { IArcGISContext } from "../../ArcGISContext";
import { IHubUserOrgSettings } from "../../core/types/IHubUser";
import { request } from "@esri/arcgis-rest-request";
import { cloneObject } from "../../util";

/**
* Function to update a user's org settings. Expects the user to be an org admin in the current org.
* Currently only updates whether to show the informational banner.
* @param settings
*/
export async function updatePortalOrgSettings(
settings: IHubUserOrgSettings,
context: IArcGISContext
) {
// check that user is authed
if (!context.currentUser) {
throw new Error("User is not authenticated");
}

// check that user is org admin
if (!context.isOrgAdmin) {
throw new Error("User is not an org admin in the current org");
}

// grab and clone portalProperties
const portalProperties = cloneObject(context.portal.portalProperties);
// grab settings
const { showInformationalBanner } = settings;
// update infoBanner value in portalProperties
portalProperties.hub.settings.informationalBanner = showInformationalBanner;

// build the url
const urlPath = `/sharing/rest/portals/self/update?f=json`;
const url = `${context.portalUrl}${urlPath}`;

// send the request to update
return request(url, {
httpMethod: "POST",
params: {
portalProperties: JSON.stringify(portalProperties),
token: context.hubRequestOptions.authentication.token,
},
});
}
Loading
Loading