Skip to content

Commit

Permalink
Remove duplicated query for email shares
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Signed-off-by: npmbuildbot-nextcloud[bot] <npmbuildbot-nextcloud[bot]@users.noreply.github.com>
  • Loading branch information
danxuliu authored and skjnldsv committed Mar 22, 2021
1 parent 0f3f6a6 commit f998769
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 102 deletions.
3 changes: 1 addition & 2 deletions apps/files_sharing/lib/Controller/ShareAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ public function createShare(
}

// Only share by mail have a recipient
if ($shareType === IShare::TYPE_EMAIL) {
if (is_string($shareWith) && $shareType === IShare::TYPE_EMAIL) {
$share->setSharedWith($shareWith);
}

Expand Down Expand Up @@ -1591,7 +1591,6 @@ private function getSharesFromNode(string $viewer, $node, bool $reShares): array
IShare::TYPE_GROUP,
IShare::TYPE_LINK,
IShare::TYPE_EMAIL,
IShare::TYPE_EMAIL,
IShare::TYPE_CIRCLE,
IShare::TYPE_ROOM,
IShare::TYPE_DECK
Expand Down
1 change: 0 additions & 1 deletion apps/sharebymail/lib/Capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

namespace OCA\ShareByMail;

use OCA\ShareByMail\Settings\SettingsManager;
use OCP\Capabilities\ICapability;
use OCP\Share\IManager;

Expand Down
52 changes: 18 additions & 34 deletions lib/private/Share20/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -740,25 +740,23 @@ public function createShare(IShare $share) {
}

try {
//Verify share type
// Verify share type
if ($share->getShareType() === IShare::TYPE_USER) {
$this->userCreateChecks($share);

//Verify the expiration date
// Verify the expiration date
$share = $this->validateExpirationDateInternal($share);
} elseif ($share->getShareType() === IShare::TYPE_GROUP) {
$this->groupCreateChecks($share);

//Verify the expiration date
// Verify the expiration date
$share = $this->validateExpirationDateInternal($share);
} elseif ($share->getShareType() === IShare::TYPE_LINK
|| $share->getShareType() === IShare::TYPE_EMAIL) {
$this->linkCreateChecks($share);
$this->setLinkParent($share);

/*
* For now ignore a set token.
*/
// For now ignore a set token.
$share->setToken(
$this->secureRandom->generate(
\OC\Share\Constants::TOKEN_LENGTH,
Expand All @@ -767,7 +765,7 @@ public function createShare(IShare $share) {
);

// Verify the expiration date
$share = $this->validateExpirationDateLink($share);
$share = $this->validateExpirationDate($share);

// Verify the password
$this->verifyPassword($share->getPassword());
Expand Down Expand Up @@ -799,7 +797,8 @@ public function createShare(IShare $share) {
$oldShare = $share;
$provider = $this->factory->getProviderForType($share->getShareType());
$share = $provider->create($share);
//reuse the node we already have

// Reuse the node we already have
$share->setNode($oldShare->getNode());

// Reset the target if it is null for the new share
Expand Down Expand Up @@ -987,38 +986,23 @@ public function updateShare(IShare $share) {
|| $share->getShareType() === IShare::TYPE_EMAIL) {
$this->linkCreateChecks($share);

// The new password is not set again if it is the same as the old one.
$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->validateExpirationDateLink($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;
if (empty($plainTextPassword)) {
if (!$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
// the sharer to verify her identity
throw new \InvalidArgumentException('Can’t enable sending the password by Talk without setting a new password');
}
if ($originalShare->getSendPasswordByTalk() && !$share->getSendPasswordByTalk()) {
throw new \InvalidArgumentException('Can’t disable sending the password by Talk without setting a new password');
}
}

$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
// the sharer to verify her identity
throw new \InvalidArgumentException('Can’t enable sending the password by Talk without setting a new password');
} 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);
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Share20/Share.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
use OCP\Share\Exceptions\IllegalIDChangeException;
use OCP\Share\IShare;

class Share implements \OCP\Share\IShare {
class Share implements IShare {

/** @var string */
private $id;
Expand Down
2 changes: 1 addition & 1 deletion lib/public/Share/IShare.php
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ public function getShareOwner();
* When the share is passed to the share manager to be created
* or updated the password will be hashed.
*
* @param string $password
* @param string|null $password
* @return \OCP\Share\IShare The modified object
* @since 9.0.0
*/
Expand Down

0 comments on commit f998769

Please sign in to comment.