Skip to content

Commit b0fe408

Browse files
Merge pull request #25927 from nextcloud/enh/sharebymail/set_expiration_on_creation
Sharebymail: set expiration on creation
2 parents 9da935c + d247a5f commit b0fe408

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

apps/sharebymail/lib/ShareByMailProvider.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,8 @@ protected function createMailShare(IShare $share) {
321321
$share->getToken(),
322322
$share->getPassword(),
323323
$share->getSendPasswordByTalk(),
324-
$share->getHideDownload()
324+
$share->getHideDownload(),
325+
$share->getExpirationDate()
325326
);
326327

327328
try {
@@ -658,9 +659,10 @@ public function getChildren(IShare $parent) {
658659
* @param string $password
659660
* @param bool $sendPasswordByTalk
660661
* @param bool $hideDownload
662+
* @param \DateTime|null $expirationTime
661663
* @return int
662664
*/
663-
protected function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token, $password, $sendPasswordByTalk, $hideDownload) {
665+
protected function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token, $password, $sendPasswordByTalk, $hideDownload, $expirationTime) {
664666
$qb = $this->dbConnection->getQueryBuilder();
665667
$qb->insert('share')
666668
->setValue('share_type', $qb->createNamedParameter(IShare::TYPE_EMAIL))
@@ -677,6 +679,10 @@ protected function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $
677679
->setValue('stime', $qb->createNamedParameter(time()))
678680
->setValue('hide_download', $qb->createNamedParameter((int)$hideDownload, IQueryBuilder::PARAM_INT));
679681

682+
if ($expirationTime !== null) {
683+
$qb->setValue('expiration', $qb->createNamedParameter($expirationTime, IQueryBuilder::PARAM_DATE));
684+
}
685+
680686
/*
681687
* Added to fix https://github.com/owncloud/core/issues/22215
682688
* Can be removed once we get rid of ajax/share.php

apps/sharebymail/tests/ShareByMailProviderTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ public function testAddShareToDB() {
524524
$password = 'password';
525525
$sendPasswordByTalk = true;
526526
$hideDownload = true;
527+
$expiration = new \DateTime();
527528

528529

529530
$instance = $this->getInstance();
@@ -540,7 +541,8 @@ public function testAddShareToDB() {
540541
$token,
541542
$password,
542543
$sendPasswordByTalk,
543-
$hideDownload
544+
$hideDownload,
545+
$expiration
544546
]
545547
);
546548

@@ -565,6 +567,7 @@ public function testAddShareToDB() {
565567
$this->assertSame($password, $result[0]['password']);
566568
$this->assertSame($sendPasswordByTalk, (bool)$result[0]['password_by_talk']);
567569
$this->assertSame($hideDownload, (bool)$result[0]['hide_download']);
570+
$this->assertSame($expiration->getTimestamp(), \DateTime::createFromFormat('Y-m-d H:i:s', $result[0]['expiration'])->getTimestamp());
568571
}
569572

570573
public function testUpdate() {

0 commit comments

Comments
 (0)