Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a new message type for the case that a CPE or a CVE cannot be found. #3749

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions src/web/components/error/message.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/* Copyright (C) 2018-2022 Greenbone AG
*
* SPDX-License-Identifier: AGPL-3.0-or-later
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import React from 'react';

import {isDefined} from 'gmp/utils/identity';

import Divider from 'web/components/layout/divider';
import Layout from 'web/components/layout/layout';

import StNonAvailableIcon from 'web/components/icon/stnonavailableicon';

import PropTypes from 'web/utils/proptypes';

import MessageContainer from './messagecontainer';

const Message = ({
message,
details,
children,
'data-testid': dataTestId,
...props
}) => (
<MessageContainer data-testid={dataTestId}>

Check warning on line 38 in src/web/components/error/message.js

View check run for this annotation

Codecov / codecov/patch

src/web/components/error/message.js#L38

Added line #L38 was not covered by tests
<Divider margin="15px" align={['start', 'start']}>
<StNonAvailableIcon size="medium" />
<Layout {...props}>
<Divider>
<b data-testid="message">{message}</b>
{isDefined(details) && (
<span data-testid="message-details">{details}</span>

Check warning on line 45 in src/web/components/error/message.js

View check run for this annotation

Codecov / codecov/patch

src/web/components/error/message.js#L44-L45

Added lines #L44 - L45 were not covered by tests
)}
</Divider>
{children}
</Layout>
</Divider>
</MessageContainer>
);

Message.propTypes = {
'data-testid': PropTypes.string,
details: PropTypes.string,
message: PropTypes.string,
};

export default Message;
30 changes: 30 additions & 0 deletions src/web/components/error/messagecontainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* Copyright (C) 2018-2022 Greenbone AG
*
* SPDX-License-Identifier: AGPL-3.0-or-later
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import styled from 'styled-components';

import Layout from 'web/components/layout/layout';

const MessageContainer = styled(Layout)`
padding: 15px;
margin: 15px 15px 15px 15px;
border: 1px solid;
`;

export default MessageContainer;

// vim: set ts=2 sw=2 tw=80:
41 changes: 37 additions & 4 deletions src/web/entity/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

import ErrorMessage from 'web/components/error/errormessage';

import Message from 'web/components/error/message';

import Layout from 'web/components/layout/layout';

import Loading from 'web/components/loading/loading';
Expand All @@ -49,6 +51,10 @@
white-space: pre;
`;

const MessageContent = styled.div`
white-space: pre;
`;

class EntityPage extends React.Component {
constructor(...args) {
super(...args);
Expand Down Expand Up @@ -146,14 +152,40 @@
{entity: typeName(entityType)},
);

if (entityType === 'cpe') {
content = _(

Check warning on line 156 in src/web/entity/page.js

View check run for this annotation

Codecov / codecov/patch

src/web/entity/page.js#L156

Added line #L156 was not covered by tests
'\nThis could have the following reasons:\n' +
'1. The CPE might not be included in the official NVD CPE dictionary ' +
'yet, and no additional information is available.\n' +
'2. You might have followed an incorrect link and the CPE does ' +
'not exist.',
);
}

if (entityType === 'cve') {
content = _(
'\nThis could have the following reasons:\n' +
'1. You might have followed an incorrect link and the CVE does ' +
'not exist\n' +
'2. The CVE might not be included in the SCAP database yet. ' +
'1. The CVE might not be included in the SCAP database yet. ' +
'For new CVEs it can take a month or more until they become ' +
'available.',
'available.\n' +
'2. You might have followed an incorrect link and the CVE does ' +
'not exist.',
);
}

if (entityType === 'cpe' || entityType === 'cve') {
return (

Check warning on line 177 in src/web/entity/page.js

View check run for this annotation

Codecov / codecov/patch

src/web/entity/page.js#L177

Added line #L177 was not covered by tests
<Message
flex="column"
message={_(
'The {{entity}} you were looking for could not be found.',
{
entity: typeName(entityType),
},
)}
>
<MessageContent>{content}</MessageContent>
</Message>
);
}

Expand All @@ -171,6 +203,7 @@
</ErrorMessage>
);
}

return <ErrorMessage message={entityError.message} />;
}
return null;
Expand Down