Skip to content

Commit

Permalink
fix(app-shell): do not fetch project extensions if user has no projec…
Browse files Browse the repository at this point in the history
…t access (#3579)
  • Loading branch information
emmenko authored Aug 5, 2024
1 parent 839d185 commit ed2158c
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/spotty-dragons-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@commercetools-frontend/application-shell': patch
---

Do not fetch project extensions for navbar if user cannot access a project.
Original file line number Diff line number Diff line change
Expand Up @@ -1372,6 +1372,41 @@ describe('navbar menu links interactions', () => {
});
});
});
describe('when accessing a project that does not exist or the user has no access', () => {
it('should render page not found', async () => {
let isQueryCalled = false;
mockServer.use(
...getDefaultMockResolvers(),
graphql.query('FetchProjectExtensionsNavbar', (req, res, ctx) => {
isQueryCalled = true;
return res(
ctx.status(401),
ctx.errors([
new GraphQLError('User is not authorized', {
extensions: {
code: 'UNAUTHENTICATED',
},
}),
])
);
}),
graphql
.link(`${window.location.origin}/api/graphql`)
.query('FetchApplicationsMenu', (req, res, ctx) =>
res(ctx.data({ applicationsMenu: null }))
)
);
renderApp(null, {
environment: {
servedByProxy: 'true',
},
route: '/not-found',
});

await screen.findByText('We could not find this Project');
expect(isQueryCalled).toBe(false);
});
});
});
describe('when navbar menu items are hidden', () => {
beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ const NavBar = (props: TNavbarProps) => {
allApplicationsNavbarMenuGroups,
} = useNavbarStateManager({
environment: props.environment,
project: props.project,
});
const useFullRedirectsForLinks = Boolean(
props.environment.useFullRedirectsForLinks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
import { reportErrorToSentry } from '@commercetools-frontend/sentry';
import { WINDOW_SIZES } from '../../constants';
import useApplicationsMenu from '../../hooks/use-applications-menu';
import type { TFetchProjectQuery } from '../../types/generated/mc';
import type {
TNavbarMenu,
TNavbarMenuGroup,
Expand All @@ -31,6 +32,7 @@ import nonNullable from './non-nullable';

type HookProps = {
environment: TApplicationContext<{}>['environment'];
project: TFetchProjectQuery['project'];
};
type State = {
activeItemIndex?: string;
Expand Down Expand Up @@ -97,7 +99,7 @@ const useNavbarStateManager = (props: HookProps) => {
TFetchProjectExtensionsNavbarQuery,
TFetchProjectExtensionsNavbarQueryVariables
>(FetchProjectExtensionsNavbar, {
skip: !props.environment.servedByProxy,
skip: !props.project || !props.environment.servedByProxy,
context: {
target: GRAPHQL_TARGETS.SETTINGS_SERVICE,
},
Expand Down

0 comments on commit ed2158c

Please sign in to comment.