From a858c69b67c77ea5518225e33855ac773773fb1a Mon Sep 17 00:00:00 2001 From: LianaHus Date: Wed, 4 Mar 2020 10:52:26 +0100 Subject: [PATCH] added canCall --- src/app/ui/persmission-handler.js | 23 ++++++++++++----------- src/remixAppManager.js | 11 ++++++++--- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/app/ui/persmission-handler.js b/src/app/ui/persmission-handler.js index ac70ef84ef..b621b62a67 100644 --- a/src/app/ui/persmission-handler.js +++ b/src/app/ui/persmission-handler.js @@ -62,13 +62,15 @@ export class PermissionHandler { * Show a message to ask the user for a permission * @param {PluginProfile} from The name and hash of the plugin that make the call * @param {ModuleProfile} to The name of the plugin 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<{ allow: boolean; remember: boolean }} Answer from the user to the permission */ - async openPermission (from, to) { + async openPermission (from, to, method, message) { return new Promise((resolve, reject) => { modalDialog( `Permission needed for ${to.displayName || to.name}`, - this.form(from, to), + this.form(from, to, method, message), { label: 'Accept', fn: () => { @@ -105,11 +107,11 @@ export class PermissionHandler { * @param {ModuleProfile} to The profile of the module that receive the call * @returns {Promise} */ - async askPermission (from, to) { + 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) + if (!this.permissions[to.name][from.name]) return this.openPermission(from, to, from, message) const { allow, hash } = this.permissions[to.name][from.name] if (!allow) { @@ -119,7 +121,7 @@ export class PermissionHandler { } return hash === from.hash ? true // Allow - : this.openPermission(from, to) // New version of a plugin + : this.openPermission(from, to, method, message) // New version of a plugin } catch (err) { throw new Error(err) } @@ -129,8 +131,10 @@ export class PermissionHandler { * The permission form * @param {PluginProfile} from The name and hash of the plugin that make the call * @param {ModuleProfile} to The name of the plugin that receive the call + * @param {string} method The name of te methode to be called + * @param {string} message from the caller plugin to add more details if needed */ - form (from, to) { + 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] @@ -143,10 +147,7 @@ export class PermissionHandler { const rememberSwitch = remember ? yo`` : yo`` - const message = remember - ? `"${fromName}" has changed and would like to access "${toName}"` - : `"${fromName}" would like to access "${toName}"` - + const text = `"${fromName}"` + (remember ? `has changed and` : ``) + `would like to access to "${method}" of "${toName}"` const imgFrom = yo`` const imgTo = yo`` const pluginsImages = yo` @@ -165,7 +166,7 @@ export class PermissionHandler {
${pluginsImages}
-

${message} :

+

${text} :

${fromName}

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

${toName} :

diff --git a/src/remixAppManager.js b/src/remixAppManager.js index 8ad89c7a46..766c6eb8dc 100644 --- a/src/remixAppManager.js +++ b/src/remixAppManager.js @@ -2,6 +2,7 @@ import { PluginManager, IframePlugin } from '@remixproject/engine' import { EventEmitter } from 'events' import QueryParams from './lib/query-params' +import { PermissionHandler } from './app/ui/persmission-handler' const requiredModules = [ // services + layout views + system views 'manager', 'compilerArtefacts', 'compilerMetadata', 'contextualListener', 'editor', 'offsetToLineColumnConverter', 'network', 'theme', 'fileManager', 'contentImport', 'web3Provider', 'scriptRunner', @@ -20,6 +21,7 @@ export class RemixAppManager extends PluginManager { this.event = new EventEmitter() this.pluginsDirectory = 'https://raw.githubusercontent.com/ethereum/remix-plugins-directory/master/build/metadata.json' this.pluginLoader = new PluginLoader() + this.permissionHandler = new PermissionHandler() } async canActivate (from, to) { @@ -30,9 +32,12 @@ export class RemixAppManager extends PluginManager { return from.name === 'manager' } - async canCall (From, to, method) { - // todo This is the dafault behaviour, we could save user choises in session scope - return true + async canCall (from, to, method, message) { + // Make sure the caller of this methods is the target plugin + if (to.name !== this.currentRequest) { + return false + } + return await this.permissionHandler.askPermition(from, to, method, message) } onPluginActivated (plugin) {