Skip to content

Commit

Permalink
Clear browser cache (#3091)
Browse files Browse the repository at this point in the history
* feat(app-cache): refresh cache and warning when app package is different

* fix(frontend): Fix in check-plugin-version file

* fix(changelog): Add PR to changelog
  • Loading branch information
Desvelao committed Mar 22, 2021
1 parent 5f87aa1 commit b4d9d0a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ All notable changes to the Wazuh app project will be documented in this file.
- Added node name of agent list and detail [#3039](https://github.com/wazuh/wazuh-kibana-app/pull/3039)
- Added loading view while the user is logging to prevent permissions prompts [#3041](https://github.com/wazuh/wazuh-kibana-app/pull/3041)
- Added custom message for each possible run_as setup [#3048](https://github.com/wazuh/wazuh-kibana-app/pull/3048)
- Improve validation and prevention for caching bundles in client side [#3091](https://github.com/wazuh/wazuh-kibana-app/pull/3091)

### Fixed

Expand Down
4 changes: 0 additions & 4 deletions public/assets/meta.json

This file was deleted.

22 changes: 18 additions & 4 deletions public/utils/check-plugin-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import { GenericRequest } from '../react-services/generic-request';
import { AxiosResponse } from 'axios';
import _ from 'lodash';
import meta from '../assets/meta.json';
import { getCookies } from '../kibana-services';
import { version as appVersion, revision as appRevision} from '../../package.json';
import { getCookies, getToasts } from '../kibana-services';

type TAppInfo = {
revision: string;
Expand All @@ -39,9 +39,19 @@ export const checkPluginVersion = async () => {
};

const checkClientAppVersion = (appInfo: TAppInfo) => {
if (appInfo['app-version'] !== meta.version || appInfo.revision !== meta.revision) {
clearBrowserInfo(appInfo);
if (appInfo['app-version'] !== appVersion || appInfo.revision !== appRevision) {
if( window.history.state !== 'refreshed') {
clearBrowserInfo(appInfo);
} else {
getToasts().addDanger({
title: 'Conflict with the Wazuh app version',
text: 'The version of the Wazuh app in your browser does not correspond with the app version installed in Kibana.\nPlease clear your browser cache.\nIf the error persist please restart Kibana too.'
});
}
} else {
if(window.history.state == 'refreshed'){
window.history.replaceState('', 'wazuh');
};
const storeAppInfo = localStorage.getItem('appInfo');
!storeAppInfo && updateAppInfo(appInfo);
}
Expand All @@ -63,10 +73,14 @@ function clearBrowserInfo(appInfo: TAppInfo) {
//update localStorage
updateAppInfo(appInfo);

//replace status to avoid infinite refresh
window.history.replaceState('refreshed', 'wazuh');

// delete browser cache and hard reload
window.location.reload(true);
}

function updateAppInfo(appInfo: TAppInfo) {
localStorage.setItem('appInfo', JSON.stringify(appInfo));
}

17 changes: 0 additions & 17 deletions scripts/generate-build-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,6 @@ const fs = require('fs');
const packageJson = require('../package.json');
const { version, revision } = packageJson;

const jsonData = {
version,
revision,
};

const jsonContent = JSON.stringify(jsonData, null, 2);

//write meta.json with last version
fs.writeFile('./public/assets/meta.json', jsonContent, 'utf8', function (err) {
if (err) {
console.log('An error occurred while writing JSON Object to meta.json');
return console.log(err);
}

console.log('meta.json file has been saved with latest version number');
});

//replaces kibana.json with last
fs.readFile('kibana.json', 'utf-8', function (err, data) {
if (err) {
Expand Down

0 comments on commit b4d9d0a

Please sign in to comment.