From f34bd93e9c210ddb70dccc67b56b891d2711c48f Mon Sep 17 00:00:00 2001 From: Daniele Cammareri Date: Sun, 18 Sep 2022 17:38:42 +0200 Subject: [PATCH] console: remove allow list feature flag PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5889 GitOrigin-RevId: b9a3bab2bd83edb94137603850b405df1766e43b --- .../Services/ApiExplorer/TopNav.tsx | 24 +-- .../AllowedQueries/AddAllowedQuery.tsx | 169 ---------------- .../AllowedQueries/AllowedQueries.tsx | 67 ------- .../AllowedQueries/AllowedQueriesList.tsx | 184 ------------------ .../AllowedQueries/AllowedQueriesNotes.tsx | 29 --- .../components/Services/Settings/Sidebar.tsx | 10 +- .../src/components/Services/Settings/index.ts | 1 - .../AllowListPermissions.tsx | 4 +- .../FeatureFlags/availableFeatureFlags.ts | 10 - .../GraphQLFileUpload.tsx | 5 +- .../__snapshots__/settings.test.ts.snap | 0 .../fixtures.ts} | 0 .../settings.test.ts | 4 +- .../QueryCollectionOperationDialog}/utils.ts | 0 console/src/routes.js | 5 - .../__snapshots__/settings.test.ts.snap | 97 --------- .../Settings/__tests__/fixtures/allow-list.ts | 94 --------- .../Settings/__tests__/settings.test.ts | 20 -- 18 files changed, 12 insertions(+), 711 deletions(-) delete mode 100644 console/src/components/Services/Settings/AllowedQueries/AddAllowedQuery.tsx delete mode 100644 console/src/components/Services/Settings/AllowedQueries/AllowedQueries.tsx delete mode 100644 console/src/components/Services/Settings/AllowedQueries/AllowedQueriesList.tsx delete mode 100644 console/src/components/Services/Settings/AllowedQueries/AllowedQueriesNotes.tsx rename console/src/{components/Services/Settings/__tests__ => features/QueryCollections/components/QueryCollectionOperationDialog}/__snapshots__/settings.test.ts.snap (100%) rename console/src/{components/Services/Settings/__tests__/fixtures/allow-list.ts => features/QueryCollections/components/QueryCollectionOperationDialog/fixtures.ts} (100%) rename console/src/{components/Services/Settings/__tests__ => features/QueryCollections/components/QueryCollectionOperationDialog}/settings.test.ts (81%) rename console/src/{components/Services/Settings/AllowedQueries => features/QueryCollections/components/QueryCollectionOperationDialog}/utils.ts (100%) delete mode 100644 frontend/libs/console/legacy-oss/src/lib/components/Services/Settings/__tests__/__snapshots__/settings.test.ts.snap delete mode 100644 frontend/libs/console/legacy-oss/src/lib/components/Services/Settings/__tests__/fixtures/allow-list.ts delete mode 100644 frontend/libs/console/legacy-oss/src/lib/components/Services/Settings/__tests__/settings.test.ts diff --git a/console/src/components/Services/ApiExplorer/TopNav.tsx b/console/src/components/Services/ApiExplorer/TopNav.tsx index c7df2c44b8f..add6a9a1a97 100644 --- a/console/src/components/Services/ApiExplorer/TopNav.tsx +++ b/console/src/components/Services/ApiExplorer/TopNav.tsx @@ -1,20 +1,12 @@ import React from 'react'; import { Link, RouteComponentProps } from 'react-router'; import { canAccessSecuritySettings } from '@/utils/permissions'; -import { - availableFeatureFlagIds, - useIsFeatureFlagEnabled, -} from '@/features/FeatureFlags'; type TopNavProps = { location: RouteComponentProps['location']; }; const TopNav: React.FC = ({ location }) => { - const { enabled: allowListEnabled } = useIsFeatureFlagEnabled( - availableFeatureFlagIds.allowListId - ); - const sectionsData = [ [ { @@ -31,16 +23,12 @@ const TopNav: React.FC = ({ location }) => { }, ], [ - ...(allowListEnabled - ? [ - { - key: 'allow-list', - link: '/api/allow-list', - dataTestVal: 'allow-list', - title: 'Allow List', - }, - ] - : []), + { + key: 'allow-list', + link: '/api/allow-list', + dataTestVal: 'allow-list', + title: 'Allow List', + }, ], ]; diff --git a/console/src/components/Services/Settings/AllowedQueries/AddAllowedQuery.tsx b/console/src/components/Services/Settings/AllowedQueries/AddAllowedQuery.tsx deleted file mode 100644 index a5f0caab6a2..00000000000 --- a/console/src/components/Services/Settings/AllowedQueries/AddAllowedQuery.tsx +++ /dev/null @@ -1,169 +0,0 @@ -import React, { useState } from 'react'; -import AceEditor from 'react-ace'; -import { isConsoleError } from '@/components/Common/utils/jsUtils'; - -import ExpandableEditor from '../../../Common/Layout/ExpandableEditor/Editor'; -import Tooltip from '../../../Common/Tooltip/Tooltip'; - -import { readFile, parseQueryString, renameDuplicates } from './utils'; -import { showErrorNotification } from '../../Common/Notification'; -import { addAllowedQueries } from '../../../../metadata/actions'; -import { allowedQueriesCollection } from '../../../../metadata/utils'; -import { AllowedQueriesCollection } from '../../../../metadata/reducer'; -import { Dispatch } from '../../../../types'; -import { inputStyles } from '../constants'; - -const defaultManualQuery: AllowedQueriesCollection = { - name: '', - query: '', - collection: allowedQueriesCollection, -}; - -type AddAllowedQueryProps = { - dispatch: Dispatch; - allowedQueries: AllowedQueriesCollection[]; -}; - -const AddAllowedQuery: React.FC = props => { - const { dispatch, allowedQueries } = props; - - const [manualQuery, setManualQuery] = - useState(defaultManualQuery); - const [graphqlFile, setGraphqlFile] = useState(null); - - const handleManualCollapse = () => { - setManualQuery(defaultManualQuery); - }; - - const handleManualSubmit = (toggle: () => void) => { - dispatch(addAllowedQueries([manualQuery], toggle)); - }; - - const handleFileUploadCollapse = () => {}; - - const handleFileUploadSubmit = (toggle: () => void) => { - const addFileQueries = (content: string) => { - try { - const fileQueries = parseQueryString(content); - const updatedQueries = renameDuplicates(fileQueries, allowedQueries); - dispatch(addAllowedQueries(updatedQueries, toggle)); - } catch (error) { - if (isConsoleError(error)) { - dispatch( - showErrorNotification('Uploading operations failed', error.message) - ); - } - } - }; - - readFile(graphqlFile, addFileQueries); - }; - - const handleNameChange = (e: React.ChangeEvent) => { - setManualQuery({ - ...manualQuery, - name: e.target.value, - }); - }; - - const handleQueryChange = (val: string) => { - setManualQuery({ - ...manualQuery, - query: val, - }); - }; - - const manualQueryInput = () => ( -
-
-
- Query name: - -
- -
-
-
-
- Operation: -
- -
-
-
- ); - - const handleFileUpload = (e: React.ChangeEvent) => { - const files = e.target.files; - setGraphqlFile(files![0]); - }; - - const fileUploadInput = () => ( -
-
- Graphql File: - -
- -
- ); - - return ( -
-

- Add new operations to allow-list -

-
-
- -
-
OR
-
- -
-
-
- ); -}; - -export default AddAllowedQuery; diff --git a/console/src/components/Services/Settings/AllowedQueries/AllowedQueries.tsx b/console/src/components/Services/Settings/AllowedQueries/AllowedQueries.tsx deleted file mode 100644 index abc446b019d..00000000000 --- a/console/src/components/Services/Settings/AllowedQueries/AllowedQueries.tsx +++ /dev/null @@ -1,67 +0,0 @@ -import React from 'react'; - -import { browserHistory } from 'react-router'; -import { - availableFeatureFlagIds, - FeatureFlagToast, - useIsFeatureFlagEnabled, -} from '@/features/FeatureFlags'; - -import AllowedQueriesNotes from './AllowedQueriesNotes'; -import AddAllowedQuery from './AddAllowedQuery'; -import AllowedQueriesList from './AllowedQueriesList'; - -import { getAllowedQueries } from '../../../../metadata/selector'; -import { Dispatch, ReduxState } from '../../../../types'; -import { mapDispatchToPropsEmpty } from '../../../Common/utils/reactUtils'; -import { AllowedQueriesCollection } from '../../../../metadata/reducer'; - -interface Props { - dispatch: Dispatch; - allowedQueries: AllowedQueriesCollection[]; -} - -const AllowedQueries: React.FC = props => { - const { dispatch, allowedQueries } = props; - - const { enabled: featureFlagEnabled } = useIsFeatureFlagEnabled( - availableFeatureFlagIds.allowListId - ); - - if (featureFlagEnabled) { - browserHistory.push('/api/allow-list'); - } - - return ( -
-
-

Allow List

-
- -
- -
- -
-
- -
- ); -}; - -const mapStateToProps = (state: ReduxState) => { - return { - allowedQueries: getAllowedQueries(state), - }; -}; - -const allowedQueriesConnector = (connect: any) => - connect(mapStateToProps, mapDispatchToPropsEmpty)(AllowedQueries); - -export default allowedQueriesConnector; diff --git a/console/src/components/Services/Settings/AllowedQueries/AllowedQueriesList.tsx b/console/src/components/Services/Settings/AllowedQueries/AllowedQueriesList.tsx deleted file mode 100644 index a1d544cc7cb..00000000000 --- a/console/src/components/Services/Settings/AllowedQueries/AllowedQueriesList.tsx +++ /dev/null @@ -1,184 +0,0 @@ -import React, { useState } from 'react'; -import AceEditor from 'react-ace'; - -import { Button } from '@/new-components/Button'; -import ExpandableEditor from '../../../Common/Layout/ExpandableEditor/Editor'; - -import { getConfirmation } from '../../../Common/utils/jsUtils'; -import { - updateAllowedQuery, - deleteAllowedQuery, - deleteAllowList, -} from '../../../../metadata/actions'; -import { AllowedQueriesCollection } from '../../../../metadata/reducer'; -import { Dispatch } from '../../../../types'; -import { getCollectionNames, checkLastQuery } from './utils'; -import Tooltip from '../../../Common/Tooltip/Tooltip'; -import { inputStyles } from '../constants'; - -type AllowedQueriesListProps = { - dispatch: Dispatch; - allowedQueries: AllowedQueriesCollection[]; -}; - -type ModifiedQuery = Record; - -const AllowedQueriesList: React.FC = props => { - const [modifiedQueries, setModifiedQueries] = useState({}); - const { allowedQueries, dispatch } = props; - - const getQueryList = () => { - if (allowedQueries.length === 0) { - return
No operations in allow-list yet
; - } - - return allowedQueries.map((query, i) => { - const queryName = query.name; - const collectionName = query.collection; - const queryId = `${queryName}_${collectionName}_${i}`; - - const collapsedLabel = () => ( -
- {queryName} - - {collectionName} -
- ); - - const expandedLabel = collapsedLabel; - - const queryEditorExpanded = () => { - const modifiedQuery = modifiedQueries[queryId] || { ...query }; - - const handleNameChange = (e: React.ChangeEvent) => { - const newModifiedQueries = { ...modifiedQueries }; - newModifiedQueries[queryId].name = e.target.value; - setModifiedQueries(newModifiedQueries); - }; - - const handleQueryChange = (val: string) => { - const newModifiedQueries = { ...modifiedQueries }; - newModifiedQueries[queryId].query = val; - setModifiedQueries(newModifiedQueries); - }; - - return ( -
-
-
- Query name: - -
- -
-
-
- Operation: -
- -
-
- ); - }; - - const editorExpandCallback = () => { - const newModifiedQueries = { ...modifiedQueries }; - newModifiedQueries[queryId] = { ...query }; - setModifiedQueries(newModifiedQueries); - }; - - const editorCollapseCallback = () => { - const newModifiedQueries = { ...modifiedQueries }; - delete newModifiedQueries[queryId]; - setModifiedQueries(newModifiedQueries); - }; - - const onSubmit = () => { - dispatch( - updateAllowedQuery( - queryName, - modifiedQueries[queryId], - collectionName - ) - ); - }; - - const onDelete = () => { - const confirmMessage = `This will delete the operation "${queryName}" from the allow-list`; - const isOk = getConfirmation(confirmMessage); - if (isOk) { - const isLastQuery = checkLastQuery(collectionName, allowedQueries); - dispatch(deleteAllowedQuery(queryName, isLastQuery, collectionName)); - } - }; - - return ( -
- -
- ); - }); - }; - - const handleDeleteAll = () => { - const confirmMessage = - 'This will delete all operations from the allow-list'; - const isOk = getConfirmation(confirmMessage, true); - const collectionNames = getCollectionNames(allowedQueries); - if (isOk) { - dispatch(deleteAllowList(collectionNames)); - } - }; - - return ( -
-

- Allow List - - - -

- -
{getQueryList()}
-
- ); -}; - -export default AllowedQueriesList; diff --git a/console/src/components/Services/Settings/AllowedQueries/AllowedQueriesNotes.tsx b/console/src/components/Services/Settings/AllowedQueries/AllowedQueriesNotes.tsx deleted file mode 100644 index 9198040a4c0..00000000000 --- a/console/src/components/Services/Settings/AllowedQueries/AllowedQueriesNotes.tsx +++ /dev/null @@ -1,29 +0,0 @@ -import React from 'react'; - -const AllowedQueriesNotes: React.FC = () => { - return ( -
-
- If GraphQL Engine is started with the{' '} - HASURA_GRAPHQL_ENABLE_ALLOWLIST env var or the{' '} - --enable-allowlist flag set to true, only operations - added to the allow-list will be allowed to be executed.  - - (Read more) - -
-
- Notes -
- All allowed operations need to have a unique name for reference -
-
-
- ); -}; - -export default AllowedQueriesNotes; diff --git a/console/src/components/Services/Settings/Sidebar.tsx b/console/src/components/Services/Settings/Sidebar.tsx index c6bdd78b8d4..6464aad1f97 100644 --- a/console/src/components/Services/Settings/Sidebar.tsx +++ b/console/src/components/Services/Settings/Sidebar.tsx @@ -1,9 +1,5 @@ /* eslint-disable no-underscore-dangle */ import React from 'react'; -import { - availableFeatureFlagIds, - useIsFeatureFlagEnabled, -} from '@/features/FeatureFlags'; import { Link, RouteComponentProps } from 'react-router'; import LeftContainer from '../../Common/Layout/LeftContainer/LeftContainer'; import CheckIcon from '../../Common/Icons/Check'; @@ -48,10 +44,6 @@ interface SectionData { const Sidebar: React.FC = ({ location, metadata }) => { const sectionsData: SectionData[] = []; - const { enabled: newAllowListEnabled } = useIsFeatureFlagEnabled( - availableFeatureFlagIds.allowListId - ); - sectionsData.push({ key: 'actions', link: '/settings/metadata-actions', @@ -81,7 +73,7 @@ const Sidebar: React.FC = ({ location, metadata }) => { sectionsData.push({ key: 'allow-list', - link: newAllowListEnabled ? '/api/allow-list' : '/settings/allow-list', + link: '/api/allow-list', dataTestVal: 'allow-list-link', title: 'Allow List', }); diff --git a/console/src/components/Services/Settings/index.ts b/console/src/components/Services/Settings/index.ts index b440a898637..c401cc18427 100644 --- a/console/src/components/Services/Settings/index.ts +++ b/console/src/components/Services/Settings/index.ts @@ -1,7 +1,6 @@ export { default as metadataContainer } from './Container'; export { default as metadataOptionsContainer } from './MetadataOptions/MetadataOptions'; export { default as metadataStatusContainer } from './MetadataStatus/MetadataStatus'; -export { default as allowedQueriesContainer } from './AllowedQueries/AllowedQueries'; export { default as logoutContainer } from './Logout/Logout'; export { default as aboutContainer } from './About/About'; export { default as InheritedRolesContainer } from './InheritedRoles/InheritedRoles'; diff --git a/console/src/features/AllowLists/components/AllowListPermissions/AllowListPermissions.tsx b/console/src/features/AllowLists/components/AllowListPermissions/AllowListPermissions.tsx index 3ecff037425..82092cb036c 100644 --- a/console/src/features/AllowLists/components/AllowListPermissions/AllowListPermissions.tsx +++ b/console/src/features/AllowLists/components/AllowListPermissions/AllowListPermissions.tsx @@ -156,7 +156,7 @@ export const AllowListPermissions: React.FC = ({ - {updatingRoles.includes(roleName) ? ( + {updatingRoles.length > 0 ? ( ) : ( = ({ /> - {updatingRoles.includes(newRole) ? ( + {updatingRoles.length > 0 ? ( ) : ( { describe('renameDuplicates', () => { diff --git a/console/src/components/Services/Settings/AllowedQueries/utils.ts b/console/src/features/QueryCollections/components/QueryCollectionOperationDialog/utils.ts similarity index 100% rename from console/src/components/Services/Settings/AllowedQueries/utils.ts rename to console/src/features/QueryCollections/components/QueryCollectionOperationDialog/utils.ts diff --git a/console/src/routes.js b/console/src/routes.js index e2861c25dce..df47d18291c 100644 --- a/console/src/routes.js +++ b/console/src/routes.js @@ -19,7 +19,6 @@ import settingsContainer from './components/Services/Settings/Container'; import ApiContainer from './components/Services/ApiExplorer/Container'; import metadataOptionsConnector from './components/Services/Settings/MetadataOptions/MetadataOptions'; import metadataStatusConnector from './components/Services/Settings/MetadataStatus/MetadataStatus'; -import allowedQueriesConnector from './components/Services/Settings/AllowedQueries/AllowedQueries'; import inheritedRolesConnector from './components/Services/Settings/InheritedRoles/InheritedRoles'; import logoutConnector from './components/Services/Settings/Logout/Logout'; import aboutConnector from './components/Services/Settings/About/About'; @@ -150,10 +149,6 @@ const routes = store => { path="metadata-status" component={metadataStatusConnector(connect)} /> - diff --git a/frontend/libs/console/legacy-oss/src/lib/components/Services/Settings/__tests__/__snapshots__/settings.test.ts.snap b/frontend/libs/console/legacy-oss/src/lib/components/Services/Settings/__tests__/__snapshots__/settings.test.ts.snap deleted file mode 100644 index b52a0f9c261..00000000000 --- a/frontend/libs/console/legacy-oss/src/lib/components/Services/Settings/__tests__/__snapshots__/settings.test.ts.snap +++ /dev/null @@ -1,97 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`AllowedQueries_Utils.ts renameDuplicates should rename duplicate queries 1`] = ` -Array [ - Object { - "name": "getAuthors_1", - "query": "query getAuthors { - author { - id - name - } -}", - }, - Object { - "name": "getAuthors_2", - "query": "query getAuthors { - author { - id - name - address - } -}", - }, - Object { - "name": "getAuthors_3", - "query": "query getAuthors { - author { - id - name - age - } -}", - }, - Object { - "name": "unnamed", - "query": "{ - student { - id - name - age - } -}", - }, - Object { - "name": "unnamed_1", - "query": "{ - student { - id - name - roll - } -}", - }, - Object { - "name": "unnamed_2", - "query": "{ - student { - id - name - address - } -}", - }, - Object { - "name": "getArticles", - "query": "query getArticles { - article { - id - title - } -}", - }, - Object { - "name": "getArticle", - "query": "query getArticle { - article { - id - title - ...frag - } -} - -fragment frag on Starship { - name -}", - }, - Object { - "name": "addArticles", - "query": "mutation addArticles { - insert_articles { - id - title - } -}", - }, -] -`; diff --git a/frontend/libs/console/legacy-oss/src/lib/components/Services/Settings/__tests__/fixtures/allow-list.ts b/frontend/libs/console/legacy-oss/src/lib/components/Services/Settings/__tests__/fixtures/allow-list.ts deleted file mode 100644 index bd1af87fe13..00000000000 --- a/frontend/libs/console/legacy-oss/src/lib/components/Services/Settings/__tests__/fixtures/allow-list.ts +++ /dev/null @@ -1,94 +0,0 @@ -export const uploadedFileData = `# will be ignored by the allow-list -type Starship { - id: ID! - name: String! - length(unit: LengthUnit = METER): Float -} - -# will be ignored by the allow-list -scalar parsec - -# will be ignored by the allow-list -enum Episode { - NEWHOPE - EMPIRE - JEDI -} - -# will be stored in the allow-list -query getAuthors{ - author { - id - name - } -} - -query getAuthors{ - author { - id - name - address - } -} - -query getAuthors{ - author { - id - name - age - } -} - -query { - student { - id - name - age - } -} - -query { - student { - id - name - roll - } -} - -query { - student { - id - name - address - } -} - -fragment frag on Starship { - name -} - -# will be stored in the allow-list -query getArticles { - article { - id - title - } -} - -# will be stored in the allow-list after patching in the fragment -query getArticle { - article { - id - title - ...frag - } -} - -# will be stored in the allow-list -mutation addArticles { - insert_articles { - id - title - } -} -`; diff --git a/frontend/libs/console/legacy-oss/src/lib/components/Services/Settings/__tests__/settings.test.ts b/frontend/libs/console/legacy-oss/src/lib/components/Services/Settings/__tests__/settings.test.ts deleted file mode 100644 index cee5757a140..00000000000 --- a/frontend/libs/console/legacy-oss/src/lib/components/Services/Settings/__tests__/settings.test.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { allowedQueriesCollection } from '../../../../metadata/utils'; -import { renameDuplicates, parseQueryString } from '../AllowedQueries/utils'; -import { uploadedFileData } from './fixtures/allow-list'; - -describe('AllowedQueries_Utils.ts', () => { - describe('renameDuplicates', () => { - it('should rename duplicate queries', () => { - const allowedListQueries = [ - { - name: 'getAuthors', - query: 'query getAuthors { author {id name} }', - collection: allowedQueriesCollection, - }, - ]; - const fileQueries = parseQueryString(uploadedFileData); - const updatedQueries = renameDuplicates(fileQueries, allowedListQueries); - expect(updatedQueries).toMatchSnapshot(); - }); - }); -});