Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/sharing/lib/SharingBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 2 additions & 0 deletions lib/public/Sharing/Property/ISharePropertyType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
58 changes: 56 additions & 2 deletions tests/lib/Sharing/AbstractSharingManagerTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 6 additions & 0 deletions tests/lib/Sharing/TestSharePropertyTypeModifyValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
Loading