-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change: Improve License model and display descriptive appliance model…
…s and model types #3374 Improve displaying license
- Loading branch information
Showing
8 changed files
with
257 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* Copyright (C) 2022 Greenbone Networks GmbH | ||
* | ||
* 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 {parseDate} from 'gmp/parser'; | ||
|
||
import {License} from '../license'; | ||
|
||
describe('License tests', () => { | ||
test('should init license data via constructor', () => { | ||
const license = new License({ | ||
status: 'active', | ||
id: '12345', | ||
version: '1.0.0', | ||
title: 'Test License', | ||
type: 'trial', | ||
customerName: 'Monsters Inc.', | ||
created: parseDate('2021-08-27T06:05:21Z'), | ||
begins: parseDate('2021-08-27T07:05:21Z'), | ||
expires: parseDate('2021-09-04T07:05:21Z'), | ||
comment: 'foo', | ||
applianceModel: 'trial', | ||
applianceModelType: 'virtual', | ||
sensor: false, | ||
}); | ||
|
||
expect(license.id).toEqual('12345'); | ||
expect(license.customerName).toEqual('Monsters Inc.'); | ||
expect(license.version).toEqual('1.0.0'); | ||
expect(license.created).toEqual(parseDate('2021-08-27T06:05:21Z')); | ||
expect(license.begins).toEqual(parseDate('2021-08-27T07:05:21Z')); | ||
expect(license.expires).toEqual(parseDate('2021-09-04T07:05:21Z')); | ||
expect(license.comment).toEqual('foo'); | ||
expect(license.applianceModel).toEqual('trial'); | ||
expect(license.applianceModelType).toEqual('virtual'); | ||
expect(license.type).toEqual('trial'); | ||
}); | ||
|
||
test('should parse license data from element', () => { | ||
const license = License.fromElement({ | ||
status: 'active', | ||
content: { | ||
meta: { | ||
id: '12345', | ||
version: '1.0.0', | ||
title: 'Test License', | ||
type: 'trial', | ||
customer_name: 'Monsters Inc.', | ||
created: '2021-08-27T06:05:21Z', | ||
begins: '2021-08-27T07:05:21Z', | ||
expires: '2021-09-04T07:05:21Z', | ||
comment: 'foo', | ||
}, | ||
appliance: { | ||
model: 'trial', | ||
model_type: 'virtual', | ||
sensor: false, | ||
}, | ||
}, | ||
}); | ||
|
||
expect(license.id).toEqual('12345'); | ||
expect(license.customerName).toEqual('Monsters Inc.'); | ||
expect(license.version).toEqual('1.0.0'); | ||
expect(license.created).toEqual(parseDate('2021-08-27T06:05:21Z')); | ||
expect(license.begins).toEqual(parseDate('2021-08-27T07:05:21Z')); | ||
expect(license.expires).toEqual(parseDate('2021-09-04T07:05:21Z')); | ||
expect(license.comment).toEqual('foo'); | ||
expect(license.applianceModel).toEqual('trial'); | ||
expect(license.applianceModelType).toEqual('virtual'); | ||
expect(license.type).toEqual('trial'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/* Copyright (C) 2022 Greenbone Networks GmbH | ||
* | ||
* 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 _ from 'gmp/locale'; | ||
|
||
import {parseDate} from 'gmp/parser'; | ||
|
||
import {isDefined} from 'gmp/utils/identity'; | ||
|
||
const LICENSE_MODEL = { | ||
trial: 'Greenbone Enterprise TRIAL', | ||
'25v': 'Greenbone Enterprise 25V', | ||
25: 'Greenbone Enterprise 25', | ||
35: 'Greenbone Enterprise 35', | ||
maven: 'Greenbone Enterprise MAVEN', | ||
one: 'Greenbone Enterprise ONE', | ||
100: 'Greenbone Enterprise 100', | ||
150: 'Greenbone Enterprise 150', | ||
ceno: 'Greenbone Enterprise CENO', | ||
deca: 'Greenbone Enterprise DECA', | ||
400: 'Greenbone Enterprise 400', | ||
'400r2': 'Greenbone Enterprise 400', | ||
450: 'Greenbone Enterprise 450', | ||
'450r2': 'Greenbone Enterprise 450', | ||
tera: 'Greenbone Enterprise TERA', | ||
500: 'Greenbone Enterprise 500', | ||
510: 'Greenbone Enterprise 510', | ||
550: 'Greenbone Enterprise 550', | ||
600: 'Greenbone Enterprise 600', | ||
'600r2': 'Greenbone Enterprise 600', | ||
peta: 'Greenbone Enterprise PETA', | ||
650: 'Greenbone Enterprise 650', | ||
'650r2': 'Greenbone Enterprise 650', | ||
exa: 'Greenbone Enterprise EXA', | ||
5300: 'Greenbone Enterprise 5300', | ||
6400: 'Greenbone Enterprise 6400', | ||
5400: 'Greenbone Enterprise 5400', | ||
6500: 'Greenbone Enterprise 6500', | ||
expo: 'Greenbone Enterprise EXPO', | ||
'150c-siesta': 'Greenbone Enterprise 150C-SiESTA', | ||
}; | ||
|
||
export const getLicenseApplianceModelName = value => { | ||
const name = LICENSE_MODEL[value]; | ||
return isDefined(name) ? name : value; | ||
}; | ||
|
||
export const getLicenseApplianceModelType = value => { | ||
if (!isDefined(value)) { | ||
return value; | ||
} | ||
if (value === 'virtual') { | ||
return 'Virtual Appliance'; | ||
} | ||
if (value === 'hardware') { | ||
return 'Hardware Appliance'; | ||
} | ||
return _('Unknown'); | ||
}; | ||
|
||
export class License { | ||
constructor({ | ||
id, | ||
status, | ||
customerName, | ||
created, | ||
version, | ||
begins, | ||
expires, | ||
comment, | ||
type, | ||
applianceModel, | ||
applianceModelType, | ||
}) { | ||
this.status = status; | ||
this.id = id; | ||
this.customerName = customerName; | ||
this.version = version; | ||
this.created = created; | ||
this.begins = begins; | ||
this.expires = expires; | ||
this.comment = comment; | ||
this.type = type; | ||
|
||
this.applianceModel = applianceModel; | ||
this.applianceModelType = applianceModelType; | ||
} | ||
|
||
static fromElement(element) { | ||
const {content, status} = element; | ||
return new License({ | ||
status: status, | ||
id: content?.meta?.id, | ||
customerName: content?.meta?.customer_name, | ||
created: parseDate(content?.meta?.created), | ||
version: content?.meta?.version, | ||
begins: parseDate(content?.meta?.begins), | ||
expires: parseDate(content?.meta?.expires), | ||
comment: content?.meta?.comment, | ||
type: content?.meta?.type, | ||
applianceModel: content?.appliance?.model, | ||
applianceModelType: content?.appliance?.model_type, | ||
}); | ||
} | ||
} | ||
|
||
export default License; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.