Merge pull request #62354 from nextcloud/fix/sharingbackend/modify-value-on-save-for-default-value

fix(SharingBackend): Call ISharePropertyTypeModifyValue::modifyValueOnSave when saving default value
pull/62360/head
Kate 1 month ago committed by GitHub
commit 4900913bb1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      apps/sharing/lib/SharingBackend.php
  2. 2
      lib/public/Sharing/Property/ISharePropertyType.php
  3. 58
      tests/lib/Sharing/AbstractSharingManagerTests.php
  4. 6
      tests/lib/Sharing/TestSharePropertyTypeModifyValue.php

@ -831,7 +831,7 @@ final readonly class SharingBackend implements ISharingBackend {
->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();

@ -73,6 +73,8 @@ interface ISharePropertyType {
*
* 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;

@ -1370,11 +1370,65 @@ abstract class AbstractSharingManagerTests extends TestCase {
$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();

@ -12,6 +12,12 @@ namespace Test\Sharing;
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') {

Loading…
Cancel
Save