]> source.dussan.org Git - nextcloud-server.git/commitdiff
Sharebymail: set expiration on creation 25938/head
authorRoeland Jago Douma <roeland@famdouma.nl>
Thu, 4 Mar 2021 12:49:21 +0000 (13:49 +0100)
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>
Thu, 4 Mar 2021 18:52:43 +0000 (18:52 +0000)
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
apps/sharebymail/lib/ShareByMailProvider.php
apps/sharebymail/tests/ShareByMailProviderTest.php

index 5977cbd18bb195cf961d831ae213dbdb8a2a5241..6ac75ce85d9f9d86324e9319a7af5e53d7d01ad3 100644 (file)
@@ -321,7 +321,8 @@ class ShareByMailProvider implements IShareProvider {
                        $share->getToken(),
                        $share->getPassword(),
                        $share->getSendPasswordByTalk(),
-                       $share->getHideDownload()
+                       $share->getHideDownload(),
+                       $share->getExpirationDate()
                );
 
                try {
@@ -649,9 +650,10 @@ class ShareByMailProvider implements IShareProvider {
         * @param string $password
         * @param bool $sendPasswordByTalk
         * @param bool $hideDownload
+        * @param \DateTime|null $expirationTime
         * @return int
         */
-       protected function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token, $password, $sendPasswordByTalk, $hideDownload) {
+       protected function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token, $password, $sendPasswordByTalk, $hideDownload, $expirationTime) {
                $qb = $this->dbConnection->getQueryBuilder();
                $qb->insert('share')
                        ->setValue('share_type', $qb->createNamedParameter(IShare::TYPE_EMAIL))
@@ -668,6 +670,10 @@ class ShareByMailProvider implements IShareProvider {
                        ->setValue('stime', $qb->createNamedParameter(time()))
                        ->setValue('hide_download', $qb->createNamedParameter((int)$hideDownload, IQueryBuilder::PARAM_INT));
 
+               if ($expirationTime !== null) {
+                       $qb->setValue('expiration', $qb->createNamedParameter($expirationTime, IQueryBuilder::PARAM_DATE));
+               }
+
                /*
                 * Added to fix https://github.com/owncloud/core/issues/22215
                 * Can be removed once we get rid of ajax/share.php
index f3e8c60fbf24f90f380fa38f88c67cfc429e9cdd..7611f6aedad13da74eebc38e6e0e2331b360b2d1 100644 (file)
@@ -524,6 +524,7 @@ class ShareByMailProviderTest extends TestCase {
                $password = 'password';
                $sendPasswordByTalk = true;
                $hideDownload = true;
+               $expiration = new \DateTime();
 
 
                $instance = $this->getInstance();
@@ -540,7 +541,8 @@ class ShareByMailProviderTest extends TestCase {
                                $token,
                                $password,
                                $sendPasswordByTalk,
-                               $hideDownload
+                               $hideDownload,
+                               $expiration
                        ]
                );
 
@@ -565,6 +567,7 @@ class ShareByMailProviderTest extends TestCase {
                $this->assertSame($password, $result[0]['password']);
                $this->assertSame($sendPasswordByTalk, (bool)$result[0]['password_by_talk']);
                $this->assertSame($hideDownload, (bool)$result[0]['hide_download']);
+               $this->assertSame($expiration->getTimestamp(), \DateTime::createFromFormat('Y-m-d H:i:s', $result[0]['expiration'])->getTimestamp());
        }
 
        public function testUpdate() {