Skip to content

Commit 72e2c0a

Browse files
committed
Save expiration date for federated share when passed over API
Fixes issue that the UI checkbox for expiration date was not being saved for federated shares. Signed-off-by: Vincent Petry <vincent@nextcloud.com>
1 parent 2f074d7 commit 72e2c0a

2 files changed

Lines changed: 15 additions & 8 deletions

File tree

apps/federatedfilesharing/lib/FederatedShareProvider.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ public function create(IShare $share) {
173173
$permissions = $share->getPermissions();
174174
$sharedBy = $share->getSharedBy();
175175
$shareType = $share->getShareType();
176+
$expirationDate = $share->getExpirationDate();
176177

177178
if ($shareType === IShare::TYPE_REMOTE_GROUP &&
178179
!$this->isOutgoingServer2serverGroupShareEnabled()
@@ -219,7 +220,7 @@ public function create(IShare $share) {
219220
if ($remoteShare) {
220221
try {
221222
$ownerCloudId = $this->cloudIdManager->getCloudId($remoteShare['owner'], $remoteShare['remote']);
222-
$shareId = $this->addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $ownerCloudId->getId(), $permissions, 'tmp_token_' . time(), $shareType);
223+
$shareId = $this->addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $ownerCloudId->getId(), $permissions, 'tmp_token_' . time(), $shareType, $expirationDate);
223224
$share->setId($shareId);
224225
list($token, $remoteId) = $this->askOwnerToReShare($shareWith, $share, $shareId);
225226
// remote share was create successfully if we get a valid token as return
@@ -264,7 +265,8 @@ protected function createFederatedShare(IShare $share) {
264265
$share->getShareOwner(),
265266
$share->getPermissions(),
266267
$token,
267-
$share->getShareType()
268+
$share->getShareType(),
269+
$share->getExpirationDate()
268270
);
269271

270272
$failure = false;
@@ -370,9 +372,10 @@ protected function getShareFromExternalShareTable(IShare $share) {
370372
* @param int $permissions
371373
* @param string $token
372374
* @param int $shareType
375+
* @param \DateTime $expirationDate
373376
* @return int
374377
*/
375-
private function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token, $shareType) {
378+
private function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token, $shareType, $expirationDate) {
376379
$qb = $this->dbConnection->getQueryBuilder();
377380
$qb->insert('share')
378381
->setValue('share_type', $qb->createNamedParameter($shareType))
@@ -383,6 +386,7 @@ private function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $ui
383386
->setValue('uid_owner', $qb->createNamedParameter($uidOwner))
384387
->setValue('uid_initiator', $qb->createNamedParameter($sharedBy))
385388
->setValue('permissions', $qb->createNamedParameter($permissions))
389+
->setValue('expiration', $qb->createNamedParameter($expirationDate, IQueryBuilder::PARAM_DATE))
386390
->setValue('token', $qb->createNamedParameter($token))
387391
->setValue('stime', $qb->createNamedParameter(time()));
388392

@@ -414,6 +418,7 @@ public function update(IShare $share) {
414418
->set('permissions', $qb->createNamedParameter($share->getPermissions()))
415419
->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
416420
->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
421+
->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE))
417422
->execute();
418423

419424
// send the updated permission to the owner/initiator, if they are not the same

lib/private/Share20/Manager.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -979,15 +979,17 @@ public function updateShare(IShare $share) {
979979
$this->validateExpirationDate($share);
980980
$expirationDateUpdated = true;
981981
}
982-
} elseif ($share->getShareType() === IShare::TYPE_LINK) {
982+
} elseif ($share->getShareType() === IShare::TYPE_LINK || $share->getShareType() === IShare::TYPE_REMOTE) {
983983
$this->linkCreateChecks($share);
984984

985-
$plainTextPassword = $share->getPassword();
985+
if ($share->getShareType() === IShare::TYPE_LINK) {
986+
$plainTextPassword = $share->getPassword();
986987

987-
$this->updateSharePasswordIfNeeded($share, $originalShare);
988+
$this->updateSharePasswordIfNeeded($share, $originalShare);
988989

989-
if (empty($plainTextPassword) && $share->getSendPasswordByTalk()) {
990-
throw new \InvalidArgumentException('Can’t enable sending the password by Talk with an empty password');
990+
if (empty($plainTextPassword) && $share->getSendPasswordByTalk()) {
991+
throw new \InvalidArgumentException('Can’t enable sending the password by Talk with an empty password');
992+
}
991993
}
992994

993995
if ($share->getExpirationDate() != $originalShare->getExpirationDate()) {

0 commit comments

Comments
 (0)