Skip to content
Open
Show file tree
Hide file tree
Changes from 8 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
9 changes: 9 additions & 0 deletions .changeset/plain-dolls-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@wso2is/console": patch
"@wso2is/admin.consents.v1": patch
"@wso2is/admin.core.v1": patch
"@wso2is/common.consents.v1": patch
"@wso2is/i18n": patch
---

Add application assignment UI for policies
6 changes: 6 additions & 0 deletions apps/console/src/public/deployment.config.json

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hope these scope updates have also been added to the default.json in framework as well

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original file line number Diff line number Diff line change
Expand Up @@ -887,10 +887,16 @@
"console:consents"
],
"read": [
"internal_application_mgt_view",
"internal_claim_meta_view",
"internal_consent_mgt_element_view",
"internal_consent_mgt_purpose_app_view",
"internal_consent_mgt_purpose_view"
],
"update": [
"internal_branding_preference_policy_update",
"internal_consent_mgt_purpose_app_create",
"internal_consent_mgt_purpose_app_delete",
"internal_consent_mgt_purpose_update"
]
}
Expand Down
128 changes: 128 additions & 0 deletions features/admin.consents.v1/api/consent-policy-apps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/**
* Copyright (c) 2026, WSO2 LLC. (https://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { AsgardeoSPAClient, HttpClientInstance } from "@asgardeo/auth-react";
import { store } from "@wso2is/admin.core.v1/store";
import { HttpMethods } from "@wso2is/core/models";
import { AxiosError, AxiosRequestConfig, AxiosResponse } from "axios";

const httpClient: HttpClientInstance = AsgardeoSPAClient.getInstance()
.httpRequest.bind(AsgardeoSPAClient.getInstance());

const getPurposeAppsUrl = (purposeId: string): string =>
`${store.getState().config.endpoints.consentPolicyApps}/${purposeId}/applications`;

const getPurposeAppUrl = (purposeId: string, applicationId: string): string =>
`${getPurposeAppsUrl(purposeId)}/${applicationId}`;
Comment thread
coderabbitai[bot] marked this conversation as resolved.

const JSON_HEADERS: Record<string, string> = {
"Accept": "application/json",
"Content-Type": "application/json"
};

interface ApplicationObject {
id: string;
}

/**
* Fetches the application IDs assigned to a consent purpose.
*
* @param purposeId - The purpose UUID.
* @returns Array of application IDs, or empty array if the purpose has no assignments.
*/
export const getConsentPolicyApps = (purposeId: string): Promise<string[]> => {

Check failure on line 48 in features/admin.consents.v1/api/consent-policy-apps.ts

View workflow job for this annotation

GitHub Actions / ✂️ Knip (DEAD CODE) (20.x, 10.33.0)

✂️ Knip / Unused exports

getConsentPolicyApps in features/admin.consents.v1/api/consent-policy-apps.ts

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use custom hooks with SWR for get requests.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed with 1f48bb9

const requestConfig: AxiosRequestConfig = {
headers: JSON_HEADERS,
method: HttpMethods.GET,
url: getPurposeAppsUrl(purposeId)
};

return httpClient(requestConfig)
.then((response: AxiosResponse): string[] =>
(response.data as ApplicationObject[]).map((app: ApplicationObject): string => app.id)
)
.catch((error: AxiosError): string[] => {
if (error?.response?.status === 404) {
return [];
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
throw error;
});
};

/**
* Saves the application assignments for a consent purpose.
* Diffs against current state: adds new apps and removes de-selected ones.
*
* @param purposeId - The purpose UUID.
* @param newIds - The full desired set of application IDs.
*/
export const saveConsentPolicyApps = (purposeId: string, newIds: string[]): Promise<void> => {
return getConsentPolicyApps(purposeId)
.then((currentIds: string[]): Promise<void> => {
const currentSet: Set<string> = new Set<string>(currentIds);
const newSet: Set<string> = new Set<string>(newIds);

const toAdd: string[] = newIds.filter((id: string): boolean => !currentSet.has(id));
const toRemove: string[] = currentIds.filter((id: string): boolean => !newSet.has(id));

const addRequests: Promise<void>[] = toAdd.map((id: string): Promise<void> => {
const config: AxiosRequestConfig = {
data: { id } as ApplicationObject,
headers: JSON_HEADERS,
method: HttpMethods.POST,
url: getPurposeAppsUrl(purposeId)
};

return httpClient(config).then((): void => undefined);
});

const removeRequests: Promise<void>[] = toRemove.map((id: string): Promise<void> => {
const config: AxiosRequestConfig = {
headers: JSON_HEADERS,
method: HttpMethods.DELETE,
url: getPurposeAppUrl(purposeId, id)
};

return httpClient(config).then((): void => undefined);
});

return Promise.all([ ...addRequests, ...removeRequests ]).then((): void => undefined);
});
};

/**
* Removes all application assignments for a consent purpose.
*
* @param purposeId - The purpose UUID.
*/
export const deleteConsentPolicyApps = (purposeId: string): Promise<void> => {
return getConsentPolicyApps(purposeId)
.then((currentIds: string[]): Promise<void> => {
const removeRequests: Promise<void>[] = currentIds.map((id: string): Promise<void> => {
const config: AxiosRequestConfig = {
headers: JSON_HEADERS,
method: HttpMethods.DELETE,
url: getPurposeAppUrl(purposeId, id)
};

return httpClient(config).then((): void => undefined);
});

return Promise.all(removeRequests).then((): void => undefined);
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,9 @@ const ConsentEditorToolbar: FunctionComponent<ConsentEditorToolbarPropsInterface
const isValidPolicyUrl: boolean = !!policyUrl && URLUtils.isHttpsOrHttpUrl(policyUrl);

const handleInsertPolicyLink: () => void = (): void => {
if (isValidPolicyUrl) {
if (isLink) {
editor.dispatchCommand(TOGGLE_LINK_COMMAND, null);
} else if (isValidPolicyUrl) {
editor.dispatchCommand(TOGGLE_LINK_COMMAND, policyUrl);
}
};
Expand All @@ -419,6 +421,9 @@ const ConsentEditorToolbar: FunctionComponent<ConsentEditorToolbarPropsInterface
* based on whether a URL exists, whether it is valid, and whether text is selected.
*/
const policyLinkTooltip: () => string = (): string => {
if (isLink) {
return t("consents:policyConsents.wizard.create.form.description.removePolicyLink");
}
if (!policyUrl) {
return t("consents:policyConsents.wizard.create.form.description.insertPolicyLinkNoPolicyUrl");
}
Expand Down Expand Up @@ -479,43 +484,42 @@ const ConsentEditorToolbar: FunctionComponent<ConsentEditorToolbarPropsInterface
<ItalicIcon />
</ToolbarIconButton>
<ToolbarDivider component="span" />
<ToolbarPolicyLinkButton
component="button"
type="button"
className={ isLink ? "active" : undefined }
disabled={ disabled || (!hasSelection && !isLink) }
onClick={ handleLinkButtonClick }
aria-label={ t("consents:policyConsents.wizard.create.form.description.insertCustomLinkShort") }
>
<OxygenLinkIcon />
{ t("consents:policyConsents.wizard.create.form.description.insertCustomLinkShort") }
</ToolbarPolicyLinkButton>
{ policyUrl !== undefined && (
<>
<ToolbarDivider component="span" />
{ /*
* Wrap in a <span> so the Tooltip still shows on a disabled button.
* MUI/Oxygen Tooltip requires a non-disabled child to trigger.
*/ }
<Tooltip
title={ policyLinkTooltip() }
placement="top"
arrow
>
<span>
<ToolbarPolicyLinkButton
component="button"
type="button"
disabled={ disabled || !hasSelection || !isValidPolicyUrl }
onClick={ handleInsertPolicyLink }
aria-label={ t("consents:policyConsents.wizard.create.form.description.insertPolicyLink") }
>
<OxygenLinkIcon />
{ t("consents:policyConsents.wizard.create.form.description.insertPolicyLinkShort") }
</ToolbarPolicyLinkButton>
</span>
</Tooltip>
</>
{ policyUrl === undefined ? (
<ToolbarPolicyLinkButton
component="button"
type="button"
className={ isLink ? "active" : undefined }
disabled={ disabled || (!hasSelection && !isLink) }
onClick={ handleLinkButtonClick }
aria-label={ t(
"consents:policyConsents.wizard.create.form.description.insertCustomLinkShort"
) }
>
<OxygenLinkIcon />
{ t("consents:policyConsents.wizard.create.form.description.insertCustomLinkShort") }
</ToolbarPolicyLinkButton>
) : (
<Tooltip
title={ policyLinkTooltip() }
placement="top"
arrow
>
<span>
<ToolbarPolicyLinkButton
component="button"
type="button"
className={ isLink ? "active" : undefined }
disabled={ disabled || (!isLink && (!hasSelection || !isValidPolicyUrl)) }
onClick={ handleInsertPolicyLink }
aria-label={ t(
"consents:policyConsents.wizard.create.form.description.insertPolicyLink"
) }
>
<OxygenLinkIcon />
{ t("consents:policyConsents.wizard.create.form.description.insertPolicyLinkShort") }
</ToolbarPolicyLinkButton>
</span>
</Tooltip>
) }
</ToolbarMainRow>
</Paper>
Expand Down Expand Up @@ -678,7 +682,7 @@ export const ConsentDescriptionEditor: FunctionComponent<ConsentDescriptionEdito
/>
<HistoryPlugin />
<LinkPlugin />
<ConsentFloatingLinkEditor />
{ variant === "preference" && <ConsentFloatingLinkEditor /> }
<HtmlSyncPlugin
initialHtml={ value }
onChange={ onChange }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ export const EditPolicyConsent: FunctionComponent<EditPolicyConsentProps> = (
<Trans
i18nKey="consents:policyConsents.brandingRequired"
>
Enable branding to update default policies.{ " " }
Enable branding to update default policies.
<Link
onClick={ handleNavigateToBranding }
sx={ { cursor: "pointer" } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* under the License.
*/

import Alert from "@oxygen-ui/react/Alert";
import Autocomplete, { AutocompleteRenderInputParams } from "@oxygen-ui/react/Autocomplete";
import Box from "@oxygen-ui/react/Box";
import Card from "@oxygen-ui/react/Card";
Expand Down Expand Up @@ -43,7 +44,7 @@ import { IdentityAppsApiException } from "@wso2is/core/exceptions";
import { AlertLevels, Claim, ClaimsGetParams, FeatureAccessConfigInterface, IdentifiableComponentInterface } from "@wso2is/core/models";
import { addAlert } from "@wso2is/core/store";
import { FinalForm, FinalFormField, TextFieldAdapter } from "@wso2is/forms";
import { ContentLoader, Message, PrimaryButton } from "@wso2is/react-components";
import { ContentLoader, PrimaryButton } from "@wso2is/react-components";
import React, {
FunctionComponent,
type ReactElement,
Expand Down Expand Up @@ -561,21 +562,18 @@ export const EditPreferenceManagement: FunctionComponent<EditPreferenceManagemen
} }
/>
</Box>
<Message
type="info"
content={ (
<Trans
i18nKey="consents:preferenceManagement.form.linkHint"
<Alert severity="info">
<Trans
i18nKey="consents:preferenceManagement.form.linkHint"
>
<Link
onClick={ handleRegFlowBuilderClick }
sx={ { cursor: "pointer" } }
>
<Link
onClick={ handleRegFlowBuilderClick }
sx={ { cursor: "pointer" } }
>
this link
</Link>
</Trans>
) }
/>
this link
</Link>
</Trans>
</Alert>
</Box>
</Grid>
{ /* Preview column */ }
Expand Down
Loading
Loading