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

Fix issues with admin ui loading based on permissions #513

Merged
merged 3 commits into from
Nov 10, 2023
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
12 changes: 1 addition & 11 deletions portals/admin/src/main/webapp/site/public/conf/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:tier_view","apim:policies_import_export", "apim: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",
"apim:admin_settings", "apim:tenantInfo"]
}
"docUrl": "https://apim.docs.wso2.com/en/4.2.0/"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<ContentBase width='full' title='Dashboard' pageStyle='paperLess'>
<Grid container spacing={3} justify='center'>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) => ({
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.workflowManager;
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])) {
Expand Down
14 changes: 14 additions & 0 deletions portals/admin/src/main/webapp/source/src/app/data/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Loading