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

Clear browser cache #3091

Merged
merged 3 commits into from
Mar 22, 2021
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 @@ -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