2015-10-30 08:10:08 -04:00
|
|
|
<?php
|
2024-05-23 03:26:56 -04:00
|
|
|
|
2015-10-30 08:10:08 -04:00
|
|
|
/**
|
2024-05-23 03:26:56 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2015-10-30 08:10:08 -04:00
|
|
|
*/
|
2025-05-05 08:59:05 -04:00
|
|
|
|
2015-10-30 08:10:08 -04:00
|
|
|
namespace OC\Share20;
|
|
|
|
|
|
2016-11-17 08:18:47 -05:00
|
|
|
use OC\Files\Cache\Cache;
|
2019-11-22 14:52:10 -05:00
|
|
|
use OC\Share20\Exception\BackendError;
|
|
|
|
|
use OC\Share20\Exception\InvalidShare;
|
|
|
|
|
use OC\Share20\Exception\ProviderException;
|
2022-08-17 08:29:32 -04:00
|
|
|
use OC\User\LazyUser;
|
2025-03-20 11:20:39 -04:00
|
|
|
use OCA\Files_Sharing\AppInfo\Application;
|
2021-04-23 03:12:12 -04:00
|
|
|
use OCP\AppFramework\Utility\ITimeFactory;
|
2019-11-22 14:52:10 -05:00
|
|
|
use OCP\DB\QueryBuilder\IQueryBuilder;
|
2018-07-12 08:55:50 -04:00
|
|
|
use OCP\Defaults;
|
2016-10-31 15:19:00 -04:00
|
|
|
use OCP\Files\Folder;
|
2019-11-22 14:52:10 -05:00
|
|
|
use OCP\Files\IRootFolder;
|
|
|
|
|
use OCP\Files\Node;
|
2025-03-20 11:20:39 -04:00
|
|
|
use OCP\IConfig;
|
2019-11-22 14:52:10 -05:00
|
|
|
use OCP\IDBConnection;
|
|
|
|
|
use OCP\IGroupManager;
|
2024-07-05 03:47:40 -04:00
|
|
|
use OCP\IL10N;
|
2018-07-12 12:17:22 -04:00
|
|
|
use OCP\IURLGenerator;
|
2018-07-12 08:55:50 -04:00
|
|
|
use OCP\IUser;
|
2019-11-22 14:52:10 -05:00
|
|
|
use OCP\IUserManager;
|
2020-06-23 02:14:27 -04:00
|
|
|
use OCP\L10N\IFactory;
|
2018-07-12 08:55:50 -04:00
|
|
|
use OCP\Mail\IMailer;
|
2019-11-22 14:52:10 -05:00
|
|
|
use OCP\Share\Exceptions\ShareNotFound;
|
2022-05-18 08:54:27 -04:00
|
|
|
use OCP\Share\IAttributes;
|
2024-05-22 05:55:47 -04:00
|
|
|
use OCP\Share\IManager;
|
2018-06-19 03:20:35 -04:00
|
|
|
use OCP\Share\IShare;
|
2024-06-25 06:40:27 -04:00
|
|
|
use OCP\Share\IShareProviderSupportsAccept;
|
2025-05-05 08:59:05 -04:00
|
|
|
use OCP\Share\IShareProviderSupportsAllSharesInFolder;
|
2024-07-05 03:47:40 -04:00
|
|
|
use OCP\Share\IShareProviderWithNotification;
|
2024-02-08 09:47:39 -05:00
|
|
|
use Psr\Log\LoggerInterface;
|
2023-03-28 07:48:43 -04:00
|
|
|
use function str_starts_with;
|
2015-10-30 08:10:08 -04:00
|
|
|
|
2016-01-13 07:02:23 -05:00
|
|
|
/**
|
|
|
|
|
* Class DefaultShareProvider
|
|
|
|
|
*
|
|
|
|
|
* @package OC\Share20
|
|
|
|
|
*/
|
2025-05-05 08:59:05 -04:00
|
|
|
class DefaultShareProvider implements IShareProviderWithNotification, IShareProviderSupportsAccept, IShareProviderSupportsAllSharesInFolder {
|
2015-11-24 03:58:37 -05:00
|
|
|
public function __construct(
|
2024-07-05 03:47:40 -04:00
|
|
|
private IDBConnection $dbConn,
|
|
|
|
|
private IUserManager $userManager,
|
|
|
|
|
private IGroupManager $groupManager,
|
|
|
|
|
private IRootFolder $rootFolder,
|
|
|
|
|
private IMailer $mailer,
|
|
|
|
|
private Defaults $defaults,
|
|
|
|
|
private IFactory $l10nFactory,
|
|
|
|
|
private IURLGenerator $urlGenerator,
|
|
|
|
|
private ITimeFactory $timeFactory,
|
|
|
|
|
private LoggerInterface $logger,
|
2024-05-22 05:55:47 -04:00
|
|
|
private IManager $shareManager,
|
2025-03-20 11:20:39 -04:00
|
|
|
private IConfig $config,
|
2024-07-09 05:09:01 -04:00
|
|
|
) {
|
|
|
|
|
}
|
2015-10-30 08:10:08 -04:00
|
|
|
|
2016-01-13 07:02:23 -05:00
|
|
|
/**
|
|
|
|
|
* Return the identifier of this provider.
|
|
|
|
|
*
|
|
|
|
|
* @return string Containing only [a-zA-Z0-9]
|
|
|
|
|
*/
|
|
|
|
|
public function identifier() {
|
|
|
|
|
return 'ocinternal';
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-30 08:10:08 -04:00
|
|
|
/**
|
|
|
|
|
* Share a path
|
2015-12-15 03:53:16 -05:00
|
|
|
*
|
2016-01-27 06:13:53 -05:00
|
|
|
* @param \OCP\Share\IShare $share
|
|
|
|
|
* @return \OCP\Share\IShare The share object
|
2015-12-15 03:53:16 -05:00
|
|
|
* @throws ShareNotFound
|
|
|
|
|
* @throws \Exception
|
2015-10-30 08:10:08 -04:00
|
|
|
*/
|
2016-01-27 06:13:53 -05:00
|
|
|
public function create(\OCP\Share\IShare $share) {
|
2015-12-15 03:53:16 -05:00
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
|
|
|
|
|
|
$qb->insert('share');
|
|
|
|
|
$qb->setValue('share_type', $qb->createNamedParameter($share->getShareType()));
|
|
|
|
|
|
2024-06-26 06:45:23 -04:00
|
|
|
$expirationDate = $share->getExpirationDate();
|
|
|
|
|
if ($expirationDate !== null) {
|
|
|
|
|
$expirationDate = clone $expirationDate;
|
|
|
|
|
$expirationDate->setTimezone(new \DateTimeZone(date_default_timezone_get()));
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-24 10:49:16 -04:00
|
|
|
if ($share->getShareType() === IShare::TYPE_USER) {
|
2015-12-15 03:53:16 -05:00
|
|
|
//Set the UID of the user we share with
|
2016-02-02 10:57:50 -05:00
|
|
|
$qb->setValue('share_with', $qb->createNamedParameter($share->getSharedWith()));
|
2019-08-21 10:15:23 -04:00
|
|
|
$qb->setValue('accepted', $qb->createNamedParameter(IShare::STATUS_PENDING));
|
2019-10-28 14:22:05 -04:00
|
|
|
|
|
|
|
|
//If an expiration date is set store it
|
2024-06-26 06:45:23 -04:00
|
|
|
if ($expirationDate !== null) {
|
|
|
|
|
$qb->setValue('expiration', $qb->createNamedParameter($expirationDate, 'datetime'));
|
2019-10-28 14:22:05 -04:00
|
|
|
}
|
2024-08-27 03:29:21 -04:00
|
|
|
|
2024-09-02 09:02:50 -04:00
|
|
|
$qb->setValue('reminder_sent', $qb->createNamedParameter($share->getReminderSent(), IQueryBuilder::PARAM_BOOL));
|
2020-06-24 10:49:16 -04:00
|
|
|
} elseif ($share->getShareType() === IShare::TYPE_GROUP) {
|
2015-12-15 03:53:16 -05:00
|
|
|
//Set the GID of the group we share with
|
2016-02-02 10:57:50 -05:00
|
|
|
$qb->setValue('share_with', $qb->createNamedParameter($share->getSharedWith()));
|
2019-10-28 14:22:05 -04:00
|
|
|
|
|
|
|
|
//If an expiration date is set store it
|
2024-06-26 06:45:23 -04:00
|
|
|
if ($expirationDate !== null) {
|
|
|
|
|
$qb->setValue('expiration', $qb->createNamedParameter($expirationDate, 'datetime'));
|
2019-10-28 14:22:05 -04:00
|
|
|
}
|
2020-06-24 10:49:16 -04:00
|
|
|
} elseif ($share->getShareType() === IShare::TYPE_LINK) {
|
2018-10-16 04:31:38 -04:00
|
|
|
//set label for public link
|
|
|
|
|
$qb->setValue('label', $qb->createNamedParameter($share->getLabel()));
|
2015-12-15 03:53:16 -05:00
|
|
|
//Set the token of the share
|
|
|
|
|
$qb->setValue('token', $qb->createNamedParameter($share->getToken()));
|
|
|
|
|
|
|
|
|
|
//If a password is set store it
|
|
|
|
|
if ($share->getPassword() !== null) {
|
2017-03-30 11:03:04 -04:00
|
|
|
$qb->setValue('password', $qb->createNamedParameter($share->getPassword()));
|
2015-12-15 03:53:16 -05:00
|
|
|
}
|
|
|
|
|
|
2018-10-12 14:15:40 -04:00
|
|
|
$qb->setValue('password_by_talk', $qb->createNamedParameter($share->getSendPasswordByTalk(), IQueryBuilder::PARAM_BOOL));
|
|
|
|
|
|
2015-12-15 03:53:16 -05:00
|
|
|
//If an expiration date is set store it
|
2024-06-26 06:45:23 -04:00
|
|
|
if ($expirationDate !== null) {
|
|
|
|
|
$qb->setValue('expiration', $qb->createNamedParameter($expirationDate, 'datetime'));
|
2015-12-15 03:53:16 -05:00
|
|
|
}
|
2016-02-11 05:55:09 -05:00
|
|
|
|
2025-07-22 07:10:45 -04:00
|
|
|
$qb->setValue('parent', $qb->createNamedParameter($share->getParent()));
|
2022-06-13 10:38:34 -04:00
|
|
|
|
|
|
|
|
$qb->setValue('hide_download', $qb->createNamedParameter($share->getHideDownload() ? 1 : 0, IQueryBuilder::PARAM_INT));
|
2015-12-15 03:53:16 -05:00
|
|
|
} else {
|
|
|
|
|
throw new \Exception('invalid share type!');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set what is shares
|
|
|
|
|
$qb->setValue('item_type', $qb->createParameter('itemType'));
|
2016-01-27 14:51:26 -05:00
|
|
|
if ($share->getNode() instanceof \OCP\Files\File) {
|
2015-12-15 03:53:16 -05:00
|
|
|
$qb->setParameter('itemType', 'file');
|
|
|
|
|
} else {
|
|
|
|
|
$qb->setParameter('itemType', 'folder');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set the file id
|
2016-01-27 14:51:26 -05:00
|
|
|
$qb->setValue('item_source', $qb->createNamedParameter($share->getNode()->getId()));
|
|
|
|
|
$qb->setValue('file_source', $qb->createNamedParameter($share->getNode()->getId()));
|
2015-12-15 03:53:16 -05:00
|
|
|
|
|
|
|
|
// set the permissions
|
|
|
|
|
$qb->setValue('permissions', $qb->createNamedParameter($share->getPermissions()));
|
|
|
|
|
|
2022-05-18 08:54:27 -04:00
|
|
|
// set share attributes
|
|
|
|
|
$shareAttributes = $this->formatShareAttributes(
|
|
|
|
|
$share->getAttributes()
|
|
|
|
|
);
|
|
|
|
|
$qb->setValue('attributes', $qb->createNamedParameter($shareAttributes));
|
|
|
|
|
|
2015-12-15 03:53:16 -05:00
|
|
|
// Set who created this share
|
2016-02-02 10:57:50 -05:00
|
|
|
$qb->setValue('uid_initiator', $qb->createNamedParameter($share->getSharedBy()));
|
2015-12-15 03:53:16 -05:00
|
|
|
|
|
|
|
|
// Set who is the owner of this file/folder (and this the owner of the share)
|
2016-02-02 10:57:50 -05:00
|
|
|
$qb->setValue('uid_owner', $qb->createNamedParameter($share->getShareOwner()));
|
2015-12-15 03:53:16 -05:00
|
|
|
|
|
|
|
|
// Set the file target
|
|
|
|
|
$qb->setValue('file_target', $qb->createNamedParameter($share->getTarget()));
|
|
|
|
|
|
2021-11-26 08:42:31 -05:00
|
|
|
if ($share->getNote() !== '') {
|
|
|
|
|
$qb->setValue('note', $qb->createNamedParameter($share->getNote()));
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-15 03:53:16 -05:00
|
|
|
// Set the time this share was created
|
2021-04-23 03:12:12 -04:00
|
|
|
$shareTime = $this->timeFactory->now();
|
|
|
|
|
$qb->setValue('stime', $qb->createNamedParameter($shareTime->getTimestamp()));
|
2015-12-15 03:53:16 -05:00
|
|
|
|
|
|
|
|
// insert the data and fetch the id of the share
|
2021-04-23 03:12:12 -04:00
|
|
|
$qb->executeStatement();
|
2015-12-15 03:53:16 -05:00
|
|
|
|
2021-04-23 03:12:12 -04:00
|
|
|
// Update mandatory data
|
|
|
|
|
$id = $qb->getLastInsertId();
|
|
|
|
|
$share->setId((string)$id);
|
|
|
|
|
$share->setProviderId($this->identifier());
|
2015-12-15 03:53:16 -05:00
|
|
|
|
2021-04-23 03:12:12 -04:00
|
|
|
$share->setShareTime(\DateTime::createFromImmutable($shareTime));
|
2015-12-15 03:53:16 -05:00
|
|
|
|
2017-09-10 18:56:20 -04:00
|
|
|
$mailSendValue = $share->getMailSend();
|
2021-04-23 03:12:12 -04:00
|
|
|
$share->setMailSend(($mailSendValue === null) ? true : $mailSendValue);
|
2017-09-10 18:56:20 -04:00
|
|
|
|
2015-12-15 03:53:16 -05:00
|
|
|
return $share;
|
2015-10-30 08:10:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update a share
|
|
|
|
|
*
|
2016-01-27 06:13:53 -05:00
|
|
|
* @param \OCP\Share\IShare $share
|
|
|
|
|
* @return \OCP\Share\IShare The share object
|
2018-10-16 04:31:38 -04:00
|
|
|
* @throws ShareNotFound
|
|
|
|
|
* @throws \OCP\Files\InvalidPathException
|
|
|
|
|
* @throws \OCP\Files\NotFoundException
|
2015-10-30 08:10:08 -04:00
|
|
|
*/
|
2016-01-27 06:13:53 -05:00
|
|
|
public function update(\OCP\Share\IShare $share) {
|
2018-07-12 08:55:50 -04:00
|
|
|
$originalShare = $this->getShareById($share->getId());
|
|
|
|
|
|
2022-05-18 08:54:27 -04:00
|
|
|
$shareAttributes = $this->formatShareAttributes($share->getAttributes());
|
|
|
|
|
|
2024-06-26 06:45:23 -04:00
|
|
|
$expirationDate = $share->getExpirationDate();
|
|
|
|
|
if ($expirationDate !== null) {
|
|
|
|
|
$expirationDate = clone $expirationDate;
|
|
|
|
|
$expirationDate->setTimezone(new \DateTimeZone(date_default_timezone_get()));
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-24 10:49:16 -04:00
|
|
|
if ($share->getShareType() === IShare::TYPE_USER) {
|
2016-01-22 08:52:20 -05:00
|
|
|
/*
|
|
|
|
|
* We allow updating the recipient on user shares.
|
|
|
|
|
*/
|
|
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
|
$qb->update('share')
|
|
|
|
|
->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))
|
2016-02-02 10:57:50 -05:00
|
|
|
->set('share_with', $qb->createNamedParameter($share->getSharedWith()))
|
|
|
|
|
->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
|
|
|
|
|
->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
|
2016-01-22 08:52:20 -05:00
|
|
|
->set('permissions', $qb->createNamedParameter($share->getPermissions()))
|
2022-05-18 08:54:27 -04:00
|
|
|
->set('attributes', $qb->createNamedParameter($shareAttributes))
|
2016-01-27 14:51:26 -05:00
|
|
|
->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
|
|
|
|
|
->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
|
2024-08-21 05:42:56 -04:00
|
|
|
->set('expiration', $qb->createNamedParameter($expirationDate, IQueryBuilder::PARAM_DATETIME_MUTABLE))
|
2018-07-12 08:55:50 -04:00
|
|
|
->set('note', $qb->createNamedParameter($share->getNote()))
|
2019-08-21 21:17:17 -04:00
|
|
|
->set('accepted', $qb->createNamedParameter($share->getStatus()))
|
2024-09-02 09:02:50 -04:00
|
|
|
->set('reminder_sent', $qb->createNamedParameter($share->getReminderSent(), IQueryBuilder::PARAM_BOOL))
|
2024-10-17 09:42:21 -04:00
|
|
|
->executeStatement();
|
2020-06-24 10:49:16 -04:00
|
|
|
} elseif ($share->getShareType() === IShare::TYPE_GROUP) {
|
2016-01-22 08:52:20 -05:00
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
|
$qb->update('share')
|
|
|
|
|
->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))
|
2016-02-02 10:57:50 -05:00
|
|
|
->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
|
|
|
|
|
->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
|
2016-01-22 08:52:20 -05:00
|
|
|
->set('permissions', $qb->createNamedParameter($share->getPermissions()))
|
2022-05-18 08:54:27 -04:00
|
|
|
->set('attributes', $qb->createNamedParameter($shareAttributes))
|
2016-01-27 14:51:26 -05:00
|
|
|
->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
|
|
|
|
|
->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
|
2024-08-21 05:42:56 -04:00
|
|
|
->set('expiration', $qb->createNamedParameter($expirationDate, IQueryBuilder::PARAM_DATETIME_MUTABLE))
|
2018-07-12 08:55:50 -04:00
|
|
|
->set('note', $qb->createNamedParameter($share->getNote()))
|
2024-10-17 09:42:21 -04:00
|
|
|
->executeStatement();
|
2016-01-22 08:52:20 -05:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Update all user defined group shares
|
|
|
|
|
*/
|
|
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
|
$qb->update('share')
|
|
|
|
|
->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
|
2020-06-24 10:49:16 -04:00
|
|
|
->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(IShare::TYPE_USERGROUP)))
|
2016-02-02 10:57:50 -05:00
|
|
|
->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
|
|
|
|
|
->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
|
2016-01-27 14:51:26 -05:00
|
|
|
->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
|
|
|
|
|
->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
|
2024-08-21 05:42:56 -04:00
|
|
|
->set('expiration', $qb->createNamedParameter($expirationDate, IQueryBuilder::PARAM_DATETIME_MUTABLE))
|
2018-07-12 08:55:50 -04:00
|
|
|
->set('note', $qb->createNamedParameter($share->getNote()))
|
2024-10-17 09:42:21 -04:00
|
|
|
->executeStatement();
|
2016-01-22 08:52:20 -05:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Now update the permissions for all children that have not set it to 0
|
|
|
|
|
*/
|
|
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
|
$qb->update('share')
|
|
|
|
|
->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
|
|
|
|
|
->andWhere($qb->expr()->neq('permissions', $qb->createNamedParameter(0)))
|
|
|
|
|
->set('permissions', $qb->createNamedParameter($share->getPermissions()))
|
2022-05-18 08:54:27 -04:00
|
|
|
->set('attributes', $qb->createNamedParameter($shareAttributes))
|
2024-10-17 09:42:21 -04:00
|
|
|
->executeStatement();
|
2020-06-24 10:49:16 -04:00
|
|
|
} elseif ($share->getShareType() === IShare::TYPE_LINK) {
|
2016-01-22 08:52:20 -05:00
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
|
$qb->update('share')
|
|
|
|
|
->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))
|
2017-03-28 09:11:07 -04:00
|
|
|
->set('password', $qb->createNamedParameter($share->getPassword()))
|
2018-10-12 14:15:40 -04:00
|
|
|
->set('password_by_talk', $qb->createNamedParameter($share->getSendPasswordByTalk(), IQueryBuilder::PARAM_BOOL))
|
2016-02-02 10:57:50 -05:00
|
|
|
->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
|
|
|
|
|
->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
|
2016-01-22 08:52:20 -05:00
|
|
|
->set('permissions', $qb->createNamedParameter($share->getPermissions()))
|
2022-05-18 08:54:27 -04:00
|
|
|
->set('attributes', $qb->createNamedParameter($shareAttributes))
|
2016-01-27 14:51:26 -05:00
|
|
|
->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
|
|
|
|
|
->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
|
2016-01-22 08:52:20 -05:00
|
|
|
->set('token', $qb->createNamedParameter($share->getToken()))
|
2024-08-21 05:42:56 -04:00
|
|
|
->set('expiration', $qb->createNamedParameter($expirationDate, IQueryBuilder::PARAM_DATETIME_MUTABLE))
|
2018-07-12 08:55:50 -04:00
|
|
|
->set('note', $qb->createNamedParameter($share->getNote()))
|
2018-10-17 04:50:58 -04:00
|
|
|
->set('label', $qb->createNamedParameter($share->getLabel()))
|
2025-07-15 06:56:51 -04:00
|
|
|
->set('hide_download', $qb->createNamedParameter($share->getHideDownload() ? 1 : 0, IQueryBuilder::PARAM_INT))
|
2024-10-17 09:42:21 -04:00
|
|
|
->executeStatement();
|
2016-01-22 08:52:20 -05:00
|
|
|
}
|
|
|
|
|
|
2018-07-12 08:55:50 -04:00
|
|
|
if ($originalShare->getNote() !== $share->getNote() && $share->getNote() !== '') {
|
|
|
|
|
$this->propagateNote($share);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-01-26 08:29:30 -05:00
|
|
|
return $share;
|
2015-10-30 08:10:08 -04:00
|
|
|
}
|
|
|
|
|
|
2019-09-04 10:50:52 -04:00
|
|
|
/**
|
|
|
|
|
* Accept a share.
|
|
|
|
|
*
|
|
|
|
|
* @param IShare $share
|
|
|
|
|
* @param string $recipient
|
|
|
|
|
* @return IShare The share object
|
|
|
|
|
* @since 9.0.0
|
|
|
|
|
*/
|
|
|
|
|
public function acceptShare(IShare $share, string $recipient): IShare {
|
|
|
|
|
if ($share->getShareType() === IShare::TYPE_GROUP) {
|
|
|
|
|
$group = $this->groupManager->get($share->getSharedWith());
|
|
|
|
|
$user = $this->userManager->get($recipient);
|
|
|
|
|
|
|
|
|
|
if (is_null($group)) {
|
|
|
|
|
throw new ProviderException('Group "' . $share->getSharedWith() . '" does not exist');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!$group->inGroup($user)) {
|
|
|
|
|
throw new ProviderException('Recipient not in receiving group');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Try to fetch user specific share
|
|
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
|
$stmt = $qb->select('*')
|
|
|
|
|
->from('share')
|
2020-06-24 10:49:16 -04:00
|
|
|
->where($qb->expr()->eq('share_type', $qb->createNamedParameter(IShare::TYPE_USERGROUP)))
|
2019-09-04 10:50:52 -04:00
|
|
|
->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient)))
|
|
|
|
|
->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
|
2025-03-24 10:39:29 -04:00
|
|
|
->andWhere($qb->expr()->in('item_type', $qb->createNamedParameter(['file', 'folder'], IQueryBuilder::PARAM_STR_ARRAY)))
|
2024-10-17 09:42:21 -04:00
|
|
|
->executeQuery();
|
2019-09-04 10:50:52 -04:00
|
|
|
|
|
|
|
|
$data = $stmt->fetch();
|
2019-11-18 10:11:03 -05:00
|
|
|
$stmt->closeCursor();
|
2019-09-04 10:50:52 -04:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Check if there already is a user specific group share.
|
|
|
|
|
* If there is update it (if required).
|
|
|
|
|
*/
|
|
|
|
|
if ($data === false) {
|
|
|
|
|
$id = $this->createUserSpecificGroupShare($share, $recipient);
|
|
|
|
|
} else {
|
|
|
|
|
$id = $data['id'];
|
|
|
|
|
}
|
2020-04-10 04:35:09 -04:00
|
|
|
} elseif ($share->getShareType() === IShare::TYPE_USER) {
|
2019-09-04 10:50:52 -04:00
|
|
|
if ($share->getSharedWith() !== $recipient) {
|
|
|
|
|
throw new ProviderException('Recipient does not match');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$id = $share->getId();
|
|
|
|
|
} else {
|
|
|
|
|
throw new ProviderException('Invalid shareType');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
|
$qb->update('share')
|
|
|
|
|
->set('accepted', $qb->createNamedParameter(IShare::STATUS_ACCEPTED))
|
|
|
|
|
->where($qb->expr()->eq('id', $qb->createNamedParameter($id)))
|
2024-10-17 09:42:21 -04:00
|
|
|
->executeStatement();
|
2019-09-04 10:50:52 -04:00
|
|
|
|
|
|
|
|
return $share;
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-22 07:02:55 -04:00
|
|
|
public function getChildren(IShare $parent): array {
|
2015-10-30 08:10:08 -04:00
|
|
|
$children = [];
|
|
|
|
|
|
|
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
|
$qb->select('*')
|
|
|
|
|
->from('share')
|
2016-01-11 09:58:32 -05:00
|
|
|
->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId())))
|
2016-01-11 10:19:07 -05:00
|
|
|
->andWhere(
|
|
|
|
|
$qb->expr()->in(
|
|
|
|
|
'share_type',
|
2016-01-29 05:41:28 -05:00
|
|
|
$qb->createNamedParameter([
|
2020-06-24 10:49:16 -04:00
|
|
|
IShare::TYPE_USER,
|
|
|
|
|
IShare::TYPE_GROUP,
|
|
|
|
|
IShare::TYPE_LINK,
|
2016-01-29 05:41:28 -05:00
|
|
|
], IQueryBuilder::PARAM_INT_ARRAY)
|
2016-01-11 10:19:07 -05:00
|
|
|
)
|
|
|
|
|
)
|
2025-03-24 10:39:29 -04:00
|
|
|
->andWhere($qb->expr()->in('item_type', $qb->createNamedParameter(['file', 'folder'], IQueryBuilder::PARAM_STR_ARRAY)))
|
2015-11-10 08:14:49 -05:00
|
|
|
->orderBy('id');
|
2015-10-30 08:10:08 -04:00
|
|
|
|
2024-10-17 09:42:21 -04:00
|
|
|
$cursor = $qb->executeQuery();
|
2015-10-30 08:10:08 -04:00
|
|
|
while ($data = $cursor->fetch()) {
|
|
|
|
|
$children[] = $this->createShare($data);
|
|
|
|
|
}
|
|
|
|
|
$cursor->closeCursor();
|
|
|
|
|
|
|
|
|
|
return $children;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Delete a share
|
|
|
|
|
*
|
2016-01-27 06:13:53 -05:00
|
|
|
* @param \OCP\Share\IShare $share
|
2015-10-30 08:10:08 -04:00
|
|
|
*/
|
2016-01-27 06:13:53 -05:00
|
|
|
public function delete(\OCP\Share\IShare $share) {
|
2015-11-02 15:06:55 -05:00
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
2015-10-30 08:10:08 -04:00
|
|
|
$qb->delete('share')
|
2016-01-11 09:58:32 -05:00
|
|
|
->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())));
|
2016-01-28 14:35:46 -05:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* If the share is a group share delete all possible
|
|
|
|
|
* user defined groups shares.
|
|
|
|
|
*/
|
2020-06-24 10:49:16 -04:00
|
|
|
if ($share->getShareType() === IShare::TYPE_GROUP) {
|
2016-01-28 14:35:46 -05:00
|
|
|
$qb->orWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())));
|
2015-10-30 08:10:08 -04:00
|
|
|
}
|
2016-01-28 14:35:46 -05:00
|
|
|
|
2024-10-17 09:42:21 -04:00
|
|
|
$qb->executeStatement();
|
2015-10-30 08:10:08 -04:00
|
|
|
}
|
|
|
|
|
|
2016-01-21 08:31:09 -05:00
|
|
|
/**
|
|
|
|
|
* Unshare a share from the recipient. If this is a group share
|
|
|
|
|
* this means we need a special entry in the share db.
|
|
|
|
|
*
|
2019-09-04 10:50:52 -04:00
|
|
|
* @param IShare $share
|
2016-02-02 10:57:50 -05:00
|
|
|
* @param string $recipient UserId of recipient
|
2016-01-21 08:31:09 -05:00
|
|
|
* @throws BackendError
|
|
|
|
|
* @throws ProviderException
|
|
|
|
|
*/
|
2019-09-04 10:50:52 -04:00
|
|
|
public function deleteFromSelf(IShare $share, $recipient) {
|
|
|
|
|
if ($share->getShareType() === IShare::TYPE_GROUP) {
|
2016-02-02 10:57:50 -05:00
|
|
|
$group = $this->groupManager->get($share->getSharedWith());
|
|
|
|
|
$user = $this->userManager->get($recipient);
|
2016-01-21 08:31:09 -05:00
|
|
|
|
2017-01-19 09:02:46 -05:00
|
|
|
if (is_null($group)) {
|
|
|
|
|
throw new ProviderException('Group "' . $share->getSharedWith() . '" does not exist');
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-02 10:57:50 -05:00
|
|
|
if (!$group->inGroup($user)) {
|
2021-03-30 06:59:40 -04:00
|
|
|
// nothing left to do
|
|
|
|
|
return;
|
2016-01-21 08:31:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Try to fetch user specific share
|
|
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
|
$stmt = $qb->select('*')
|
|
|
|
|
->from('share')
|
2020-06-24 10:49:16 -04:00
|
|
|
->where($qb->expr()->eq('share_type', $qb->createNamedParameter(IShare::TYPE_USERGROUP)))
|
2016-02-02 10:57:50 -05:00
|
|
|
->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient)))
|
2016-01-21 08:31:09 -05:00
|
|
|
->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
|
2025-03-24 10:39:29 -04:00
|
|
|
->andWhere($qb->expr()->in('item_type', $qb->createNamedParameter(['file', 'folder'], IQueryBuilder::PARAM_STR_ARRAY)))
|
2024-10-17 09:42:21 -04:00
|
|
|
->executeQuery();
|
2016-01-21 08:31:09 -05:00
|
|
|
|
|
|
|
|
$data = $stmt->fetch();
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Check if there already is a user specific group share.
|
|
|
|
|
* If there is update it (if required).
|
|
|
|
|
*/
|
|
|
|
|
if ($data === false) {
|
2019-09-04 10:50:52 -04:00
|
|
|
$id = $this->createUserSpecificGroupShare($share, $recipient);
|
|
|
|
|
$permissions = $share->getPermissions();
|
|
|
|
|
} else {
|
|
|
|
|
$permissions = $data['permissions'];
|
|
|
|
|
$id = $data['id'];
|
|
|
|
|
}
|
2016-01-21 08:31:09 -05:00
|
|
|
|
2019-09-04 10:50:52 -04:00
|
|
|
if ($permissions !== 0) {
|
2016-01-21 08:31:09 -05:00
|
|
|
// Update existing usergroup share
|
|
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
|
$qb->update('share')
|
|
|
|
|
->set('permissions', $qb->createNamedParameter(0))
|
2019-09-04 10:50:52 -04:00
|
|
|
->where($qb->expr()->eq('id', $qb->createNamedParameter($id)))
|
2024-10-17 09:42:21 -04:00
|
|
|
->executeStatement();
|
2016-01-21 08:31:09 -05:00
|
|
|
}
|
2020-04-10 04:35:09 -04:00
|
|
|
} elseif ($share->getShareType() === IShare::TYPE_USER) {
|
2016-01-21 08:31:09 -05:00
|
|
|
if ($share->getSharedWith() !== $recipient) {
|
|
|
|
|
throw new ProviderException('Recipient does not match');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// We can just delete user and link shares
|
|
|
|
|
$this->delete($share);
|
|
|
|
|
} else {
|
|
|
|
|
throw new ProviderException('Invalid shareType');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-04 10:50:52 -04:00
|
|
|
protected function createUserSpecificGroupShare(IShare $share, string $recipient): int {
|
|
|
|
|
$type = $share->getNodeType();
|
|
|
|
|
|
2025-03-20 11:20:39 -04:00
|
|
|
$shareFolder = $this->config->getSystemValue('share_folder', '/');
|
|
|
|
|
$allowCustomShareFolder = $this->config->getSystemValueBool('sharing.allow_custom_share_folder', true);
|
|
|
|
|
if ($allowCustomShareFolder) {
|
|
|
|
|
$shareFolder = $this->config->getUserValue($recipient, Application::APP_ID, 'share_folder', $shareFolder);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$target = $shareFolder . '/' . $share->getNode()->getName();
|
|
|
|
|
$target = \OC\Files\Filesystem::normalizePath($target);
|
|
|
|
|
|
2019-09-04 10:50:52 -04:00
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
|
$qb->insert('share')
|
|
|
|
|
->values([
|
2020-06-24 10:49:16 -04:00
|
|
|
'share_type' => $qb->createNamedParameter(IShare::TYPE_USERGROUP),
|
2019-09-04 10:50:52 -04:00
|
|
|
'share_with' => $qb->createNamedParameter($recipient),
|
|
|
|
|
'uid_owner' => $qb->createNamedParameter($share->getShareOwner()),
|
|
|
|
|
'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()),
|
|
|
|
|
'parent' => $qb->createNamedParameter($share->getId()),
|
|
|
|
|
'item_type' => $qb->createNamedParameter($type),
|
|
|
|
|
'item_source' => $qb->createNamedParameter($share->getNodeId()),
|
|
|
|
|
'file_source' => $qb->createNamedParameter($share->getNodeId()),
|
2025-03-20 11:20:39 -04:00
|
|
|
'file_target' => $qb->createNamedParameter($target),
|
2019-09-04 10:50:52 -04:00
|
|
|
'permissions' => $qb->createNamedParameter($share->getPermissions()),
|
|
|
|
|
'stime' => $qb->createNamedParameter($share->getShareTime()->getTimestamp()),
|
2024-10-17 09:42:21 -04:00
|
|
|
])->executeStatement();
|
2019-09-04 10:50:52 -04:00
|
|
|
|
|
|
|
|
return $qb->getLastInsertId();
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-19 03:20:35 -04:00
|
|
|
/**
|
|
|
|
|
* @inheritdoc
|
|
|
|
|
*
|
|
|
|
|
* For now this only works for group shares
|
|
|
|
|
* If this gets implemented for normal shares we have to extend it
|
|
|
|
|
*/
|
|
|
|
|
public function restore(IShare $share, string $recipient): IShare {
|
|
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
|
$qb->select('permissions')
|
|
|
|
|
->from('share')
|
|
|
|
|
->where(
|
|
|
|
|
$qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))
|
|
|
|
|
);
|
2024-10-17 09:42:21 -04:00
|
|
|
$cursor = $qb->executeQuery();
|
2018-06-19 03:20:35 -04:00
|
|
|
$data = $cursor->fetch();
|
|
|
|
|
$cursor->closeCursor();
|
|
|
|
|
|
|
|
|
|
$originalPermission = $data['permissions'];
|
|
|
|
|
|
|
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
|
$qb->update('share')
|
|
|
|
|
->set('permissions', $qb->createNamedParameter($originalPermission))
|
|
|
|
|
->where(
|
|
|
|
|
$qb->expr()->eq('parent', $qb->createNamedParameter($share->getParent()))
|
|
|
|
|
)->andWhere(
|
2020-06-24 10:49:16 -04:00
|
|
|
$qb->expr()->eq('share_type', $qb->createNamedParameter(IShare::TYPE_USERGROUP))
|
2018-06-19 03:20:35 -04:00
|
|
|
)->andWhere(
|
|
|
|
|
$qb->expr()->eq('share_with', $qb->createNamedParameter($recipient))
|
|
|
|
|
);
|
|
|
|
|
|
2024-10-17 09:42:21 -04:00
|
|
|
$qb->executeStatement();
|
2018-06-19 03:20:35 -04:00
|
|
|
|
|
|
|
|
return $this->getShareById($share->getId(), $recipient);
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-29 04:27:39 -05:00
|
|
|
/**
|
|
|
|
|
* @inheritdoc
|
|
|
|
|
*/
|
2016-02-02 10:57:50 -05:00
|
|
|
public function move(\OCP\Share\IShare $share, $recipient) {
|
2020-06-24 10:49:16 -04:00
|
|
|
if ($share->getShareType() === IShare::TYPE_USER) {
|
2016-01-29 04:27:39 -05:00
|
|
|
// Just update the target
|
|
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
|
$qb->update('share')
|
|
|
|
|
->set('file_target', $qb->createNamedParameter($share->getTarget()))
|
|
|
|
|
->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))
|
2024-10-17 09:42:21 -04:00
|
|
|
->executeStatement();
|
2020-06-24 10:49:16 -04:00
|
|
|
} elseif ($share->getShareType() === IShare::TYPE_GROUP) {
|
2016-01-29 04:27:39 -05:00
|
|
|
// Check if there is a usergroup share
|
|
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
|
$stmt = $qb->select('id')
|
|
|
|
|
->from('share')
|
2020-06-24 10:49:16 -04:00
|
|
|
->where($qb->expr()->eq('share_type', $qb->createNamedParameter(IShare::TYPE_USERGROUP)))
|
2016-02-02 10:57:50 -05:00
|
|
|
->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient)))
|
2016-01-29 04:27:39 -05:00
|
|
|
->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
|
2025-03-24 10:39:29 -04:00
|
|
|
->andWhere($qb->expr()->in('item_type', $qb->createNamedParameter(['file', 'folder'], IQueryBuilder::PARAM_STR_ARRAY)))
|
2016-01-29 04:27:39 -05:00
|
|
|
->setMaxResults(1)
|
2024-10-17 09:42:21 -04:00
|
|
|
->executeQuery();
|
2016-01-29 04:27:39 -05:00
|
|
|
|
|
|
|
|
$data = $stmt->fetch();
|
|
|
|
|
$stmt->closeCursor();
|
|
|
|
|
|
2022-05-18 08:54:27 -04:00
|
|
|
$shareAttributes = $this->formatShareAttributes(
|
|
|
|
|
$share->getAttributes()
|
|
|
|
|
);
|
|
|
|
|
|
2016-01-29 04:27:39 -05:00
|
|
|
if ($data === false) {
|
|
|
|
|
// No usergroup share yet. Create one.
|
|
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
|
$qb->insert('share')
|
|
|
|
|
->values([
|
2020-06-24 10:49:16 -04:00
|
|
|
'share_type' => $qb->createNamedParameter(IShare::TYPE_USERGROUP),
|
2016-02-02 10:57:50 -05:00
|
|
|
'share_with' => $qb->createNamedParameter($recipient),
|
|
|
|
|
'uid_owner' => $qb->createNamedParameter($share->getShareOwner()),
|
|
|
|
|
'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()),
|
2016-01-29 04:27:39 -05:00
|
|
|
'parent' => $qb->createNamedParameter($share->getId()),
|
2018-01-09 13:51:50 -05:00
|
|
|
'item_type' => $qb->createNamedParameter($share->getNodeType()),
|
|
|
|
|
'item_source' => $qb->createNamedParameter($share->getNodeId()),
|
|
|
|
|
'file_source' => $qb->createNamedParameter($share->getNodeId()),
|
2016-01-29 04:27:39 -05:00
|
|
|
'file_target' => $qb->createNamedParameter($share->getTarget()),
|
|
|
|
|
'permissions' => $qb->createNamedParameter($share->getPermissions()),
|
2022-05-18 08:54:27 -04:00
|
|
|
'attributes' => $qb->createNamedParameter($shareAttributes),
|
2016-01-29 04:27:39 -05:00
|
|
|
'stime' => $qb->createNamedParameter($share->getShareTime()->getTimestamp()),
|
2024-10-17 09:42:21 -04:00
|
|
|
])->executeStatement();
|
2016-01-29 04:27:39 -05:00
|
|
|
} else {
|
|
|
|
|
// Already a usergroup share. Update it.
|
|
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
|
$qb->update('share')
|
|
|
|
|
->set('file_target', $qb->createNamedParameter($share->getTarget()))
|
|
|
|
|
->where($qb->expr()->eq('id', $qb->createNamedParameter($data['id'])))
|
2024-10-17 09:42:21 -04:00
|
|
|
->executeStatement();
|
2016-01-29 04:27:39 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $share;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-23 10:32:52 -04:00
|
|
|
public function getSharesInFolder($userId, Folder $node, $reshares, $shallow = true) {
|
2024-03-07 05:59:53 -05:00
|
|
|
if (!$shallow) {
|
|
|
|
|
throw new \Exception('non-shallow getSharesInFolder is no longer supported');
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-05 08:59:05 -04:00
|
|
|
return $this->getSharesInFolderInternal($userId, $node, $reshares);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getAllSharesInFolder(Folder $node): array {
|
|
|
|
|
return $this->getSharesInFolderInternal(null, $node, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return array<int, list<IShare>>
|
|
|
|
|
*/
|
|
|
|
|
private function getSharesInFolderInternal(?string $userId, Folder $node, ?bool $reshares): array {
|
2016-06-18 16:04:56 -04:00
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
2022-03-31 05:38:26 -04:00
|
|
|
$qb->select('s.*',
|
2023-01-20 05:45:08 -05:00
|
|
|
'f.fileid', 'f.path', 'f.permissions AS f_permissions', 'f.storage', 'f.path_hash',
|
|
|
|
|
'f.parent AS f_parent', 'f.name', 'f.mimetype', 'f.mimepart', 'f.size', 'f.mtime', 'f.storage_mtime',
|
|
|
|
|
'f.encrypted', 'f.unencrypted_size', 'f.etag', 'f.checksum')
|
2016-06-18 16:04:56 -04:00
|
|
|
->from('share', 's')
|
2025-03-24 10:39:29 -04:00
|
|
|
->andWhere($qb->expr()->in('item_type', $qb->createNamedParameter(['file', 'folder'], IQueryBuilder::PARAM_STR_ARRAY)));
|
2016-06-18 16:04:56 -04:00
|
|
|
|
2025-03-24 10:39:29 -04:00
|
|
|
$qb->andWhere($qb->expr()->in('share_type', $qb->createNamedParameter([IShare::TYPE_USER, IShare::TYPE_GROUP, IShare::TYPE_LINK], IQueryBuilder::PARAM_INT_ARRAY)));
|
2016-06-18 16:04:56 -04:00
|
|
|
|
2025-05-05 08:59:05 -04:00
|
|
|
if ($userId !== null) {
|
|
|
|
|
/**
|
|
|
|
|
* Reshares for this user are shares where they are the owner.
|
|
|
|
|
*/
|
|
|
|
|
if ($reshares !== true) {
|
|
|
|
|
$qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)));
|
|
|
|
|
} else {
|
|
|
|
|
$qb->andWhere(
|
|
|
|
|
$qb->expr()->orX(
|
|
|
|
|
$qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)),
|
|
|
|
|
$qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
2016-06-18 16:04:56 -04:00
|
|
|
}
|
|
|
|
|
|
2022-03-17 12:19:24 -04:00
|
|
|
// todo? maybe get these from the oc_mounts table
|
2022-04-27 08:46:28 -04:00
|
|
|
$childMountNodes = array_filter($node->getDirectoryListing(), function (Node $node): bool {
|
2022-03-17 12:19:24 -04:00
|
|
|
return $node->getInternalPath() === '';
|
|
|
|
|
});
|
2022-04-27 08:46:28 -04:00
|
|
|
$childMountRootIds = array_map(function (Node $node): int {
|
2022-03-17 12:19:24 -04:00
|
|
|
return $node->getId();
|
|
|
|
|
}, $childMountNodes);
|
|
|
|
|
|
2022-01-12 14:44:38 -05:00
|
|
|
$qb->innerJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid'));
|
2024-03-07 05:59:53 -05:00
|
|
|
$qb->andWhere(
|
|
|
|
|
$qb->expr()->orX(
|
|
|
|
|
$qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId())),
|
|
|
|
|
$qb->expr()->in('f.fileid', $qb->createParameter('chunk'))
|
|
|
|
|
)
|
|
|
|
|
);
|
2016-06-18 16:04:56 -04:00
|
|
|
|
|
|
|
|
$qb->orderBy('id');
|
|
|
|
|
|
|
|
|
|
$shares = [];
|
2022-04-27 08:46:28 -04:00
|
|
|
|
|
|
|
|
$chunks = array_chunk($childMountRootIds, 1000);
|
|
|
|
|
|
|
|
|
|
// Force the request to be run when there is 0 mount.
|
|
|
|
|
if (count($chunks) === 0) {
|
|
|
|
|
$chunks = [[]];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ($chunks as $chunk) {
|
|
|
|
|
$qb->setParameter('chunk', $chunk, IQueryBuilder::PARAM_INT_ARRAY);
|
|
|
|
|
$cursor = $qb->executeQuery();
|
|
|
|
|
while ($data = $cursor->fetch()) {
|
|
|
|
|
$shares[$data['fileid']][] = $this->createShare($data);
|
|
|
|
|
}
|
|
|
|
|
$cursor->closeCursor();
|
2016-06-18 16:04:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $shares;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-30 08:10:08 -04:00
|
|
|
/**
|
2016-03-11 02:51:07 -05:00
|
|
|
* @inheritdoc
|
2015-10-30 08:10:08 -04:00
|
|
|
*/
|
2016-02-02 10:57:50 -05:00
|
|
|
public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) {
|
2015-12-03 04:51:41 -05:00
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
|
$qb->select('*')
|
2016-03-09 05:19:57 -05:00
|
|
|
->from('share')
|
2025-03-24 10:39:29 -04:00
|
|
|
->andWhere($qb->expr()->in('item_type', $qb->createNamedParameter(['file', 'folder'], IQueryBuilder::PARAM_STR_ARRAY)));
|
2015-12-03 04:51:41 -05:00
|
|
|
|
|
|
|
|
$qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter($shareType)));
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Reshares for this user are shares where they are the owner.
|
|
|
|
|
*/
|
|
|
|
|
if ($reshares === false) {
|
2016-03-07 04:40:49 -05:00
|
|
|
$qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)));
|
2015-12-03 04:51:41 -05:00
|
|
|
} else {
|
2018-11-01 11:46:38 -04:00
|
|
|
if ($node === null) {
|
2018-10-29 05:03:52 -04:00
|
|
|
$qb->andWhere(
|
|
|
|
|
$qb->expr()->orX(
|
|
|
|
|
$qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)),
|
|
|
|
|
$qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
2015-12-03 04:51:41 -05:00
|
|
|
}
|
|
|
|
|
|
2016-01-20 08:07:56 -05:00
|
|
|
if ($node !== null) {
|
|
|
|
|
$qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId())));
|
2015-12-03 04:51:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($limit !== -1) {
|
|
|
|
|
$qb->setMaxResults($limit);
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-19 08:35:16 -05:00
|
|
|
$qb->setFirstResult($offset);
|
2015-12-03 04:51:41 -05:00
|
|
|
$qb->orderBy('id');
|
|
|
|
|
|
2024-10-17 09:42:21 -04:00
|
|
|
$cursor = $qb->executeQuery();
|
2015-12-03 04:51:41 -05:00
|
|
|
$shares = [];
|
|
|
|
|
while ($data = $cursor->fetch()) {
|
|
|
|
|
$shares[] = $this->createShare($data);
|
|
|
|
|
}
|
|
|
|
|
$cursor->closeCursor();
|
|
|
|
|
|
|
|
|
|
return $shares;
|
2015-10-30 08:10:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2016-01-29 04:07:28 -05:00
|
|
|
* @inheritdoc
|
2015-10-30 08:10:08 -04:00
|
|
|
*/
|
2016-02-02 10:57:50 -05:00
|
|
|
public function getShareById($id, $recipientId = null) {
|
2015-10-30 08:10:08 -04:00
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
|
|
|
|
|
|
$qb->select('*')
|
|
|
|
|
->from('share')
|
2016-01-11 10:19:07 -05:00
|
|
|
->where($qb->expr()->eq('id', $qb->createNamedParameter($id)))
|
|
|
|
|
->andWhere(
|
|
|
|
|
$qb->expr()->in(
|
|
|
|
|
'share_type',
|
2016-01-29 04:07:28 -05:00
|
|
|
$qb->createNamedParameter([
|
2020-06-24 10:49:16 -04:00
|
|
|
IShare::TYPE_USER,
|
|
|
|
|
IShare::TYPE_GROUP,
|
|
|
|
|
IShare::TYPE_LINK,
|
2016-01-29 04:07:28 -05:00
|
|
|
], IQueryBuilder::PARAM_INT_ARRAY)
|
2016-01-11 10:19:07 -05:00
|
|
|
)
|
2016-03-09 05:19:57 -05:00
|
|
|
)
|
2025-03-24 10:39:29 -04:00
|
|
|
->andWhere($qb->expr()->in('item_type', $qb->createNamedParameter(['file', 'folder'], IQueryBuilder::PARAM_STR_ARRAY)));
|
2016-11-17 08:18:47 -05:00
|
|
|
|
2024-10-17 09:42:21 -04:00
|
|
|
$cursor = $qb->executeQuery();
|
2015-10-30 08:10:08 -04:00
|
|
|
$data = $cursor->fetch();
|
|
|
|
|
$cursor->closeCursor();
|
|
|
|
|
|
|
|
|
|
if ($data === false) {
|
|
|
|
|
throw new ShareNotFound();
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-14 10:44:59 -05:00
|
|
|
try {
|
|
|
|
|
$share = $this->createShare($data);
|
|
|
|
|
} catch (InvalidShare $e) {
|
|
|
|
|
throw new ShareNotFound();
|
|
|
|
|
}
|
2015-10-30 08:10:08 -04:00
|
|
|
|
2016-01-29 04:07:28 -05:00
|
|
|
// If the recipient is set for a group share resolve to that user
|
2020-06-24 10:49:16 -04:00
|
|
|
if ($recipientId !== null && $share->getShareType() === IShare::TYPE_GROUP) {
|
2024-03-05 10:42:13 -05:00
|
|
|
$share = $this->resolveGroupShares([(int)$share->getId() => $share], $recipientId)[0];
|
2016-01-29 04:07:28 -05:00
|
|
|
}
|
|
|
|
|
|
2015-10-30 08:10:08 -04:00
|
|
|
return $share;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get shares for a given path
|
|
|
|
|
*
|
|
|
|
|
* @param \OCP\Files\Node $path
|
2016-02-02 10:57:50 -05:00
|
|
|
* @return \OCP\Share\IShare[]
|
2015-10-30 08:10:08 -04:00
|
|
|
*/
|
2015-12-15 03:53:16 -05:00
|
|
|
public function getSharesByPath(Node $path) {
|
|
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
|
|
|
|
|
|
$cursor = $qb->select('*')
|
|
|
|
|
->from('share')
|
|
|
|
|
->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId())))
|
2025-03-24 10:39:29 -04:00
|
|
|
->andWhere($qb->expr()->in('share_type', $qb->createNamedParameter([IShare::TYPE_USER, IShare::TYPE_GROUP, IShare::TYPE_LINK], IQueryBuilder::PARAM_INT_ARRAY)))
|
|
|
|
|
->andWhere($qb->expr()->in('item_type', $qb->createNamedParameter(['file', 'folder'], IQueryBuilder::PARAM_STR_ARRAY)))
|
2024-11-25 04:26:52 -05:00
|
|
|
->orderBy('id', 'ASC')
|
2024-10-17 09:42:21 -04:00
|
|
|
->executeQuery();
|
2015-12-15 03:53:16 -05:00
|
|
|
|
|
|
|
|
$shares = [];
|
|
|
|
|
while ($data = $cursor->fetch()) {
|
|
|
|
|
$shares[] = $this->createShare($data);
|
|
|
|
|
}
|
|
|
|
|
$cursor->closeCursor();
|
|
|
|
|
|
|
|
|
|
return $shares;
|
2015-10-30 08:10:08 -04:00
|
|
|
}
|
|
|
|
|
|
2016-09-02 05:23:55 -04:00
|
|
|
/**
|
|
|
|
|
* Returns whether the given database result can be interpreted as
|
|
|
|
|
* a share with accessible file (not trashed, not deleted)
|
|
|
|
|
*/
|
|
|
|
|
private function isAccessibleResult($data) {
|
|
|
|
|
// exclude shares leading to deleted file entries
|
2020-03-26 08:49:47 -04:00
|
|
|
if ($data['fileid'] === null || $data['path'] === null) {
|
2016-09-02 05:23:55 -04:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// exclude shares leading to trashbin on home storages
|
|
|
|
|
$pathSections = explode('/', $data['path'], 2);
|
|
|
|
|
// FIXME: would not detect rare md5'd home storage case properly
|
2017-03-28 09:11:07 -04:00
|
|
|
if ($pathSections[0] !== 'files'
|
2023-05-15 07:47:19 -04:00
|
|
|
&& (str_starts_with($data['storage_string_id'], 'home::') || str_starts_with($data['storage_string_id'], 'object::user'))) {
|
2016-09-02 05:23:55 -04:00
|
|
|
return false;
|
2023-03-28 07:48:43 -04:00
|
|
|
} elseif ($pathSections[0] === '__groupfolders'
|
|
|
|
|
&& str_starts_with($pathSections[1], 'trash/')
|
|
|
|
|
) {
|
|
|
|
|
// exclude shares leading to trashbin on group folders storages
|
|
|
|
|
return false;
|
2016-09-02 05:23:55 -04:00
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-30 08:10:08 -04:00
|
|
|
/**
|
2016-01-29 09:26:04 -05:00
|
|
|
* @inheritdoc
|
2015-10-30 08:10:08 -04:00
|
|
|
*/
|
2016-02-02 10:57:50 -05:00
|
|
|
public function getSharedWith($userId, $shareType, $node, $limit, $offset) {
|
2016-01-19 07:55:51 -05:00
|
|
|
/** @var Share[] $shares */
|
2015-12-03 04:51:41 -05:00
|
|
|
$shares = [];
|
|
|
|
|
|
2020-06-24 10:49:16 -04:00
|
|
|
if ($shareType === IShare::TYPE_USER) {
|
2016-01-19 07:55:51 -05:00
|
|
|
//Get shares directly with this user
|
2015-12-03 04:51:41 -05:00
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
2016-11-17 08:18:47 -05:00
|
|
|
$qb->select('s.*',
|
|
|
|
|
'f.fileid', 'f.path', 'f.permissions AS f_permissions', 'f.storage', 'f.path_hash',
|
|
|
|
|
'f.parent AS f_parent', 'f.name', 'f.mimetype', 'f.mimepart', 'f.size', 'f.mtime', 'f.storage_mtime',
|
|
|
|
|
'f.encrypted', 'f.unencrypted_size', 'f.etag', 'f.checksum'
|
|
|
|
|
)
|
2016-09-02 05:23:55 -04:00
|
|
|
->selectAlias('st.id', 'storage_string_id')
|
|
|
|
|
->from('share', 's')
|
|
|
|
|
->leftJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid'))
|
|
|
|
|
->leftJoin('f', 'storages', 'st', $qb->expr()->eq('f.storage', 'st.numeric_id'));
|
2015-12-03 04:51:41 -05:00
|
|
|
|
|
|
|
|
// Order by id
|
2016-09-02 05:23:55 -04:00
|
|
|
$qb->orderBy('s.id');
|
2015-12-03 04:51:41 -05:00
|
|
|
|
|
|
|
|
// Set limit and offset
|
|
|
|
|
if ($limit !== -1) {
|
|
|
|
|
$qb->setMaxResults($limit);
|
|
|
|
|
}
|
|
|
|
|
$qb->setFirstResult($offset);
|
|
|
|
|
|
2020-06-24 10:49:16 -04:00
|
|
|
$qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(IShare::TYPE_USER)))
|
2016-03-09 05:19:57 -05:00
|
|
|
->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId)))
|
2025-03-24 10:39:29 -04:00
|
|
|
->andWhere($qb->expr()->in('item_type', $qb->createNamedParameter(['file', 'folder'], IQueryBuilder::PARAM_STR_ARRAY)));
|
2015-12-03 04:51:41 -05:00
|
|
|
|
2016-01-29 09:26:04 -05:00
|
|
|
// Filter by node if provided
|
|
|
|
|
if ($node !== null) {
|
|
|
|
|
$qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId())));
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-17 09:42:21 -04:00
|
|
|
$cursor = $qb->executeQuery();
|
2015-12-03 04:51:41 -05:00
|
|
|
|
|
|
|
|
while ($data = $cursor->fetch()) {
|
2020-11-09 10:26:09 -05:00
|
|
|
if ($data['fileid'] && $data['path'] === null) {
|
|
|
|
|
$data['path'] = (string)$data['path'];
|
|
|
|
|
$data['name'] = (string)$data['name'];
|
|
|
|
|
$data['checksum'] = (string)$data['checksum'];
|
|
|
|
|
}
|
2016-09-02 05:23:55 -04:00
|
|
|
if ($this->isAccessibleResult($data)) {
|
|
|
|
|
$shares[] = $this->createShare($data);
|
|
|
|
|
}
|
2015-12-03 04:51:41 -05:00
|
|
|
}
|
|
|
|
|
$cursor->closeCursor();
|
2020-06-24 10:49:16 -04:00
|
|
|
} elseif ($shareType === IShare::TYPE_GROUP) {
|
2022-08-17 08:29:32 -04:00
|
|
|
$user = new LazyUser($userId, $this->userManager);
|
|
|
|
|
$allGroups = $this->groupManager->getUserGroupIds($user);
|
2016-01-19 07:55:51 -05:00
|
|
|
|
2016-01-26 06:58:41 -05:00
|
|
|
/** @var Share[] $shares2 */
|
|
|
|
|
$shares2 = [];
|
|
|
|
|
|
2016-01-19 07:55:51 -05:00
|
|
|
$start = 0;
|
|
|
|
|
while (true) {
|
2022-08-16 05:17:27 -04:00
|
|
|
$groups = array_slice($allGroups, $start, 1000);
|
|
|
|
|
$start += 1000;
|
2016-01-19 07:55:51 -05:00
|
|
|
|
|
|
|
|
if ($groups === []) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
2016-11-17 17:30:50 -05:00
|
|
|
$qb->select('s.*',
|
|
|
|
|
'f.fileid', 'f.path', 'f.permissions AS f_permissions', 'f.storage', 'f.path_hash',
|
|
|
|
|
'f.parent AS f_parent', 'f.name', 'f.mimetype', 'f.mimepart', 'f.size', 'f.mtime', 'f.storage_mtime',
|
|
|
|
|
'f.encrypted', 'f.unencrypted_size', 'f.etag', 'f.checksum'
|
|
|
|
|
)
|
2016-09-02 05:23:55 -04:00
|
|
|
->selectAlias('st.id', 'storage_string_id')
|
|
|
|
|
->from('share', 's')
|
|
|
|
|
->leftJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid'))
|
|
|
|
|
->leftJoin('f', 'storages', 'st', $qb->expr()->eq('f.storage', 'st.numeric_id'))
|
|
|
|
|
->orderBy('s.id')
|
2016-01-19 07:55:51 -05:00
|
|
|
->setFirstResult(0);
|
|
|
|
|
|
|
|
|
|
if ($limit !== -1) {
|
2016-01-20 08:07:56 -05:00
|
|
|
$qb->setMaxResults($limit - count($shares));
|
2016-01-19 07:55:51 -05:00
|
|
|
}
|
|
|
|
|
|
2016-01-29 09:26:04 -05:00
|
|
|
// Filter by node if provided
|
|
|
|
|
if ($node !== null) {
|
|
|
|
|
$qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId())));
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-04 11:42:28 -04:00
|
|
|
$groups = array_filter($groups);
|
2016-01-19 07:55:51 -05:00
|
|
|
|
2020-06-24 10:49:16 -04:00
|
|
|
$qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(IShare::TYPE_GROUP)))
|
2016-03-09 05:19:57 -05:00
|
|
|
->andWhere($qb->expr()->in('share_with', $qb->createNamedParameter(
|
|
|
|
|
$groups,
|
|
|
|
|
IQueryBuilder::PARAM_STR_ARRAY
|
|
|
|
|
)))
|
2025-03-24 10:39:29 -04:00
|
|
|
->andWhere($qb->expr()->in('item_type', $qb->createNamedParameter(['file', 'folder'], IQueryBuilder::PARAM_STR_ARRAY)));
|
2016-01-19 07:55:51 -05:00
|
|
|
|
2024-10-17 09:42:21 -04:00
|
|
|
$cursor = $qb->executeQuery();
|
2016-01-19 07:55:51 -05:00
|
|
|
while ($data = $cursor->fetch()) {
|
2016-01-20 08:07:56 -05:00
|
|
|
if ($offset > 0) {
|
|
|
|
|
$offset--;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2016-09-02 05:23:55 -04:00
|
|
|
|
|
|
|
|
if ($this->isAccessibleResult($data)) {
|
2024-03-05 10:42:13 -05:00
|
|
|
$share = $this->createShare($data);
|
|
|
|
|
$shares2[$share->getId()] = $share;
|
2016-09-02 05:23:55 -04:00
|
|
|
}
|
2016-01-19 07:55:51 -05:00
|
|
|
}
|
|
|
|
|
$cursor->closeCursor();
|
|
|
|
|
}
|
2016-01-20 08:07:56 -05:00
|
|
|
|
|
|
|
|
/*
|
2020-04-09 03:22:29 -04:00
|
|
|
* Resolve all group shares to user specific shares
|
|
|
|
|
*/
|
2016-10-06 08:27:44 -04:00
|
|
|
$shares = $this->resolveGroupShares($shares2, $userId);
|
2015-12-03 04:51:41 -05:00
|
|
|
} else {
|
2016-01-20 08:17:25 -05:00
|
|
|
throw new BackendError('Invalid backend');
|
2015-12-03 04:51:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $shares;
|
2015-10-30 08:10:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2016-01-14 10:44:59 -05:00
|
|
|
* Get a share by token
|
2015-10-30 08:10:08 -04:00
|
|
|
*
|
|
|
|
|
* @param string $token
|
2016-02-02 10:57:50 -05:00
|
|
|
* @return \OCP\Share\IShare
|
2016-01-14 10:44:59 -05:00
|
|
|
* @throws ShareNotFound
|
2015-10-30 08:10:08 -04:00
|
|
|
*/
|
2016-01-14 10:44:59 -05:00
|
|
|
public function getShareByToken($token) {
|
|
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
|
|
|
|
|
|
$cursor = $qb->select('*')
|
|
|
|
|
->from('share')
|
2020-06-24 10:49:16 -04:00
|
|
|
->where($qb->expr()->eq('share_type', $qb->createNamedParameter(IShare::TYPE_LINK)))
|
2016-01-14 10:44:59 -05:00
|
|
|
->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token)))
|
2025-03-24 10:39:29 -04:00
|
|
|
->andWhere($qb->expr()->in('item_type', $qb->createNamedParameter(['file', 'folder'], IQueryBuilder::PARAM_STR_ARRAY)))
|
2024-10-12 11:51:56 -04:00
|
|
|
->executeQuery();
|
2016-01-14 10:44:59 -05:00
|
|
|
|
|
|
|
|
$data = $cursor->fetch();
|
|
|
|
|
|
|
|
|
|
if ($data === false) {
|
|
|
|
|
throw new ShareNotFound();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$share = $this->createShare($data);
|
|
|
|
|
} catch (InvalidShare $e) {
|
|
|
|
|
throw new ShareNotFound();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $share;
|
2015-10-30 08:10:08 -04:00
|
|
|
}
|
2016-11-17 08:18:47 -05:00
|
|
|
|
2015-10-30 08:10:08 -04:00
|
|
|
/**
|
2024-08-27 03:29:21 -04:00
|
|
|
* Create a share object from a database row
|
2015-10-30 08:10:08 -04:00
|
|
|
*
|
|
|
|
|
* @param mixed[] $data
|
2016-01-27 14:51:26 -05:00
|
|
|
* @return \OCP\Share\IShare
|
2016-01-15 15:15:25 -05:00
|
|
|
* @throws InvalidShare
|
2015-10-30 08:10:08 -04:00
|
|
|
*/
|
|
|
|
|
private function createShare($data) {
|
2016-05-11 14:48:27 -04:00
|
|
|
$share = new Share($this->rootFolder, $this->userManager);
|
2015-10-30 08:10:08 -04:00
|
|
|
$share->setId((int)$data['id'])
|
|
|
|
|
->setShareType((int)$data['share_type'])
|
2015-11-02 15:06:55 -05:00
|
|
|
->setPermissions((int)$data['permissions'])
|
2015-11-06 06:05:19 -05:00
|
|
|
->setTarget($data['file_target'])
|
2020-11-09 10:26:09 -05:00
|
|
|
->setNote((string)$data['note'])
|
2018-10-16 04:31:38 -04:00
|
|
|
->setMailSend((bool)$data['mail_send'])
|
2019-08-21 10:15:23 -04:00
|
|
|
->setStatus((int)$data['accepted'])
|
2024-10-12 11:51:56 -04:00
|
|
|
->setLabel($data['label'] ?? '');
|
2015-10-30 08:10:08 -04:00
|
|
|
|
2016-01-27 14:51:26 -05:00
|
|
|
$shareTime = new \DateTime();
|
|
|
|
|
$shareTime->setTimestamp((int)$data['stime']);
|
|
|
|
|
$share->setShareTime($shareTime);
|
|
|
|
|
|
2020-06-24 10:49:16 -04:00
|
|
|
if ($share->getShareType() === IShare::TYPE_USER) {
|
2016-02-02 10:57:50 -05:00
|
|
|
$share->setSharedWith($data['share_with']);
|
2022-08-17 08:29:32 -04:00
|
|
|
$displayName = $this->userManager->getDisplayName($data['share_with']);
|
|
|
|
|
if ($displayName !== null) {
|
|
|
|
|
$share->setSharedWithDisplayName($displayName);
|
2019-07-03 05:31:25 -04:00
|
|
|
}
|
2020-06-24 10:49:16 -04:00
|
|
|
} elseif ($share->getShareType() === IShare::TYPE_GROUP) {
|
2016-02-02 10:57:50 -05:00
|
|
|
$share->setSharedWith($data['share_with']);
|
2022-10-08 10:05:52 -04:00
|
|
|
$group = $this->groupManager->get($data['share_with']);
|
|
|
|
|
if ($group !== null) {
|
|
|
|
|
$share->setSharedWithDisplayName($group->getDisplayName());
|
|
|
|
|
}
|
2020-06-24 10:49:16 -04:00
|
|
|
} elseif ($share->getShareType() === IShare::TYPE_LINK) {
|
2017-03-28 09:11:07 -04:00
|
|
|
$share->setPassword($data['password']);
|
2018-10-12 14:15:40 -04:00
|
|
|
$share->setSendPasswordByTalk((bool)$data['password_by_talk']);
|
2015-10-30 08:10:08 -04:00
|
|
|
$share->setToken($data['token']);
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-18 08:54:27 -04:00
|
|
|
$share = $this->updateShareAttributes($share, $data['attributes']);
|
|
|
|
|
|
2016-03-07 04:40:49 -05:00
|
|
|
$share->setSharedBy($data['uid_initiator']);
|
|
|
|
|
$share->setShareOwner($data['uid_owner']);
|
2015-11-23 11:10:58 -05:00
|
|
|
|
2016-02-04 06:51:23 -05:00
|
|
|
$share->setNodeId((int)$data['file_source']);
|
2016-02-04 08:28:09 -05:00
|
|
|
$share->setNodeType($data['item_type']);
|
2015-10-30 08:10:08 -04:00
|
|
|
|
|
|
|
|
if ($data['expiration'] !== null) {
|
|
|
|
|
$expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']);
|
|
|
|
|
$share->setExpirationDate($expiration);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-17 08:18:47 -05:00
|
|
|
if (isset($data['f_permissions'])) {
|
|
|
|
|
$entryData = $data;
|
|
|
|
|
$entryData['permissions'] = $entryData['f_permissions'];
|
2017-07-23 15:03:26 -04:00
|
|
|
$entryData['parent'] = $entryData['f_parent'];
|
2016-11-17 08:18:47 -05:00
|
|
|
$share->setNodeCacheEntry(Cache::cacheEntryFromData($entryData,
|
|
|
|
|
\OC::$server->getMimeTypeLoader()));
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-13 07:02:23 -05:00
|
|
|
$share->setProviderId($this->identifier());
|
2018-10-18 06:38:07 -04:00
|
|
|
$share->setHideDownload((int)$data['hide_download'] === 1);
|
2024-09-02 09:02:50 -04:00
|
|
|
$share->setReminderSent((bool)$data['reminder_sent']);
|
2016-01-13 07:02:23 -05:00
|
|
|
|
2015-10-30 08:10:08 -04:00
|
|
|
return $share;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-19 07:55:51 -05:00
|
|
|
/**
|
2024-03-05 10:42:13 -05:00
|
|
|
* Update the data from group shares with any per-user modifications
|
|
|
|
|
*
|
|
|
|
|
* @param array<int, Share> $shareMap shares indexed by share id
|
2016-10-06 08:27:44 -04:00
|
|
|
* @param $userId
|
|
|
|
|
* @return Share[] The updates shares if no update is found for a share return the original
|
2016-01-19 07:55:51 -05:00
|
|
|
*/
|
2024-03-05 10:42:13 -05:00
|
|
|
private function resolveGroupShares($shareMap, $userId) {
|
|
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
|
$query = $qb->select('*')
|
|
|
|
|
->from('share')
|
|
|
|
|
->where($qb->expr()->eq('share_with', $qb->createNamedParameter($userId)))
|
|
|
|
|
->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(IShare::TYPE_USERGROUP)))
|
2025-03-24 10:39:29 -04:00
|
|
|
->andWhere($qb->expr()->in('item_type', $qb->createNamedParameter(['file', 'folder'], IQueryBuilder::PARAM_STR_ARRAY)));
|
2024-03-05 10:42:13 -05:00
|
|
|
|
|
|
|
|
// this is called with either all group shares or one group share.
|
|
|
|
|
// for all shares it's easier to just only search by share_with,
|
|
|
|
|
// for a single share it's efficient to filter by parent
|
|
|
|
|
if (count($shareMap) === 1) {
|
|
|
|
|
$share = reset($shareMap);
|
|
|
|
|
$query->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())));
|
|
|
|
|
}
|
2016-10-06 08:27:44 -04:00
|
|
|
|
2024-10-17 09:42:21 -04:00
|
|
|
$stmt = $query->executeQuery();
|
2016-10-06 08:27:44 -04:00
|
|
|
|
2024-03-05 10:42:13 -05:00
|
|
|
while ($data = $stmt->fetch()) {
|
2024-03-19 08:09:10 -04:00
|
|
|
if (array_key_exists($data['parent'], $shareMap)) {
|
|
|
|
|
$shareMap[$data['parent']]->setPermissions((int)$data['permissions']);
|
|
|
|
|
$shareMap[$data['parent']]->setStatus((int)$data['accepted']);
|
|
|
|
|
$shareMap[$data['parent']]->setTarget($data['file_target']);
|
|
|
|
|
$shareMap[$data['parent']]->setParent($data['parent']);
|
|
|
|
|
}
|
2016-01-19 07:55:51 -05:00
|
|
|
}
|
|
|
|
|
|
2024-03-05 10:42:13 -05:00
|
|
|
return array_values($shareMap);
|
2016-01-19 07:55:51 -05:00
|
|
|
}
|
|
|
|
|
|
2016-04-04 06:28:19 -04:00
|
|
|
/**
|
|
|
|
|
* A user is deleted from the system
|
|
|
|
|
* So clean up the relevant shares.
|
|
|
|
|
*
|
|
|
|
|
* @param string $uid
|
|
|
|
|
* @param int $shareType
|
|
|
|
|
*/
|
|
|
|
|
public function userDeleted($uid, $shareType) {
|
|
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
|
|
|
|
|
|
$qb->delete('share');
|
|
|
|
|
|
2020-06-24 10:49:16 -04:00
|
|
|
if ($shareType === IShare::TYPE_USER) {
|
2016-04-04 06:28:19 -04:00
|
|
|
/*
|
|
|
|
|
* Delete all user shares that are owned by this user
|
|
|
|
|
* or that are received by this user
|
|
|
|
|
*/
|
|
|
|
|
|
2020-06-24 10:49:16 -04:00
|
|
|
$qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(IShare::TYPE_USER)));
|
2016-04-04 06:28:19 -04:00
|
|
|
|
|
|
|
|
$qb->andWhere(
|
|
|
|
|
$qb->expr()->orX(
|
|
|
|
|
$qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)),
|
|
|
|
|
$qb->expr()->eq('share_with', $qb->createNamedParameter($uid))
|
|
|
|
|
)
|
|
|
|
|
);
|
2020-06-24 10:49:16 -04:00
|
|
|
} elseif ($shareType === IShare::TYPE_GROUP) {
|
2016-04-04 06:28:19 -04:00
|
|
|
/*
|
|
|
|
|
* Delete all group shares that are owned by this user
|
|
|
|
|
* Or special user group shares that are received by this user
|
|
|
|
|
*/
|
|
|
|
|
$qb->where(
|
|
|
|
|
$qb->expr()->andX(
|
2025-03-24 10:39:29 -04:00
|
|
|
$qb->expr()->in('share_type', $qb->createNamedParameter([IShare::TYPE_GROUP, IShare::TYPE_USERGROUP], IQueryBuilder::PARAM_INT_ARRAY)),
|
2016-04-04 06:28:19 -04:00
|
|
|
$qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid))
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$qb->orWhere(
|
|
|
|
|
$qb->expr()->andX(
|
2020-06-24 10:49:16 -04:00
|
|
|
$qb->expr()->eq('share_type', $qb->createNamedParameter(IShare::TYPE_USERGROUP)),
|
2016-04-04 06:28:19 -04:00
|
|
|
$qb->expr()->eq('share_with', $qb->createNamedParameter($uid))
|
|
|
|
|
)
|
|
|
|
|
);
|
2020-06-24 10:49:16 -04:00
|
|
|
} elseif ($shareType === IShare::TYPE_LINK) {
|
2016-04-04 06:28:19 -04:00
|
|
|
/*
|
|
|
|
|
* Delete all link shares owned by this user.
|
|
|
|
|
* And all link shares initiated by this user (until #22327 is in)
|
|
|
|
|
*/
|
2020-06-24 10:49:16 -04:00
|
|
|
$qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(IShare::TYPE_LINK)));
|
2016-04-04 06:28:19 -04:00
|
|
|
|
|
|
|
|
$qb->andWhere(
|
|
|
|
|
$qb->expr()->orX(
|
|
|
|
|
$qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)),
|
|
|
|
|
$qb->expr()->eq('uid_initiator', $qb->createNamedParameter($uid))
|
|
|
|
|
)
|
|
|
|
|
);
|
2020-01-28 10:00:03 -05:00
|
|
|
} else {
|
2024-02-08 09:47:39 -05:00
|
|
|
$e = new \InvalidArgumentException('Default share provider tried to delete all shares for type: ' . $shareType);
|
2024-07-05 03:47:40 -04:00
|
|
|
$this->logger->error($e->getMessage(), ['exception' => $e]);
|
2020-01-28 10:00:03 -05:00
|
|
|
return;
|
2016-04-04 06:28:19 -04:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 09:42:21 -04:00
|
|
|
$qb->executeStatement();
|
2016-04-04 06:28:19 -04:00
|
|
|
}
|
2016-04-12 03:46:25 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Delete all shares received by this group. As well as any custom group
|
|
|
|
|
* shares for group members.
|
|
|
|
|
*
|
|
|
|
|
* @param string $gid
|
|
|
|
|
*/
|
|
|
|
|
public function groupDeleted($gid) {
|
|
|
|
|
/*
|
|
|
|
|
* First delete all custom group shares for group members
|
|
|
|
|
*/
|
|
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
|
$qb->select('id')
|
|
|
|
|
->from('share')
|
2020-06-24 10:49:16 -04:00
|
|
|
->where($qb->expr()->eq('share_type', $qb->createNamedParameter(IShare::TYPE_GROUP)))
|
2016-04-12 03:46:25 -04:00
|
|
|
->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid)));
|
|
|
|
|
|
2024-10-17 09:42:21 -04:00
|
|
|
$cursor = $qb->executeQuery();
|
2016-04-12 03:46:25 -04:00
|
|
|
$ids = [];
|
|
|
|
|
while ($row = $cursor->fetch()) {
|
|
|
|
|
$ids[] = (int)$row['id'];
|
|
|
|
|
}
|
|
|
|
|
$cursor->closeCursor();
|
|
|
|
|
|
|
|
|
|
if (!empty($ids)) {
|
|
|
|
|
$chunks = array_chunk($ids, 100);
|
2024-08-06 08:46:50 -04:00
|
|
|
|
|
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
|
$qb->delete('share')
|
|
|
|
|
->where($qb->expr()->eq('share_type', $qb->createNamedParameter(IShare::TYPE_USERGROUP)))
|
|
|
|
|
->andWhere($qb->expr()->in('parent', $qb->createParameter('parents')));
|
|
|
|
|
|
2016-04-12 03:46:25 -04:00
|
|
|
foreach ($chunks as $chunk) {
|
2024-08-06 08:46:50 -04:00
|
|
|
$qb->setParameter('parents', $chunk, IQueryBuilder::PARAM_INT_ARRAY);
|
2024-10-17 09:42:21 -04:00
|
|
|
$qb->executeStatement();
|
2016-04-12 03:46:25 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Now delete all the group shares
|
|
|
|
|
*/
|
|
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
|
$qb->delete('share')
|
2020-06-24 10:49:16 -04:00
|
|
|
->where($qb->expr()->eq('share_type', $qb->createNamedParameter(IShare::TYPE_GROUP)))
|
2016-04-12 03:46:25 -04:00
|
|
|
->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid)));
|
2024-10-17 09:42:21 -04:00
|
|
|
$qb->executeStatement();
|
2016-04-12 03:46:25 -04:00
|
|
|
}
|
2016-04-13 09:00:12 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Delete custom group shares to this group for this user
|
|
|
|
|
*
|
|
|
|
|
* @param string $uid
|
|
|
|
|
* @param string $gid
|
2024-06-13 11:05:29 -04:00
|
|
|
* @return void
|
2016-04-13 09:00:12 -04:00
|
|
|
*/
|
|
|
|
|
public function userDeletedFromGroup($uid, $gid) {
|
|
|
|
|
/*
|
|
|
|
|
* Get all group shares
|
|
|
|
|
*/
|
|
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
|
$qb->select('id')
|
|
|
|
|
->from('share')
|
2020-06-24 10:49:16 -04:00
|
|
|
->where($qb->expr()->eq('share_type', $qb->createNamedParameter(IShare::TYPE_GROUP)))
|
2016-04-13 09:00:12 -04:00
|
|
|
->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid)));
|
|
|
|
|
|
2024-05-22 05:55:47 -04:00
|
|
|
$cursor = $qb->executeQuery();
|
2016-04-13 09:00:12 -04:00
|
|
|
$ids = [];
|
|
|
|
|
while ($row = $cursor->fetch()) {
|
|
|
|
|
$ids[] = (int)$row['id'];
|
|
|
|
|
}
|
|
|
|
|
$cursor->closeCursor();
|
|
|
|
|
|
|
|
|
|
if (!empty($ids)) {
|
|
|
|
|
$chunks = array_chunk($ids, 100);
|
2024-08-06 08:46:50 -04:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Delete all special shares with this user for the found group shares
|
|
|
|
|
*/
|
|
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
|
$qb->delete('share')
|
|
|
|
|
->where($qb->expr()->eq('share_type', $qb->createNamedParameter(IShare::TYPE_USERGROUP)))
|
|
|
|
|
->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($uid)))
|
|
|
|
|
->andWhere($qb->expr()->in('parent', $qb->createParameter('parents')));
|
|
|
|
|
|
2016-04-13 09:00:12 -04:00
|
|
|
foreach ($chunks as $chunk) {
|
2024-08-06 08:46:50 -04:00
|
|
|
$qb->setParameter('parents', $chunk, IQueryBuilder::PARAM_INT_ARRAY);
|
2024-05-22 05:55:47 -04:00
|
|
|
$qb->executeStatement();
|
2016-04-13 09:00:12 -04:00
|
|
|
}
|
|
|
|
|
}
|
2024-05-22 05:55:47 -04:00
|
|
|
|
|
|
|
|
if ($this->shareManager->shareWithGroupMembersOnly()) {
|
2024-06-13 11:05:29 -04:00
|
|
|
$user = $this->userManager->get($uid);
|
|
|
|
|
if ($user === null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$userGroups = $this->groupManager->getUserGroupIds($user);
|
|
|
|
|
$userGroups = array_diff($userGroups, $this->shareManager->shareWithGroupMembersOnlyExcludeGroupsList());
|
|
|
|
|
|
|
|
|
|
// Delete user shares received by the user from users in the group.
|
|
|
|
|
$userReceivedShares = $this->shareManager->getSharedWith($uid, IShare::TYPE_USER, null, -1);
|
|
|
|
|
foreach ($userReceivedShares as $share) {
|
|
|
|
|
$owner = $this->userManager->get($share->getSharedBy());
|
|
|
|
|
if ($owner === null) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
$ownerGroups = $this->groupManager->getUserGroupIds($owner);
|
|
|
|
|
$mutualGroups = array_intersect($userGroups, $ownerGroups);
|
2024-05-22 05:55:47 -04:00
|
|
|
|
2024-06-13 11:05:29 -04:00
|
|
|
if (count($mutualGroups) === 0) {
|
|
|
|
|
$this->shareManager->deleteShare($share);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Delete user shares from the user to users in the group.
|
|
|
|
|
$userEmittedShares = $this->shareManager->getSharesBy($uid, IShare::TYPE_USER, null, true, -1);
|
|
|
|
|
foreach ($userEmittedShares as $share) {
|
|
|
|
|
$recipient = $this->userManager->get($share->getSharedWith());
|
|
|
|
|
if ($recipient === null) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
$recipientGroups = $this->groupManager->getUserGroupIds($recipient);
|
|
|
|
|
$mutualGroups = array_intersect($userGroups, $recipientGroups);
|
|
|
|
|
|
|
|
|
|
if (count($mutualGroups) === 0) {
|
|
|
|
|
$this->shareManager->deleteShare($share);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-22 05:55:47 -04:00
|
|
|
}
|
2016-04-13 09:00:12 -04:00
|
|
|
}
|
2016-12-22 15:44:21 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @inheritdoc
|
|
|
|
|
*/
|
|
|
|
|
public function getAccessList($nodes, $currentAccess) {
|
|
|
|
|
$ids = [];
|
|
|
|
|
foreach ($nodes as $node) {
|
|
|
|
|
$ids[] = $node->getId();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
|
|
2025-03-24 10:39:29 -04:00
|
|
|
$shareTypes = [IShare::TYPE_USER, IShare::TYPE_GROUP, IShare::TYPE_LINK];
|
2016-12-22 15:44:21 -05:00
|
|
|
|
|
|
|
|
if ($currentAccess) {
|
2025-03-24 10:39:29 -04:00
|
|
|
$shareTypes[] = IShare::TYPE_USERGROUP;
|
2016-12-22 15:44:21 -05:00
|
|
|
}
|
|
|
|
|
|
2017-03-27 10:06:31 -04:00
|
|
|
$qb->select('id', 'parent', 'share_type', 'share_with', 'file_source', 'file_target', 'permissions')
|
2016-12-22 15:44:21 -05:00
|
|
|
->from('share')
|
|
|
|
|
->where(
|
2025-03-24 10:39:29 -04:00
|
|
|
$qb->expr()->in('share_type', $qb->createNamedParameter($shareTypes, IQueryBuilder::PARAM_INT_ARRAY))
|
2016-12-22 15:44:21 -05:00
|
|
|
)
|
|
|
|
|
->andWhere($qb->expr()->in('file_source', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY)))
|
2025-03-24 10:39:29 -04:00
|
|
|
->andWhere($qb->expr()->in('item_type', $qb->createNamedParameter(['file', 'folder'], IQueryBuilder::PARAM_STR_ARRAY)));
|
2025-01-29 11:29:30 -05:00
|
|
|
|
|
|
|
|
// Ensure accepted is true for user and usergroup type
|
|
|
|
|
$qb->andWhere(
|
|
|
|
|
$qb->expr()->orX(
|
|
|
|
|
$qb->expr()->andX(
|
|
|
|
|
$qb->expr()->neq('share_type', $qb->createNamedParameter(IShare::TYPE_USER)),
|
|
|
|
|
$qb->expr()->neq('share_type', $qb->createNamedParameter(IShare::TYPE_USERGROUP)),
|
|
|
|
|
),
|
|
|
|
|
$qb->expr()->eq('accepted', $qb->createNamedParameter(IShare::STATUS_ACCEPTED, IQueryBuilder::PARAM_INT)),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
|
2024-10-17 09:42:21 -04:00
|
|
|
$cursor = $qb->executeQuery();
|
2016-12-22 15:44:21 -05:00
|
|
|
|
|
|
|
|
$users = [];
|
|
|
|
|
$link = false;
|
|
|
|
|
while ($row = $cursor->fetch()) {
|
|
|
|
|
$type = (int)$row['share_type'];
|
2020-06-24 10:49:16 -04:00
|
|
|
if ($type === IShare::TYPE_USER) {
|
2016-12-22 15:44:21 -05:00
|
|
|
$uid = $row['share_with'];
|
2023-07-07 06:13:21 -04:00
|
|
|
$users[$uid] = $users[$uid] ?? [];
|
2017-03-27 10:06:31 -04:00
|
|
|
$users[$uid][$row['id']] = $row;
|
2020-06-24 10:49:16 -04:00
|
|
|
} elseif ($type === IShare::TYPE_GROUP) {
|
2016-12-22 15:44:21 -05:00
|
|
|
$gid = $row['share_with'];
|
|
|
|
|
$group = $this->groupManager->get($gid);
|
|
|
|
|
|
Fix 500 Internal Server Error on writing
In some not yet completely determined configurations, the following error could occur while writing a file:
Error: Call to a member function getUsers() on null
/var/www/nextcloud/lib/private/Share20/Manager.php - line 1277: OC\Share20\DefaultShareProvider->getAccessList(Array, true)
/var/www/nextcloud/lib/private/Share20/ShareHelper.php - line 51: OC\Share20\Manager->getAccessList(Object(OC\Files\Node\Folder), true, true)
/var/www/nextcloud/apps/activity/lib/FilesHooks.php - line 616: OC\Share20\ShareHelper->getPathsForAccessList(Object(OC\Files\Node\File))
/var/www/nextcloud/apps/activity/lib/FilesHooks.php - line 196: OCA\Activity\FilesHooks->getUserPathsFromPath('/path/to/file', 'user')
/var/www/nextcloud/apps/activity/lib/FilesHooks.php - line 157: OCA\Activity\FilesHooks->addNotificationsForFileAction('/path/to/file', 'file_changed', 'changed_self', 'changed_by')
/var/www/nextcloud/apps/activity/lib/FilesHooksStatic.php - line 55: OCA\Activity\FilesHooks->fileUpdate('/path/to/file')
/var/www/nextcloud/lib/private/legacy/hook.php - line 106: OCA\Activity\FilesHooksStatic fileUpdate(Array)
/var/www/nextcloud/lib/private/Files/View.php - line 1245: OC_Hook emit('OC_Filesystem', 'post_update', Array)
/var/www/nextcloud/lib/private/Files/View.php - line 1173: OC\Files\View->runHooks(Array, '/path/to/file', true)
/var/www/nextcloud/lib/private/Files/View.php - line 679: OC\Files\View->basicOperation('file_put_conten...', '/path/to/file', Array, '<?xml version="...')
/var/www/nextcloud/lib/private/Files/Node/File.php - line 64: OC\Files\View->file_put_contents('/path/to/file', '<?xml version="...')
[...]
Signed-off-by: Jan-Philipp Litza <janphilipp@litza.de>
2017-06-16 05:38:22 -04:00
|
|
|
if ($group === null) {
|
2016-12-22 15:44:21 -05:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$userList = $group->getUsers();
|
|
|
|
|
foreach ($userList as $user) {
|
2017-03-27 10:06:31 -04:00
|
|
|
$uid = $user->getUID();
|
2023-07-07 06:13:21 -04:00
|
|
|
$users[$uid] = $users[$uid] ?? [];
|
2017-03-27 10:06:31 -04:00
|
|
|
$users[$uid][$row['id']] = $row;
|
2016-12-22 15:44:21 -05:00
|
|
|
}
|
2020-06-24 10:49:16 -04:00
|
|
|
} elseif ($type === IShare::TYPE_LINK) {
|
2016-12-22 15:44:21 -05:00
|
|
|
$link = true;
|
2020-06-24 10:49:16 -04:00
|
|
|
} elseif ($type === IShare::TYPE_USERGROUP && $currentAccess === true) {
|
2017-04-10 10:22:12 -04:00
|
|
|
$uid = $row['share_with'];
|
2023-07-07 06:13:21 -04:00
|
|
|
$users[$uid] = $users[$uid] ?? [];
|
2017-04-10 10:22:12 -04:00
|
|
|
$users[$uid][$row['id']] = $row;
|
2016-12-22 15:44:21 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$cursor->closeCursor();
|
|
|
|
|
|
2017-04-10 10:22:12 -04:00
|
|
|
if ($currentAccess === true) {
|
2017-04-11 06:40:36 -04:00
|
|
|
$users = array_map([$this, 'filterSharesOfUser'], $users);
|
2017-04-10 10:22:12 -04:00
|
|
|
$users = array_filter($users);
|
2017-04-11 06:40:36 -04:00
|
|
|
} else {
|
|
|
|
|
$users = array_keys($users);
|
2017-04-10 10:22:12 -04:00
|
|
|
}
|
2016-12-22 15:44:21 -05:00
|
|
|
|
2017-03-27 10:06:31 -04:00
|
|
|
return ['users' => $users, 'public' => $link];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* For each user the path with the fewest slashes is returned
|
|
|
|
|
* @param array $shares
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
protected function filterSharesOfUser(array $shares) {
|
|
|
|
|
// Group shares when the user has a share exception
|
|
|
|
|
foreach ($shares as $id => $share) {
|
|
|
|
|
$type = (int)$share['share_type'];
|
|
|
|
|
$permissions = (int)$share['permissions'];
|
|
|
|
|
|
2020-06-24 10:49:16 -04:00
|
|
|
if ($type === IShare::TYPE_USERGROUP) {
|
2017-03-27 10:06:31 -04:00
|
|
|
unset($shares[$share['parent']]);
|
|
|
|
|
|
|
|
|
|
if ($permissions === 0) {
|
|
|
|
|
unset($shares[$id]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$best = [];
|
|
|
|
|
$bestDepth = 0;
|
|
|
|
|
foreach ($shares as $id => $share) {
|
2021-10-25 08:33:19 -04:00
|
|
|
$depth = substr_count(($share['file_target'] ?? ''), '/');
|
2017-03-27 10:06:31 -04:00
|
|
|
if (empty($best) || $depth < $bestDepth) {
|
|
|
|
|
$bestDepth = $depth;
|
|
|
|
|
$best = [
|
|
|
|
|
'node_id' => $share['file_source'],
|
|
|
|
|
'node_path' => $share['file_target'],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $best;
|
2016-12-22 15:44:21 -05:00
|
|
|
}
|
2018-07-12 08:55:50 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* propagate notes to the recipients
|
|
|
|
|
*
|
|
|
|
|
* @param IShare $share
|
|
|
|
|
* @throws \OCP\Files\NotFoundException
|
|
|
|
|
*/
|
|
|
|
|
private function propagateNote(IShare $share) {
|
2020-06-24 10:49:16 -04:00
|
|
|
if ($share->getShareType() === IShare::TYPE_USER) {
|
2018-07-12 08:55:50 -04:00
|
|
|
$user = $this->userManager->get($share->getSharedWith());
|
|
|
|
|
$this->sendNote([$user], $share);
|
2020-06-24 10:49:16 -04:00
|
|
|
} elseif ($share->getShareType() === IShare::TYPE_GROUP) {
|
2018-07-12 08:55:50 -04:00
|
|
|
$group = $this->groupManager->get($share->getSharedWith());
|
|
|
|
|
$groupMembers = $group->getUsers();
|
|
|
|
|
$this->sendNote($groupMembers, $share);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-05 08:27:49 -04:00
|
|
|
public function sendMailNotification(IShare $share): bool {
|
2024-07-05 03:47:40 -04:00
|
|
|
try {
|
2024-07-05 08:02:53 -04:00
|
|
|
// Check user
|
|
|
|
|
$user = $this->userManager->get($share->getSharedWith());
|
|
|
|
|
if ($user === null) {
|
|
|
|
|
$this->logger->debug('Share notification not sent to ' . $share->getSharedWith() . ' because user could not be found.', ['app' => 'share']);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-05 03:47:40 -04:00
|
|
|
// Handle user shares
|
|
|
|
|
if ($share->getShareType() === IShare::TYPE_USER) {
|
2024-07-05 08:02:53 -04:00
|
|
|
// Check email address
|
|
|
|
|
$emailAddress = $user->getEMailAddress();
|
|
|
|
|
if ($emailAddress === null || $emailAddress === '') {
|
2024-07-05 03:47:40 -04:00
|
|
|
$this->logger->debug('Share notification not sent to ' . $share->getSharedWith() . ' because email address is not set.', ['app' => 'share']);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-05 08:02:53 -04:00
|
|
|
$userLang = $this->l10nFactory->getUserLanguage($user);
|
|
|
|
|
$l = $this->l10nFactory->get('lib', $userLang);
|
|
|
|
|
$this->sendUserShareMail(
|
|
|
|
|
$l,
|
|
|
|
|
$share->getNode()->getName(),
|
|
|
|
|
$this->urlGenerator->linkToRouteAbsolute('files_sharing.Accept.accept', ['shareId' => $share->getFullId()]),
|
|
|
|
|
$share->getSharedBy(),
|
|
|
|
|
$emailAddress,
|
|
|
|
|
$share->getExpirationDate(),
|
|
|
|
|
$share->getNote()
|
|
|
|
|
);
|
|
|
|
|
$this->logger->debug('Sent share notification to ' . $emailAddress . ' for share with ID ' . $share->getId() . '.', ['app' => 'share']);
|
2024-07-05 03:47:40 -04:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
$this->logger->error('Share notification mail could not be sent.', ['exception' => $e]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Send mail notifications for the user share type
|
|
|
|
|
*
|
|
|
|
|
* @param IL10N $l Language of the recipient
|
|
|
|
|
* @param string $filename file/folder name
|
|
|
|
|
* @param string $link link to the file/folder
|
|
|
|
|
* @param string $initiator user ID of share sender
|
|
|
|
|
* @param string $shareWith email address of share receiver
|
|
|
|
|
* @param \DateTime|null $expiration
|
|
|
|
|
* @param string $note
|
|
|
|
|
* @throws \Exception
|
|
|
|
|
*/
|
|
|
|
|
protected function sendUserShareMail(
|
|
|
|
|
IL10N $l,
|
|
|
|
|
$filename,
|
|
|
|
|
$link,
|
|
|
|
|
$initiator,
|
|
|
|
|
$shareWith,
|
|
|
|
|
?\DateTime $expiration = null,
|
|
|
|
|
$note = '') {
|
|
|
|
|
$initiatorUser = $this->userManager->get($initiator);
|
|
|
|
|
$initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator;
|
|
|
|
|
|
|
|
|
|
$message = $this->mailer->createMessage();
|
|
|
|
|
|
|
|
|
|
$emailTemplate = $this->mailer->createEMailTemplate('files_sharing.RecipientNotification', [
|
|
|
|
|
'filename' => $filename,
|
|
|
|
|
'link' => $link,
|
|
|
|
|
'initiator' => $initiatorDisplayName,
|
|
|
|
|
'expiration' => $expiration,
|
|
|
|
|
'shareWith' => $shareWith,
|
|
|
|
|
]);
|
|
|
|
|
|
2024-12-10 03:39:00 -05:00
|
|
|
$emailTemplate->setSubject($l->t('%1$s shared %2$s with you', [$initiatorDisplayName, $filename]));
|
2024-07-05 03:47:40 -04:00
|
|
|
$emailTemplate->addHeader();
|
2024-12-10 03:39:00 -05:00
|
|
|
$emailTemplate->addHeading($l->t('%1$s shared %2$s with you', [$initiatorDisplayName, $filename]), false);
|
2024-07-05 03:47:40 -04:00
|
|
|
|
|
|
|
|
if ($note !== '') {
|
|
|
|
|
$emailTemplate->addBodyText(htmlspecialchars($note), $note);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$emailTemplate->addBodyButton(
|
2024-12-10 03:39:00 -05:00
|
|
|
$l->t('Open %s', [$filename]),
|
2024-07-05 03:47:40 -04:00
|
|
|
$link
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$message->setTo([$shareWith]);
|
|
|
|
|
|
|
|
|
|
// The "From" contains the sharers name
|
|
|
|
|
$instanceName = $this->defaults->getName();
|
|
|
|
|
$senderName = $l->t(
|
|
|
|
|
'%1$s via %2$s',
|
|
|
|
|
[
|
|
|
|
|
$initiatorDisplayName,
|
|
|
|
|
$instanceName,
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
$message->setFrom([\OCP\Util::getDefaultEmailAddress('noreply') => $senderName]);
|
|
|
|
|
|
|
|
|
|
// The "Reply-To" is set to the sharer if an mail address is configured
|
|
|
|
|
// also the default footer contains a "Do not reply" which needs to be adjusted.
|
2024-07-09 09:38:33 -04:00
|
|
|
if ($initiatorUser) {
|
|
|
|
|
$initiatorEmail = $initiatorUser->getEMailAddress();
|
|
|
|
|
if ($initiatorEmail !== null) {
|
|
|
|
|
$message->setReplyTo([$initiatorEmail => $initiatorDisplayName]);
|
|
|
|
|
$emailTemplate->addFooter($instanceName . ($this->defaults->getSlogan() !== '' ? ' - ' . $this->defaults->getSlogan() : ''));
|
|
|
|
|
} else {
|
|
|
|
|
$emailTemplate->addFooter();
|
|
|
|
|
}
|
2024-07-05 03:47:40 -04:00
|
|
|
} else {
|
2024-07-09 09:38:33 -04:00
|
|
|
$emailTemplate->addFooter();
|
2024-07-05 03:47:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$message->useTemplate($emailTemplate);
|
|
|
|
|
$failedRecipients = $this->mailer->send($message);
|
|
|
|
|
if (!empty($failedRecipients)) {
|
|
|
|
|
$this->logger->error('Share notification mail could not be sent to: ' . implode(', ', $failedRecipients));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-12 08:55:50 -04:00
|
|
|
/**
|
|
|
|
|
* send note by mail
|
|
|
|
|
*
|
|
|
|
|
* @param array $recipients
|
|
|
|
|
* @param IShare $share
|
|
|
|
|
* @throws \OCP\Files\NotFoundException
|
|
|
|
|
*/
|
|
|
|
|
private function sendNote(array $recipients, IShare $share) {
|
2020-06-23 02:14:27 -04:00
|
|
|
$toListByLanguage = [];
|
2018-07-12 08:55:50 -04:00
|
|
|
|
|
|
|
|
foreach ($recipients as $recipient) {
|
|
|
|
|
/** @var IUser $recipient */
|
|
|
|
|
$email = $recipient->getEMailAddress();
|
|
|
|
|
if ($email) {
|
2020-06-23 02:45:01 -04:00
|
|
|
$language = $this->l10nFactory->getUserLanguage($recipient);
|
2020-06-23 02:14:27 -04:00
|
|
|
if (!isset($toListByLanguage[$language])) {
|
|
|
|
|
$toListByLanguage[$language] = [];
|
|
|
|
|
}
|
|
|
|
|
$toListByLanguage[$language][$email] = $recipient->getDisplayName();
|
2018-07-12 08:55:50 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-23 02:14:27 -04:00
|
|
|
if (empty($toListByLanguage)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ($toListByLanguage as $l10n => $toList) {
|
2018-07-12 08:55:50 -04:00
|
|
|
$filename = $share->getNode()->getName();
|
|
|
|
|
$initiator = $share->getSharedBy();
|
|
|
|
|
$note = $share->getNote();
|
|
|
|
|
|
2020-06-23 02:14:27 -04:00
|
|
|
$l = $this->l10nFactory->get('lib', $l10n);
|
|
|
|
|
|
2018-07-12 08:55:50 -04:00
|
|
|
$initiatorUser = $this->userManager->get($initiator);
|
|
|
|
|
$initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator;
|
|
|
|
|
$initiatorEmailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null;
|
2024-12-10 03:39:00 -05:00
|
|
|
$plainHeading = $l->t('%1$s shared %2$s with you and wants to add:', [$initiatorDisplayName, $filename]);
|
|
|
|
|
$htmlHeading = $l->t('%1$s shared %2$s with you and wants to add', [$initiatorDisplayName, $filename]);
|
2018-07-12 08:55:50 -04:00
|
|
|
$message = $this->mailer->createMessage();
|
|
|
|
|
|
2018-07-12 10:05:24 -04:00
|
|
|
$emailTemplate = $this->mailer->createEMailTemplate('defaultShareProvider.sendNote');
|
2018-07-12 08:55:50 -04:00
|
|
|
|
2024-12-10 03:39:00 -05:00
|
|
|
$emailTemplate->setSubject($l->t('%s added a note to a file shared with you', [$initiatorDisplayName]));
|
2018-07-12 08:55:50 -04:00
|
|
|
$emailTemplate->addHeader();
|
2018-07-12 12:17:22 -04:00
|
|
|
$emailTemplate->addHeading($htmlHeading, $plainHeading);
|
2018-07-12 10:05:24 -04:00
|
|
|
$emailTemplate->addBodyText(htmlspecialchars($note), $note);
|
2018-07-12 13:32:35 -04:00
|
|
|
|
|
|
|
|
$link = $this->urlGenerator->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $share->getNode()->getId()]);
|
|
|
|
|
$emailTemplate->addBodyButton(
|
2024-12-10 03:39:00 -05:00
|
|
|
$l->t('Open %s', [$filename]),
|
2018-07-12 13:32:35 -04:00
|
|
|
$link
|
|
|
|
|
);
|
|
|
|
|
|
2018-07-12 08:55:50 -04:00
|
|
|
|
|
|
|
|
// The "From" contains the sharers name
|
|
|
|
|
$instanceName = $this->defaults->getName();
|
2020-06-23 02:14:27 -04:00
|
|
|
$senderName = $l->t(
|
2018-07-12 11:07:11 -04:00
|
|
|
'%1$s via %2$s',
|
2018-07-12 08:55:50 -04:00
|
|
|
[
|
|
|
|
|
$initiatorDisplayName,
|
|
|
|
|
$instanceName
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
$message->setFrom([\OCP\Util::getDefaultEmailAddress($instanceName) => $senderName]);
|
|
|
|
|
if ($initiatorEmailAddress !== null) {
|
|
|
|
|
$message->setReplyTo([$initiatorEmailAddress => $initiatorDisplayName]);
|
|
|
|
|
$emailTemplate->addFooter($instanceName . ' - ' . $this->defaults->getSlogan());
|
|
|
|
|
} else {
|
|
|
|
|
$emailTemplate->addFooter();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (count($toList) === 1) {
|
|
|
|
|
$message->setTo($toList);
|
|
|
|
|
} else {
|
|
|
|
|
$message->setTo([]);
|
|
|
|
|
$message->setBcc($toList);
|
|
|
|
|
}
|
|
|
|
|
$message->useTemplate($emailTemplate);
|
|
|
|
|
$this->mailer->send($message);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-29 11:56:06 -04:00
|
|
|
|
|
|
|
|
public function getAllShares(): iterable {
|
|
|
|
|
$qb = $this->dbConn->getQueryBuilder();
|
|
|
|
|
|
|
|
|
|
$qb->select('*')
|
|
|
|
|
->from('share')
|
2025-03-24 10:39:29 -04:00
|
|
|
->where($qb->expr()->in('share_type', $qb->createNamedParameter([IShare::TYPE_USER, IShare::TYPE_GROUP, IShare::TYPE_LINK], IQueryBuilder::PARAM_INT_ARRAY)));
|
2019-10-29 11:56:06 -04:00
|
|
|
|
2024-10-17 09:42:21 -04:00
|
|
|
$cursor = $qb->executeQuery();
|
2019-10-29 11:56:06 -04:00
|
|
|
while ($data = $cursor->fetch()) {
|
|
|
|
|
try {
|
|
|
|
|
$share = $this->createShare($data);
|
|
|
|
|
} catch (InvalidShare $e) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
yield $share;
|
|
|
|
|
}
|
|
|
|
|
$cursor->closeCursor();
|
|
|
|
|
}
|
2022-05-18 08:54:27 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Load from database format (JSON string) to IAttributes
|
|
|
|
|
*
|
2022-07-15 11:11:54 -04:00
|
|
|
* @return IShare the modified share
|
2022-05-18 08:54:27 -04:00
|
|
|
*/
|
2024-07-05 08:27:49 -04:00
|
|
|
protected function updateShareAttributes(IShare $share, ?string $data): IShare {
|
2022-05-25 11:23:02 -04:00
|
|
|
if ($data !== null && $data !== '') {
|
2022-05-18 08:54:27 -04:00
|
|
|
$attributes = new ShareAttributes();
|
|
|
|
|
$compressedAttributes = \json_decode($data, true);
|
2022-07-15 11:11:54 -04:00
|
|
|
if ($compressedAttributes === false || $compressedAttributes === null) {
|
|
|
|
|
return $share;
|
|
|
|
|
}
|
2022-05-18 08:54:27 -04:00
|
|
|
foreach ($compressedAttributes as $compressedAttribute) {
|
|
|
|
|
$attributes->setAttribute(
|
|
|
|
|
$compressedAttribute[0],
|
|
|
|
|
$compressedAttribute[1],
|
|
|
|
|
$compressedAttribute[2]
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
$share->setAttributes($attributes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $share;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Format IAttributes to database format (JSON string)
|
|
|
|
|
*/
|
2024-07-05 08:27:49 -04:00
|
|
|
protected function formatShareAttributes(?IAttributes $attributes): ?string {
|
2022-05-18 08:54:27 -04:00
|
|
|
if ($attributes === null || empty($attributes->toArray())) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$compressedAttributes = [];
|
|
|
|
|
foreach ($attributes->toArray() as $attribute) {
|
|
|
|
|
$compressedAttributes[] = [
|
|
|
|
|
0 => $attribute['scope'],
|
|
|
|
|
1 => $attribute['key'],
|
2024-07-05 08:27:49 -04:00
|
|
|
2 => $attribute['value']
|
2022-05-18 08:54:27 -04:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
return \json_encode($compressedAttributes);
|
|
|
|
|
}
|
2016-01-25 11:17:36 -05:00
|
|
|
}
|