Skip to content

Commit

Permalink
Merge pull request #25938 from nextcloud/backport/25927/stable20
Browse files Browse the repository at this point in the history
[stable20] Sharebymail: set expiration on creation
  • Loading branch information
rullzer authored Mar 9, 2021
2 parents 791868f + 3089c74 commit 0d02124
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
10 changes: 8 additions & 2 deletions apps/sharebymail/lib/ShareByMailProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,8 @@ protected function createMailShare(IShare $share) {
$share->getToken(),
$share->getPassword(),
$share->getSendPasswordByTalk(),
$share->getHideDownload()
$share->getHideDownload(),
$share->getExpirationDate()
);

try {
Expand Down Expand Up @@ -649,9 +650,10 @@ public function getChildren(IShare $parent) {
* @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))
Expand All @@ -668,6 +670,10 @@ protected function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $
->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
Expand Down
5 changes: 4 additions & 1 deletion apps/sharebymail/tests/ShareByMailProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ public function testAddShareToDB() {
$password = 'password';
$sendPasswordByTalk = true;
$hideDownload = true;
$expiration = new \DateTime();


$instance = $this->getInstance();
Expand All @@ -540,7 +541,8 @@ public function testAddShareToDB() {
$token,
$password,
$sendPasswordByTalk,
$hideDownload
$hideDownload,
$expiration
]
);

Expand All @@ -565,6 +567,7 @@ public function testAddShareToDB() {
$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() {
Expand Down

0 comments on commit 0d02124

Please sign in to comment.