added method to permissions storage

pull/1/head
LianaHus 5 years ago committed by Liana Husikyan
parent c4d95541f3
commit 3db22b13a3
  1. 6
      package-lock.json
  2. 2
      package.json
  3. 4
      src/app/components/plugin-manager-settings.js
  4. 3
      src/app/files/fileManager.js
  5. 37
      src/app/ui/persmission-handler.js
  6. 9
      src/remixAppManager.js
  7. 6
      test-browser/tests/pluginManager.js

6
package-lock.json generated

@ -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",

@ -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"

@ -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`
<footer class="bg-light ${css.permissions} remix-bg-opacity">
<button onclick="${() => this.openDialog()}" class="btn btn-primary settings-button" data-id="pluginManagerSettingsButton">Settings</button>
<button onclick="${() => this.openDialog()}" class="btn btn-primary settings-button" data-id="pluginManagerPermissionsButton">Permissions</button>
</footer>`
}

@ -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

@ -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<boolean>}
*/
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`<input type="checkbox" onchange="${switchMode}" checkbox class="form-check-input" id="remember" data-id="permissionHandlerRememberChecked">`
@ -161,6 +164,12 @@ export class PermissionHandler {
globalRegistry.get('themeModule').api.fixInvert(imgFrom)
globalRegistry.get('themeModule').api.fixInvert(imgTo)
const pluginMessage = message ? yo`
<div>
<h6>Description</h6>
<p>${message}</p>
</div>
` : ``
return yo`
<section class="${css.permission}">
${pluginsImages}
@ -170,7 +179,7 @@ export class PermissionHandler {
<p>${from.description || yo`<i>No description Provided</i>`}</p>
<h6>${toName} :</p>
<p>${to.description || yo`<i>No description Provided</i>`}</p>
<p>${message}</p>
${pluginMessage}
</article>
<article class="${css.remember}">

@ -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) {

@ -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)

Loading…
Cancel
Save