Skip to content
This repository has been archived by the owner on Dec 27, 2023. It is now read-only.

Commit

Permalink
Merge branch '2021.11' into 2022.11
Browse files Browse the repository at this point in the history
  • Loading branch information
pschuele committed May 12, 2022
2 parents b9fa27e + 0b7f71b commit 49ecc16
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 18 deletions.
41 changes: 26 additions & 15 deletions tests/tine20/Admin/Frontend/Json/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @package Admin
* @license http://www.gnu.org/licenses/agpl.html
* @copyright Copyright (c) 2008-2020 Metaways Infosystems GmbH (http://www.metaways.de)
* @copyright Copyright (c) 2008-2022 Metaways Infosystems GmbH (http://www.metaways.de)
* @author Philipp Schüle <p.schuele@metaways.de>
*/

Expand Down Expand Up @@ -161,13 +161,13 @@ public function testSaveAccountWithExistingName()

try {
$account = $this->_json->saveUser($accountData);
$this->fail('Updating an account with existing login name should throw exception: ' . print_r($account, TRUE));
self::fail('Updating an account with existing login name should throw exception: ' . print_r($account, TRUE));
} catch (Tinebase_Exception_SystemGeneric $tesg) {
$this->assertEquals('Login name already exists. Please choose another one.', $tesg->getMessage());
self::assertEquals('Login name already exists. Please choose another one.', $tesg->getMessage());
}
}

public function testSaveAccountWithoutEmail()
public function testSaveAccountWithAndWithoutEmail()
{
$this->_skipWithoutEmailSystemAccountConfig();

Expand All @@ -187,20 +187,31 @@ public function testSaveAccountWithoutEmail()
$accountData['emailUser'] = $emailUser;
$accountData['accountEmailAddress'] = null;
$account = $this->_json->saveUser($accountData);

self::assertEmpty($account['accountEmailAddress']);

$filter = Tinebase_Model_Filter_FilterGroup::getFilterForModel(Felamimail_Model_Account::class, [
['field' => 'user_id', 'operator' => 'equals', 'value' => $account['accountId']]
]);
$emailAccounts = Admin_Controller_EmailAccount::getInstance()->search($filter);
// remove instance to prevent acl pollution
Admin_Controller_EmailAccount::destroyInstance();
self::assertCount(0, $emailAccounts,'empty mail account created: ' . print_r($emailAccounts->toArray(), true));

// assert no email account has been created
self::assertFalse(isset($account['xprops'][Tinebase_Model_FullUser::XPROP_EMAIL_USERID_IMAP]), 'imap user found!');
self::assertFalse(isset($account['xprops'][Tinebase_Model_FullUser::XPROP_EMAIL_USERID_SMTP]), 'smtp user found!');
self::assertEmpty($account['accountEmailAddress']);

if (Tinebase_Application::getInstance()->isInstalled('Felamimail')) {
$filter = Tinebase_Model_Filter_FilterGroup::getFilterForModel(Felamimail_Model_Account::class, [
['field' => 'user_id', 'operator' => 'equals', 'value' => $account['accountId']]
]);
$emailAccounts = Admin_Controller_EmailAccount::getInstance()->search($filter);
// remove instance to prevent acl pollution
Admin_Controller_EmailAccount::destroyInstance();
self::assertCount(0, $emailAccounts, 'empty mail account created: ' . print_r($emailAccounts->toArray(), true));

// add email address -> accounts should be created
$account['accountEmailAddress'] = $account['accountLoginName'] . '@' . TestServer::getPrimaryMailDomain();
$account['accountPassword'] = Tinebase_Record_Abstract::generateUID('20');
$account = $this->_json->saveUser($account);
self::assertTrue(isset($account['xprops'][Tinebase_Model_FullUser::XPROP_EMAIL_USERID_IMAP]), 'imap user not found!');
self::assertTrue(isset($account['xprops'][Tinebase_Model_FullUser::XPROP_EMAIL_USERID_SMTP]), 'smtp user not found!');
$emailAccounts = Admin_Controller_EmailAccount::getInstance()->search($filter);
// remove instance to prevent acl pollution
Admin_Controller_EmailAccount::destroyInstance();
self::assertCount(1, $emailAccounts);
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tine20/Admin/Controller/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ public function update(Tinebase_Model_FullUser $_user, $_password = null, $_pass
}
$this->_checkLoginNameLength($_user);
$this->_checkPrimaryGroupExistance($_user);
$deactivated = false;

$this->_checkSystemEmailAccountCreation($_user, $oldUser, $_password);
$this->_checkSystemEmailAccountDuplicate($_user, $oldUser);
Expand Down Expand Up @@ -256,6 +255,7 @@ public function update(Tinebase_Model_FullUser $_user, $_password = null, $_pass
$event = new Admin_Event_UpdateAccount;
$event->account = $user;
$event->oldAccount = $oldUser;
$event->pwd = $_password;
Tinebase_Event::fireEvent($event);

if (!empty($_password) && !empty($_passwordRepeat)) {
Expand Down
2 changes: 2 additions & 0 deletions tine20/Admin/Event/UpdateAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ class Admin_Event_UpdateAccount extends Tinebase_Event_Abstract
* @var Tinebase_Model_FullUser
*/
public $oldAccount;

public $pwd;
}
2 changes: 1 addition & 1 deletion tine20/Felamimail/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ protected function _handleEvent(Tinebase_Event_Abstract $_eventObject)
if (Tinebase_Config::getInstance()->{Tinebase_Config::IMAP}
->{Tinebase_Config::IMAP_USE_SYSTEM_ACCOUNT}) {
Felamimail_Controller_Account::getInstance()->updateSystemAccount(
$_eventObject->account, $_eventObject->oldAccount);
$_eventObject->account, $_eventObject->oldAccount, $_eventObject->pwd);
}
break;
case Tinebase_Event_User_DeleteAccount::class:
Expand Down
6 changes: 5 additions & 1 deletion tine20/Felamimail/Controller/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -2219,10 +2219,11 @@ public static function getVisibleAccountsFilterForUser($user = null)
/**
* @param Tinebase_Model_FullUser $user
* @param Tinebase_Model_FullUser $oldUser
* @param ?string $pwd
* @throws Tinebase_Exception_AccessDenied
* @throws Tinebase_Exception_InvalidArgument
*/
public function updateSystemAccount(Tinebase_Model_FullUser $user, Tinebase_Model_FullUser $oldUser)
public function updateSystemAccount(Tinebase_Model_FullUser $user, Tinebase_Model_FullUser $oldUser, ?string $pwd = null)
{
$checks = Felamimail_Controller_Account::getInstance()->doContainerACLChecks(false);
$systemaccount = null;
Expand All @@ -2242,6 +2243,9 @@ public function updateSystemAccount(Tinebase_Model_FullUser $user, Tinebase_Mode
$systemaccount->name = $user->accountEmailAddress;
$updateSystemAccount = true;
}
if (! $systemaccount && !empty($user->accountEmailAddress)) {
$this->createSystemAccount($user, $pwd);
}
}

if ($updateSystemAccount) {
Expand Down

0 comments on commit 49ecc16

Please sign in to comment.