forked from wso2/identity-apps
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request wso2#4388 from SujanSanjula96/fix-api-resource-ui-1
Fix API Resource UI access control to support system APIs
- Loading branch information
Showing
7 changed files
with
144 additions
and
25 deletions.
There are no files selected for viewing
This file contains 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,5 @@ | ||
--- | ||
"@wso2is/console": patch | ||
--- | ||
|
||
Fix API Resource UI access control to support system APIs |
This file contains 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 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 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 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 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
99 changes: 99 additions & 0 deletions
99
apps/console/src/features/api-resources/utils/api-resource-utils.ts
This file contains 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,99 @@ | ||
/** | ||
* Copyright (c) 2023, 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 { hasRequiredScopes } from "@wso2is/core/helpers"; | ||
import { FeatureConfigInterface } from "../../core"; | ||
import { APIResourcesConstants } from "../constants/api-resources-constants"; | ||
|
||
export class APIResourceUtils { | ||
|
||
/** | ||
* Private constructor to avoid object instantiation from outside | ||
* the class. | ||
*/ | ||
private constructor() { } | ||
|
||
/** | ||
* Check whether the API resource read is allowed. | ||
* | ||
* @param featureConfig - Feature config. | ||
* @param allowedScopes - Allowed scopes. | ||
* @returns True if the API resource read is allowed. | ||
*/ | ||
public static isAPIResourceReadAllowed(featureConfig: FeatureConfigInterface, | ||
allowedScopes: string): boolean { | ||
|
||
return hasRequiredScopes(featureConfig?.apiResources, | ||
featureConfig?.apiResources?.scopes?.read, allowedScopes); | ||
} | ||
|
||
/** | ||
* Check whether the API resource update is allowed. | ||
* | ||
* @param featureConfig - Feature config. | ||
* @param allowedScopes - Allowed scopes. | ||
* @returns True if the API resource update is allowed. | ||
*/ | ||
public static isAPIResourceUpdateAllowed(featureConfig: FeatureConfigInterface, | ||
allowedScopes: string): boolean { | ||
|
||
return hasRequiredScopes(featureConfig?.apiResources, | ||
featureConfig?.apiResources?.scopes?.update, allowedScopes); | ||
} | ||
|
||
/** | ||
* Check whether the API resource create is allowed. | ||
* | ||
* @param featureConfig - Feature config. | ||
* @param allowedScopes - Allowed scopes. | ||
* @returns True if the API resource create is allowed. | ||
*/ | ||
public static isAPIResourceCreateAllowed(featureConfig: FeatureConfigInterface, | ||
allowedScopes: string): boolean { | ||
|
||
return hasRequiredScopes(featureConfig?.apiResources, | ||
featureConfig?.apiResources?.scopes?.create, allowedScopes); | ||
} | ||
|
||
/** | ||
* Check whether the API resource delete is allowed. | ||
* | ||
* @param featureConfig - Feature config. | ||
* @param allowedScopes - Allowed scopes. | ||
* @returns True if the API resource delete is allowed. | ||
*/ | ||
public static isAPIResourceDeleteAllowed(featureConfig: FeatureConfigInterface, | ||
allowedScopes: string): boolean { | ||
|
||
return hasRequiredScopes(featureConfig?.apiResources, | ||
featureConfig?.apiResources?.scopes?.delete, allowedScopes); | ||
} | ||
|
||
/** | ||
* Check whether the API resource is a system API. | ||
* | ||
* @param type - API Resource type. | ||
* @returns True if the API resource is a system API. | ||
*/ | ||
public static isSystemAPI(type: string): boolean { | ||
|
||
return type === APIResourcesConstants.SYSTEM | ||
|| type === APIResourcesConstants.SYSTEM_ORG | ||
|| type === APIResourcesConstants.SYSTEM_FEATURE; | ||
} | ||
} |