diff --git a/frontend/src/component/changeRequest/ChangeRequest.test.tsx b/frontend/src/component/changeRequest/ChangeRequest.test.tsx
index c49005f0f6..19e7048253 100644
--- a/frontend/src/component/changeRequest/ChangeRequest.test.tsx
+++ b/frontend/src/component/changeRequest/ChangeRequest.test.tsx
@@ -192,6 +192,10 @@ const otherRequests = (feature: string) => {
version: 1,
tags: [],
});
+ testServerRoute(server, `api/admin/tag-types`, {
+ tagTypes: [],
+ version: 1,
+ });
testServerRoute(server, 'api/admin/user', {
user: {
isAPI: false,
diff --git a/frontend/src/component/changeRequest/ChangeRequestPermissions.test.tsx b/frontend/src/component/changeRequest/ChangeRequestPermissions.test.tsx
index bfb3c63958..5074e4eef2 100644
--- a/frontend/src/component/changeRequest/ChangeRequestPermissions.test.tsx
+++ b/frontend/src/component/changeRequest/ChangeRequestPermissions.test.tsx
@@ -73,6 +73,10 @@ const setupOtherRoutes = (feature: string) => {
version: 1,
tags: [],
});
+ testServerRoute(server, `api/admin/tag-types`, {
+ tagTypes: [],
+ version: 1,
+ });
testServerRoute(server, `api/admin/tags/simple`, {
version: 1,
tags: [],
diff --git a/frontend/src/component/providers/AccessProvider/AccessProvider.tsx b/frontend/src/component/providers/AccessProvider/AccessProvider.tsx
index 02b1332dcf..2b98525909 100644
--- a/frontend/src/component/providers/AccessProvider/AccessProvider.tsx
+++ b/frontend/src/component/providers/AccessProvider/AccessProvider.tsx
@@ -1,6 +1,6 @@
import { ReactElement, ReactNode, useMemo } from 'react';
import AccessContext, { IAccessContext } from 'contexts/AccessContext';
-import { ADMIN } from './permissions';
+import { ADMIN, SKIP_CHANGE_REQUEST } from './permissions';
import { IPermission } from 'interfaces/user';
import { useAuthPermissions } from 'hooks/api/getters/useAuth/useAuthPermissions';
@@ -63,7 +63,7 @@ const checkPermission = (
return false;
}
- if (p.permission === ADMIN) {
+ if (p.permission === ADMIN && permission !== SKIP_CHANGE_REQUEST) {
return true;
}
diff --git a/frontend/src/hooks/useChangeRequestsEnabled.test.tsx b/frontend/src/hooks/useChangeRequestsEnabled.test.tsx
new file mode 100644
index 0000000000..f91e7eaf97
--- /dev/null
+++ b/frontend/src/hooks/useChangeRequestsEnabled.test.tsx
@@ -0,0 +1,76 @@
+import { render, screen } from '@testing-library/react';
+import { AccessProviderMock } from '../component/providers/AccessProvider/AccessProviderMock';
+import { useChangeRequestsEnabled } from './useChangeRequestsEnabled';
+import { FC } from 'react';
+import { testServerRoute, testServerSetup } from '../utils/testServer';
+import {
+ SKIP_CHANGE_REQUEST,
+ ADMIN,
+} from '../component/providers/AccessProvider/permissions';
+
+const project = 'project';
+const environment = 'production';
+
+const TestComponent: FC = () => {
+ const { isChangeRequestConfigured } = useChangeRequestsEnabled(project);
+
+ const string = isChangeRequestConfigured('production')
+ ? 'change request'
+ : 'regular mode';
+
+ return
{string}
;
+};
+
+const server = testServerSetup();
+
+testServerRoute(
+ server,
+ `/api/admin/projects/${project}/change-requests/config`,
+ [
+ {
+ environment,
+ changeRequestEnabled: true,
+ },
+ ]
+);
+testServerRoute(server, '/api/admin/ui-config', {
+ versionInfo: {
+ current: { enterprise: 'present' },
+ },
+});
+
+test('SKIP_CHANGE_REQUEST disables change request mode', async () => {
+ render(
+
+
+
+ );
+
+ const result = await screen.findByText('change request');
+ expect(result).toBeInTheDocument();
+
+ render(
+
+
+
+ );
+
+ const regularModeElement = await screen.findByText('regular mode');
+ expect(regularModeElement).toBeInTheDocument();
+});
diff --git a/frontend/src/hooks/useChangeRequestsEnabled.ts b/frontend/src/hooks/useChangeRequestsEnabled.ts
index 9c174181dc..da487d3465 100644
--- a/frontend/src/hooks/useChangeRequestsEnabled.ts
+++ b/frontend/src/hooks/useChangeRequestsEnabled.ts
@@ -1,17 +1,26 @@
+import { SKIP_CHANGE_REQUEST } from 'component/providers/AccessProvider/permissions';
import React from 'react';
import { useChangeRequestConfig } from './api/getters/useChangeRequestConfig/useChangeRequestConfig';
+import { useCheckProjectPermissions } from './useHasAccess';
export const useChangeRequestsEnabled = (projectId: string) => {
const { data } = useChangeRequestConfig(projectId);
+ const checkAccess = useCheckProjectPermissions(projectId);
const isChangeRequestConfigured = React.useCallback(
(environment: string): boolean => {
- return data.some(draft => {
- return (
- draft.environment === environment &&
- draft.changeRequestEnabled
- );
- });
+ const canSkipChangeRequest = checkAccess(
+ SKIP_CHANGE_REQUEST,
+ environment
+ );
+ return canSkipChangeRequest
+ ? false
+ : data.some(draft => {
+ return (
+ draft.environment === environment &&
+ draft.changeRequestEnabled
+ );
+ });
},
[JSON.stringify(data)]
);
diff --git a/frontend/src/hooks/useHasAccess.ts b/frontend/src/hooks/useHasAccess.ts
index 87c65650b3..63b3a56841 100644
--- a/frontend/src/hooks/useHasAccess.ts
+++ b/frontend/src/hooks/useHasAccess.ts
@@ -15,7 +15,7 @@ import useProject from './api/getters/useProject/useProject';
* This is for features not integrated with change request.
* If the feature is integrated with change request, use useCheckProjectAccess instead.
*/
-const useCheckProjectPermissions = (projectId?: string) => {
+export const useCheckProjectPermissions = (projectId?: string) => {
const { hasAccess } = useContext(AccessContext);
const checkPermission = (
diff --git a/src/migrations/20230411085947-skip-change-request-ui.js b/src/migrations/20230411085947-skip-change-request-ui.js
new file mode 100644
index 0000000000..7f2b6c2dc1
--- /dev/null
+++ b/src/migrations/20230411085947-skip-change-request-ui.js
@@ -0,0 +1,19 @@
+'use strict';
+
+exports.up = function (db, callback) {
+ db.runSql(
+ `
+ UPDATE permissions SET display_name = 'Skip change request process' WHERE permission = 'SKIP_CHANGE_REQUEST';
+ `,
+ callback,
+ );
+};
+
+exports.down = function (db, callback) {
+ db.runSql(
+ `
+ UPDATE permissions SET display_name = 'Skip change request process (API-only)' WHERE permission = 'SKIP_CHANGE_REQUEST';
+ `,
+ callback,
+ );
+};