diff --git a/src/app/services/actions/permissions-action-creator.ts b/src/app/services/actions/permissions-action-creator.ts
index 97fd62357..3a97a6461 100644
--- a/src/app/services/actions/permissions-action-creator.ts
+++ b/src/app/services/actions/permissions-action-creator.ts
@@ -37,6 +37,7 @@ export function fetchScopes(query?: IQuery): Function {
try {
const { devxApi } = getState();
let permissionsUrl = `${devxApi}/permissions`;
+ let hasUrl = false; // whether permissions are for a specific url
if (query) {
const signature = sanitizeQueryUrl(query.sampleUrl);
@@ -47,6 +48,7 @@ export function fetchScopes(query?: IQuery): Function {
}
permissionsUrl = `${permissionsUrl}?requesturl=/${requestUrl}&method=${query.selectedVerb}`;
+ hasUrl = true;
}
const headers = {
@@ -61,7 +63,9 @@ export function fetchScopes(query?: IQuery): Function {
const response = await fetch(permissionsUrl, options);
if (response.ok) {
const scopes = await response.json();
- return dispatch(fetchScopesSuccess(scopes));
+ return dispatch(fetchScopesSuccess({
+ hasUrl, scopes
+ }));
}
throw (response);
} catch (error) {
diff --git a/src/app/services/reducers/permissions-reducer.ts b/src/app/services/reducers/permissions-reducer.ts
index d7ac1a3f8..5925fcd25 100644
--- a/src/app/services/reducers/permissions-reducer.ts
+++ b/src/app/services/reducers/permissions-reducer.ts
@@ -1,31 +1,42 @@
import { IAction } from '../../../types/action';
+import { IPermission } from '../../../types/permissions';
import { FETCH_SCOPES_ERROR, FETCH_SCOPES_PENDING, FETCH_SCOPES_SUCCESS } from '../redux-constants';
const initialState = {
pending: false,
data: [],
+ hasUrl: false,
error: null
};
+interface IPermissionsResponse {
+ hasUrl: boolean;
+ scopes: IPermission[];
+}
+
export function scopes(state = initialState, action: IAction): any {
switch (action.type) {
case FETCH_SCOPES_SUCCESS:
+ const response: IPermissionsResponse = { ...action.response as IPermissionsResponse };
return {
pending: false,
- data: action.response,
+ data: response.scopes,
+ hasUrl: response.hasUrl,
error: null
};
case FETCH_SCOPES_ERROR:
return {
pending: false,
error: action.response,
+ hasUrl: false,
data: []
};
case FETCH_SCOPES_PENDING:
return {
pending: true,
data: [],
- error: null
+ error: null,
+ hasUrl: false
};
default:
return state;
diff --git a/src/app/views/query-runner/request/permissions/PanelList.tsx b/src/app/views/query-runner/request/permissions/PanelList.tsx
index 95f751e31..f2abcfc7e 100644
--- a/src/app/views/query-runner/request/permissions/PanelList.tsx
+++ b/src/app/views/query-runner/request/permissions/PanelList.tsx
@@ -7,40 +7,59 @@ import {
SearchBox,
SelectionMode
} from 'office-ui-fabric-react';
-import React from 'react';
+import React, { useEffect, useState } from 'react';
import { FormattedMessage } from 'react-intl';
+import { useSelector } from 'react-redux';
import { SortOrder } from '../../../../../types/enums';
import { IPermission } from '../../../../../types/permissions';
import { dynamicSort } from '../../../../utils/dynamic-sort';
import { generateGroupsFromList } from '../../../../utils/generate-groups';
+import { setConsentedStatus } from './util';
interface IPanelList {
messages: any;
- permissions: IPermission[];
columns: any[];
classes: any;
selection: any;
renderItemColumn: any;
- searchValueChanged: Function;
renderDetailsHeader: Function;
}
-const PanelList = ({ messages, permissions,
+const PanelList = ({ messages,
columns, classes, selection,
- renderItemColumn, searchValueChanged, renderDetailsHeader }: IPanelList) => {
+ renderItemColumn, renderDetailsHeader }: IPanelList) => {
+ const { consentedScopes, scopes, tokenPresent } = useSelector((state: any) => state);
+ const [permissions, setPermissions] = useState(scopes.data.sort(dynamicSort('value', SortOrder.ASC)));
const permissionsList: any[] = [];
- permissions.forEach(perm => {
- const permission: any = {...perm};
+
+ useEffect(() => {
+ setConsentedStatus(tokenPresent, permissions, consentedScopes);
+ }, [scopes, consentedScopes]);
+
+ permissions.forEach((perm: any) => {
+ const permission: any = { ...perm };
const permissionValue = permission.value;
const groupName = permissionValue.split('.')[0];
permission.groupName = groupName;
permissionsList.push(permission);
});
+ const searchValueChanged = (event: any, value?: string): void => {
+ let filteredPermissions = scopes.data;
+ if (value) {
+ const keyword = value.toLowerCase();
+
+ filteredPermissions = scopes.data.filter((permission: IPermission) => {
+ const name = permission.value.toLowerCase();
+ return name.includes(keyword);
+ });
+ }
+ setPermissions(filteredPermissions);
+ };
+
const groups = generateGroupsFromList(permissionsList, 'groupName');
- permissions = permissions.sort(dynamicSort('value', SortOrder.ASC));
return (
<>
@@ -55,7 +74,7 @@ const PanelList = ({ messages, permissions,
searchValueChanged(event, newValue)}
styles={{ field: { paddingLeft: 10 } }}
/>
-