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

Fix loading timezone and locale at login #1426

Merged
merged 3 commits into from
May 27, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Cleanup get_report function in gsad [#1263](https://github.com/greenbone/gsa/pull/1263)

### Fixed
- Fix loading data on login [#1426](https://github.com/greenbone/gsa/pull/1426)
- Fix result undefined error on result details [#1423](https://github.com/greenbone/gsa/pull/1423)
- Fix showing Scanner Preferences in EditScanConfigDialog [#1420](https://github.com/greenbone/gsa/pull/1420)
- Don't crash if second result for delta is undefined [#1418](https://github.com/greenbone/gsa/pull/1418)
Expand Down
2 changes: 1 addition & 1 deletion gsa/src/gmp/commands/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class LoginCommand extends HttpCommand {
login: username,
password,
}).then(
response => new Login(response.data),
response => new Login(response),
rej => {
if (rej.isError && rej.isError()) {
switch (rej.status) {
Expand Down
24 changes: 14 additions & 10 deletions gsa/src/gmp/models/__tests__/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,20 @@ import Login from 'gmp/models/login';
describe('Login model tests', () => {
test('should set all properties correctly', () => {
const elem = {
client_address: '1.2.3.4',
guest: '0',
i18n: 'en',
role: 'admin',
severity: '8.5',
timezone: 'UTC',
token: '123abc',
vendor_version: '42',
version: '1337',
session: '12345',
data: {
client_address: '1.2.3.4',
guest: '0',
role: 'admin',
severity: '8.5',
token: '123abc',
session: '12345',
},
meta: {
i18n: 'en',
timezone: 'UTC',
vendor_version: '42',
version: '1337',
},
};
const login = new Login(elem);
const login2 = new Login({});
Expand Down
22 changes: 11 additions & 11 deletions gsa/src/gmp/models/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ import {isDefined} from 'gmp/utils/identity';

class Login {
constructor(elem) {
this.clientAddress = elem.client_address;
this.guest = elem.guest;
this.locale = elem.i18n;
this.role = elem.role;
this.severity = elem.severity;
this.timezone = elem.timezone;
this.token = elem.token;
this.vendorVersion = elem.vendor_version;
this.version = elem.version;

const unixSeconds = parseInt(elem.session);
const {data = {}, meta = {}} = elem;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi the Login model should be reworked to get all necessary values as arguments to the constructor again and should not have to know anything about meta and data. The command must pass the arguments from meta and data to the model instead.

this.clientAddress = data.client_address;
this.guest = data.guest;
this.locale = meta.i18n;
this.role = data.role;
this.severity = data.severity;
this.timezone = meta.timezone;
this.token = data.token;
this.vendorVersion = meta.vendor_version;
this.version = meta.version;
const unixSeconds = parseInt(data.session);

this.sessionTimeout = isDefined(unixSeconds)
? moment.unix(unixSeconds)
Expand Down