Skip to content

Commit b343b93

Browse files
committed
fix: load share properties from legacy shares
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent 70085a6 commit b343b93

1 file changed

Lines changed: 40 additions & 3 deletions

File tree

apps/files_sharing/lib/Sharing/LegacyBackend.php

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
use NCU\Sharing\ISharingManager;
1616
use NCU\Sharing\Permission\ISharePermissionType;
1717
use NCU\Sharing\Permission\SharePermission;
18+
use NCU\Sharing\Property\ISharePropertyType;
19+
use NCU\Sharing\Property\ShareProperty;
1820
use NCU\Sharing\Recipient\IShareRecipientType;
1921
use NCU\Sharing\Recipient\ShareRecipient;
2022
use NCU\Sharing\Share;
@@ -25,6 +27,7 @@
2527
use OC\Core\Sharing\Property\ExpirationDateSharePropertyType;
2628
use OC\Core\Sharing\Property\LabelSharePropertyType;
2729
use OC\Core\Sharing\Property\NoteSharePropertyType;
30+
use OC\Core\Sharing\Property\PasswordSharePropertyType;
2831
use OC\Core\Sharing\Recipient\EmailShareRecipientType;
2932
use OC\Core\Sharing\Recipient\GroupShareRecipientType;
3033
use OC\Core\Sharing\Recipient\TeamShareRecipientType;
@@ -361,8 +364,19 @@ public function getShare(string $id): Share {
361364
null,
362365
);
363366

364-
// TODO
365-
$properties = [];
367+
if (!$this->checkAllSame($legacyShares, fn (IShare $share) => $share->getExpirationDate())) {
368+
throw new \Exception('All legacy shares sharing a share id don\'t have the expiration date');
369+
}
370+
if (!$this->checkAllSame($legacyShares, fn (IShare $share) => $share->getPassword())) {
371+
throw new \Exception('All legacy shares sharing a share id don\'t have the password');
372+
}
373+
if (!$this->checkAllSame($legacyShares, fn (IShare $share) => $share->getLabel())) {
374+
throw new \Exception('All legacy shares sharing a share id don\'t have the label');
375+
}
376+
if (!$this->checkAllSame($legacyShares, fn (IShare $share) => $share->getNote())) {
377+
throw new \Exception('All legacy shares sharing a share id don\'t have the note');
378+
}
379+
$properties = $this->extractProperties($legacyShares[0]);
366380

367381
if (!$this->checkAllSame($legacyShares, fn (IShare $share) => $share->getAttributes())) {
368382
throw new \Exception('All legacy shares sharing a share id don\'t have the same attributes');
@@ -392,7 +406,7 @@ public function getShare(string $id): Share {
392406
$id,
393407
$owner,
394408
// TODO
395-
0,
409+
\DateTimeImmutable::createFromMutable($legacyShares[0]->getShareTime()),
396410
// TODO
397411
ShareState::Active,
398412
array_values($sources),
@@ -603,4 +617,27 @@ private function splitLegacySharedWith(int $shareType, string $sharedWith): arra
603617
];
604618
}
605619
}
620+
621+
/**
622+
* @param IShare $share
623+
* @return ShareProperty[]
624+
*/
625+
private function extractProperties(IShare $share): array {
626+
$properties = [];
627+
628+
if ($expire = $share->getExpirationDate()) {
629+
$properties[] = new ShareProperty(ExpirationDateSharePropertyType::class, $expire->format(DateTimeInterface::ATOM));
630+
}
631+
if ($password = $share->getPassword()) {
632+
$properties[] = new ShareProperty(PasswordSharePropertyType::class, $password);
633+
}
634+
if ($label = $share->getLabel()) {
635+
$properties[] = new ShareProperty(LabelSharePropertyType::class, $label);
636+
}
637+
if ($note = $share->getNote()) {
638+
$properties[] = new ShareProperty(NoteSharePropertyType::class, $note);
639+
}
640+
641+
return $properties;
642+
}
606643
}

0 commit comments

Comments
 (0)