diff --git a/js/config.js b/js/config.js index fa63467d..fafb8315 100644 --- a/js/config.js +++ b/js/config.js @@ -425,6 +425,9 @@ module.exports = { saveUserConfig, clearCachedConfigs, - readConfigFileSync + readConfigFileSync, + + // use only if you specifically need to read global config fields + getGlobalConfigField, }; diff --git a/js/utils/isWhiteList.js b/js/utils/isWhiteList.js index 4f76230b..a6a49899 100644 --- a/js/utils/isWhiteList.js +++ b/js/utils/isWhiteList.js @@ -1,6 +1,6 @@ 'use strict'; -const { getConfigField } = require('./../config.js'); +const { getGlobalConfigField } = require('./../config.js'); const parseDomain = require('parse-domain'); const isEqual = require('lodash.isequal'); @@ -12,7 +12,7 @@ const isEqual = require('lodash.isequal'); function isWhiteList(url) { return new Promise((resolve, reject) => { - getConfigField('whiteListURL').then((whiteList) => { + getGlobalConfigField('whiteListURL').then((whiteList) => { if (checkWhiteList(url, whiteList)) { return resolve(); diff --git a/js/windowMgr.js b/js/windowMgr.js index 1720fbca..2be46bc6 100644 --- a/js/windowMgr.js +++ b/js/windowMgr.js @@ -463,11 +463,18 @@ function doCreateMainWindow(initialUrl, initialBounds) { } }); - mainWindow.webContents.on('will-navigate', function(event, navigatedUrl){ - // TODO: need inputs from design to implement error dialog - isWhiteList(navigatedUrl).catch(() => { - event.preventDefault(); - }); + // whenever the main window is navigated for ex: window.location.href or url redirect + mainWindow.webContents.on('will-navigate', function(event, navigatedURL) { + isWhiteList(navigatedURL) + .catch(() => { + event.preventDefault(); + electron.dialog.showMessageBox(mainWindow, { + type: 'warning', + buttons: [ 'Ok' ], + title: 'Not Allowed', + message: `Sorry, you are not allowed to access this website (${navigatedURL}), please contact your administrator for more details`, + }); + }); }); }