Skip to content

Commit 82cec44

Browse files
committed
fixup! feat: add delegation backend
Signed-off-by: Hamza <hamzamahjoubi221@gmail.com>
1 parent 70aa887 commit 82cec44

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

lib/Controller/AccountsController.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,18 @@ public function index(): JSONResponse {
9898
foreach ($mailAccounts as $mailAccount) {
9999
$conf = $mailAccount->jsonSerialize();
100100
$conf['aliases'] = $this->aliasesService->findAll($conf['accountId'], $this->currentUserId);
101+
$conf['isDelegated'] = false;
101102
$json[] = $conf;
102103
}
104+
105+
$delegatedAccounts = $this->accountService->findDelegatedAccounts($this->currentUserId);
106+
foreach ($delegatedAccounts as $delegatedAccount) {
107+
$conf = $delegatedAccount->jsonSerialize();
108+
$conf['isDelegated'] = true;
109+
$conf['aliases'] = $this->aliasesService->findAll($conf['accountId'], $delegatedAccount->getUserId());
110+
$json[] = $conf;
111+
}
112+
103113
return new JSONResponse($json);
104114
}
105115

lib/Service/AccountService.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use OCA\Mail\BackgroundJob\RepairSyncJob;
1818
use OCA\Mail\BackgroundJob\SyncJob;
1919
use OCA\Mail\BackgroundJob\TrainImportanceClassifierJob;
20+
use OCA\Mail\Db\DelegationMapper;
2021
use OCA\Mail\Db\MailAccount;
2122
use OCA\Mail\Db\MailAccountMapper;
2223
use OCA\Mail\Exception\ClientException;
@@ -56,6 +57,7 @@ public function __construct(
5657
IMAPClientFactory $imapClientFactory,
5758
private readonly IConfig $config,
5859
private readonly ITimeFactory $timeFactory,
60+
private DelegationMapper $delegationMapper,
5961
) {
6062
$this->mapper = $mapper;
6163
$this->aliasesService = $aliasesService;
@@ -75,6 +77,23 @@ public function findByUserId(string $currentUserId): array {
7577
return $this->accounts[$currentUserId];
7678
}
7779

80+
/**
81+
* @param string $userId
82+
* @return list<Account>
83+
*/
84+
public function findDelegatedAccounts(string $userId): array {
85+
$delegations = $this->delegationMapper->findDelegatedAccountsForUser($userId);
86+
$accounts = [];
87+
foreach ($delegations as $delegation) {
88+
try {
89+
$accounts[] = new Account($this->mapper->findById($delegation->getAccountId()));
90+
} catch (DoesNotExistException) {
91+
// Account was deleted but delegation record remains — skip
92+
}
93+
}
94+
return $accounts;
95+
}
96+
7897
/**
7998
* @param int $id
8099
*

0 commit comments

Comments
 (0)