Commit 3db22b13 authored by LianaHus's avatar LianaHus Committed by Liana Husikyan

added method to permissions storage

parent c4d95541
...@@ -1778,9 +1778,9 @@ ...@@ -1778,9 +1778,9 @@
"integrity": "sha512-ePDxG9UuU9Kobk90ZUjtmDW8IT9U7aRb1/Rl9683MRNM+ur0ocHL2v7TPH2ajTiVSBUFbbeW8vKIt9jrb0JIAA==" "integrity": "sha512-ePDxG9UuU9Kobk90ZUjtmDW8IT9U7aRb1/Rl9683MRNM+ur0ocHL2v7TPH2ajTiVSBUFbbeW8vKIt9jrb0JIAA=="
}, },
"@remixproject/engine": { "@remixproject/engine": {
"version": "0.2.0-alpha.4", "version": "0.2.0-alpha.6",
"resolved": "https://registry.npmjs.org/@remixproject/engine/-/engine-0.2.0-alpha.4.tgz", "resolved": "https://registry.npmjs.org/@remixproject/engine/-/engine-0.2.0-alpha.6.tgz",
"integrity": "sha512-AY6HaF7Y4fR1oOdz60B2zt+gGftaT5fZWSl5ka7UuDHZUzeouNMx4O1+Uk4376Mv+M3vdmpGFo6KgfsZj6wSJw==" "integrity": "sha512-UgtFmG90wKzmsghGmvvGexj1bMjdgAPIn/del70WXX6RNfGiTxCO1a1Q/EWrFO0OJ9jXty5181zt+sJpQOoMCw=="
}, },
"@resolver-engine/core": { "@resolver-engine/core": {
"version": "0.3.3", "version": "0.3.3",
......
...@@ -79,7 +79,7 @@ ...@@ -79,7 +79,7 @@
"yo-yoify": "^3.7.3" "yo-yoify": "^3.7.3"
}, },
"dependencies": { "dependencies": {
"@remixproject/engine": "^0.2.0-alpha.4", "@remixproject/engine": "^0.2.0-alpha.6",
"http-server": "^0.11.1", "http-server": "^0.11.1",
"remixd": "0.1.8-alpha.10", "remixd": "0.1.8-alpha.10",
"standard": "^8.5.0" "standard": "^8.5.0"
......
...@@ -49,7 +49,7 @@ export class PluginManagerSettings { ...@@ -49,7 +49,7 @@ export class PluginManagerSettings {
const fromLocal = window.localStorage.getItem('plugins/permissions') const fromLocal = window.localStorage.getItem('plugins/permissions')
this.permissions = JSON.parse(fromLocal || '{}') this.permissions = JSON.parse(fromLocal || '{}')
this.currentSetting = this.settings() this.currentSetting = this.settings()
modalDialog('Plugin Manager Settings', this.currentSetting, modalDialog('Plugin Manager Permissions', this.currentSetting,
{ fn: () => this.onValidation() }, { fn: () => this.onValidation() },
) )
} }
...@@ -128,7 +128,7 @@ export class PluginManagerSettings { ...@@ -128,7 +128,7 @@ export class PluginManagerSettings {
render () { render () {
return yo` return yo`
<footer class="bg-light ${css.permissions} remix-bg-opacity"> <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>` </footer>`
} }
......
...@@ -9,7 +9,6 @@ const toaster = require('../ui/tooltip') ...@@ -9,7 +9,6 @@ const toaster = require('../ui/tooltip')
const modalDialogCustom = require('../ui/modal-dialog-custom') const modalDialogCustom = require('../ui/modal-dialog-custom')
const helper = require('../../lib/helper.js') const helper = require('../../lib/helper.js')
import { Plugin } from '@remixproject/engine' import { Plugin } from '@remixproject/engine'
import { isNative } from '../../remixAppManager.js'
import * as packageJson from '../../../package.json' import * as packageJson from '../../../package.json'
/* /*
...@@ -173,7 +172,7 @@ class FileManager extends Plugin { ...@@ -173,7 +172,7 @@ class FileManager extends Plugin {
toaster.hide() toaster.hide()
} }
if (this.currentRequest) { if (this.currentRequest) {
const canCall = this.call('manager', 'canCall', { name: this.currentRequest.from }, this.profile, 'setFile') const canCall = await this.askUserPermission('setFile', '')
if (canCall) { if (canCall) {
this._setFileInternal(path, content) this._setFileInternal(path, content)
return return
......
...@@ -33,8 +33,8 @@ const css = csjs` ...@@ -33,8 +33,8 @@ const css = csjs`
} }
` `
function notAllowWarning (from, to) { function notAllowWarning (from, to, method) {
return `${from.displayName || from.name} is not allowed to call ${to.displayName || to.name}.` return `${from.displayName || from.name} is not allowed to call ${method} method of ${to.displayName || to.name}.`
} }
export class PermissionHandler { export class PermissionHandler {
...@@ -74,8 +74,8 @@ export class PermissionHandler { ...@@ -74,8 +74,8 @@ export class PermissionHandler {
{ {
label: 'Accept', label: 'Accept',
fn: () => { fn: () => {
if (this.permissions[to.name][from.name]) { if (this.permissions[to.name][method][from.name]) {
this.permissions[to.name][from.name] = { this.permissions[to.name][method][from.name] = {
allow: true, allow: true,
hash: from.hash hash: from.hash
} }
...@@ -87,14 +87,14 @@ export class PermissionHandler { ...@@ -87,14 +87,14 @@ export class PermissionHandler {
{ {
label: 'Decline', label: 'Decline',
fn: () => { fn: () => {
if (this.permissions[to.name][from.name]) { if (this.permissions[to.name][method][from.name]) {
this.permissions[to.name][from.name] = { this.permissions[to.name][method][from.name] = {
allow: false, allow: false,
hash: from.hash hash: from.hash
} }
this.persistPermissions() this.persistPermissions()
} }
reject(notAllowWarning(from, to)) reject(notAllowWarning(from, to, method))
} }
} }
) )
...@@ -105,17 +105,20 @@ export class PermissionHandler { ...@@ -105,17 +105,20 @@ export class PermissionHandler {
* Check if a plugin has the permission to call another plugin and askPermission if needed * 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 {PluginProfile} from the profile of the plugin that make the call
* @param {ModuleProfile} to The profile of the module that receive 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>} * @returns {Promise<boolean>}
*/ */
async askPermission (from, to, method, message) { async askPermission (from, to, method, message) {
try { try {
this.permissions = this._getFromLocal() this.permissions = this._getFromLocal()
if (!this.permissions[to.name]) this.permissions[to.name] = {} 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) { if (!allow) {
const warning = notAllowWarning(from, to) const warning = notAllowWarning(from, to, method)
addTooltip(warning) addTooltip(warning)
return false return false
} }
...@@ -137,12 +140,12 @@ export class PermissionHandler { ...@@ -137,12 +140,12 @@ export class PermissionHandler {
form (from, to, method, message) { form (from, to, method, message) {
const fromName = from.displayName || from.name const fromName = from.displayName || from.name
const toName = to.displayName || to.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) => { const switchMode = (e) => {
e.target.checked e.target.checked
? this.permissions[to.name][from.name] = {} ? this.permissions[to.name][method][from.name] = {}
: delete this.permissions[to.name][from.name] : delete this.permissions[to.name][method][from.name]
} }
const rememberSwitch = remember const rememberSwitch = remember
? yo`<input type="checkbox" onchange="${switchMode}" checkbox class="form-check-input" id="remember" data-id="permissionHandlerRememberChecked">` ? yo`<input type="checkbox" onchange="${switchMode}" checkbox class="form-check-input" id="remember" data-id="permissionHandlerRememberChecked">`
...@@ -161,6 +164,12 @@ export class PermissionHandler { ...@@ -161,6 +164,12 @@ export class PermissionHandler {
globalRegistry.get('themeModule').api.fixInvert(imgFrom) globalRegistry.get('themeModule').api.fixInvert(imgFrom)
globalRegistry.get('themeModule').api.fixInvert(imgTo) globalRegistry.get('themeModule').api.fixInvert(imgTo)
const pluginMessage = message ? yo`
<div>
<h6>Description</h6>
<p>${message}</p>
</div>
` : ``
return yo` return yo`
<section class="${css.permission}"> <section class="${css.permission}">
${pluginsImages} ${pluginsImages}
...@@ -170,7 +179,7 @@ export class PermissionHandler { ...@@ -170,7 +179,7 @@ export class PermissionHandler {
<p>${from.description || yo`<i>No description Provided</i>`}</p> <p>${from.description || yo`<i>No description Provided</i>`}</p>
<h6>${toName} :</p> <h6>${toName} :</p>
<p>${to.description || yo`<i>No description Provided</i>`}</p> <p>${to.description || yo`<i>No description Provided</i>`}</p>
<p>${message}</p> ${pluginMessage}
</article> </article>
<article class="${css.remember}"> <article class="${css.remember}">
......
...@@ -34,12 +34,15 @@ export class RemixAppManager extends PluginManager { ...@@ -34,12 +34,15 @@ export class RemixAppManager extends PluginManager {
async canCall (from, to, method, message) { async canCall (from, to, method, message) {
// Make sure the caller of this methods is the target plugin // Make sure the caller of this methods is the target plugin
if (to.name !== this.currentRequest) { if (to !== this.currentRequest.from) {
return false return false
} }
if (isNative) // skipping native plugins' requests
if (isNative(from)) {
return true 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) { onPluginActivated (plugin) {
......
...@@ -61,7 +61,7 @@ module.exports = { ...@@ -61,7 +61,7 @@ module.exports = {
/* /*
'Should grant plugin permission (ZOKRATES)': function (browser) { 'Should grant plugin permission (ZOKRATES)': function (browser) {
browser.waitForElementVisible('*[data-id="pluginManagerComponentPluginManager"]') browser.waitForElementVisible('*[data-id="pluginManagerComponentPluginManager"]')
.click('*[data-id="pluginManagerSettingsButton"]') .click('*[data-id="pluginManagerPermissionsButton"]')
.waitForElementVisible('*[data-id="pluginManagerSettingsPermissionForm"]') .waitForElementVisible('*[data-id="pluginManagerSettingsPermissionForm"]')
.assert.containsText('*[data-id="pluginManagerSettingsPermissionForm"]', 'No Permission requested yet') .assert.containsText('*[data-id="pluginManagerSettingsPermissionForm"]', 'No Permission requested yet')
.modalFooterOKClick() .modalFooterOKClick()
...@@ -84,8 +84,8 @@ module.exports = { ...@@ -84,8 +84,8 @@ module.exports = {
'Should revert plugin permission (ZOKRATES)': function (browser) { 'Should revert plugin permission (ZOKRATES)': function (browser) {
browser.waitForElementVisible('*[data-id="verticalIconsSettingsIcons"]') browser.waitForElementVisible('*[data-id="verticalIconsSettingsIcons"]')
.click('*[data-id="verticalIconsSettingsIcons"]') .click('*[data-id="verticalIconsSettingsIcons"]')
.waitForElementVisible('*[data-id="pluginManagerSettingsButton"]') .waitForElementVisible('*[data-id="pluginManagerPermissionsButton"]')
.click('*[data-id="pluginManagerSettingsButton"]') .click('*[data-id="pluginManagerPermissionsButton"]')
.waitForElementVisible('*[data-id="modalDialogContainer"]') .waitForElementVisible('*[data-id="modalDialogContainer"]')
.click('*[data-id="pluginManagerSettingsPermissionForm"]') .click('*[data-id="pluginManagerSettingsPermissionForm"]')
.pause(2000) .pause(2000)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment