diff --git a/package-lock.json b/package-lock.json index d0e1a3db8c..e3137d1169 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1778,9 +1778,9 @@ "integrity": "sha512-ePDxG9UuU9Kobk90ZUjtmDW8IT9U7aRb1/Rl9683MRNM+ur0ocHL2v7TPH2ajTiVSBUFbbeW8vKIt9jrb0JIAA==" }, "@remixproject/engine": { - "version": "0.2.0-alpha.4", - "resolved": "https://registry.npmjs.org/@remixproject/engine/-/engine-0.2.0-alpha.4.tgz", - "integrity": "sha512-AY6HaF7Y4fR1oOdz60B2zt+gGftaT5fZWSl5ka7UuDHZUzeouNMx4O1+Uk4376Mv+M3vdmpGFo6KgfsZj6wSJw==" + "version": "0.2.0-alpha.6", + "resolved": "https://registry.npmjs.org/@remixproject/engine/-/engine-0.2.0-alpha.6.tgz", + "integrity": "sha512-UgtFmG90wKzmsghGmvvGexj1bMjdgAPIn/del70WXX6RNfGiTxCO1a1Q/EWrFO0OJ9jXty5181zt+sJpQOoMCw==" }, "@resolver-engine/core": { "version": "0.3.3", diff --git a/package.json b/package.json index 9d475d7665..c5af7283e0 100644 --- a/package.json +++ b/package.json @@ -79,7 +79,7 @@ "yo-yoify": "^3.7.3" }, "dependencies": { - "@remixproject/engine": "^0.2.0-alpha.4", + "@remixproject/engine": "^0.2.0-alpha.6", "http-server": "^0.11.1", "remixd": "0.1.8-alpha.10", "standard": "^8.5.0" diff --git a/src/app/components/plugin-manager-settings.js b/src/app/components/plugin-manager-settings.js index 88448f31b2..9185721387 100644 --- a/src/app/components/plugin-manager-settings.js +++ b/src/app/components/plugin-manager-settings.js @@ -49,7 +49,7 @@ export class PluginManagerSettings { const fromLocal = window.localStorage.getItem('plugins/permissions') this.permissions = JSON.parse(fromLocal || '{}') this.currentSetting = this.settings() - modalDialog('Plugin Manager Settings', this.currentSetting, + modalDialog('Plugin Manager Permissions', this.currentSetting, { fn: () => this.onValidation() }, ) } @@ -128,7 +128,7 @@ export class PluginManagerSettings { render () { return yo` ` } diff --git a/src/app/files/fileManager.js b/src/app/files/fileManager.js index 840affca99..fc04454455 100644 --- a/src/app/files/fileManager.js +++ b/src/app/files/fileManager.js @@ -9,7 +9,6 @@ const toaster = require('../ui/tooltip') const modalDialogCustom = require('../ui/modal-dialog-custom') const helper = require('../../lib/helper.js') import { Plugin } from '@remixproject/engine' -import { isNative } from '../../remixAppManager.js' import * as packageJson from '../../../package.json' /* @@ -173,7 +172,7 @@ class FileManager extends Plugin { toaster.hide() } if (this.currentRequest) { - const canCall = this.call('manager', 'canCall', { name: this.currentRequest.from }, this.profile, 'setFile') + const canCall = await this.askUserPermission('setFile', '') if (canCall) { this._setFileInternal(path, content) return diff --git a/src/app/ui/persmission-handler.js b/src/app/ui/persmission-handler.js index 89b2a1d7af..ac5becf8a5 100644 --- a/src/app/ui/persmission-handler.js +++ b/src/app/ui/persmission-handler.js @@ -33,8 +33,8 @@ const css = csjs` } ` -function notAllowWarning (from, to) { - return `${from.displayName || from.name} is not allowed to call ${to.displayName || to.name}.` +function notAllowWarning (from, to, method) { + return `${from.displayName || from.name} is not allowed to call ${method} method of ${to.displayName || to.name}.` } export class PermissionHandler { @@ -74,8 +74,8 @@ export class PermissionHandler { { label: 'Accept', fn: () => { - if (this.permissions[to.name][from.name]) { - this.permissions[to.name][from.name] = { + if (this.permissions[to.name][method][from.name]) { + this.permissions[to.name][method][from.name] = { allow: true, hash: from.hash } @@ -87,14 +87,14 @@ export class PermissionHandler { { label: 'Decline', fn: () => { - if (this.permissions[to.name][from.name]) { - this.permissions[to.name][from.name] = { + if (this.permissions[to.name][method][from.name]) { + this.permissions[to.name][method][from.name] = { allow: false, hash: from.hash } this.persistPermissions() } - reject(notAllowWarning(from, to)) + reject(notAllowWarning(from, to, method)) } } ) @@ -105,17 +105,20 @@ export class PermissionHandler { * Check if a plugin has the permission to call another plugin and askPermission if needed * @param {PluginProfile} from the profile of the plugin that make the call * @param {ModuleProfile} to The profile of the module that receive the call + * @param {string} method The name of the function to be called + * @param {string} message from the caller plugin to add more details if needed * @returns {Promise} */ async askPermission (from, to, method, message) { try { this.permissions = this._getFromLocal() if (!this.permissions[to.name]) this.permissions[to.name] = {} - if (!this.permissions[to.name][from.name]) return this.openPermission(from, to, from, message) + if (!this.permissions[to.name][method]) this.permissions[to.name][method] = {} + if (!this.permissions[to.name][method][from.name]) return this.openPermission(from, to, method, message) - const { allow, hash } = this.permissions[to.name][from.name] + const { allow, hash } = this.permissions[to.name][method][from.name] if (!allow) { - const warning = notAllowWarning(from, to) + const warning = notAllowWarning(from, to, method) addTooltip(warning) return false } @@ -137,12 +140,12 @@ export class PermissionHandler { form (from, to, method, message) { const fromName = from.displayName || from.name const toName = to.displayName || to.name - const remember = this.permissions[to.name][from.name] + const remember = this.permissions[to.name][method][from.name] const switchMode = (e) => { e.target.checked - ? this.permissions[to.name][from.name] = {} - : delete this.permissions[to.name][from.name] + ? this.permissions[to.name][method][from.name] = {} + : delete this.permissions[to.name][method][from.name] } const rememberSwitch = remember ? yo`` @@ -161,6 +164,12 @@ export class PermissionHandler { globalRegistry.get('themeModule').api.fixInvert(imgFrom) globalRegistry.get('themeModule').api.fixInvert(imgTo) + const pluginMessage = message ? yo` +
+
Description
+

${message}

+
+ ` : `` return yo`
${pluginsImages} @@ -170,7 +179,7 @@ export class PermissionHandler {

${from.description || yo`No description Provided`}

${toName} :

${to.description || yo`No description Provided`}

-

${message}

+ ${pluginMessage}
diff --git a/src/remixAppManager.js b/src/remixAppManager.js index 7ba0dc6104..4e98b0e030 100644 --- a/src/remixAppManager.js +++ b/src/remixAppManager.js @@ -34,12 +34,15 @@ export class RemixAppManager extends PluginManager { async canCall (from, to, method, message) { // Make sure the caller of this methods is the target plugin - if (to.name !== this.currentRequest) { + if (to !== this.currentRequest.from) { return false } - if (isNative) + // skipping native plugins' requests + if (isNative(from)) { return true - return await this.permissionHandler.askPermition(from, to, method, message) + } + // ask the user for permission + return await this.permissionHandler.askPermission(this.profiles[from], this.profiles[to], method, message) } onPluginActivated (plugin) { diff --git a/test-browser/tests/pluginManager.js b/test-browser/tests/pluginManager.js index 1c4ea63578..c363afcecd 100644 --- a/test-browser/tests/pluginManager.js +++ b/test-browser/tests/pluginManager.js @@ -61,7 +61,7 @@ module.exports = { /* 'Should grant plugin permission (ZOKRATES)': function (browser) { browser.waitForElementVisible('*[data-id="pluginManagerComponentPluginManager"]') - .click('*[data-id="pluginManagerSettingsButton"]') + .click('*[data-id="pluginManagerPermissionsButton"]') .waitForElementVisible('*[data-id="pluginManagerSettingsPermissionForm"]') .assert.containsText('*[data-id="pluginManagerSettingsPermissionForm"]', 'No Permission requested yet') .modalFooterOKClick() @@ -84,8 +84,8 @@ module.exports = { 'Should revert plugin permission (ZOKRATES)': function (browser) { browser.waitForElementVisible('*[data-id="verticalIconsSettingsIcons"]') .click('*[data-id="verticalIconsSettingsIcons"]') - .waitForElementVisible('*[data-id="pluginManagerSettingsButton"]') - .click('*[data-id="pluginManagerSettingsButton"]') + .waitForElementVisible('*[data-id="pluginManagerPermissionsButton"]') + .click('*[data-id="pluginManagerPermissionsButton"]') .waitForElementVisible('*[data-id="modalDialogContainer"]') .click('*[data-id="pluginManagerSettingsPermissionForm"]') .pause(2000)