From 1ab748ab61a973d54a72b5c36c08e63458b9e4f0 Mon Sep 17 00:00:00 2001 From: grnd-alt Date: Wed, 8 Apr 2026 11:43:50 +0200 Subject: [PATCH] fix: Handle share attributes in the share provider Signed-off-by: grnd-alt --- lib/Sharing/DeckShareProvider.php | 85 +++++++++++++++++++++++++++---- 1 file changed, 76 insertions(+), 9 deletions(-) diff --git a/lib/Sharing/DeckShareProvider.php b/lib/Sharing/DeckShareProvider.php index b71c3f7182..2e0c1fc73a 100644 --- a/lib/Sharing/DeckShareProvider.php +++ b/lib/Sharing/DeckShareProvider.php @@ -29,7 +29,6 @@ use OC\Files\Cache\Cache; use OCA\Deck\Cache\AttachmentCacheHelper; use OCA\Deck\Db\Acl; -use OCA\Deck\Db\Board; use OCA\Deck\Db\BoardMapper; use OCA\Deck\Db\CardMapper; use OCA\Deck\Db\User; @@ -48,6 +47,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; @@ -150,6 +150,11 @@ public function create(IShare $share) { ) );*/ + // set share attributes + $shareAttributes = $this->formatShareAttributes( + $share->getAttributes() + ); + $shareId = $this->addShareToDB( $share->getSharedWith(), $share->getSharedBy(), @@ -159,7 +164,8 @@ public function create(IShare $share) { $share->getTarget(), $share->getPermissions(), $share->getToken() ?? '', - $share->getExpirationDate() + $share->getExpirationDate(), + $shareAttributes ); $data = $this->getRawShare($shareId); @@ -180,6 +186,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( @@ -191,7 +198,8 @@ private function addShareToDB( string $target, int $permissions, string $token, - ?\DateTime $expirationDate + ?\DateTime $expirationDate, + ?string $attributes = null ): int { $qb = $this->dbConnection->getQueryBuilder(); $qb->insert('share') @@ -211,6 +219,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(); @@ -281,6 +293,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; } @@ -312,8 +327,14 @@ public function update(IShare $share) { ->set('permissions', $qb->createNamedParameter($share->getPermissions())) ->set('item_source', $qb->createNamedParameter($share->getNode()->getId())) ->set('file_source', $qb->createNamedParameter($share->getNode()->getId())) - ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) - ->execute(); + ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)); + + $shareAttributes = $this->formatShareAttributes($share->getAttributes()); + if ($shareAttributes !== null) { + $qb->set('attributes', $qb->createNamedParameter($shareAttributes)); + } + + $qb->execute(); /* * Update all user defined group shares @@ -325,8 +346,14 @@ public function update(IShare $share) { ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) ->set('item_source', $qb->createNamedParameter($share->getNode()->getId())) ->set('file_source', $qb->createNamedParameter($share->getNode()->getId())) - ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) - ->execute(); + ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)); + + + if ($shareAttributes !== null) { + $qb->set('attributes', $qb->createNamedParameter($shareAttributes)); + } + + $qb->execute(); /* * Now update the permissions for all children that have not set it to 0 @@ -335,12 +362,52 @@ public function update(IShare $share) { $qb->update('share') ->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))) ->andWhere($qb->expr()->neq('permissions', $qb->createNamedParameter(0))) - ->set('permissions', $qb->createNamedParameter($share->getPermissions())) - ->execute(); + ->set('permissions', $qb->createNamedParameter($share->getPermissions())); + + if ($shareAttributes !== null) { + $qb->set('attributes', $qb->createNamedParameter($shareAttributes)); + } + $qb->execute(); return $share; } + protected function updateShareAttributes(IShare $share, ?string $data): IShare { + 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; + } + + 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; + } + /** * @inheritDoc */