From 001263f3ec885401ea9141fbfe80903fafa2a4e4 Mon Sep 17 00:00:00 2001 From: Julius Knorr Date: Fri, 23 May 2025 15:48:50 +0200 Subject: [PATCH 1/2] fix: Handle share attributes in the share provider Signed-off-by: Julius Knorr --- lib/Sharing/DeckShareProvider.php | 54 ++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/lib/Sharing/DeckShareProvider.php b/lib/Sharing/DeckShareProvider.php index 8dc8e02f7..90d22976d 100644 --- a/lib/Sharing/DeckShareProvider.php +++ b/lib/Sharing/DeckShareProvider.php @@ -32,6 +32,7 @@ use OCP\IL10N; use OCP\Share\Exceptions\GenericShareException; use OCP\Share\Exceptions\ShareNotFound; +use OCP\Share\IAttributes; use OCP\Share\IManager; use OCP\Share\IShare; @@ -113,6 +114,11 @@ public function create(IShare $share) { ) );*/ + // set share attributes + $shareAttributes = $this->formatShareAttributes( + $share->getAttributes() + ); + $shareId = $this->addShareToDB( $share->getSharedWith(), $share->getSharedBy(), @@ -122,7 +128,8 @@ public function create(IShare $share) { $share->getTarget(), $share->getPermissions(), $share->getToken() ?? '', - $share->getExpirationDate() + $share->getExpirationDate(), + $shareAttributes ); $data = $this->getRawShare($shareId); @@ -143,6 +150,7 @@ public function create(IShare $share) { * @param int $permissions * @param string $token * @param \DateTime|null $expirationDate + * @param string|null $attributes * @return int */ private function addShareToDB( @@ -155,6 +163,7 @@ private function addShareToDB( int $permissions, string $token, ?\DateTime $expirationDate, + ?string $attributes = null, ): int { $qb = $this->dbConnection->getQueryBuilder(); $qb->insert('share') @@ -174,6 +183,10 @@ private function addShareToDB( $qb->setValue('expiration', $qb->createNamedParameter($expirationDate, 'datetime')); } + if ($attributes !== null) { + $qb->setValue('attributes', $qb->createNamedParameter($attributes)); + } + $qb->executeStatement(); return $qb->getLastInsertId(); @@ -244,6 +257,9 @@ private function createShareObject(array $data): IShare { $entryData['parent'] = $entryData['f_parent']; $share->setNodeCacheEntry(Cache::cacheEntryFromData($entryData, $this->mimeTypeLoader)); } + + $share = $this->updateShareAttributes($share, $data['attributes'] ?? null); + return $share; } @@ -1026,6 +1042,42 @@ public function getAllShares(): iterable { $cursor->closeCursor(); } + protected function updateShareAttributes(IShare $share, ?string $data): IShare { + if ($data !== null && $data !== '') { + $attributes = $share->getAttributes() ?? $share->newAttributes(); + $compressedAttributes = \json_decode($data, true); + if ($compressedAttributes === false || $compressedAttributes === null) { + return $share; + } + foreach ($compressedAttributes as $compressedAttribute) { + $attributes->setAttribute( + $compressedAttribute[0], + $compressedAttribute[1], + $compressedAttribute[2] + ); + } + $share->setAttributes($attributes); + } + + return $share; + } + + protected function formatShareAttributes(?IAttributes $attributes): ?string { + if ($attributes === null || empty($attributes->toArray())) { + return null; + } + + $compressedAttributes = []; + foreach ($attributes->toArray() as $attribute) { + $compressedAttributes[] = [ + 0 => $attribute['scope'], + 1 => $attribute['key'], + 2 => $attribute['value'] + ]; + } + return \json_encode($compressedAttributes) ?: null; + } + public function getOrphanedAttachmentShares(): array { $allCardIds = $this->cardMapper->getAllCardIds(); From 4e5dfe1708840033bb6daa1f66596b656fc1b92a Mon Sep 17 00:00:00 2001 From: grnd-alt Date: Tue, 24 Feb 2026 14:29:07 +0100 Subject: [PATCH 2/2] chore: wrap share updates in transaction Signed-off-by: grnd-alt [skip ci] --- lib/Sharing/DeckShareProvider.php | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/Sharing/DeckShareProvider.php b/lib/Sharing/DeckShareProvider.php index 90d22976d..c4841613b 100644 --- a/lib/Sharing/DeckShareProvider.php +++ b/lib/Sharing/DeckShareProvider.php @@ -1043,22 +1043,22 @@ public function getAllShares(): iterable { } protected function updateShareAttributes(IShare $share, ?string $data): IShare { - if ($data !== null && $data !== '') { - $attributes = $share->getAttributes() ?? $share->newAttributes(); - $compressedAttributes = \json_decode($data, true); - if ($compressedAttributes === false || $compressedAttributes === null) { - return $share; - } - foreach ($compressedAttributes as $compressedAttribute) { - $attributes->setAttribute( - $compressedAttribute[0], - $compressedAttribute[1], - $compressedAttribute[2] - ); - } - $share->setAttributes($attributes); + if ($data === null || $data === '') { + return $share; } - + $attributes = $share->getAttributes() ?? $share->newAttributes(); + $compressedAttributes = \json_decode($data, true); + if ($compressedAttributes === false || $compressedAttributes === null) { + return $share; + } + foreach ($compressedAttributes as $compressedAttribute) { + $attributes->setAttribute( + $compressedAttribute[0], + $compressedAttribute[1], + $compressedAttribute[2] + ); + } + $share->setAttributes($attributes); return $share; }