Skip to content

Commit

Permalink
fix(Felamimail/Account): make default account preference work
Browse files Browse the repository at this point in the history
... when another user deletes an account (for example the admin)
  • Loading branch information
pschuele committed Sep 26, 2024
1 parent c2d8fd0 commit 7f5dfb5
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions tine20/Felamimail/Controller/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,17 @@ protected function _updateDefaultAccountPreference($_accounts)
$usersWithPref = $pref->getUsersWithPref(Felamimail_Preference::DEFAULTACCOUNT, $account->getId());
foreach ($usersWithPref as $userId) {
$defaultAccountId = '';
if (Tinebase_Core::getUser()->getId() === $userId) {
// try to find fallback default account
$accounts = $this->search();
if (count($accounts) > 0) {
$systemAccount = $accounts->filter('type', Tinebase_EmailUser_Model_Account::TYPE_SYSTEM);
$defaultAccountId = count($systemAccount) > 0 ? $systemAccount->getFirstRecord()->getId() : $accounts->getFirstRecord()->getId();
}
// try to find fallback default account
$accounts = $this->_backend->search(Tinebase_Model_Filter_FilterGroup::getFilterForModel(
Felamimail_Model_Account::class, [
['field' => 'user_id', 'operator' => 'equals', 'value' => $userId]
], _options: ['ignoreAcl' => true]
));
if (count($accounts) > 0) {
$systemAccount = $accounts->filter('type', Tinebase_EmailUser_Model_Account::TYPE_SYSTEM);
$defaultAccountId = count($systemAccount) > 0
? $systemAccount->getFirstRecord()->getId()
: $accounts->getFirstRecord()->getId();
}

$pref->setValueForUser(Felamimail_Preference::DEFAULTACCOUNT, $defaultAccountId, $userId);
Expand Down

0 comments on commit 7f5dfb5

Please sign in to comment.