diff options
author | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2020-10-20 13:58:01 +0200 |
---|---|---|
committer | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2021-03-22 06:50:45 +0100 |
commit | a100186e5e7dcbe95faa453d28b5cf0d20948639 (patch) | |
tree | afea689f2b87338975c74aabba950d85f7dca338 /lib | |
parent | 5e519fe17a2d4940993f4d866dfdd68269265a12 (diff) | |
download | nextcloud-server-a100186e5e7dcbe95faa453d28b5cf0d20948639.tar.gz nextcloud-server-a100186e5e7dcbe95faa453d28b5cf0d20948639.zip |
Sharing link & mail parity
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Share20/Manager.php | 42 | ||||
-rw-r--r-- | lib/private/Share20/ProviderFactory.php | 4 |
2 files changed, 27 insertions, 19 deletions
diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index 64767baa5cc..a0778319a7b 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -228,18 +228,19 @@ class Manager implements IManager { throw new \InvalidArgumentException('SharedWith is not a valid group'); } } elseif ($share->getShareType() === IShare::TYPE_LINK) { + // No check for TYPE_EMAIL here as we have a recipient for them if ($share->getSharedWith() !== null) { throw new \InvalidArgumentException('SharedWith should be empty'); } - } elseif ($share->getShareType() === IShare::TYPE_REMOTE) { + } elseif ($share->getShareType() === IShare::TYPE_EMAIL) { if ($share->getSharedWith() === null) { throw new \InvalidArgumentException('SharedWith should not be empty'); } - } elseif ($share->getShareType() === IShare::TYPE_REMOTE_GROUP) { + } elseif ($share->getShareType() === IShare::TYPE_REMOTE) { if ($share->getSharedWith() === null) { throw new \InvalidArgumentException('SharedWith should not be empty'); } - } elseif ($share->getShareType() === IShare::TYPE_EMAIL) { + } elseif ($share->getShareType() === IShare::TYPE_REMOTE_GROUP) { if ($share->getSharedWith() === null) { throw new \InvalidArgumentException('SharedWith should not be empty'); } @@ -750,7 +751,8 @@ class Manager implements IManager { //Verify the expiration date $share = $this->validateExpirationDateInternal($share); - } elseif ($share->getShareType() === IShare::TYPE_LINK) { + } elseif ($share->getShareType() === IShare::TYPE_LINK + || $share->getShareType() === IShare::TYPE_EMAIL) { $this->linkCreateChecks($share); $this->setLinkParent($share); @@ -764,23 +766,16 @@ class Manager implements IManager { ) ); - //Verify the expiration date + // Verify the expiration date $share = $this->validateExpirationDateLink($share); - //Verify the password + // Verify the password $this->verifyPassword($share->getPassword()); // If a password is set. Hash it! if ($share->getPassword() !== null) { $share->setPassword($this->hasher->hash($share->getPassword())); } - } elseif ($share->getShareType() === IShare::TYPE_EMAIL) { - $share->setToken( - $this->secureRandom->generate( - \OC\Share\Constants::TOKEN_LENGTH, - \OCP\Security\ISecureRandom::CHAR_HUMAN_READABLE - ) - ); } // Cannot share with the owner @@ -988,7 +983,8 @@ class Manager implements IManager { $this->validateExpirationDateInternal($share); $expirationDateUpdated = true; } - } elseif ($share->getShareType() === IShare::TYPE_LINK) { + } elseif ($share->getShareType() === IShare::TYPE_LINK + || $share->getShareType() === IShare::TYPE_EMAIL) { $this->linkCreateChecks($share); $plainTextPassword = $share->getPassword(); @@ -1011,6 +1007,9 @@ class Manager implements IManager { if (!empty($plainTextPassword) && !$this->updateSharePasswordIfNeeded($share, $originalShare)) { $plainTextPassword = null; } + + $this->updateSharePasswordIfNeeded($share, $originalShare); + if (empty($plainTextPassword) && !$originalShare->getSendPasswordByTalk() && $share->getSendPasswordByTalk()) { // If the same password was already sent by mail the recipient // would already have access to the share without having to call @@ -1019,6 +1018,12 @@ class Manager implements IManager { } elseif (empty($plainTextPassword) && $originalShare->getSendPasswordByTalk() && !$share->getSendPasswordByTalk()) { throw new \InvalidArgumentException('Can’t disable sending the password by Talk without setting a new password'); } + + if ($share->getExpirationDate() != $originalShare->getExpirationDate()) { + // Verify the expiration date + $this->validateExpirationDate($share); + $expirationDateUpdated = true; + } } $this->pathCreateChecks($share->getNode()); @@ -1218,7 +1223,8 @@ class Manager implements IManager { * @inheritdoc */ public function moveShare(IShare $share, $recipientId) { - if ($share->getShareType() === IShare::TYPE_LINK) { + if ($share->getShareType() === IShare::TYPE_LINK + || $share->getShareType() === IShare::TYPE_EMAIL) { throw new \InvalidArgumentException('Can’t change target of link share'); } @@ -1480,10 +1486,10 @@ class Manager implements IManager { $this->checkExpireDate($share); /* - * Reduce the permissions for link shares if public upload is not enabled + * Reduce the permissions for link or email shares if public upload is not enabled */ - if ($share->getShareType() === IShare::TYPE_LINK && - !$this->shareApiLinkAllowPublicUpload()) { + if (($share->getShareType() === IShare::TYPE_LINK || $share->getShareType() === IShare::TYPE_EMAIL) + && !$this->shareApiLinkAllowPublicUpload()) { $share->setPermissions($share->getPermissions() & ~(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE)); } diff --git a/lib/private/Share20/ProviderFactory.php b/lib/private/Share20/ProviderFactory.php index 643a4fac4c5..1998da1682f 100644 --- a/lib/private/Share20/ProviderFactory.php +++ b/lib/private/Share20/ProviderFactory.php @@ -43,6 +43,7 @@ use OCA\ShareByMail\ShareByMailProvider; use OCP\Defaults; use OCP\EventDispatcher\IEventDispatcher; use OCP\IServerContainer; +use OCP\Share\IManager; use OCP\Share\IProviderFactory; use OCP\Share\IShare; use OCP\Share\IShareProvider; @@ -195,7 +196,8 @@ class ProviderFactory implements IProviderFactory { $settingsManager, $this->serverContainer->query(Defaults::class), $this->serverContainer->getHasher(), - $this->serverContainer->get(IEventDispatcher::class) + $this->serverContainer->get(IEventDispatcher::class), + $this->serverContainer->get(IManager::class) ); } |