Device manager - hide unverified security recommendation when only current session is unverified (PSG-639) (#9228)

* scroll to filtered list from security recommendations

* test sessionmanager scroll to

* stable snapshot

* fix strict errors

* prtidy

* dont show security rec section when only curent session is unverified
pull/28217/head
Kerry 2022-09-05 11:10:12 +02:00 committed by GitHub
parent 219f4fae3d
commit 85f92308f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 2 deletions

View File

@ -29,11 +29,13 @@ import {
interface Props { interface Props {
devices: DevicesDictionary; devices: DevicesDictionary;
currentDeviceId: DeviceWithVerification['device_id'];
goToFilteredList: (filter: DeviceSecurityVariation) => void; goToFilteredList: (filter: DeviceSecurityVariation) => void;
} }
const SecurityRecommendations: React.FC<Props> = ({ const SecurityRecommendations: React.FC<Props> = ({
devices, devices,
currentDeviceId,
goToFilteredList, goToFilteredList,
}) => { }) => {
const devicesArray = Object.values<DeviceWithVerification>(devices); const devicesArray = Object.values<DeviceWithVerification>(devices);
@ -41,7 +43,12 @@ const SecurityRecommendations: React.FC<Props> = ({
const unverifiedDevicesCount = filterDevicesBySecurityRecommendation( const unverifiedDevicesCount = filterDevicesBySecurityRecommendation(
devicesArray, devicesArray,
[DeviceSecurityVariation.Unverified], [DeviceSecurityVariation.Unverified],
).length; )
// filter out the current device
// as unverfied warning and actions
// will be shown in current session section
.filter((device) => device.device_id !== currentDeviceId)
.length;
const inactiveDevicesCount = filterDevicesBySecurityRecommendation( const inactiveDevicesCount = filterDevicesBySecurityRecommendation(
devicesArray, devicesArray,
[DeviceSecurityVariation.Inactive], [DeviceSecurityVariation.Inactive],

View File

@ -62,7 +62,11 @@ const SessionManagerTab: React.FC = () => {
}, [scrollIntoViewTimeoutRef]); }, [scrollIntoViewTimeoutRef]);
return <SettingsTab heading={_t('Sessions')}> return <SettingsTab heading={_t('Sessions')}>
<SecurityRecommendations devices={devices} goToFilteredList={onGoToFilteredList} /> <SecurityRecommendations
devices={devices}
goToFilteredList={onGoToFilteredList}
currentDeviceId={currentDeviceId}
/>
<CurrentDeviceSection <CurrentDeviceSection
device={currentDevice} device={currentDevice}
isLoading={isLoading} isLoading={isLoading}

View File

@ -34,6 +34,7 @@ describe('<SecurityRecommendations />', () => {
const defaultProps = { const defaultProps = {
devices: {}, devices: {},
goToFilteredList: jest.fn(), goToFilteredList: jest.fn(),
currentDeviceId: 'abc123',
}; };
const getComponent = (props = {}) => const getComponent = (props = {}) =>
(<SecurityRecommendations {...defaultProps} {...props} />); (<SecurityRecommendations {...defaultProps} {...props} />);
@ -53,6 +54,16 @@ describe('<SecurityRecommendations />', () => {
expect(container).toMatchSnapshot(); expect(container).toMatchSnapshot();
}); });
it('does not render unverified devices section when only the current device is unverified', () => {
const devices = {
[unverifiedNoMetadata.device_id]: unverifiedNoMetadata,
[verifiedNoMetadata.device_id]: verifiedNoMetadata,
};
const { container } = render(getComponent({ devices, currentDeviceId: unverifiedNoMetadata.device_id }));
// nothing to render
expect(container.firstChild).toBeFalsy();
});
it('renders inactive devices section when user has inactive devices', () => { it('renders inactive devices section when user has inactive devices', () => {
const devices = { const devices = {
[verifiedNoMetadata.device_id]: verifiedNoMetadata, [verifiedNoMetadata.device_id]: verifiedNoMetadata,