2013-10-23 10:03:57 -04:00
|
|
|
<?php
|
2024-05-27 11:39:07 -04:00
|
|
|
|
2015-02-26 05:37:37 -05:00
|
|
|
/**
|
2024-05-27 11:39:07 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2015-02-26 05:37:37 -05:00
|
|
|
*/
|
2015-08-30 13:13:01 -04:00
|
|
|
namespace OCA\DAV\Connector\Sabre;
|
2015-02-12 06:29:01 -05:00
|
|
|
|
2017-07-31 16:46:19 -04:00
|
|
|
use OC\AppFramework\Http\Request;
|
2024-10-03 11:35:56 -04:00
|
|
|
use OC\FilesMetadata\Model\FilesMetadata;
|
2025-06-25 08:35:02 -04:00
|
|
|
use OC\User\NoUserException;
|
2024-08-27 06:59:06 -04:00
|
|
|
use OCA\DAV\Connector\Sabre\Exception\InvalidPath;
|
2025-01-30 10:56:48 -05:00
|
|
|
use OCA\Files_Sharing\External\Mount as SharingExternalMount;
|
2025-04-29 10:42:09 -04:00
|
|
|
use OCP\Accounts\IAccountManager;
|
2018-06-25 05:14:26 -04:00
|
|
|
use OCP\Constants;
|
2016-06-01 10:17:57 -04:00
|
|
|
use OCP\Files\ForbiddenException;
|
2024-08-27 06:59:06 -04:00
|
|
|
use OCP\Files\IFilenameValidator;
|
|
|
|
|
use OCP\Files\InvalidPathException;
|
2025-04-14 08:47:18 -04:00
|
|
|
use OCP\Files\Storage\ISharedStorage;
|
2019-11-22 14:52:10 -05:00
|
|
|
use OCP\Files\StorageNotAvailableException;
|
2023-11-14 06:01:29 -05:00
|
|
|
use OCP\FilesMetadata\Exceptions\FilesMetadataException;
|
2023-11-08 06:35:01 -05:00
|
|
|
use OCP\FilesMetadata\Exceptions\FilesMetadataNotFoundException;
|
|
|
|
|
use OCP\FilesMetadata\IFilesMetadataManager;
|
|
|
|
|
use OCP\FilesMetadata\Model\IMetadataValueWrapper;
|
2019-11-22 14:52:10 -05:00
|
|
|
use OCP\IConfig;
|
2016-07-26 07:15:12 -04:00
|
|
|
use OCP\IPreview;
|
2019-11-22 14:52:10 -05:00
|
|
|
use OCP\IRequest;
|
2021-07-21 08:23:49 -04:00
|
|
|
use OCP\IUserSession;
|
2024-08-27 06:59:06 -04:00
|
|
|
use OCP\L10N\IFactory;
|
2016-03-21 07:27:13 -04:00
|
|
|
use Sabre\DAV\Exception\Forbidden;
|
2016-02-28 13:41:46 -05:00
|
|
|
use Sabre\DAV\Exception\NotFound;
|
2015-02-25 05:45:44 -05:00
|
|
|
use Sabre\DAV\IFile;
|
2019-11-22 14:52:10 -05:00
|
|
|
use Sabre\DAV\PropFind;
|
|
|
|
|
use Sabre\DAV\PropPatch;
|
2022-04-12 08:01:13 -04:00
|
|
|
use Sabre\DAV\Server;
|
2023-11-06 20:21:29 -05:00
|
|
|
use Sabre\DAV\ServerPlugin;
|
2016-03-21 07:27:13 -04:00
|
|
|
use Sabre\DAV\Tree;
|
2019-11-22 14:52:10 -05:00
|
|
|
use Sabre\HTTP\RequestInterface;
|
|
|
|
|
use Sabre\HTTP\ResponseInterface;
|
2015-02-12 06:29:01 -05:00
|
|
|
|
2016-04-12 08:26:42 -04:00
|
|
|
class FilesPlugin extends ServerPlugin {
|
2013-10-23 10:03:57 -04:00
|
|
|
// namespace
|
2020-04-10 10:54:27 -04:00
|
|
|
public const NS_OWNCLOUD = 'http://owncloud.org/ns';
|
|
|
|
|
public const NS_NEXTCLOUD = 'http://nextcloud.org/ns';
|
|
|
|
|
public const FILEID_PROPERTYNAME = '{http://owncloud.org/ns}id';
|
|
|
|
|
public const INTERNAL_FILEID_PROPERTYNAME = '{http://owncloud.org/ns}fileid';
|
|
|
|
|
public const PERMISSIONS_PROPERTYNAME = '{http://owncloud.org/ns}permissions';
|
|
|
|
|
public const SHARE_PERMISSIONS_PROPERTYNAME = '{http://open-collaboration-services.org/ns}share-permissions';
|
|
|
|
|
public const OCM_SHARE_PERMISSIONS_PROPERTYNAME = '{http://open-cloud-mesh.org/ns}share-permissions';
|
2022-06-02 05:24:39 -04:00
|
|
|
public const SHARE_ATTRIBUTES_PROPERTYNAME = '{http://nextcloud.org/ns}share-attributes';
|
2020-04-10 10:54:27 -04:00
|
|
|
public const DOWNLOADURL_PROPERTYNAME = '{http://owncloud.org/ns}downloadURL';
|
|
|
|
|
public const SIZE_PROPERTYNAME = '{http://owncloud.org/ns}size';
|
|
|
|
|
public const GETETAG_PROPERTYNAME = '{DAV:}getetag';
|
|
|
|
|
public const LASTMODIFIED_PROPERTYNAME = '{DAV:}lastmodified';
|
2021-11-29 05:25:48 -05:00
|
|
|
public const CREATIONDATE_PROPERTYNAME = '{DAV:}creationdate';
|
2022-10-10 15:20:07 -04:00
|
|
|
public const DISPLAYNAME_PROPERTYNAME = '{DAV:}displayname';
|
2020-04-10 10:54:27 -04:00
|
|
|
public const OWNER_ID_PROPERTYNAME = '{http://owncloud.org/ns}owner-id';
|
|
|
|
|
public const OWNER_DISPLAY_NAME_PROPERTYNAME = '{http://owncloud.org/ns}owner-display-name';
|
|
|
|
|
public const CHECKSUMS_PROPERTYNAME = '{http://owncloud.org/ns}checksums';
|
|
|
|
|
public const DATA_FINGERPRINT_PROPERTYNAME = '{http://owncloud.org/ns}data-fingerprint';
|
|
|
|
|
public const HAS_PREVIEW_PROPERTYNAME = '{http://nextcloud.org/ns}has-preview';
|
|
|
|
|
public const MOUNT_TYPE_PROPERTYNAME = '{http://nextcloud.org/ns}mount-type';
|
2024-01-30 11:20:03 -05:00
|
|
|
public const MOUNT_ROOT_PROPERTYNAME = '{http://nextcloud.org/ns}is-mount-root';
|
2024-08-22 18:25:42 -04:00
|
|
|
public const IS_FEDERATED_PROPERTYNAME = '{http://nextcloud.org/ns}is-federated';
|
2020-04-10 10:54:27 -04:00
|
|
|
public const METADATA_ETAG_PROPERTYNAME = '{http://nextcloud.org/ns}metadata_etag';
|
|
|
|
|
public const UPLOAD_TIME_PROPERTYNAME = '{http://nextcloud.org/ns}upload_time';
|
|
|
|
|
public const CREATION_TIME_PROPERTYNAME = '{http://nextcloud.org/ns}creation_time';
|
|
|
|
|
public const SHARE_NOTE = '{http://nextcloud.org/ns}note';
|
2025-04-14 08:47:18 -04:00
|
|
|
public const SHARE_HIDE_DOWNLOAD_PROPERTYNAME = '{http://nextcloud.org/ns}hide-download';
|
2022-02-15 10:18:41 -05:00
|
|
|
public const SUBFOLDER_COUNT_PROPERTYNAME = '{http://nextcloud.org/ns}contained-folder-count';
|
|
|
|
|
public const SUBFILE_COUNT_PROPERTYNAME = '{http://nextcloud.org/ns}contained-file-count';
|
2023-11-06 20:21:29 -05:00
|
|
|
public const FILE_METADATA_PREFIX = '{http://nextcloud.org/ns}metadata-';
|
2023-11-08 08:52:50 -05:00
|
|
|
public const HIDDEN_PROPERTYNAME = '{http://nextcloud.org/ns}hidden';
|
2023-08-07 07:40:01 -04:00
|
|
|
|
2022-04-12 08:01:13 -04:00
|
|
|
/** Reference to main server object */
|
2022-05-05 18:01:08 -04:00
|
|
|
private ?Server $server = null;
|
2021-07-21 08:23:49 -04:00
|
|
|
|
2015-07-13 08:20:35 -04:00
|
|
|
/**
|
2024-08-27 06:59:06 -04:00
|
|
|
* @param Tree $tree
|
|
|
|
|
* @param IConfig $config
|
|
|
|
|
* @param IRequest $request
|
|
|
|
|
* @param IPreview $previewManager
|
|
|
|
|
* @param IUserSession $userSession
|
|
|
|
|
* @param bool $isPublic Whether this is public WebDAV. If true, some returned information will be stripped off.
|
|
|
|
|
* @param bool $downloadAttachment
|
|
|
|
|
* @return void
|
2016-03-21 07:27:13 -04:00
|
|
|
*/
|
2024-08-27 06:59:06 -04:00
|
|
|
public function __construct(
|
|
|
|
|
private Tree $tree,
|
|
|
|
|
private IConfig $config,
|
|
|
|
|
private IRequest $request,
|
|
|
|
|
private IPreview $previewManager,
|
|
|
|
|
private IUserSession $userSession,
|
|
|
|
|
private IFilenameValidator $validator,
|
2025-04-29 10:42:09 -04:00
|
|
|
private IAccountManager $accountManager,
|
2024-08-27 06:59:06 -04:00
|
|
|
private bool $isPublic = false,
|
|
|
|
|
private bool $downloadAttachment = true,
|
|
|
|
|
) {
|
2015-02-12 06:29:01 -05:00
|
|
|
}
|
|
|
|
|
|
2013-10-23 10:03:57 -04:00
|
|
|
/**
|
|
|
|
|
* This initializes the plugin.
|
|
|
|
|
*
|
2014-01-09 08:25:48 -05:00
|
|
|
* This function is called by \Sabre\DAV\Server, after
|
2013-10-23 10:03:57 -04:00
|
|
|
* addPlugin is called.
|
|
|
|
|
*
|
|
|
|
|
* This method should set up the required event subscriptions.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2022-04-12 08:01:13 -04:00
|
|
|
public function initialize(Server $server) {
|
2015-12-03 09:55:10 -05:00
|
|
|
$server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc';
|
2016-07-26 07:15:12 -04:00
|
|
|
$server->xml->namespaceMap[self::NS_NEXTCLOUD] = 'nc';
|
2015-02-12 06:29:01 -05:00
|
|
|
$server->protectedProperties[] = self::FILEID_PROPERTYNAME;
|
2015-11-18 05:41:04 -05:00
|
|
|
$server->protectedProperties[] = self::INTERNAL_FILEID_PROPERTYNAME;
|
2015-02-12 06:29:01 -05:00
|
|
|
$server->protectedProperties[] = self::PERMISSIONS_PROPERTYNAME;
|
2016-03-03 14:58:18 -05:00
|
|
|
$server->protectedProperties[] = self::SHARE_PERMISSIONS_PROPERTYNAME;
|
2018-06-25 05:14:26 -04:00
|
|
|
$server->protectedProperties[] = self::OCM_SHARE_PERMISSIONS_PROPERTYNAME;
|
2022-06-02 05:24:39 -04:00
|
|
|
$server->protectedProperties[] = self::SHARE_ATTRIBUTES_PROPERTYNAME;
|
2015-02-12 06:29:01 -05:00
|
|
|
$server->protectedProperties[] = self::SIZE_PROPERTYNAME;
|
|
|
|
|
$server->protectedProperties[] = self::DOWNLOADURL_PROPERTYNAME;
|
2015-11-02 09:05:16 -05:00
|
|
|
$server->protectedProperties[] = self::OWNER_ID_PROPERTYNAME;
|
|
|
|
|
$server->protectedProperties[] = self::OWNER_DISPLAY_NAME_PROPERTYNAME;
|
2016-02-08 05:55:07 -05:00
|
|
|
$server->protectedProperties[] = self::CHECKSUMS_PROPERTYNAME;
|
2016-04-18 05:18:50 -04:00
|
|
|
$server->protectedProperties[] = self::DATA_FINGERPRINT_PROPERTYNAME;
|
2016-07-26 07:15:12 -04:00
|
|
|
$server->protectedProperties[] = self::HAS_PREVIEW_PROPERTYNAME;
|
2017-04-26 08:53:11 -04:00
|
|
|
$server->protectedProperties[] = self::MOUNT_TYPE_PROPERTYNAME;
|
2024-08-22 18:25:42 -04:00
|
|
|
$server->protectedProperties[] = self::IS_FEDERATED_PROPERTYNAME;
|
2018-12-05 09:20:44 -05:00
|
|
|
$server->protectedProperties[] = self::SHARE_NOTE;
|
2015-02-12 06:29:01 -05:00
|
|
|
|
|
|
|
|
// normally these cannot be changed (RFC4918), but we want them modifiable through PROPPATCH
|
2015-10-13 06:51:21 -04:00
|
|
|
$allowedProperties = ['{DAV:}getetag'];
|
2015-02-12 06:29:01 -05:00
|
|
|
$server->protectedProperties = array_diff($server->protectedProperties, $allowedProperties);
|
2013-10-23 10:03:57 -04:00
|
|
|
|
|
|
|
|
$this->server = $server;
|
2020-03-26 04:30:18 -04:00
|
|
|
$this->server->on('propFind', [$this, 'handleGetProperties']);
|
|
|
|
|
$this->server->on('propPatch', [$this, 'handleUpdateProperties']);
|
|
|
|
|
$this->server->on('afterBind', [$this, 'sendFileIdHeader']);
|
|
|
|
|
$this->server->on('afterWriteContent', [$this, 'sendFileIdHeader']);
|
2015-02-25 05:45:44 -05:00
|
|
|
$this->server->on('afterMethod:GET', [$this,'httpGet']);
|
2020-03-26 04:30:18 -04:00
|
|
|
$this->server->on('afterMethod:GET', [$this, 'handleDownloadToken']);
|
2024-09-20 11:38:36 -04:00
|
|
|
$this->server->on('afterResponse', function ($request, ResponseInterface $response): void {
|
2015-05-21 11:52:13 -04:00
|
|
|
$body = $response->getBody();
|
|
|
|
|
if (is_resource($body)) {
|
|
|
|
|
fclose($body);
|
|
|
|
|
}
|
|
|
|
|
});
|
2015-10-06 09:36:54 -04:00
|
|
|
$this->server->on('beforeMove', [$this, 'checkMove']);
|
2024-08-27 06:59:06 -04:00
|
|
|
$this->server->on('beforeCopy', [$this, 'checkCopy']);
|
2015-10-06 09:36:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2024-08-27 06:59:06 -04:00
|
|
|
* Plugin that checks if a copy can actually be performed.
|
2016-04-12 08:26:42 -04:00
|
|
|
*
|
2015-10-06 09:36:54 -04:00
|
|
|
* @param string $source source path
|
2024-08-27 06:59:06 -04:00
|
|
|
* @param string $target target path
|
|
|
|
|
* @throws NotFound If the source does not exist
|
|
|
|
|
* @throws InvalidPath If the target is invalid
|
2015-10-06 09:36:54 -04:00
|
|
|
*/
|
2024-08-27 06:59:06 -04:00
|
|
|
public function checkCopy($source, $target): void {
|
2016-04-12 09:51:09 -04:00
|
|
|
$sourceNode = $this->tree->getNodeForPath($source);
|
2016-06-06 11:01:27 -04:00
|
|
|
if (!$sourceNode instanceof Node) {
|
2016-04-12 08:26:42 -04:00
|
|
|
return;
|
|
|
|
|
}
|
2015-10-06 09:36:54 -04:00
|
|
|
|
2024-08-27 06:59:06 -04:00
|
|
|
// Ensure source exists
|
|
|
|
|
$sourceNodeFileInfo = $sourceNode->getFileInfo();
|
|
|
|
|
if ($sourceNodeFileInfo === null) {
|
|
|
|
|
throw new NotFound($source . ' does not exist');
|
|
|
|
|
}
|
|
|
|
|
// Ensure the target name is valid
|
|
|
|
|
try {
|
|
|
|
|
[$targetPath, $targetName] = \Sabre\Uri\split($target);
|
|
|
|
|
$this->validator->validateFilename($targetName);
|
|
|
|
|
} catch (InvalidPathException $e) {
|
|
|
|
|
throw new InvalidPath($e->getMessage(), false);
|
|
|
|
|
}
|
|
|
|
|
// Ensure the target path is valid
|
|
|
|
|
$segments = array_slice(explode('/', $targetPath), 2);
|
|
|
|
|
foreach ($segments as $segment) {
|
|
|
|
|
if ($this->validator->isFilenameValid($segment) === false) {
|
|
|
|
|
$l = \OCP\Server::get(IFactory::class)->get('dav');
|
|
|
|
|
throw new InvalidPath($l->t('Invalid target path'));
|
2020-04-09 03:22:29 -04:00
|
|
|
}
|
2024-08-27 06:59:06 -04:00
|
|
|
}
|
|
|
|
|
}
|
2017-07-24 15:14:06 -04:00
|
|
|
|
2024-08-27 06:59:06 -04:00
|
|
|
/**
|
|
|
|
|
* Plugin that checks if a move can actually be performed.
|
|
|
|
|
*
|
|
|
|
|
* @param string $source source path
|
|
|
|
|
* @param string $target target path
|
|
|
|
|
* @throws Forbidden If the source is not deletable
|
|
|
|
|
* @throws NotFound If the source does not exist
|
|
|
|
|
* @throws InvalidPath If the target name is invalid
|
|
|
|
|
*/
|
|
|
|
|
public function checkMove(string $source, string $target): void {
|
|
|
|
|
$sourceNode = $this->tree->getNodeForPath($source);
|
|
|
|
|
if (!$sourceNode instanceof Node) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// First check copyable (move only needs additional delete permission)
|
|
|
|
|
$this->checkCopy($source, $target);
|
|
|
|
|
|
|
|
|
|
// The source needs to be deletable for moving
|
|
|
|
|
$sourceNodeFileInfo = $sourceNode->getFileInfo();
|
|
|
|
|
if (!$sourceNodeFileInfo->isDeletable()) {
|
|
|
|
|
throw new Forbidden($source . ' cannot be deleted');
|
2015-10-06 09:36:54 -04:00
|
|
|
}
|
2024-12-23 13:24:39 -05:00
|
|
|
|
|
|
|
|
// The source is not allowed to be the parent of the target
|
|
|
|
|
if (str_starts_with($source, $target . '/')) {
|
|
|
|
|
throw new Forbidden($source . ' cannot be moved to it\'s parent');
|
|
|
|
|
}
|
2015-02-25 05:45:44 -05:00
|
|
|
}
|
|
|
|
|
|
2015-11-19 06:01:55 -05:00
|
|
|
/**
|
|
|
|
|
* This sets a cookie to be able to recognize the start of the download
|
|
|
|
|
* the content must not be longer than 32 characters and must only contain
|
|
|
|
|
* alphanumeric characters
|
|
|
|
|
*
|
|
|
|
|
* @param RequestInterface $request
|
|
|
|
|
* @param ResponseInterface $response
|
|
|
|
|
*/
|
2020-04-10 10:51:06 -04:00
|
|
|
public function handleDownloadToken(RequestInterface $request, ResponseInterface $response) {
|
2015-11-19 06:01:55 -05:00
|
|
|
$queryParams = $request->getQueryParameters();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* this sets a cookie to be able to recognize the start of the download
|
|
|
|
|
* the content must not be longer than 32 characters and must only contain
|
|
|
|
|
* alphanumeric characters
|
|
|
|
|
*/
|
|
|
|
|
if (isset($queryParams['downloadStartSecret'])) {
|
|
|
|
|
$token = $queryParams['downloadStartSecret'];
|
|
|
|
|
if (!isset($token[32])
|
|
|
|
|
&& preg_match('!^[a-zA-Z0-9]+$!', $token) === 1) {
|
|
|
|
|
// FIXME: use $response->setHeader() instead
|
|
|
|
|
setcookie('ocDownloadStarted', $token, time() + 20, '/');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-25 05:45:44 -05:00
|
|
|
/**
|
2016-01-29 15:50:48 -05:00
|
|
|
* Add headers to file download
|
|
|
|
|
*
|
2015-02-25 05:45:44 -05:00
|
|
|
* @param RequestInterface $request
|
|
|
|
|
* @param ResponseInterface $response
|
|
|
|
|
*/
|
2020-04-10 10:51:06 -04:00
|
|
|
public function httpGet(RequestInterface $request, ResponseInterface $response) {
|
2015-02-25 05:45:44 -05:00
|
|
|
// Only handle valid files
|
2015-03-26 15:45:39 -04:00
|
|
|
$node = $this->tree->getNodeForPath($request->getPath());
|
2015-02-25 05:45:44 -05:00
|
|
|
if (!($node instanceof IFile)) {
|
|
|
|
|
return;
|
2020-04-10 08:19:56 -04:00
|
|
|
}
|
2015-02-25 05:45:44 -05:00
|
|
|
|
2016-12-14 11:35:27 -05:00
|
|
|
// adds a 'Content-Disposition: attachment' header in case no disposition
|
|
|
|
|
// header has been set before
|
|
|
|
|
if ($this->downloadAttachment
|
|
|
|
|
&& $response->getHeader('Content-Disposition') === null) {
|
2016-06-09 05:29:20 -04:00
|
|
|
$filename = $node->getName();
|
|
|
|
|
if ($this->request->isUserAgent(
|
|
|
|
|
[
|
2017-07-31 16:46:19 -04:00
|
|
|
Request::USER_AGENT_IE,
|
|
|
|
|
Request::USER_AGENT_ANDROID_MOBILE_CHROME,
|
|
|
|
|
Request::USER_AGENT_FREEBOX,
|
2016-06-09 05:29:20 -04:00
|
|
|
])) {
|
|
|
|
|
$response->addHeader('Content-Disposition', 'attachment; filename="' . rawurlencode($filename) . '"');
|
|
|
|
|
} else {
|
|
|
|
|
$response->addHeader('Content-Disposition', 'attachment; filename*=UTF-8\'\'' . rawurlencode($filename)
|
|
|
|
|
. '; filename="' . rawurlencode($filename) . '"');
|
|
|
|
|
}
|
2016-03-21 07:27:13 -04:00
|
|
|
}
|
2016-01-29 15:50:48 -05:00
|
|
|
|
2024-10-10 06:40:31 -04:00
|
|
|
if ($node instanceof File) {
|
2016-02-19 04:56:43 -05:00
|
|
|
//Add OC-Checksum header
|
|
|
|
|
$checksum = $node->getChecksum();
|
2016-02-28 13:41:46 -05:00
|
|
|
if ($checksum !== null && $checksum !== '') {
|
2016-02-19 04:56:43 -05:00
|
|
|
$response->addHeader('OC-Checksum', $checksum);
|
|
|
|
|
}
|
2016-01-29 15:50:48 -05:00
|
|
|
}
|
2021-02-22 09:59:26 -05:00
|
|
|
$response->addHeader('X-Accel-Buffering', 'no');
|
2013-10-23 10:03:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Adds all ownCloud-specific properties
|
|
|
|
|
*
|
2015-02-12 06:29:01 -05:00
|
|
|
* @param PropFind $propFind
|
2014-01-09 08:25:48 -05:00
|
|
|
* @param \Sabre\DAV\INode $node
|
2013-10-23 10:03:57 -04:00
|
|
|
* @return void
|
|
|
|
|
*/
|
2015-02-12 06:29:01 -05:00
|
|
|
public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node) {
|
2016-04-13 11:31:01 -04:00
|
|
|
$httpRequest = $this->server->httpRequest;
|
|
|
|
|
|
2024-10-10 06:40:31 -04:00
|
|
|
if ($node instanceof Node) {
|
2017-05-26 06:36:42 -04:00
|
|
|
/**
|
|
|
|
|
* This was disabled, because it made dir listing throw an exception,
|
|
|
|
|
* so users were unable to navigate into folders where one subitem
|
|
|
|
|
* is blocked by the files_accesscontrol app, see:
|
|
|
|
|
* https://github.com/nextcloud/files_accesscontrol/issues/65
|
2020-04-08 16:24:54 -04:00
|
|
|
* if (!$node->getFileInfo()->isReadable()) {
|
|
|
|
|
* // avoid detecting files through this means
|
|
|
|
|
* throw new NotFound();
|
|
|
|
|
* }
|
2017-05-26 06:36:42 -04:00
|
|
|
*/
|
2013-10-23 10:03:57 -04:00
|
|
|
|
2020-04-09 07:53:40 -04:00
|
|
|
$propFind->handle(self::FILEID_PROPERTYNAME, function () use ($node) {
|
2015-02-12 06:29:01 -05:00
|
|
|
return $node->getFileId();
|
|
|
|
|
});
|
2013-10-23 10:03:57 -04:00
|
|
|
|
2020-04-09 07:53:40 -04:00
|
|
|
$propFind->handle(self::INTERNAL_FILEID_PROPERTYNAME, function () use ($node) {
|
2015-11-18 05:41:04 -05:00
|
|
|
return $node->getInternalFileId();
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-09 07:53:40 -04:00
|
|
|
$propFind->handle(self::PERMISSIONS_PROPERTYNAME, function () use ($node) {
|
2015-07-13 08:20:35 -04:00
|
|
|
$perms = $node->getDavPermissions();
|
|
|
|
|
if ($this->isPublic) {
|
|
|
|
|
// remove mount information
|
|
|
|
|
$perms = str_replace(['S', 'M'], '', $perms);
|
|
|
|
|
}
|
|
|
|
|
return $perms;
|
2015-02-12 06:29:01 -05:00
|
|
|
});
|
2014-05-02 11:37:16 -04:00
|
|
|
|
2020-04-09 07:53:40 -04:00
|
|
|
$propFind->handle(self::SHARE_PERMISSIONS_PROPERTYNAME, function () use ($node, $httpRequest) {
|
2021-07-21 08:23:49 -04:00
|
|
|
$user = $this->userSession->getUser();
|
|
|
|
|
if ($user === null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2016-04-13 11:31:01 -04:00
|
|
|
return $node->getSharePermissions(
|
2021-07-21 08:23:49 -04:00
|
|
|
$user->getUID()
|
2016-04-13 11:31:01 -04:00
|
|
|
);
|
2016-03-03 14:58:18 -05:00
|
|
|
});
|
|
|
|
|
|
2022-04-12 08:01:13 -04:00
|
|
|
$propFind->handle(self::OCM_SHARE_PERMISSIONS_PROPERTYNAME, function () use ($node, $httpRequest): ?string {
|
2021-07-21 08:23:49 -04:00
|
|
|
$user = $this->userSession->getUser();
|
|
|
|
|
if ($user === null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2018-06-25 05:14:26 -04:00
|
|
|
$ncPermissions = $node->getSharePermissions(
|
2021-07-21 08:23:49 -04:00
|
|
|
$user->getUID()
|
2018-06-25 05:14:26 -04:00
|
|
|
);
|
|
|
|
|
$ocmPermissions = $this->ncPermissions2ocmPermissions($ncPermissions);
|
2023-01-19 13:19:22 -05:00
|
|
|
return json_encode($ocmPermissions, JSON_THROW_ON_ERROR);
|
2018-06-25 05:14:26 -04:00
|
|
|
});
|
|
|
|
|
|
2022-06-02 05:24:39 -04:00
|
|
|
$propFind->handle(self::SHARE_ATTRIBUTES_PROPERTYNAME, function () use ($node, $httpRequest) {
|
2023-01-19 13:19:22 -05:00
|
|
|
return json_encode($node->getShareAttributes(), JSON_THROW_ON_ERROR);
|
2022-06-02 05:24:39 -04:00
|
|
|
});
|
|
|
|
|
|
2022-04-12 08:01:13 -04:00
|
|
|
$propFind->handle(self::GETETAG_PROPERTYNAME, function () use ($node): string {
|
2016-03-21 07:27:13 -04:00
|
|
|
return $node->getETag();
|
2015-02-12 06:29:01 -05:00
|
|
|
});
|
2016-03-10 14:53:56 -05:00
|
|
|
|
2022-04-12 08:01:13 -04:00
|
|
|
$propFind->handle(self::OWNER_ID_PROPERTYNAME, function () use ($node): ?string {
|
2016-03-10 14:53:56 -05:00
|
|
|
$owner = $node->getOwner();
|
2017-03-02 09:26:00 -05:00
|
|
|
if (!$owner) {
|
|
|
|
|
return null;
|
|
|
|
|
} else {
|
|
|
|
|
return $owner->getUID();
|
|
|
|
|
}
|
2016-03-10 14:53:56 -05:00
|
|
|
});
|
2022-04-12 08:01:13 -04:00
|
|
|
$propFind->handle(self::OWNER_DISPLAY_NAME_PROPERTYNAME, function () use ($node): ?string {
|
2016-03-10 14:53:56 -05:00
|
|
|
$owner = $node->getOwner();
|
2017-03-02 09:26:00 -05:00
|
|
|
if (!$owner) {
|
|
|
|
|
return null;
|
2025-04-29 10:42:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get current user to see if we're in a public share or not
|
|
|
|
|
$user = $this->userSession->getUser();
|
|
|
|
|
|
|
|
|
|
// If the user is logged in, we can return the display name
|
|
|
|
|
if ($user !== null) {
|
2017-03-02 09:26:00 -05:00
|
|
|
return $owner->getDisplayName();
|
|
|
|
|
}
|
2025-04-29 10:42:09 -04:00
|
|
|
|
|
|
|
|
// Check if the user published their display name
|
2025-06-25 08:35:02 -04:00
|
|
|
try {
|
|
|
|
|
$ownerAccount = $this->accountManager->getAccount($owner);
|
|
|
|
|
} catch (NoUserException) {
|
|
|
|
|
// do not lock process if owner is not local
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-29 10:42:09 -04:00
|
|
|
$ownerNameProperty = $ownerAccount->getProperty(IAccountManager::PROPERTY_DISPLAYNAME);
|
|
|
|
|
|
|
|
|
|
// Since we are not logged in, we need to have at least the published scope
|
|
|
|
|
if ($ownerNameProperty->getScope() === IAccountManager::SCOPE_PUBLISHED) {
|
|
|
|
|
return $owner->getDisplayName();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
2016-03-10 14:53:56 -05:00
|
|
|
});
|
2016-04-18 05:18:50 -04:00
|
|
|
|
2016-07-26 07:15:12 -04:00
|
|
|
$propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function () use ($node) {
|
2023-01-19 13:19:22 -05:00
|
|
|
return json_encode($this->previewManager->isAvailable($node->getFileInfo()), JSON_THROW_ON_ERROR);
|
2016-07-26 07:15:12 -04:00
|
|
|
});
|
2023-01-23 09:03:56 -05:00
|
|
|
$propFind->handle(self::SIZE_PROPERTYNAME, function () use ($node): int|float {
|
2016-11-21 09:03:45 -05:00
|
|
|
return $node->getSize();
|
|
|
|
|
});
|
2017-05-08 08:34:36 -04:00
|
|
|
$propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function () use ($node) {
|
|
|
|
|
return $node->getFileInfo()->getMountPoint()->getMountType();
|
|
|
|
|
});
|
2018-12-05 09:20:44 -05:00
|
|
|
|
2024-01-30 11:20:03 -05:00
|
|
|
/**
|
|
|
|
|
* This is a special property which is used to determine if a node
|
|
|
|
|
* is a mount root or not, e.g. a shared folder.
|
|
|
|
|
* If so, then the node can only be unshared and not deleted.
|
|
|
|
|
* @see https://github.com/nextcloud/server/blob/cc75294eb6b16b916a342e69998935f89222619d/lib/private/Files/View.php#L696-L698
|
|
|
|
|
*/
|
|
|
|
|
$propFind->handle(self::MOUNT_ROOT_PROPERTYNAME, function () use ($node) {
|
|
|
|
|
return $node->getNode()->getInternalPath() === '' ? 'true' : 'false';
|
|
|
|
|
});
|
|
|
|
|
|
2024-08-05 11:51:45 -04:00
|
|
|
$propFind->handle(self::SHARE_NOTE, function () use ($node): ?string {
|
2021-07-21 08:23:49 -04:00
|
|
|
$user = $this->userSession->getUser();
|
2018-12-05 09:20:44 -05:00
|
|
|
return $node->getNoteFromShare(
|
2024-08-02 08:30:52 -04:00
|
|
|
$user?->getUID()
|
2018-12-05 09:20:44 -05:00
|
|
|
);
|
|
|
|
|
});
|
2016-04-18 05:18:50 -04:00
|
|
|
|
2025-04-14 08:47:18 -04:00
|
|
|
$propFind->handle(self::SHARE_HIDE_DOWNLOAD_PROPERTYNAME, function () use ($node) {
|
|
|
|
|
$storage = $node->getNode()->getStorage();
|
|
|
|
|
if ($storage->instanceOfStorage(ISharedStorage::class)) {
|
|
|
|
|
/** @var ISharedStorage $storage */
|
|
|
|
|
return match($storage->getShare()->getHideDownload()) {
|
|
|
|
|
true => 'true',
|
|
|
|
|
false => 'false',
|
|
|
|
|
};
|
|
|
|
|
} else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2024-08-05 11:51:45 -04:00
|
|
|
$propFind->handle(self::DATA_FINGERPRINT_PROPERTYNAME, function () {
|
2016-04-18 05:18:50 -04:00
|
|
|
return $this->config->getSystemValue('data-fingerprint', '');
|
|
|
|
|
});
|
2021-11-29 05:25:48 -05:00
|
|
|
$propFind->handle(self::CREATIONDATE_PROPERTYNAME, function () use ($node) {
|
|
|
|
|
return (new \DateTimeImmutable())
|
|
|
|
|
->setTimestamp($node->getFileInfo()->getCreationTime())
|
|
|
|
|
->format(\DateTimeInterface::ATOM);
|
|
|
|
|
});
|
2021-11-23 10:55:33 -05:00
|
|
|
$propFind->handle(self::CREATION_TIME_PROPERTYNAME, function () use ($node) {
|
|
|
|
|
return $node->getFileInfo()->getCreationTime();
|
|
|
|
|
});
|
2023-11-06 20:21:29 -05:00
|
|
|
|
|
|
|
|
foreach ($node->getFileInfo()->getMetadata() as $metadataKey => $metadataValue) {
|
|
|
|
|
$propFind->handle(self::FILE_METADATA_PREFIX . $metadataKey, $metadataValue);
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-08 08:52:50 -05:00
|
|
|
$propFind->handle(self::HIDDEN_PROPERTYNAME, function () use ($node) {
|
2023-12-18 05:44:44 -05:00
|
|
|
$isLivePhoto = isset($node->getFileInfo()->getMetadata()['files-live-photo']);
|
|
|
|
|
$isMovFile = $node->getFileInfo()->getMimetype() === 'video/quicktime';
|
|
|
|
|
return ($isLivePhoto && $isMovFile) ? 'true' : 'false';
|
2023-11-08 08:52:50 -05:00
|
|
|
});
|
|
|
|
|
|
2022-10-10 15:20:07 -04:00
|
|
|
/**
|
|
|
|
|
* Return file/folder name as displayname. The primary reason to
|
2023-01-23 09:03:56 -05:00
|
|
|
* implement it this way is to avoid costly fallback to
|
2022-10-10 15:20:07 -04:00
|
|
|
* CustomPropertiesBackend (esp. visible when querying all files
|
|
|
|
|
* in a folder).
|
|
|
|
|
*/
|
|
|
|
|
$propFind->handle(self::DISPLAYNAME_PROPERTYNAME, function () use ($node) {
|
|
|
|
|
return $node->getName();
|
|
|
|
|
});
|
2024-08-22 18:25:42 -04:00
|
|
|
|
|
|
|
|
$propFind->handle(self::IS_FEDERATED_PROPERTYNAME, function () use ($node) {
|
|
|
|
|
return $node->getFileInfo()->getMountPoint()
|
2025-01-30 10:56:48 -05:00
|
|
|
instanceof SharingExternalMount;
|
2024-08-22 18:25:42 -04:00
|
|
|
});
|
2013-10-23 10:03:57 -04:00
|
|
|
}
|
|
|
|
|
|
2024-10-10 06:40:31 -04:00
|
|
|
if ($node instanceof File) {
|
2020-04-09 07:53:40 -04:00
|
|
|
$propFind->handle(self::DOWNLOADURL_PROPERTYNAME, function () use ($node) {
|
2015-12-09 11:31:14 -05:00
|
|
|
try {
|
|
|
|
|
$directDownloadUrl = $node->getDirectDownload();
|
|
|
|
|
if (isset($directDownloadUrl['url'])) {
|
|
|
|
|
return $directDownloadUrl['url'];
|
|
|
|
|
}
|
|
|
|
|
} catch (StorageNotAvailableException $e) {
|
|
|
|
|
return false;
|
2016-06-01 10:17:57 -04:00
|
|
|
} catch (ForbiddenException $e) {
|
|
|
|
|
return false;
|
2015-02-12 06:29:01 -05:00
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
});
|
2016-01-29 15:50:48 -05:00
|
|
|
|
2020-04-09 07:53:40 -04:00
|
|
|
$propFind->handle(self::CHECKSUMS_PROPERTYNAME, function () use ($node) {
|
2016-01-29 15:50:48 -05:00
|
|
|
$checksum = $node->getChecksum();
|
2020-03-25 16:53:04 -04:00
|
|
|
if ($checksum === null || $checksum === '') {
|
2016-02-28 13:41:46 -05:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-08 05:55:07 -05:00
|
|
|
return new ChecksumList($checksum);
|
2016-01-29 15:50:48 -05:00
|
|
|
});
|
|
|
|
|
|
2020-04-09 07:53:40 -04:00
|
|
|
$propFind->handle(self::UPLOAD_TIME_PROPERTYNAME, function () use ($node) {
|
2019-10-30 12:24:55 -04:00
|
|
|
return $node->getFileInfo()->getUploadTime();
|
|
|
|
|
});
|
2014-12-15 09:20:24 -05:00
|
|
|
}
|
|
|
|
|
|
2022-02-15 10:18:41 -05:00
|
|
|
if ($node instanceof Directory) {
|
2020-04-09 07:53:40 -04:00
|
|
|
$propFind->handle(self::SIZE_PROPERTYNAME, function () use ($node) {
|
2015-02-12 06:29:01 -05:00
|
|
|
return $node->getSize();
|
|
|
|
|
});
|
2018-01-30 06:25:49 -05:00
|
|
|
|
2022-02-15 10:18:41 -05:00
|
|
|
$requestProperties = $propFind->getRequestedProperties();
|
2022-04-04 17:15:00 -04:00
|
|
|
|
2022-02-15 10:18:41 -05:00
|
|
|
if (in_array(self::SUBFILE_COUNT_PROPERTYNAME, $requestProperties, true)
|
|
|
|
|
|| in_array(self::SUBFOLDER_COUNT_PROPERTYNAME, $requestProperties, true)) {
|
|
|
|
|
$nbFiles = 0;
|
|
|
|
|
$nbFolders = 0;
|
|
|
|
|
foreach ($node->getChildren() as $child) {
|
|
|
|
|
if ($child instanceof File) {
|
|
|
|
|
$nbFiles++;
|
|
|
|
|
} elseif ($child instanceof Directory) {
|
|
|
|
|
$nbFolders++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$propFind->handle(self::SUBFILE_COUNT_PROPERTYNAME, $nbFiles);
|
|
|
|
|
$propFind->handle(self::SUBFOLDER_COUNT_PROPERTYNAME, $nbFolders);
|
|
|
|
|
}
|
2014-08-29 05:39:02 -04:00
|
|
|
}
|
2013-10-23 10:03:57 -04:00
|
|
|
}
|
|
|
|
|
|
2018-06-25 05:14:26 -04:00
|
|
|
/**
|
|
|
|
|
* translate Nextcloud permissions to OCM Permissions
|
|
|
|
|
*
|
|
|
|
|
* @param $ncPermissions
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
protected function ncPermissions2ocmPermissions($ncPermissions) {
|
|
|
|
|
$ocmPermissions = [];
|
|
|
|
|
|
|
|
|
|
if ($ncPermissions & Constants::PERMISSION_SHARE) {
|
|
|
|
|
$ocmPermissions[] = 'share';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($ncPermissions & Constants::PERMISSION_READ) {
|
|
|
|
|
$ocmPermissions[] = 'read';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (($ncPermissions & Constants::PERMISSION_CREATE)
|
|
|
|
|
|| ($ncPermissions & Constants::PERMISSION_UPDATE)) {
|
|
|
|
|
$ocmPermissions[] = 'write';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $ocmPermissions;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-12 06:29:01 -05:00
|
|
|
/**
|
|
|
|
|
* Update ownCloud-specific properties
|
|
|
|
|
*
|
|
|
|
|
* @param string $path
|
|
|
|
|
* @param PropPatch $propPatch
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function handleUpdateProperties($path, PropPatch $propPatch) {
|
2017-02-08 12:18:38 -05:00
|
|
|
$node = $this->tree->getNodeForPath($path);
|
2024-10-10 06:40:31 -04:00
|
|
|
if (!($node instanceof Node)) {
|
2017-02-08 12:18:38 -05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-09 07:53:40 -04:00
|
|
|
$propPatch->handle(self::LASTMODIFIED_PROPERTYNAME, function ($time) use ($node) {
|
2015-02-12 06:29:01 -05:00
|
|
|
if (empty($time)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
$node->touch($time);
|
|
|
|
|
return true;
|
|
|
|
|
});
|
2020-04-09 07:53:40 -04:00
|
|
|
$propPatch->handle(self::GETETAG_PROPERTYNAME, function ($etag) use ($node) {
|
2015-02-12 06:29:01 -05:00
|
|
|
if (empty($etag)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2022-04-12 08:01:13 -04:00
|
|
|
return $node->setEtag($etag) !== -1;
|
2015-02-12 06:29:01 -05:00
|
|
|
});
|
2021-11-29 05:25:48 -05:00
|
|
|
$propPatch->handle(self::CREATIONDATE_PROPERTYNAME, function ($time) use ($node) {
|
|
|
|
|
if (empty($time)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
$dateTime = new \DateTimeImmutable($time);
|
|
|
|
|
$node->setCreationTime($dateTime->getTimestamp());
|
|
|
|
|
return true;
|
|
|
|
|
});
|
2020-04-09 07:53:40 -04:00
|
|
|
$propPatch->handle(self::CREATION_TIME_PROPERTYNAME, function ($time) use ($node) {
|
2019-10-30 12:24:55 -04:00
|
|
|
if (empty($time)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
$node->setCreationTime((int)$time);
|
|
|
|
|
return true;
|
|
|
|
|
});
|
2023-11-08 06:35:01 -05:00
|
|
|
|
2023-11-14 06:01:29 -05:00
|
|
|
$this->handleUpdatePropertiesMetadata($propPatch, $node);
|
2023-11-08 06:35:01 -05:00
|
|
|
|
2023-11-14 06:01:29 -05:00
|
|
|
/**
|
|
|
|
|
* Disable modification of the displayname property for files and
|
|
|
|
|
* folders via PROPPATCH. See PROPFIND for more information.
|
|
|
|
|
*/
|
|
|
|
|
$propPatch->handle(self::DISPLAYNAME_PROPERTYNAME, function ($displayName) {
|
|
|
|
|
return 403;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* handle the update of metadata from PROPPATCH requests
|
|
|
|
|
*
|
|
|
|
|
* @param PropPatch $propPatch
|
|
|
|
|
* @param Node $node
|
|
|
|
|
*
|
|
|
|
|
* @throws FilesMetadataException
|
|
|
|
|
*/
|
|
|
|
|
private function handleUpdatePropertiesMetadata(PropPatch $propPatch, Node $node): void {
|
|
|
|
|
$userId = $this->userSession->getUser()?->getUID();
|
2024-03-28 11:13:19 -04:00
|
|
|
if ($userId === null) {
|
2023-11-14 06:01:29 -05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$accessRight = $this->getMetadataFileAccessRight($node, $userId);
|
|
|
|
|
$filesMetadataManager = $this->initFilesMetadataManager();
|
2023-11-08 06:35:01 -05:00
|
|
|
$knownMetadata = $filesMetadataManager->getKnownMetadata();
|
|
|
|
|
|
|
|
|
|
foreach ($propPatch->getRemainingMutations() as $mutation) {
|
|
|
|
|
if (!str_starts_with($mutation, self::FILE_METADATA_PREFIX)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-14 06:01:29 -05:00
|
|
|
$propPatch->handle(
|
|
|
|
|
$mutation,
|
|
|
|
|
function (mixed $value) use ($accessRight, $knownMetadata, $node, $mutation, $filesMetadataManager): bool {
|
2024-10-03 11:35:56 -04:00
|
|
|
/** @var FilesMetadata $metadata */
|
2023-11-14 06:01:29 -05:00
|
|
|
$metadata = $filesMetadataManager->getMetadata((int)$node->getFileId(), true);
|
2024-10-03 11:35:56 -04:00
|
|
|
$metadata->setStorageId($node->getNode()->getStorage()->getCache()->getNumericStorageId());
|
2023-11-14 06:01:29 -05:00
|
|
|
$metadataKey = substr($mutation, strlen(self::FILE_METADATA_PREFIX));
|
2023-11-08 06:35:01 -05:00
|
|
|
|
2023-11-14 06:01:29 -05:00
|
|
|
// confirm metadata key is editable via PROPPATCH
|
|
|
|
|
if ($knownMetadata->getEditPermission($metadataKey) < $accessRight) {
|
|
|
|
|
throw new FilesMetadataException('you do not have enough rights to update \'' . $metadataKey . '\' on this node');
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-17 06:04:18 -05:00
|
|
|
if ($value === null) {
|
|
|
|
|
$metadata->unset($metadataKey);
|
|
|
|
|
$filesMetadataManager->saveMetadata($metadata);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-14 06:01:29 -05:00
|
|
|
// If the metadata is unknown, it defaults to string.
|
|
|
|
|
try {
|
|
|
|
|
$type = $knownMetadata->getType($metadataKey);
|
|
|
|
|
} catch (FilesMetadataNotFoundException) {
|
|
|
|
|
$type = IMetadataValueWrapper::TYPE_STRING;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch ($type) {
|
|
|
|
|
case IMetadataValueWrapper::TYPE_STRING:
|
|
|
|
|
$metadata->setString($metadataKey, $value, $knownMetadata->isIndex($metadataKey));
|
|
|
|
|
break;
|
|
|
|
|
case IMetadataValueWrapper::TYPE_INT:
|
|
|
|
|
$metadata->setInt($metadataKey, $value, $knownMetadata->isIndex($metadataKey));
|
|
|
|
|
break;
|
|
|
|
|
case IMetadataValueWrapper::TYPE_FLOAT:
|
|
|
|
|
$metadata->setFloat($metadataKey, $value);
|
|
|
|
|
break;
|
|
|
|
|
case IMetadataValueWrapper::TYPE_BOOL:
|
|
|
|
|
$metadata->setBool($metadataKey, $value, $knownMetadata->isIndex($metadataKey));
|
|
|
|
|
break;
|
|
|
|
|
case IMetadataValueWrapper::TYPE_ARRAY:
|
|
|
|
|
$metadata->setArray($metadataKey, $value);
|
|
|
|
|
break;
|
|
|
|
|
case IMetadataValueWrapper::TYPE_STRING_LIST:
|
2024-03-07 08:48:57 -05:00
|
|
|
$metadata->setStringList($metadataKey, $value, $knownMetadata->isIndex($metadataKey));
|
2023-11-14 06:01:29 -05:00
|
|
|
break;
|
|
|
|
|
case IMetadataValueWrapper::TYPE_INT_LIST:
|
2024-03-07 08:48:57 -05:00
|
|
|
$metadata->setIntList($metadataKey, $value, $knownMetadata->isIndex($metadataKey));
|
2023-11-14 06:01:29 -05:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$filesMetadataManager->saveMetadata($metadata);
|
2023-11-08 06:35:01 -05:00
|
|
|
|
2023-11-14 06:01:29 -05:00
|
|
|
return true;
|
2023-11-08 06:35:01 -05:00
|
|
|
}
|
2023-11-14 06:01:29 -05:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-08 06:35:01 -05:00
|
|
|
|
2023-11-14 06:01:29 -05:00
|
|
|
/**
|
|
|
|
|
* init default internal metadata
|
|
|
|
|
*
|
|
|
|
|
* @return IFilesMetadataManager
|
|
|
|
|
*/
|
|
|
|
|
private function initFilesMetadataManager(): IFilesMetadataManager {
|
|
|
|
|
/** @var IFilesMetadataManager $manager */
|
|
|
|
|
$manager = \OCP\Server::get(IFilesMetadataManager::class);
|
|
|
|
|
$manager->initMetadata('files-live-photo', IMetadataValueWrapper::TYPE_STRING, false, IMetadataValueWrapper::EDIT_REQ_OWNERSHIP);
|
|
|
|
|
|
|
|
|
|
return $manager;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* based on owner and shares, returns the bottom limit to update related metadata
|
|
|
|
|
*
|
|
|
|
|
* @param Node $node
|
|
|
|
|
* @param string $userId
|
|
|
|
|
*
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
private function getMetadataFileAccessRight(Node $node, string $userId): int {
|
|
|
|
|
if ($node->getOwner()?->getUID() === $userId) {
|
|
|
|
|
return IMetadataValueWrapper::EDIT_REQ_OWNERSHIP;
|
|
|
|
|
} else {
|
|
|
|
|
$filePermissions = $node->getSharePermissions($userId);
|
|
|
|
|
if ($filePermissions & Constants::PERMISSION_UPDATE) {
|
|
|
|
|
return IMetadataValueWrapper::EDIT_REQ_WRITE_PERMISSION;
|
|
|
|
|
}
|
2023-11-08 06:35:01 -05:00
|
|
|
}
|
|
|
|
|
|
2023-11-14 06:01:29 -05:00
|
|
|
return IMetadataValueWrapper::EDIT_REQ_READ_PERMISSION;
|
2015-02-12 06:29:01 -05:00
|
|
|
}
|
|
|
|
|
|
2013-10-25 07:20:59 -04:00
|
|
|
/**
|
2014-05-11 16:51:30 -04:00
|
|
|
* @param string $filePath
|
2024-03-28 12:15:01 -04:00
|
|
|
* @param ?\Sabre\DAV\INode $node
|
|
|
|
|
* @return void
|
2014-01-09 08:25:48 -05:00
|
|
|
* @throws \Sabre\DAV\Exception\BadRequest
|
2013-10-25 07:20:59 -04:00
|
|
|
*/
|
2024-03-28 11:13:19 -04:00
|
|
|
public function sendFileIdHeader($filePath, ?\Sabre\DAV\INode $node = null) {
|
2013-11-20 10:14:08 -05:00
|
|
|
// we get the node for the given $filePath here because in case of afterCreateFile $node is the parent folder
|
2025-04-14 09:16:44 -04:00
|
|
|
try {
|
|
|
|
|
$node = $this->server->tree->getNodeForPath($filePath);
|
|
|
|
|
if ($node instanceof Node) {
|
|
|
|
|
$fileId = $node->getFileId();
|
|
|
|
|
if (!is_null($fileId)) {
|
|
|
|
|
$this->server->httpResponse->setHeader('OC-FileId', $fileId);
|
|
|
|
|
}
|
2013-10-25 07:20:59 -04:00
|
|
|
}
|
2025-04-14 09:16:44 -04:00
|
|
|
} catch (NotFound) {
|
2013-10-25 07:20:59 -04:00
|
|
|
}
|
|
|
|
|
}
|
2013-10-23 10:03:57 -04:00
|
|
|
}
|