From fd293b723bda8e9616a3ba077055a6bfe1adea92 Mon Sep 17 00:00:00 2001 From: djmaze Date: Mon, 9 Aug 2021 11:13:10 +0200 Subject: [PATCH] Resolve Issue #104 --- dev/Remote/Admin/Fetch.js | 12 ++++---- dev/Settings/Admin/Packages.js | 9 +++--- dev/View/Popup/Plugin.js | 13 ++++++--- .../app/libraries/RainLoop/Actions/Admin.php | 28 +++++++++++-------- 4 files changed, 36 insertions(+), 26 deletions(-) diff --git a/dev/Remote/Admin/Fetch.js b/dev/Remote/Admin/Fetch.js index 7fd451842..ff89fb919 100644 --- a/dev/Remote/Admin/Fetch.js +++ b/dev/Remote/Admin/Fetch.js @@ -85,11 +85,11 @@ class RemoteAdminFetch extends AbstractFetchRemote { /** * @param {?Function} fCallback - * @param {string} sName + * @param {string} sId */ - plugin(fCallback, sName) { + plugin(fCallback, sId) { this.defaultRequest(fCallback, 'AdminPluginLoad', { - Name: sName + Id: sId }); } @@ -125,12 +125,12 @@ class RemoteAdminFetch extends AbstractFetchRemote { /** * @param {?Function} fCallback - * @param {string} sName + * @param {string} sId * @param {boolean} bDisabled */ - pluginDisable(fCallback, sName, bDisabled) { + pluginDisable(fCallback, sId, bDisabled) { this.defaultRequest(fCallback, 'AdminPluginDisable', { - Name: sName, + Id: sId, Disabled: bDisabled ? 1 : 0 }); } diff --git a/dev/Settings/Admin/Packages.js b/dev/Settings/Admin/Packages.js index 6c1e9ab19..818cd788f 100644 --- a/dev/Settings/Admin/Packages.js +++ b/dev/Settings/Admin/Packages.js @@ -47,7 +47,7 @@ export class PackagesAdminSettings { // configurePlugin let el = event.target.closestWithin('.package-configure', oDom), data = el ? ko.dataFor(el) : 0; - data && Remote.plugin((iError, data) => iError || showScreenPopup(PluginPopupView, [data.Result]), data.name) + data && Remote.plugin((iError, data) => iError || showScreenPopup(PluginPopupView, [data.Result]), data.id) // disablePlugin el = event.target.closestWithin('.package-active', oDom); data = el ? ko.dataFor(el) : 0; @@ -94,10 +94,11 @@ export class PackagesAdminSettings { } disablePlugin(plugin) { - let b = !plugin.enabled(); - plugin.enabled(b); + let b = plugin.enabled(); + plugin.enabled(!b); Remote.pluginDisable((iError, data) => { if (iError) { + plugin.enabled(b); this.packagesError( (Notification.UnsupportedPluginPackage === iError && data && data.ErrorMessage) ? data.ErrorMessage @@ -105,7 +106,7 @@ export class PackagesAdminSettings { ); } // PackageAdminStore.fetch(); - }, plugin.name, !b); + }, plugin.id, b); } } diff --git a/dev/View/Popup/Plugin.js b/dev/View/Popup/Plugin.js index 4f2a61d72..2734f9b48 100644 --- a/dev/View/Popup/Plugin.js +++ b/dev/View/Popup/Plugin.js @@ -16,6 +16,7 @@ class PluginPopupView extends AbstractViewPopup { this.addObservables({ saveError: '', + id: '', name: '', readme: '' }); @@ -36,15 +37,17 @@ class PluginPopupView extends AbstractViewPopup { } saveCommand() { - const list = {}; - list.Name = this.name(); + const list = { + Id: this.id(), + Settings: {} + }; this.configures.forEach(oItem => { let value = oItem.value(); if (false === value || true === value) { - value = value ? '1' : '0'; + value = value ? 1 : 0; } - list['_' + oItem.Name] = value; + list.Settings[oItem.Name] = value; }); this.saveError(''); @@ -56,11 +59,13 @@ class PluginPopupView extends AbstractViewPopup { } onShow(oPlugin) { + this.id(''); this.name(''); this.readme(''); this.configures([]); if (oPlugin) { + this.id(oPlugin.Id); this.name(oPlugin.Name); this.readme(oPlugin.Readme); diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Admin.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Admin.php index 5bf43c4cf..019f15089 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Admin.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Admin.php @@ -789,12 +789,12 @@ trait Admin { $this->IsAdminLoggined(); - $sName = (string) $this->GetActionParam('Name', ''); + $sId = (string) $this->GetActionParam('Id', ''); $bDisable = '1' === (string) $this->GetActionParam('Disabled', '1'); if (!$bDisable) { - $oPlugin = $this->Plugins()->CreatePluginByName($sName); + $oPlugin = $this->Plugins()->CreatePluginByName($sId); if ($oPlugin) { $sValue = $oPlugin->Supported(); @@ -809,7 +809,7 @@ trait Admin } } - return $this->DefaultResponse(__FUNCTION__, $this->pluginEnable($sName, !$bDisable)); + return $this->DefaultResponse(__FUNCTION__, $this->pluginEnable($sId, !$bDisable)); } public function DoAdminPluginLoad() : array @@ -817,15 +817,16 @@ trait Admin $this->IsAdminLoggined(); $mResult = false; - $sName = (string) $this->GetActionParam('Name', ''); + $sId = (string) $this->GetActionParam('Id', ''); - if (!empty($sName)) + if (!empty($sId)) { - $oPlugin = $this->Plugins()->CreatePluginByName($sName); + $oPlugin = $this->Plugins()->CreatePluginByName($sId); if ($oPlugin) { $mResult = array( - 'Name' => $sName, + 'Id' => $sId, + 'Name' => $oPlugin->Name(), 'Readme' => $oPlugin->Description(), 'Config' => array() ); @@ -860,20 +861,22 @@ trait Admin $this->IsAdminLoggined(); $mResult = false; - $sName = (string) $this->GetActionParam('Name', ''); + $sId = (string) $this->GetActionParam('Id', ''); - if (!empty($sName)) + if (!empty($sId)) { - $oPlugin = $this->Plugins()->CreatePluginByName($sName); + $oPlugin = $this->Plugins()->CreatePluginByName($sId); if ($oPlugin) { $oConfig = $oPlugin->Config(); $aMap = $oPlugin->ConfigMap(); if (is_array($aMap)) { + $aSettings = (array) $this->GetActionParam('Settings', []); foreach ($aMap as $oItem) { - $sValue = $this->GetActionParam('_'.$oItem->Name(), $oConfig->Get('plugin', $oItem->Name())); + $sKey = $oItem->Name(); + $sValue = $aSettings[$sKey] ?? $oConfig->Get('plugin', $sKey); if (PluginPropertyType::PASSWORD !== $oItem->Type() || APP_DUMMY !== $sValue) { $mResultValue = null; @@ -893,13 +896,14 @@ trait Admin case PluginPropertyType::PASSWORD: case PluginPropertyType::STRING: case PluginPropertyType::STRING_TEXT: + case PluginPropertyType::URL: $mResultValue = (string) $sValue; break; } if (null !== $mResultValue) { - $oConfig->Set('plugin', $oItem->Name(), $mResultValue); + $oConfig->Set('plugin', $sKey, $mResultValue); } } }