Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'apps/sharebymail/lib/ShareByMailProvider.php')
-rw-r--r--apps/sharebymail/lib/ShareByMailProvider.php57
1 files changed, 37 insertions, 20 deletions
diff --git a/apps/sharebymail/lib/ShareByMailProvider.php b/apps/sharebymail/lib/ShareByMailProvider.php
index c1438c01125..1e767b7f859 100644
--- a/apps/sharebymail/lib/ShareByMailProvider.php
+++ b/apps/sharebymail/lib/ShareByMailProvider.php
@@ -52,6 +52,7 @@ use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\Files\Node;
use OCP\HintException;
+use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IL10N;
use OCP\ILogger;
@@ -75,6 +76,8 @@ use OCP\Share\IShareProvider;
*/
class ShareByMailProvider implements IShareProvider {
+ private IConfig $config;
+
/** @var IDBConnection */
private $dbConnection;
@@ -126,7 +129,8 @@ class ShareByMailProvider implements IShareProvider {
return 'ocMailShare';
}
- public function __construct(IDBConnection $connection,
+ public function __construct(IConfig $config,
+ IDBConnection $connection,
ISecureRandom $secureRandom,
IUserManager $userManager,
IRootFolder $rootFolder,
@@ -140,6 +144,7 @@ class ShareByMailProvider implements IShareProvider {
IHasher $hasher,
IEventDispatcher $eventDispatcher,
IShareManager $shareManager) {
+ $this->config = $config;
$this->dbConnection = $connection;
$this->secureRandom = $secureRandom;
$this->userManager = $userManager;
@@ -190,9 +195,14 @@ class ShareByMailProvider implements IShareProvider {
}
$shareId = $this->createMailShare($share);
- $send = $this->sendPassword($share, $password);
- if ($passwordEnforced && $send === false) {
- $this->sendPasswordToOwner($share, $password);
+
+ // Sends share password to receiver when it's a permanent one (otherwise she will have to request it via the showShare UI)
+ // or to owner when the password shall be given during a Talk session
+ if ($this->config->getSystemValue('allow_mail_share_permanent_password') || $share->getSendPasswordByTalk()) {
+ $send = $this->sendPassword($share, $password);
+ if ($passwordEnforced && $send === false) {
+ $this->sendPasswordToOwner($share, $password);
+ }
}
$this->createShareActivity($share);
@@ -327,6 +337,7 @@ class ShareByMailProvider implements IShareProvider {
$share->getPermissions(),
$share->getToken(),
$share->getPassword(),
+ $share->getPasswordExpirationTime(),
$share->getSendPasswordByTalk(),
$share->getHideDownload(),
$share->getLabel(),
@@ -673,23 +684,24 @@ class ShareByMailProvider implements IShareProvider {
}
/**
- * add share to the database and return the ID
- *
- * @param int $itemSource
- * @param string $itemType
- * @param string $shareWith
- * @param string $sharedBy
- * @param string $uidOwner
- * @param int $permissions
- * @param string $token
- * @param string $password
- * @param bool $sendPasswordByTalk
- * @param bool $hideDownload
- * @param string $label
- * @param \DateTime|null $expirationTime
- * @return int
+ * Add share to the database and return the ID
*/
- protected function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token, $password, $sendPasswordByTalk, $hideDownload, $label, $expirationTime, $note = ''): int {
+ protected function addShareToDB(
+ ?int $itemSource,
+ ?string $itemType,
+ ?string $shareWith,
+ ?string $sharedBy,
+ ?string $uidOwner,
+ ?int $permissions,
+ ?string $token,
+ ?string $password,
+ ?\DateTimeInterface $passwordExpirationTime,
+ ?bool $sendPasswordByTalk,
+ ?bool $hideDownload,
+ ?string $label,
+ ?\DateTimeInterface $expirationTime,
+ ?string $note = ''
+ ): int {
$qb = $this->dbConnection->getQueryBuilder();
$qb->insert('share')
->setValue('share_type', $qb->createNamedParameter(IShare::TYPE_EMAIL))
@@ -702,6 +714,7 @@ class ShareByMailProvider implements IShareProvider {
->setValue('permissions', $qb->createNamedParameter($permissions))
->setValue('token', $qb->createNamedParameter($token))
->setValue('password', $qb->createNamedParameter($password))
+ ->setValue('password_expiration_time', $qb->createNamedParameter($passwordExpirationTime, IQueryBuilder::PARAM_DATE))
->setValue('password_by_talk', $qb->createNamedParameter($sendPasswordByTalk, IQueryBuilder::PARAM_BOOL))
->setValue('stime', $qb->createNamedParameter(time()))
->setValue('hide_download', $qb->createNamedParameter((int)$hideDownload, IQueryBuilder::PARAM_INT))
@@ -739,6 +752,7 @@ class ShareByMailProvider implements IShareProvider {
($originalShare->getSendPasswordByTalk() && !$share->getSendPasswordByTalk()))) {
$this->sendPassword($share, $plainTextPassword);
}
+
/*
* We allow updating the permissions and password of mail shares
*/
@@ -749,6 +763,7 @@ class ShareByMailProvider implements IShareProvider {
->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
->set('password', $qb->createNamedParameter($share->getPassword()))
+ ->set('password_expiration_time', $qb->createNamedParameter($share->getPasswordExpirationTime(), IQueryBuilder::PARAM_DATE))
->set('label', $qb->createNamedParameter($share->getLabel()))
->set('password_by_talk', $qb->createNamedParameter($share->getSendPasswordByTalk(), IQueryBuilder::PARAM_BOOL))
->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE))
@@ -1012,6 +1027,8 @@ class ShareByMailProvider implements IShareProvider {
$share->setShareTime($shareTime);
$share->setSharedWith($data['share_with']);
$share->setPassword($data['password']);
+ $passwordExpirationTime = \DateTime::createFromFormat('Y-m-d H:i:s', $data['password_expiration_time']);
+ $share->setPasswordExpirationTime($passwordExpirationTime !== false? $passwordExpirationTime : null);
$share->setLabel($data['label']);
$share->setSendPasswordByTalk((bool)$data['password_by_talk']);
$share->setHideDownload((bool)$data['hide_download']);