diff --git a/README.md b/README.md index c1bbd48..fb4ae34 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: 24, 25, 26 ## Install 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/appinfo/info.xml b/nextcloud-app/appinfo/info.xml index 7181a2b..82953ac 100644 --- a/nextcloud-app/appinfo/info.xml +++ b/nextcloud-app/appinfo/info.xml @@ -28,7 +28,7 @@ AGPL ZeXtras - 0.8.23 + 0.8.26 ZimbraDrive auth integration @@ -41,8 +41,8 @@ zimbra.png - - + + diff --git a/nextcloud-app/lib/Migration/Version000826Date20230504093000.php b/nextcloud-app/lib/Migration/Version000826Date20230504093000.php new file mode 100644 index 0000000..897623f --- /dev/null +++ b/nextcloud-app/lib/Migration/Version000826Date20230504093000.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 { + } +} diff --git a/nextcloud-app/lib/auth/abstractzimbrausersbackend.php b/nextcloud-app/lib/auth/abstractzimbrausersbackend.php index 969a6a0..644d284 100644 --- a/nextcloud-app/lib/auth/abstractzimbrausersbackend.php +++ b/nextcloud-app/lib/auth/abstractzimbrausersbackend.php @@ -24,6 +24,12 @@ use OCA\ZimbraDrive\Settings\AppSettings; 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; +use OC\Accounts\Account; abstract class AbstractZimbraUsersBackend extends RetroCompatibleBackend { @@ -57,7 +63,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,8 +72,16 @@ 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 + $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() ); } @@ -99,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) @@ -110,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) @@ -144,54 +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 - { - $userData = $this->accountManager->getUser($user); - $userEmailAddress = $userData[AccountManager::PROPERTY_EMAIL]['value']; - } 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 - { - $userData = $this->accountManager->getUser($user); - $userData[AccountManager::PROPERTY_EMAIL]['value'] = $userEmail; - $this->accountManager->updateUser($user, $userData); - } 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 restoreUserDisplayNameIfChanged(User $user, $userDisplayName) + 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(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); } }