-
Notifications
You must be signed in to change notification settings - Fork 383
Add application assignment UI for policies #10422
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
Open
hwupathum
wants to merge
9
commits into
wso2:master
Choose a base branch
from
hwupathum:default-policies
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8363be9
UX improvements
hwupathum ffc6d37
Application assignment UI
hwupathum b1d56b0
Add permissions
hwupathum 3125b7e
Add changeset 🦋
hwupathum 088e24a
Fix review comments
hwupathum 0dc74ec
Fix type errors
hwupathum 1f48bb9
Fix review comments
hwupathum 9da9c5e
Update console permissions
hwupathum cb797a6
Fix review comments
hwupathum File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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}`; | ||
|
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[]> => { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's use custom hooks with SWR for get requests.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 []; | ||
| } | ||
|
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); | ||
| }); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in wso2/carbon-identity-framework#8136