diff --git a/apps/remix-ide/src/app/files/fileManager.ts b/apps/remix-ide/src/app/files/fileManager.ts index c4523551be..db42bc3335 100644 --- a/apps/remix-ide/src/app/files/fileManager.ts +++ b/apps/remix-ide/src/app/files/fileManager.ts @@ -562,7 +562,7 @@ class FileManager extends Plugin { async setFileContent(path, content) { if (this.currentRequest) { - const canCall = await this.askUserPermission('writeFile', '') + const canCall = await this.askUserPermission(`writeFile`, `modifying ${path} ...`) const required = this.appManager.isRequired(this.currentRequest.from) if (canCall && !required) { // inform the user about modification after permission is granted and even if permission was saved before diff --git a/apps/remix-ide/src/app/plugins/permission-handler-plugin.tsx b/apps/remix-ide/src/app/plugins/permission-handler-plugin.tsx index 62748a53af..f4dbf5d095 100644 --- a/apps/remix-ide/src/app/plugins/permission-handler-plugin.tsx +++ b/apps/remix-ide/src/app/plugins/permission-handler-plugin.tsx @@ -13,12 +13,14 @@ const profile = { } export class PermissionHandlerPlugin extends Plugin { permissions: any + sessionPermissions: any currentVersion: number fallbackMemory: boolean constructor() { super(profile) this.fallbackMemory = false this.permissions = this._getFromLocal() + this.sessionPermissions = {} this.currentVersion = 1 // here we remove the old permissions saved before adding 'permissionVersion' // since with v1 the structure has been changed because of new engine ^0.2.0-alpha.6 changes @@ -44,14 +46,22 @@ export class PermissionHandlerPlugin extends Plugin { } } - switchMode (from: Profile, to: Profile, method: string, set: boolean) { - set + switchMode (from: Profile, to: Profile, method: string, set: boolean, sensitiveCall: boolean) { + if (sensitiveCall) { + set + ? this.sessionPermissions[to.name][method][from.name] = {} + : delete this.sessionPermissions[to.name][method][from.name] + } else { + set ? this.permissions[to.name][method][from.name] = {} : delete this.permissions[to.name][method][from.name] + } } clear() { localStorage.removeItem('plugins/permissions') + this.permissions = this._getFromLocal() + this.sessionPermissions = {} } notAllowWarning(from: Profile, to: Profile, method: string) { @@ -72,12 +82,18 @@ export class PermissionHandlerPlugin extends Plugin { */ async askPermission(from: Profile, to: Profile, method: string, message: string, sensitiveCall: boolean) { try { - this.permissions = this._getFromLocal() - if (!this.permissions[to.name]) this.permissions[to.name] = {} - 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, sensitiveCall) + if (sensitiveCall) { + if (!this.sessionPermissions[to.name]) this.sessionPermissions[to.name] = {} + if (!this.sessionPermissions[to.name][method]) this.sessionPermissions[to.name][method] = {} + if (!this.sessionPermissions[to.name][method][from.name]) return this.openPermission(from, to, method, message, sensitiveCall) + } else { + this.permissions = this._getFromLocal() + if (!this.permissions[to.name]) this.permissions[to.name] = {} + 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, sensitiveCall) + } - const { allow, hash } = this.permissions[to.name][method][from.name] + const { allow, hash } = sensitiveCall ? this.sessionPermissions[to.name][method][from.name] : this.permissions[to.name][method][from.name] if (!allow) { const warning = this.notAllowWarning(from, to, method) this.call('notification', 'toast', warning) @@ -92,7 +108,12 @@ export class PermissionHandlerPlugin extends Plugin { } async openPermission(from: Profile, to: Profile, method: string, message: string, sensitiveCall: boolean) { - const remember = this.permissions[to.name][method][from.name] + let remember + if (sensitiveCall) { + remember = this.sessionPermissions[to.name][method][from.name] + } else { + remember = this.permissions[to.name][method][from.name] + } const value: PermissionHandlerValue = { from, to, @@ -112,22 +133,40 @@ export class PermissionHandlerPlugin extends Plugin { const result = await this.call('notification', 'modal', modal) return new Promise((resolve, reject) => { if (result) { - if (this.permissions[to.name][method][from.name]) { - this.permissions[to.name][method][from.name] = { - allow: true, - hash: from.hash - } - this.persistPermissions() + if (sensitiveCall) { + if (this.sessionPermissions[to.name][method][from.name]) { + this.sessionPermissions[to.name][method][from.name] = { + allow: true, + hash: from.hash + } + } + } else { + if (this.permissions[to.name][method][from.name]) { + this.permissions[to.name][method][from.name] = { + allow: true, + hash: from.hash + } + this.persistPermissions() + } } resolve(true) } else { - if (this.permissions[to.name][method][from.name]) { - this.permissions[to.name][method][from.name] = { - allow: false, - hash: from.hash + if (sensitiveCall) { + if (this.sessionPermissions[to.name][method][from.name]) { + this.sessionPermissions[to.name][method][from.name] = { + allow: false, + hash: from.hash + } } - this.persistPermissions() - } + } else { + if (this.permissions[to.name][method][from.name]) { + this.permissions[to.name][method][from.name] = { + allow: false, + hash: from.hash + } + this.persistPermissions() + } + } reject(this.notAllowWarning(from, to, method)) } }) diff --git a/apps/remix-ide/src/app/tabs/locales/en/permissionHandler.json b/apps/remix-ide/src/app/tabs/locales/en/permissionHandler.json index 70a0e690f9..d41fe6c68e 100644 --- a/apps/remix-ide/src/app/tabs/locales/en/permissionHandler.json +++ b/apps/remix-ide/src/app/tabs/locales/en/permissionHandler.json @@ -4,7 +4,7 @@ "permissionHandler.permissionHandlerMessage": "\"{from}\" {rememberText} would like to access to \"{method}\" of \"{to}\"`", "permissionHandler.description": "Description", "permissionHandler.noDescriptionProvided": "No description Provided", - "permissionHandler.makeSureYouTrustThisPlugin": "Make sure you trust this plugin before processing this call.", + "permissionHandler.makeSureYouTrustThisPlugin": "Make sure you trust this plugin before processing this call. If you choose to remember the choice for this specific call, the value will be kept only for the current session.", "permissionHandler.rememberThisChoice": "Remember this choice", "permissionHandler.resetAllPermissions": "Reset all Permissions", "permissionHandler.permissionNeededFor": "Permission needed for {to}", diff --git a/libs/remix-ui/permission-handler/src/lib/permission-dialog.tsx b/libs/remix-ui/permission-handler/src/lib/permission-dialog.tsx index 802050244b..fb2b1376c4 100644 --- a/libs/remix-ui/permission-handler/src/lib/permission-dialog.tsx +++ b/libs/remix-ui/permission-handler/src/lib/permission-dialog.tsx @@ -10,12 +10,9 @@ const PermissionHandlerDialog = (props: PermissionHandlerProps) => { const intl = useIntl() const switchMode = (e: any) => { - props.plugin.switchMode(from, to, method, e.target.checked) + props.plugin.switchMode(from, to, method, e.target.checked, sensitiveCall) } - const rememberSwitch = () => { - return - } const reset = () => { props.plugin.clear() setFeedback(intl.formatMessage({ id: 'permissionHandler.allPermissionsReset' })) @@ -57,9 +54,9 @@ const PermissionHandlerDialog = (props: PermissionHandlerProps) => { { sensitiveCall ?

: '' }
- { !sensitiveCall &&
- {rememberSwitch()} - + {
+ +
}