44
55/**
66 * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
7- * SPDX-License-Identifier: AGPL-3.0-only
7+ * SPDX-License-Identifier: AGPL-3.0-or-later
88 */
99
1010namespace OCA \Mail \Service ;
1111
12+ use OCA \Mail \Db \Delegation ;
13+ use OCA \Mail \Db \DelegationMapper ;
1214use OCP \AppFramework \Db \DoesNotExistException ;
1315use Psr \Log \LoggerInterface ;
14- use OCA \Mail \Db \Delegation ;
15- use OCA \Mail \Db \DelegationMapper ;
1616
1717class DelegationService {
1818
19-
20- public function __construct (
21- private DelegationMapper $ delegationMapper ,
22- private LoggerInterface $ logger
23- ){}
24-
25- public function delegate (int $ accountId , string $ userId ){
26- $ delegation = new Delegation ();
27- $ delegation ->setAccountId ($ accountId );
28- $ delegation ->setUserId ($ userId );
29- $ this ->delegationMapper ->insert ($ delegation );
30- }
31-
32- public function findDelgatedAccountForUser (string $ userId ): array {
33- return $ this ->delegationMapper ->findDelegatedAccountsForUser ($ userId );
34- }
35-
36- public function findDelegatedToUsersForAccount (string $ accountId ): array {
37- return $ this ->delegationMapper ->findDelegatedToUsers ($ accountId );
38- }
39-
40- public function unDelegate (int $ accountId , string $ userId ) {
41- try {
42- $ delegation = $ this ->delegationMapper ->find ($ accountId ,$ userId );
43-
44- } catch (DoesNotExistException $ e ) {
45- $ this ->logger ->warning ("Delegation of account: $ accountId not found for user: $ userId " , ['exception ' => $ e ]);
46- }
47- if ( !$ delegation ){
48- return ;
49- }
50- $ this ->delegationMapper ->delete ($ delegation );
51-
52- }
53-
54- }
19+ public function __construct (
20+ private DelegationMapper $ delegationMapper ,
21+ private LoggerInterface $ logger ,
22+ ) {
23+ }
24+
25+ public function delegate (int $ accountId , string $ userId ): void {
26+ $ delegation = new Delegation ();
27+ $ delegation ->setAccountId ($ accountId );
28+ $ delegation ->setUserId ($ userId );
29+ $ this ->delegationMapper ->insert ($ delegation );
30+ }
31+
32+ public function findDelegatedAccountForUser (string $ userId ): array {
33+ return $ this ->delegationMapper ->findDelegatedAccountsForUser ($ userId );
34+ }
35+
36+ public function findDelegatedToUsersForAccount (string $ accountId ): array {
37+ return $ this ->delegationMapper ->findDelegatedToUsers ($ accountId );
38+ }
39+
40+ public function unDelegate (int $ accountId , string $ userId ): void {
41+ try {
42+ $ delegation = $ this ->delegationMapper ->find ($ accountId , $ userId );
43+ } catch (DoesNotExistException $ e ) {
44+ $ this ->logger ->warning ("Delegation of account: $ accountId not found for user: $ userId " , ['exception ' => $ e ]);
45+ return ;
46+ }
47+ $ this ->delegationMapper ->delete ($ delegation );
48+ }
49+ }
0 commit comments