only get organizations if user is signed in (#57279)
This commit is contained in:
@@ -3,6 +3,8 @@ import React from 'react';
|
||||
import { Provider } from 'react-redux';
|
||||
|
||||
import { OrgRole } from '@grafana/data';
|
||||
import { ContextSrv, setContextSrv } from 'app/core/services/context_srv';
|
||||
import { getUserOrganizations } from 'app/features/org/state/actions';
|
||||
import { configureStore } from 'app/store/configureStore';
|
||||
import * as appTypes from 'app/types';
|
||||
|
||||
@@ -92,4 +94,22 @@ describe('OrganisationSwitcher', () => {
|
||||
|
||||
expect(screen.getByRole('button', { name: /change organization/i })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should not render and not try to get user organizations if not signed in', () => {
|
||||
const contextSrv = new ContextSrv();
|
||||
contextSrv.user.isSignedIn = false;
|
||||
setContextSrv(contextSrv);
|
||||
|
||||
renderWithProvider({
|
||||
initialState: {
|
||||
organization: {
|
||||
organization: { name: 'test', id: 1 },
|
||||
userOrgs: [],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
expect(screen.queryByRole('combobox', { name: 'Change organization' })).not.toBeInTheDocument();
|
||||
expect(getUserOrganizations).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@ import { SelectableValue } from '@grafana/data';
|
||||
import { locationService } from '@grafana/runtime';
|
||||
import { useTheme2 } from '@grafana/ui';
|
||||
import { useMediaQueryChange } from 'app/core/hooks/useMediaQueryChange';
|
||||
import { contextSrv } from 'app/core/services/context_srv';
|
||||
import { getUserOrganizations, setUserOrganization } from 'app/features/org/state/actions';
|
||||
import { useDispatch, useSelector, UserOrg } from 'app/types';
|
||||
|
||||
@@ -23,7 +24,9 @@ export function OrganizationSwitcher() {
|
||||
}
|
||||
};
|
||||
useEffect(() => {
|
||||
dispatch(getUserOrganizations());
|
||||
if (contextSrv.isSignedIn) {
|
||||
dispatch(getUserOrganizations());
|
||||
}
|
||||
}, [dispatch]);
|
||||
|
||||
const breakpoint = theme.breakpoints.values.sm;
|
||||
|
||||
Reference in New Issue
Block a user