From 97c0f81a2ee6c909a17a5a875f2b289ea43b0eda Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Tue, 6 Aug 2024 21:41:52 +0200 Subject: [PATCH] allow multi-account in nc with oauth login --- dev/Knoin/AbstractViews.js | 5 ++--- dev/Knoin/Knoin.js | 2 +- dev/View/Popup/Compose.js | 8 ++++---- dev/View/Popup/Contacts.js | 4 ---- plugins/nextcloud/index.php | 7 +++++++ .../v/0.0.0/app/templates/Views/User/PopupsIdentity.html | 2 +- 6 files changed, 15 insertions(+), 13 deletions(-) diff --git a/dev/Knoin/AbstractViews.js b/dev/Knoin/AbstractViews.js index 828318b30..409e44386 100644 --- a/dev/Knoin/AbstractViews.js +++ b/dev/Knoin/AbstractViews.js @@ -60,10 +60,9 @@ export class AbstractViewPopup extends AbstractView this.keyScope.scope = name; this.modalVisible = ko.observable(false).extend({ rateLimit: 0 }); this.close = () => this.modalVisible(false); + this.tryToClose = () => (false === this.onClose()) || this.close(); addShortcut('escape,close', '', name, () => { - if (this.modalVisible() && false !== this.onClose()) { - this.close(); - } + this.modalVisible() && this.tryToClose(); return false; // return true; Issue with supported modal close }); diff --git a/dev/Knoin/Knoin.js b/dev/Knoin/Knoin.js index df348375c..12d07d1cb 100644 --- a/dev/Knoin/Knoin.js +++ b/dev/Knoin/Knoin.js @@ -167,7 +167,7 @@ const if (screenName && fireEvent('sm-show-screen', screenName + (subPart ? '/' + subPart : ''), 1)) { // Close all popups for (let vm of visiblePopups) { - (false === vm.onClose()) || vm.close(); + vm.tryToClose(); } let vmScreen = screen(screenName); diff --git a/dev/View/Popup/Compose.js b/dev/View/Popup/Compose.js index 9c4e63954..3a875d587 100644 --- a/dev/View/Popup/Compose.js +++ b/dev/View/Popup/Compose.js @@ -298,7 +298,7 @@ export class ComposePopupView extends AbstractViewPopup { ] }); - this.tryToClose = this.tryToClose.debounce(200); + this.doClose = this.doClose.debounce(200); this.iTimer = 0; @@ -665,7 +665,7 @@ export class ComposePopupView extends AbstractViewPopup { this.saveCommand(); } - this.tryToClose(); + this.doClose(); } contactsCommand() { @@ -1072,7 +1072,7 @@ export class ComposePopupView extends AbstractViewPopup { }, 100); } - tryToClose() { + doClose() { if (AskPopupView.hidden()) { if (ComposePopupView.inEdit() || (this.isEmptyForm() && !this.draftUid())) { this.close(); @@ -1218,7 +1218,7 @@ export class ComposePopupView extends AbstractViewPopup { }); addShortcut('escape,close', 'shift', ScopeCompose, () => { - this.tryToClose(); + this.doClose(); return false; }); diff --git a/dev/View/Popup/Contacts.js b/dev/View/Popup/Contacts.js index 15b6d61f3..342a6d504 100644 --- a/dev/View/Popup/Contacts.js +++ b/dev/View/Popup/Contacts.js @@ -314,10 +314,6 @@ export class ContactsPopupView extends AbstractViewPopup { } } - tryToClose() { - (false === this.onClose()) || this.close(); - } - onClose() { const contact = this.contact(); if (AskPopupView.hidden() && contact?.hasChanges()) { diff --git a/plugins/nextcloud/index.php b/plugins/nextcloud/index.php index bb7c4f686..c3a769eb6 100644 --- a/plugins/nextcloud/index.php +++ b/plugins/nextcloud/index.php @@ -90,8 +90,15 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin public function beforeLogin(\RainLoop\Model\Account $oAccount, \MailSo\Net\NetClient $oClient, \MailSo\Net\ConnectSettings $oSettings) : void { // https://apps.nextcloud.com/apps/oidc_login + $ocUser = \OC::$server->getUserSession()->getUser(); + $sNcEmail = $ocUser->getEMailAddress() ?: $ocUser->getPrimaryEMailAddress(); + + // Only login with OIDC access token if + // it is enabled in config, the user is currently logged in with OIDC + // and the current snappymail account is the OIDC account if (\OC::$server->getConfig()->getAppValue('snappymail', 'snappymail-autologin-oidc', false) && \OC::$server->getSession()->get('is_oidc') + && $sNcEmail === $oSettings->username // && $oClient->supportsAuthType('OAUTHBEARER') // v2.28 ) { $sAccessToken = \OC::$server->getSession()->get('oidc_access_token'); diff --git a/snappymail/v/0.0.0/app/templates/Views/User/PopupsIdentity.html b/snappymail/v/0.0.0/app/templates/Views/User/PopupsIdentity.html index ebf739b65..201205a66 100644 --- a/snappymail/v/0.0.0/app/templates/Views/User/PopupsIdentity.html +++ b/snappymail/v/0.0.0/app/templates/Views/User/PopupsIdentity.html @@ -1,5 +1,5 @@
- × + ×