From 8e1ffcaf656236c283791d2a43b10bde10263d8b Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Wed, 1 Apr 2020 14:10:26 +0200 Subject: [PATCH] Add basic permission edition menu to service nav right click --- resources/js/index.js | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/resources/js/index.js b/resources/js/index.js index 48c1a39..7a43886 100644 --- a/resources/js/index.js +++ b/resources/js/index.js @@ -49,7 +49,51 @@ function openServiceContextMenu(event, serviceId) { }, enabled: ready, })); + menu.append(new MenuItem({type: "separator"})); + + let permissionsMenu = []; + if (ready) { + for (const domain in service.permissions) { + if (service.permissions.hasOwnProperty(domain)) { + const domainPermissionsMenu = []; + + const domainPermissions = service.permissions[domain]; + for (const permission of domainPermissions) { + domainPermissionsMenu.push({ + label: (permission.authorized ? '✓' : '❌') + ' ' + permission.name, + submenu: [{ + label: 'Toggle', + click: () => { + permission.authorized = !permission.authorized; + updateServicePermissions(serviceId); + }, + }, { + label: 'Forget', + click: () => { + service.permissions[domain] = domainPermissions.filter(p => p !== permission); + }, + }], + }); + } + + if (domainPermissionsMenu.length > 0) { + permissionsMenu.push({ + label: domain, + submenu: domainPermissionsMenu, + }); + } + } + } + } + menu.append(new MenuItem({ + label: 'Permissions', + enabled: ready, + submenu: permissionsMenu, + })); + + menu.append(new MenuItem({type: "separator"})); + menu.append(new MenuItem({ label: 'Edit', click: () => { ipcRenderer.send('openServiceSettings', serviceId);