1010namespace OCA \Deck \ShareReview ;
1111
1212use OCA \Deck \Db \Acl ;
13+ use OCA \Deck \Db \AclMapper ;
1314use OCA \Deck \Service \BoardService ;
1415use OCA \ShareReview \Sources \ISource ;
1516use OCP \AppFramework \Db \DoesNotExistException ;
1617use OCP \Constants ;
1718use OCP \DB \Exception ;
18- use OCP \DB \QueryBuilder \IQueryBuilder ;
1919use OCP \EventDispatcher \IEventDispatcher ;
20- use OCP \IDBConnection ;
20+ use OCP \IL10N ;
2121use OCP \Share \IShare ;
2222use Psr \Log \LoggerInterface ;
2323
2424class ShareReviewSource implements ISource {
2525
26- private const ACL_TABLE = 'deck_board_acl ' ;
27- private const BOARDS_TABLE = 'deck_boards ' ;
2826 private const PERMISSION_MANAGE = 32 ;
2927
3028 public function __construct (
31- private IDBConnection $ db ,
32- private LoggerInterface $ logger ,
29+ private readonly AclMapper $ aclMapper ,
30+ private readonly LoggerInterface $ logger ,
3331 private readonly BoardService $ boardService ,
3432 private readonly IEventDispatcher $ eventDispatcher ,
33+ private readonly IL10N $ l ,
3534 ) {
3635 }
3736
@@ -40,27 +39,19 @@ public function getName(): string {
4039 }
4140
4241 /**
43- * @return list<array{id: int, app: string, object: string, initiator: string, type: int, recipient: string, permissions: int, password: bool, time: string, action: string}>
42+ * @return list<array{id: int, object: string, initiator: string, type: int, recipient: string, permissions: int, password: bool, time: string, action: string}>
4443 */
4544 public function getShares (): array {
46- $ rawShares = $ this ->fetchAllShares ();
47- $ appName = $ this ->getName ();
48- $ formatted = [];
49- foreach ($ rawShares as $ share ) {
50- $ formatted [] = [
51- 'id ' => (int )$ share ['id ' ],
52- 'app ' => $ appName ,
53- 'object ' => $ this ->resolveObjectName ($ share ),
54- 'initiator ' => (string )$ share ['board_owner ' ],
55- 'type ' => $ this ->mapParticipantType ((int )$ share ['type ' ]),
56- 'recipient ' => (string )$ share ['participant ' ],
57- 'permissions ' => $ this ->computePermissions ($ share ),
58- 'password ' => false ,
59- 'time ' => date ('Y-m-d H:i:s ' , max ((int )$ share ['created_at ' ], (int )$ share ['last_modified_at ' ])),
60- 'action ' => '' ,
61- ];
45+ try {
46+ $ rawShares = $ this ->aclMapper ->findAllForShareReview ();
47+ } catch (Exception $ e ) {
48+ $ this ->logger ->error ('Deck ShareReview: failed to fetch shares: {message} ' , ['message ' => $ e ->getMessage ()]);
49+ return [];
6250 }
63- return $ formatted ;
51+ return array_map (
52+ fn (array $ share ) => $ this ->buildShare ($ share )->toArray (),
53+ $ rawShares ,
54+ );
6455 }
6556
6657 public function deleteShare (string $ shareId ): bool {
@@ -76,41 +67,32 @@ public function deleteShare(string $shareId): bool {
7667 }
7768
7869 try {
79- $ this ->boardService ->deleteAclForShareReview ((int ) $ shareId );
70+ $ this ->boardService ->deleteAclForShareReview ((int )$ shareId );
8071 return true ;
8172 } catch (DoesNotExistException ) {
8273 return false ;
8374 }
8475 }
8576
86- /** @return list<array<string, mixed>> */
87- private function fetchAllShares (): array {
88- try {
89- $ qb = $ this ->db ->getQueryBuilder ();
90- $ qb ->select (
91- 'a.id ' , 'a.board_id ' , 'a.type ' , 'a.participant ' ,
92- 'a.permission_edit ' , 'a.permission_share ' , 'a.permission_manage ' , 'a.created_at ' , 'a.last_modified_at '
93- )
94- ->selectAlias ('b.title ' , 'board_title ' )
95- ->selectAlias ('b.owner ' , 'board_owner ' )
96- ->from (self ::ACL_TABLE , 'a ' )
97- ->leftJoin ('a ' , self ::BOARDS_TABLE , 'b ' , $ qb ->expr ()->eq ('a.board_id ' , 'b.id ' ))
98- ->orderBy ('a.id ' , 'ASC ' );
99- $ result = $ qb ->executeQuery ();
100- $ rows = $ result ->fetchAll ();
101- $ result ->closeCursor ();
102- return $ rows ;
103- } catch (Exception $ e ) {
104- $ this ->logger ->error ('Deck ShareReview: failed to fetch shares: {message} ' , ['message ' => $ e ->getMessage ()]);
105- return [];
106- }
77+ /** @param array<string, mixed> $share */
78+ private function buildShare (array $ share ): ShareReviewShare {
79+ return new ShareReviewShare (
80+ id: (int )$ share ['id ' ],
81+ object: $ this ->resolveObjectName ($ share ),
82+ initiator: (string )$ share ['board_owner ' ],
83+ type: $ this ->mapParticipantType ((int )$ share ['type ' ]),
84+ recipient: (string )$ share ['participant ' ],
85+ permissions: $ this ->computePermissions ($ share ),
86+ time: date ('Y-m-d H:i:s ' , max ((int )$ share ['created_at ' ], (int )$ share ['last_modified_at ' ])),
87+ );
10788 }
10889
10990 /** @param array<string, mixed> $share */
11091 private function resolveObjectName (array $ share ): string {
11192 $ title = (string )($ share ['board_title ' ] ?? '' );
11293 $ boardId = (int )($ share ['board_id ' ] ?? $ share ['id ' ]);
113- return ($ title !== '' ? $ title : "Board $ boardId " ) . ' (Board) ' ;
94+ $ label = $ title !== '' ? $ title : $ this ->l ->t ('Board %d ' , [$ boardId ]);
95+ return $ this ->l ->t ('%s (Board) ' , [$ label ]);
11496 }
11597
11698 private function mapParticipantType (int $ type ): int {
@@ -119,10 +101,15 @@ private function mapParticipantType(int $type): int {
119101 Acl::PERMISSION_TYPE_GROUP => IShare::TYPE_GROUP ,
120102 Acl::PERMISSION_TYPE_REMOTE => IShare::TYPE_REMOTE ,
121103 Acl::PERMISSION_TYPE_CIRCLE => IShare::TYPE_CIRCLE ,
122- default => IShare:: TYPE_USER ,
104+ default => $ this -> fallbackParticipantType ( $ type ) ,
123105 };
124106 }
125107
108+ private function fallbackParticipantType (int $ type ): int {
109+ $ this ->logger ->warning ('Deck ShareReview: unknown ACL participant type {type}, defaulting to user share ' , ['type ' => $ type ]);
110+ return IShare::TYPE_USER ;
111+ }
112+
126113 /** @param array<string, mixed> $share */
127114 private function computePermissions (array $ share ): int {
128115 $ permissions = Constants::PERMISSION_READ ;
0 commit comments