diff --git a/apps/sharing/lib/SharingBackend.php b/apps/sharing/lib/SharingBackend.php index 93b3e59375c5c..28c65d3b081f0 100644 --- a/apps/sharing/lib/SharingBackend.php +++ b/apps/sharing/lib/SharingBackend.php @@ -831,7 +831,7 @@ private function list(ShareAccessContext $accessContext, ?string $filterShareID, ->values([ 'share_id' => $qb->createNamedParameter($id), 'property_class' => $qb->createNamedParameter($propertyTypeClass), - 'property_value' => $qb->createNamedParameter($value), + 'property_value' => $qb->createNamedParameter($propertyType instanceof ISharePropertyTypeModifyValue ? $propertyType->modifyValueOnSave(null, $value) : $value), ]) ->executeStatement(); diff --git a/lib/public/Sharing/Property/ISharePropertyType.php b/lib/public/Sharing/Property/ISharePropertyType.php index 3c978fb49de80..877a261c21e8a 100644 --- a/lib/public/Sharing/Property/ISharePropertyType.php +++ b/lib/public/Sharing/Property/ISharePropertyType.php @@ -73,6 +73,8 @@ public function isRequired(): bool; * * A default value must be returned, if {@see self::isRequired()} returns true. * + * If the class also implements {@see ISharePropertyTypeModifyValue}, {@see ISharePropertyTypeModifyValue::modifyValueOnSave()} will be called when the value is saved to the database, but the value will be returned to the user as-is. + * * @since 35.0.0 */ public function getDefaultValue(): ?string; diff --git a/tests/lib/Sharing/AbstractSharingManagerTests.php b/tests/lib/Sharing/AbstractSharingManagerTests.php index 27e32eaadb675..5479ef5648fe5 100644 --- a/tests/lib/Sharing/AbstractSharingManagerTests.php +++ b/tests/lib/Sharing/AbstractSharingManagerTests.php @@ -1370,11 +1370,65 @@ public function testUpdateSharePropertyModifyProperties(): void { $id = $this->manager->createShare($accessContext); $this->manager->addShareSource($accessContext, $id, new ShareSource(TestShareSourceType1::class, 'source1')); $this->manager->addShareRecipient($accessContext, $id, new ShareRecipient(TestShareRecipientType1::class, 'recipient1', null)); - $this->manager->getShare($accessContext, $id); - $this->manager->updateShareProperty($accessContext, $id, new ShareProperty(TestSharePropertyTypeModifyValue::class, 'old-value')); $this->dbConnection->commit(); + $share = $this->getShare($accessContext, $id); + $this->assertEquals([ + [ + 'class' => TestSharePropertyType1::class, + 'display_name' => 'TestSharePropertyType1', + 'hint' => 'hint TestSharePropertyType1', + 'priority' => 1, + 'advanced' => false, + 'required' => false, + 'value' => null, + 'type' => 'enum', + 'valid_values' => ['valid1'], + ], + [ + 'class' => TestSharePropertyTypeModifyValue::class, + 'display_name' => 'TestSharePropertyTypeModifyValue', + 'hint' => 'hint TestSharePropertyTypeModifyValue', + 'priority' => 1, + 'advanced' => false, + 'required' => false, + 'value' => 'modify-on-save', + 'type' => 'enum', + 'valid_values' => ['old-value', 'modify-on-save-old-value', 'modify-on-save', 'modify-on-load'], + ], + ], $share['properties']); + + $share = $this->getShare($accessContext, $id); + $this->assertEquals([ + [ + 'class' => TestSharePropertyType1::class, + 'display_name' => 'TestSharePropertyType1', + 'hint' => 'hint TestSharePropertyType1', + 'priority' => 1, + 'advanced' => false, + 'required' => false, + 'value' => null, + 'type' => 'enum', + 'valid_values' => ['valid1'], + ], + [ + 'class' => TestSharePropertyTypeModifyValue::class, + 'display_name' => 'TestSharePropertyTypeModifyValue', + 'hint' => 'hint TestSharePropertyTypeModifyValue', + 'priority' => 1, + 'advanced' => false, + 'required' => false, + 'value' => 'modified-on-save', + 'type' => 'enum', + 'valid_values' => ['old-value', 'modify-on-save-old-value', 'modify-on-save', 'modify-on-load'], + ], + ], $share['properties']); + + $this->dbConnection->beginTransaction(); + $this->manager->updateShareProperty($accessContext, $id, new ShareProperty(TestSharePropertyTypeModifyValue::class, 'old-value')); + $this->dbConnection->commit(); + $before = $this->manager->generateTimestamp(); $share = $this->updateShareProperty($accessContext, $id, new ShareProperty(TestSharePropertyTypeModifyValue::class, 'modify-on-save-old-value')); $after = $this->manager->generateTimestamp(); diff --git a/tests/lib/Sharing/TestSharePropertyTypeModifyValue.php b/tests/lib/Sharing/TestSharePropertyTypeModifyValue.php index b3ff114b671d6..1a784b1b271cd 100644 --- a/tests/lib/Sharing/TestSharePropertyTypeModifyValue.php +++ b/tests/lib/Sharing/TestSharePropertyTypeModifyValue.php @@ -12,6 +12,12 @@ use OCP\Sharing\Property\ISharePropertyTypeModifyValue; final class TestSharePropertyTypeModifyValue extends TestSharePropertyType1 implements ISharePropertyTypeModifyValue { + + #[\Override] + public function getDefaultValue(): string { + return 'modify-on-save'; + } + #[\Override] public function modifyValueOnSave(?string $oldValue, ?string $newValue): ?string { if ($newValue === 'modify-on-save') {