From 4264377a3dcfd2b58c8f7c22fb03e2a92c9a4b6e Mon Sep 17 00:00:00 2001 From: Chamila Adhikarinayake Date: Fri, 3 Nov 2023 15:59:01 +0530 Subject: [PATCH 1/3] Fix issues with admin ui loading based on permissions --- portals/admin/src/main/webapp/site/public/conf/settings.json | 4 ++-- .../src/app/components/AdminPages/Dashboard/Dashboard.jsx | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/portals/admin/src/main/webapp/site/public/conf/settings.json b/portals/admin/src/main/webapp/site/public/conf/settings.json index 8cb4dcab2d6..68cef408d4e 100644 --- a/portals/admin/src/main/webapp/site/public/conf/settings.json +++ b/portals/admin/src/main/webapp/site/public/conf/settings.json @@ -22,12 +22,12 @@ "docUrl": "https://apim.docs.wso2.com/en/4.2.0/", "roles": { "workflowManager": ["apim:api_workflow_view", "apim:api_workflow_approve", "apim:tenantInfo", "openid", "apim:admin_settings"], - "policyManager": ["apim:tier_view","apim:policies_import_export", "apim:tier_manage", "apim:tenantInfo", + "policyManager": ["apim:admin_tier_view", "apim:admin_tier_manage", "apim:tenantInfo", "apim:bl_view", "apim:bl_manage", "openid", "apim:admin_settings"], "categoriesManager": ["apim:api_category", "openid", "apim:tenantInfo", "apim:admin_settings"], "keyManagers": ["apim:keymanagers_manage", "openid", "apim:tenantInfo", "apim:admin_settings"], "gatewayManager": ["apim:environment_manage", "openid", "apim:admin_settings", "apim:environment_read"], - "settingsManager": ["apim:app_owner_change", "apim:app_import_export", "apim:admin_application_view","apim:scope_manage", "openid", + "settingsManager": ["apim:app_owner_change", "apim:admin_application_view","apim:scope_manage", "openid", "apim:admin_settings", "apim:tenantInfo"] } } diff --git a/portals/admin/src/main/webapp/source/src/app/components/AdminPages/Dashboard/Dashboard.jsx b/portals/admin/src/main/webapp/source/src/app/components/AdminPages/Dashboard/Dashboard.jsx index 065e437dd81..e45f6960ea5 100644 --- a/portals/admin/src/main/webapp/source/src/app/components/AdminPages/Dashboard/Dashboard.jsx +++ b/portals/admin/src/main/webapp/source/src/app/components/AdminPages/Dashboard/Dashboard.jsx @@ -31,8 +31,8 @@ import { useAppContext } from 'AppComponents/Shared/AppContext'; export default function Dashboard() { const { user: { _scopes } } = useAppContext(); const hasWorkflowViewPermission = _scopes.includes('apim:api_workflow_view'); - const hasPolicyViewPermission = _scopes.includes('apim:tier_view'); - const hasAPICategoryViewPermission = _scopes.includes('apim:admin_operations'); + const hasPolicyViewPermission = _scopes.includes('apim:admin_tier_view'); + const hasAPICategoryViewPermission = _scopes.includes('apim:api_category'); return ( From 0fb1e0ca4e4fe1f87173cd6565c138657a5b8026 Mon Sep 17 00:00:00 2001 From: Chamila Adhikarinayake Date: Mon, 6 Nov 2023 12:49:45 +0530 Subject: [PATCH 2/3] Fix category page not loading issue --- .../admin/src/main/webapp/source/src/app/data/AuthManager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/portals/admin/src/main/webapp/source/src/app/data/AuthManager.js b/portals/admin/src/main/webapp/source/src/app/data/AuthManager.js index fdb25503458..a562068ccf2 100644 --- a/portals/admin/src/main/webapp/source/src/app/data/AuthManager.js +++ b/portals/admin/src/main/webapp/source/src/app/data/AuthManager.js @@ -152,7 +152,7 @@ class AuthManager { } else if (val === 'keyManagers') { value = Configurations.app.roles.keyManagers; } else if (val === 'categoriesManager') { - value = Configurations.app.roles.workflowManager; + value = Configurations.app.roles.categoriesManager; } else if (val === 'gatewayManager') { value = Configurations.app.roles.gatewayManager; } From 58b5e53dbac0a8dd9c0dfa5645499e87a40e2f87 Mon Sep 17 00:00:00 2001 From: Chamila Adhikarinayake Date: Thu, 9 Nov 2023 14:14:36 +0530 Subject: [PATCH 3/3] Move allowed scopes to a constant file --- .../src/main/webapp/site/public/conf/settings.json | 12 +----------- .../source/src/app/components/Base/Navigator.jsx | 13 +++++++------ .../main/webapp/source/src/app/data/AuthManager.js | 12 ++++++------ .../main/webapp/source/src/app/data/Constants.js | 14 ++++++++++++++ 4 files changed, 28 insertions(+), 23 deletions(-) diff --git a/portals/admin/src/main/webapp/site/public/conf/settings.json b/portals/admin/src/main/webapp/site/public/conf/settings.json index 68cef408d4e..c36779fa65b 100644 --- a/portals/admin/src/main/webapp/site/public/conf/settings.json +++ b/portals/admin/src/main/webapp/site/public/conf/settings.json @@ -19,16 +19,6 @@ "enabled": true, "timeout": 2000 }, - "docUrl": "https://apim.docs.wso2.com/en/4.2.0/", - "roles": { - "workflowManager": ["apim:api_workflow_view", "apim:api_workflow_approve", "apim:tenantInfo", "openid", "apim:admin_settings"], - "policyManager": ["apim:admin_tier_view", "apim:admin_tier_manage", "apim:tenantInfo", - "apim:bl_view", "apim:bl_manage", "openid", "apim:admin_settings"], - "categoriesManager": ["apim:api_category", "openid", "apim:tenantInfo", "apim:admin_settings"], - "keyManagers": ["apim:keymanagers_manage", "openid", "apim:tenantInfo", "apim:admin_settings"], - "gatewayManager": ["apim:environment_manage", "openid", "apim:admin_settings", "apim:environment_read"], - "settingsManager": ["apim:app_owner_change", "apim:admin_application_view","apim:scope_manage", "openid", - "apim:admin_settings", "apim:tenantInfo"] - } + "docUrl": "https://apim.docs.wso2.com/en/4.2.0/" } } diff --git a/portals/admin/src/main/webapp/source/src/app/components/Base/Navigator.jsx b/portals/admin/src/main/webapp/source/src/app/components/Base/Navigator.jsx index ce41d6539a2..2cde173e118 100644 --- a/portals/admin/src/main/webapp/source/src/app/components/Base/Navigator.jsx +++ b/portals/admin/src/main/webapp/source/src/app/components/Base/Navigator.jsx @@ -13,6 +13,7 @@ import RouteMenuMapping from 'AppComponents/Base/RouteMenuMapping'; import { Link as RouterLink, withRouter } from 'react-router-dom'; import Link from '@material-ui/core/Link'; import Configurations from 'Config'; +import CONSTS from 'AppData/Constants'; import NavigatorChildren from './NavigatorChildren'; const styles = (theme) => ({ @@ -88,12 +89,12 @@ function Navigator(props) { return true; }; - const isWorkflowManager = hasPermission(Configurations.app.roles.workflowManager); - const isSettingsManager = hasPermission(Configurations.app.roles.settingsManager); - const isPolicyManager = hasPermission(Configurations.app.roles.policyManager); - const iskeyManagers = hasPermission(Configurations.app.roles.keyManagers); - const isAPICategory = hasPermission(Configurations.app.roles.categoriesManager); - const isGatewayManager = hasPermission(Configurations.app.roles.gatewayManager); + const isWorkflowManager = hasPermission(CONSTS.Roles.WORKFLOW_MANAGER); + const isSettingsManager = hasPermission(CONSTS.Roles.SETTINGS_MANAGER); + const isPolicyManager = hasPermission(CONSTS.Roles.POLICY_MANAGER); + const iskeyManagers = hasPermission(CONSTS.Roles.KEY_MANAGER); + const isAPICategory = hasPermission(CONSTS.Roles.CATEGORY_MANAGER); + const isGatewayManager = hasPermission(CONSTS.Roles.GATEWAY_MANAGER); const entireArray = []; const checkRouteMenuMapping = routeMenuMapping; diff --git a/portals/admin/src/main/webapp/source/src/app/data/AuthManager.js b/portals/admin/src/main/webapp/source/src/app/data/AuthManager.js index a562068ccf2..f3fc5330766 100644 --- a/portals/admin/src/main/webapp/source/src/app/data/AuthManager.js +++ b/portals/admin/src/main/webapp/source/src/app/data/AuthManager.js @@ -144,17 +144,17 @@ class AuthManager { static hasPermission = (scopes, val) => { let value; if (val === 'workflowManager') { - value = Configurations.app.roles.workflowManager; + value = CONSTS.Roles.WORKFLOW_MANAGER; } else if (val === 'settingsManager') { - value = Configurations.app.roles.settingsManager; + value = CONSTS.Roles.SETTINGS_MANAGER; } else if (val === 'policyManager') { - value = Configurations.app.roles.policyManager; + value = CONSTS.Roles.POLICY_MANAGER; } else if (val === 'keyManagers') { - value = Configurations.app.roles.keyManagers; + value = CONSTS.Roles.KEY_MANAGER; } else if (val === 'categoriesManager') { - value = Configurations.app.roles.categoriesManager; + value = CONSTS.Roles.CATEGORY_MANAGER; } else if (val === 'gatewayManager') { - value = Configurations.app.roles.gatewayManager; + value = CONSTS.Roles.GATEWAY_MANAGER; } for (let i = 0; i < value.length; i++) { if (!scopes.includes(value[i])) { diff --git a/portals/admin/src/main/webapp/source/src/app/data/Constants.js b/portals/admin/src/main/webapp/source/src/app/data/Constants.js index b6159183535..0181c00fd95 100644 --- a/portals/admin/src/main/webapp/source/src/app/data/Constants.js +++ b/portals/admin/src/main/webapp/source/src/app/data/Constants.js @@ -28,6 +28,20 @@ const CONSTS = { DEFAULT_MIN_SCOPES_TO_LOGIN: ['apim:api_workflow_view', 'apim:api_workflow_approve', 'apim:tenantInfo', 'apim:admin_settings', 'apim:tier_view', 'apim:policies_import_export', 'apim:tier_manage', 'apim:bl_manage', ], + Roles: { + WORKFLOW_MANAGER: ['apim:api_workflow_view', 'apim:api_workflow_approve', 'apim:tenantInfo', 'openid', + 'apim:admin_settings', + ], + POLICY_MANAGER: ['apim:tier_view', 'apim:policies_import_export', 'apim:tier_manage', 'apim:tenantInfo', + 'apim:bl_view', 'apim:bl_manage', 'openid', 'apim:admin_settings', + ], + CATEGORY_MANAGER: ['apim:api_category', 'openid', 'apim:tenantInfo', 'apim:admin_settings'], + KEY_MANAGER: ['apim:keymanagers_manage', 'openid', 'apim:tenantInfo', 'apim:admin_settings'], + GATEWAY_MANAGER: ['apim:environment_manage', 'openid', 'apim:admin_settings', 'apim:environment_read'], + SETTINGS_MANAGER: ['apim:app_owner_change', 'apim:app_import_export', 'apim:admin_application_view', + 'apim:scope_manage', 'openid', 'apim:admin_settings', 'apim:tenantInfo', + ], + }, }; export default CONSTS;