From 6a6bc683eabdead081ff4d0ea6c1612febede8ef Mon Sep 17 00:00:00 2001 From: Adrian Gibanel bTactic Date: Wed, 10 May 2023 19:14:22 +0200 Subject: [PATCH 01/10] Nextcloud-18 info.xml --- nextcloud-app/appinfo/info.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nextcloud-app/appinfo/info.xml b/nextcloud-app/appinfo/info.xml index 7181a2b..c6afec2 100644 --- a/nextcloud-app/appinfo/info.xml +++ b/nextcloud-app/appinfo/info.xml @@ -28,7 +28,7 @@ AGPL ZeXtras - 0.8.23 + 0.8.25 ZimbraDrive auth integration @@ -41,8 +41,8 @@ zimbra.png - - + + From df87dfd11cd8acd8e83f9aa4c7bcc698d692d96a Mon Sep 17 00:00:00 2001 From: Adrian Gibanel bTactic Date: Wed, 10 May 2023 12:38:30 +0200 Subject: [PATCH 02/10] Nextcloud-18 abstractzimbrausersbackend.php --- nextcloud-app/lib/auth/abstractzimbrausersbackend.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nextcloud-app/lib/auth/abstractzimbrausersbackend.php b/nextcloud-app/lib/auth/abstractzimbrausersbackend.php index 969a6a0..a046961 100644 --- a/nextcloud-app/lib/auth/abstractzimbrausersbackend.php +++ b/nextcloud-app/lib/auth/abstractzimbrausersbackend.php @@ -67,7 +67,8 @@ public function __construct($server = null, $zimbraAuthenticationBackend = null) $this->accountManager = new AccountManager( $server->getDatabaseConnection(), $server->getEventDispatcher(), - $server->getJobList() //Nextcloud >= 12.0.1 + $server->getJobList(), // Nextcloud >= 12.0.1 + $this->logger // Nexcloud >= 18.0.0 ); } From 7af3fc1e7a84f9734cfa8b6fd114d7605484d5d9 Mon Sep 17 00:00:00 2001 From: Leon Kos Date: Sun, 8 Jan 2023 20:38:46 +0100 Subject: [PATCH 03/10] Update to Nextcloud 21 interface --- README.md | 3 +-- nextcloud-app/lib/auth/abstractzimbrausersbackend.php | 4 +++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c1bbd48..ec2da1f 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,7 @@ Features: - Attach Nextcloud / ownCloud files to email. Supported Versions: -- Nextcloud: 9, 10, 11, 12, 13 -- ownCloud: 9, 9.1, 10 +- Nextcloud: 21 ## Install diff --git a/nextcloud-app/lib/auth/abstractzimbrausersbackend.php b/nextcloud-app/lib/auth/abstractzimbrausersbackend.php index a046961..46ff1ca 100644 --- a/nextcloud-app/lib/auth/abstractzimbrausersbackend.php +++ b/nextcloud-app/lib/auth/abstractzimbrausersbackend.php @@ -24,6 +24,7 @@ use OCA\ZimbraDrive\Settings\AppSettings; use OC\User\User; use OCP\IServerContainer; +use Psr\Log\LoggerInterface; abstract class AbstractZimbraUsersBackend extends RetroCompatibleBackend { @@ -57,7 +58,7 @@ public function __construct($server = null, $zimbraAuthenticationBackend = null) $this->zimbraAuthenticationBackend = $zimbraAuthenticationBackend; } - $this->logger = $server->getLogger(); + $this->logger = $server->get(LoggerInterface::class); $this->config = $server->getConfig(); $this->userManager = $server->getUserManager(); $this->groupManager = $server->getGroupManager(); @@ -66,6 +67,7 @@ public function __construct($server = null, $zimbraAuthenticationBackend = null) { $this->accountManager = new AccountManager( $server->getDatabaseConnection(), + $this->config, // Nextcloud >= 21 $server->getEventDispatcher(), $server->getJobList(), // Nextcloud >= 12.0.1 $this->logger // Nexcloud >= 18.0.0 From 33add144140ba613a4e120bfc98214e1ed015c3e Mon Sep 17 00:00:00 2001 From: Adrian Gibanel bTactic Date: Thu, 4 May 2023 12:55:37 +0200 Subject: [PATCH 04/10] Nextcloud 22 - Database support update. --- nextcloud-app/appinfo/database.xml | 55 ------------------ .../Version000825Date20230504093000.php | 58 +++++++++++++++++++ 2 files changed, 58 insertions(+), 55 deletions(-) delete mode 100644 nextcloud-app/appinfo/database.xml create mode 100644 nextcloud-app/lib/Migration/Version000825Date20230504093000.php diff --git a/nextcloud-app/appinfo/database.xml b/nextcloud-app/appinfo/database.xml deleted file mode 100644 index cce4a60..0000000 --- a/nextcloud-app/appinfo/database.xml +++ /dev/null @@ -1,55 +0,0 @@ - - - - - - *dbname* - true - false - - utf8 - - - - *dbprefix*zimbradrive_users - - - - - uid - text - - true - 256 - - - - display_name - text - - false - 256 - - - - -
- -
diff --git a/nextcloud-app/lib/Migration/Version000825Date20230504093000.php b/nextcloud-app/lib/Migration/Version000825Date20230504093000.php new file mode 100644 index 0000000..d08dc54 --- /dev/null +++ b/nextcloud-app/lib/Migration/Version000825Date20230504093000.php @@ -0,0 +1,58 @@ +hasTable('zimbradrive_users')) { + $table = $schema->createTable('zimbradrive_users'); + $table->addColumn('uid', 'string', [ + 'notnull' => true, + 'length' => 256, + 'default' => '', + ]); + $table->addColumn('display_name', 'string', [ + 'notnull' => false, + 'length' => 256, + ]); + $table->setPrimaryKey(['uid']); + } + return $schema; + } + + /** + * @param IOutput $output + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` + * @param array $options + */ + public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void { + } +} From 876502d028da414bf98beb23b9a365c8ca96be82 Mon Sep 17 00:00:00 2001 From: Adrian Gibanel bTactic Date: Thu, 4 May 2023 15:03:54 +0200 Subject: [PATCH 05/10] AccountManager constructor call was updated to Nextcloud 24. --- .../lib/auth/abstractzimbrausersbackend.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/nextcloud-app/lib/auth/abstractzimbrausersbackend.php b/nextcloud-app/lib/auth/abstractzimbrausersbackend.php index 46ff1ca..f2e0fa2 100644 --- a/nextcloud-app/lib/auth/abstractzimbrausersbackend.php +++ b/nextcloud-app/lib/auth/abstractzimbrausersbackend.php @@ -25,6 +25,10 @@ use OC\User\User; use OCP\IServerContainer; use Psr\Log\LoggerInterface; +use OCP\Security\VerificationToken\IVerificationToken; +use OCP\Defaults; +use OCP\L10N\IFactory; +use OCP\IURLGenerator; abstract class AbstractZimbraUsersBackend extends RetroCompatibleBackend { @@ -69,8 +73,14 @@ public function __construct($server = null, $zimbraAuthenticationBackend = null) $server->getDatabaseConnection(), $this->config, // Nextcloud >= 21 $server->getEventDispatcher(), - $server->getJobList(), // Nextcloud >= 12.0.1 - $this->logger // Nexcloud >= 18.0.0 + $server->getJobList(), //Nextcloud >= 12.0.1 + $this->logger, // Nexcloud >= 18.0.0 + $server->get(IVerificationToken::class), + $server->getMailer(), + $server->get(Defaults::class), + $server->get(IFactory::class), + $server->get(IURLGenerator::class), + $server->getCrypto() ); } From ab37cf58b8f02db5f7650c8b49e19864f5c14aaf Mon Sep 17 00:00:00 2001 From: Adrian Gibanel bTactic Date: Thu, 4 May 2023 19:02:13 +0200 Subject: [PATCH 06/10] Update minimum and maximum Nextcloud versions. --- nextcloud-app/appinfo/info.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nextcloud-app/appinfo/info.xml b/nextcloud-app/appinfo/info.xml index c6afec2..6c788ac 100644 --- a/nextcloud-app/appinfo/info.xml +++ b/nextcloud-app/appinfo/info.xml @@ -42,7 +42,7 @@ - + From 417d0c665e49f9ae52029f355a21ed06b156acdc Mon Sep 17 00:00:00 2001 From: Adrian Gibanel bTactic Date: Thu, 4 May 2023 21:08:22 +0200 Subject: [PATCH 07/10] User getAccount instead of getUser. --- .../lib/auth/abstractzimbrausersbackend.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/nextcloud-app/lib/auth/abstractzimbrausersbackend.php b/nextcloud-app/lib/auth/abstractzimbrausersbackend.php index f2e0fa2..1a651c1 100644 --- a/nextcloud-app/lib/auth/abstractzimbrausersbackend.php +++ b/nextcloud-app/lib/auth/abstractzimbrausersbackend.php @@ -171,8 +171,13 @@ private function restoreUserEmailIfChanged(User $user, $userEmail) private function getUserEmailAddress(User $user){ if(!is_null($this->accountManager)) //Nextcloud 11 { - $userData = $this->accountManager->getUser($user); - $userEmailAddress = $userData[AccountManager::PROPERTY_EMAIL]['value']; + $account = $this->accountManager->getAccount($user); + if(!is_null($account->getProperty(AccountManager::PROPERTY_EMAIL))) + { + $userEmailAddress = $account->getProperty(AccountManager::PROPERTY_EMAIL)->getValue(); + } else { + $userEmailAddress = ''; + } } else { $userEmailAddress = $user->getEMailAddress(); @@ -183,9 +188,9 @@ private function getUserEmailAddress(User $user){ private function setUserEmailAddress(User $user, $userEmail){ if(!is_null($this->accountManager)) //Nextcloud 11 { - $userData = $this->accountManager->getUser($user); - $userData[AccountManager::PROPERTY_EMAIL]['value'] = $userEmail; - $this->accountManager->updateUser($user, $userData); + $account = $this->accountManager->getAccount($user); + $account->setProperty(AccountManager::PROPERTY_EMAIL, $userEmail, AccountManager::SCOPE_LOCAL, AccountManager::NOT_VERIFIED); + $this->accountManager->updateAccount($account); } else { $user->setEMailAddress($userEmail); From 49771385579a8f63a9324aaf882525bc85a71354 Mon Sep 17 00:00:00 2001 From: Adrian Gibanel bTactic Date: Thu, 4 May 2023 22:18:03 +0200 Subject: [PATCH 08/10] User getAccount instead of getUser. (2) --- .../lib/auth/abstractzimbrausersbackend.php | 92 +++++++++---------- 1 file changed, 43 insertions(+), 49 deletions(-) diff --git a/nextcloud-app/lib/auth/abstractzimbrausersbackend.php b/nextcloud-app/lib/auth/abstractzimbrausersbackend.php index 1a651c1..644d284 100644 --- a/nextcloud-app/lib/auth/abstractzimbrausersbackend.php +++ b/nextcloud-app/lib/auth/abstractzimbrausersbackend.php @@ -29,6 +29,7 @@ use OCP\Defaults; use OCP\L10N\IFactory; use OCP\IURLGenerator; +use OC\Accounts\Account; abstract class AbstractZimbraUsersBackend extends RetroCompatibleBackend { @@ -112,7 +113,9 @@ public function checkPassword($uid, $password) { $this->createUser($zimbraUser->getUid(), $zimbraUser->getDisplayName()); } - $this->setDefaultUserAttributes($zimbraUser); + $user = $this->userManager->get($zimbraUser->getUid()); + $account = $this->accountManager->getAccount($user); + $this->setDefaultUserAttributes($zimbraUser, $account); return $zimbraUser->getUid(); } catch (\Exception $ignore) @@ -123,24 +126,32 @@ public function checkPassword($uid, $password) /** * @param ZimbraUser $zimbraUser + * @param Account $account */ - private function setDefaultUserAttributes($zimbraUser){ - $user = $this->userManager->get($zimbraUser->getUid()); - $this->restoreUserEmailIfChanged($user, $zimbraUser->getEmail()); - $this->restoreUserDisplayNameIfChanged($user, $zimbraUser->getDisplayName()); - $this->setDefaultGroups($user); + private function setDefaultUserAttributes($zimbraUser, $account){ + $this->restoreUserEmailIfChanged($account, $zimbraUser->getEmail()); + $this->restoreUserDisplayNameIfChanged($account, $zimbraUser->getDisplayName()); + $this->setDefaultGroups($account); } /** - * @param $user User + * @param $account Account */ - private function setDefaultGroups($user) + private function setDefaultGroups($account) { + $user = $account->getUser(); + + $accountEmail = ''; + if(!is_null($account->getProperty(AccountManager::PROPERTY_EMAIL))) + { + $accountEmail = $account->getProperty(AccountManager::PROPERTY_EMAIL)->getValue(); + } + if ($this->setZimbraGroupToUsers) { $this->insertUserInGroup($user, self::ZIMBRA_GROUP); } - $this->insertUserInGroup($user, $this->getEmailDomain($user->getEMailAddress())); + $this->insertUserInGroup($user, $this->getEmailDomain($accountEmail)); } private function getEmailDomain($email) @@ -157,59 +168,42 @@ private function getEmailDomain($email) protected abstract function createUser($userId, $userDisplayName); /** - * @param $user User + * @param $account Account * @param $userEmail string */ - private function restoreUserEmailIfChanged(User $user, $userEmail) + private function restoreUserEmailIfChanged(Account $account, $userEmail) { - if( $this->getUserEmailAddress($user) !== $userEmail) + $accountEmail = ''; + if(!is_null($account->getProperty(AccountManager::PROPERTY_EMAIL))) { - $this->setUserEmailAddress($user, $userEmail); + $accountEmail = $account->getProperty(AccountManager::PROPERTY_EMAIL)->getValue(); } - } - - private function getUserEmailAddress(User $user){ - if(!is_null($this->accountManager)) //Nextcloud 11 - { - $account = $this->accountManager->getAccount($user); - if(!is_null($account->getProperty(AccountManager::PROPERTY_EMAIL))) - { - $userEmailAddress = $account->getProperty(AccountManager::PROPERTY_EMAIL)->getValue(); - } else { - $userEmailAddress = ''; - } - } else + if( $accountEmail !== $userEmail) { - $userEmailAddress = $user->getEMailAddress(); + $this->setUserEmailAddress($account, $userEmail); } - return $userEmailAddress; } - private function setUserEmailAddress(User $user, $userEmail){ - if(!is_null($this->accountManager)) //Nextcloud 11 - { - $account = $this->accountManager->getAccount($user); - $account->setProperty(AccountManager::PROPERTY_EMAIL, $userEmail, AccountManager::SCOPE_LOCAL, AccountManager::NOT_VERIFIED); - $this->accountManager->updateAccount($account); - } else - { - $user->setEMailAddress($userEmail); - } + private function setUserEmailAddress(Account $account, $userEmail){ + $account->setProperty(AccountManager::PROPERTY_EMAIL, $userEmail, AccountManager::SCOPE_LOCAL, AccountManager::NOT_VERIFIED); + $this->accountManager->updateAccount($account); + } + + private function setUserDisplayName(Account $account, $userDisplayName){ + $account->setProperty(AccountManager::PROPERTY_DISPLAYNAME, $userDisplayName, AccountManager::SCOPE_LOCAL, AccountManager::NOT_VERIFIED); + $this->accountManager->updateAccount($account); } - private function restoreUserDisplayNameIfChanged(User $user, $userDisplayName) + private function restoreUserDisplayNameIfChanged(Account $account, $userDisplayName) { - if($user->getDisplayName() !== $userDisplayName) + $accountDisplayName = ''; + if(!is_null($account->getProperty(AccountManager::PROPERTY_DISPLAYNAME))) { - if(!is_null($this->accountManager)) //Nextcloud 11 - { - $userData = $this->accountManager->getUser($user); - $userData[AccountManager::PROPERTY_DISPLAYNAME]['value'] = $userDisplayName; - $this->accountManager->updateUser($user, $userData); - } else - { - $user->setDisplayName($userDisplayName); - } + $accountDisplayName = $account->getProperty(AccountManager::PROPERTY_DISPLAYNAME)->getValue(); + } + if( $accountDisplayName !== $userDisplayName) + { + $this->setUserDisplayName($account, $userDisplayName); } } From e80267a88085b0692441886ab4b4b77c720c4b03 Mon Sep 17 00:00:00 2001 From: Adrian Gibanel bTactic Date: Thu, 4 May 2023 19:03:13 +0200 Subject: [PATCH 09/10] Bump current version to 0.8.26 so that we can update it. --- nextcloud-app/appinfo/info.xml | 2 +- ...te20230504093000.php => Version000826Date20230504093000.php} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename nextcloud-app/lib/Migration/{Version000825Date20230504093000.php => Version000826Date20230504093000.php} (95%) diff --git a/nextcloud-app/appinfo/info.xml b/nextcloud-app/appinfo/info.xml index 6c788ac..82953ac 100644 --- a/nextcloud-app/appinfo/info.xml +++ b/nextcloud-app/appinfo/info.xml @@ -28,7 +28,7 @@ AGPL ZeXtras - 0.8.25 + 0.8.26 ZimbraDrive auth integration diff --git a/nextcloud-app/lib/Migration/Version000825Date20230504093000.php b/nextcloud-app/lib/Migration/Version000826Date20230504093000.php similarity index 95% rename from nextcloud-app/lib/Migration/Version000825Date20230504093000.php rename to nextcloud-app/lib/Migration/Version000826Date20230504093000.php index d08dc54..897623f 100644 --- a/nextcloud-app/lib/Migration/Version000825Date20230504093000.php +++ b/nextcloud-app/lib/Migration/Version000826Date20230504093000.php @@ -12,7 +12,7 @@ /** * Auto-generated migration step: Please modify to your needs! */ -class Version000825Date20230504093000 extends SimpleMigrationStep { +class Version000826Date20230504093000 extends SimpleMigrationStep { /** * @param IOutput $output From 88338aa4b519fe8341a94cb0e3f4bf83ee72473e Mon Sep 17 00:00:00 2001 From: Adrian Gibanel bTactic Date: Wed, 10 May 2023 19:21:24 +0200 Subject: [PATCH 10/10] Updated Nextcloud versions to 24, 25 and 26. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ec2da1f..fb4ae34 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Features: - Attach Nextcloud / ownCloud files to email. Supported Versions: -- Nextcloud: 21 +- Nextcloud: 24, 25, 26 ## Install