diff --git a/build/integration/features/bootstrap/SharingContext.php b/build/integration/features/bootstrap/SharingContext.php
index b1a4c1aa48b9c..c38440709a57f 100644
--- a/build/integration/features/bootstrap/SharingContext.php
+++ b/build/integration/features/bootstrap/SharingContext.php
@@ -44,6 +44,5 @@ protected function resetAppConfigs() {
$this->deleteServerConfig('core', 'shareapi_default_expire_date');
$this->deleteServerConfig('core', 'shareapi_expire_after_n_days');
$this->deleteServerConfig('core', 'link_defaultExpDays');
- $this->deleteServerConfig('sharebymail', 'enforcePasswordProtection');
}
}
diff --git a/build/integration/sharing_features/sharing-v1.feature b/build/integration/sharing_features/sharing-v1.feature
index 00a754d54d3b6..2c391805331b5 100644
--- a/build/integration/sharing_features/sharing-v1.feature
+++ b/build/integration/sharing_features/sharing-v1.feature
@@ -84,7 +84,7 @@ Feature: sharing
Scenario: Creating a new mail share with password when password protection is enforced
Given dummy mail server is listening
And As an "admin"
- And parameter "enforcePasswordProtection" of app "sharebymail" is set to "yes"
+ And parameter "shareapi_enforce_links_password" of app "core" is set to "yes"
And user "user0" exists
And As an "user0"
When creating a share with
diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php
index 9a2b413896b00..c53a6331a8fef 100644
--- a/lib/private/Share20/Manager.php
+++ b/lib/private/Share20/Manager.php
@@ -227,18 +227,19 @@ protected function generalCreateChecks(IShare $share) {
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');
}
@@ -745,7 +746,8 @@ public function createShare(IShare $share) {
//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);
@@ -769,13 +771,6 @@ public function createShare(IShare $share) {
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
@@ -979,29 +974,19 @@ public function updateShare(IShare $share) {
$this->validateExpirationDate($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();
-
- $this->updateSharePasswordIfNeeded($share, $originalShare);
-
- if (empty($plainTextPassword) && $share->getSendPasswordByTalk()) {
- throw new \InvalidArgumentException('Can’t enable sending the password by Talk with an empty password');
- }
-
- if ($share->getExpirationDate() != $originalShare->getExpirationDate()) {
- //Verify the expiration date
- $this->validateExpirationDate($share);
- $expirationDateUpdated = true;
- }
- } elseif ($share->getShareType() === IShare::TYPE_EMAIL) {
// The new password is not set again if it is the same as the old
// one.
$plainTextPassword = $share->getPassword();
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
@@ -1010,6 +995,12 @@ public function updateShare(IShare $share) {
} 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());
@@ -1209,7 +1200,8 @@ public function restoreShare(IShare $share, string $recipientId): IShare {
* @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');
}
@@ -1471,10 +1463,10 @@ public function getShareByToken($token) {
$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 643a4fac4c5fb..1998da1682fa3 100644
--- a/lib/private/Share20/ProviderFactory.php
+++ b/lib/private/Share20/ProviderFactory.php
@@ -43,6 +43,7 @@
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 @@ protected function getShareByMailProvider() {
$settingsManager,
$this->serverContainer->query(Defaults::class),
$this->serverContainer->getHasher(),
- $this->serverContainer->get(IEventDispatcher::class)
+ $this->serverContainer->get(IEventDispatcher::class),
+ $this->serverContainer->get(IManager::class)
);
}