Port Encryption/file to new getAccessList
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
parent
88299ec27c
commit
a1edcc8ecf
|
@ -25,12 +25,21 @@
|
||||||
namespace OC\Encryption;
|
namespace OC\Encryption;
|
||||||
|
|
||||||
use OC\Cache\CappedMemoryCache;
|
use OC\Cache\CappedMemoryCache;
|
||||||
|
use OCP\Files\IRootFolder;
|
||||||
|
use OCP\Files\NotFoundException;
|
||||||
|
use OCP\Share\IManager;
|
||||||
|
|
||||||
class File implements \OCP\Encryption\IFile {
|
class File implements \OCP\Encryption\IFile {
|
||||||
|
|
||||||
/** @var Util */
|
/** @var Util */
|
||||||
protected $util;
|
protected $util;
|
||||||
|
|
||||||
|
/** @var IRootFolder */
|
||||||
|
private $rootFolder;
|
||||||
|
|
||||||
|
/** @var IManager */
|
||||||
|
private $shareManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* cache results of already checked folders
|
* cache results of already checked folders
|
||||||
*
|
*
|
||||||
|
@ -38,9 +47,13 @@ class File implements \OCP\Encryption\IFile {
|
||||||
*/
|
*/
|
||||||
protected $cache;
|
protected $cache;
|
||||||
|
|
||||||
public function __construct(Util $util) {
|
public function __construct(Util $util,
|
||||||
|
IRootFolder $rootFolder,
|
||||||
|
IManager $shareManager) {
|
||||||
$this->util = $util;
|
$this->util = $util;
|
||||||
$this->cache = new CappedMemoryCache();
|
$this->cache = new CappedMemoryCache();
|
||||||
|
$this->rootFolder = $rootFolder;
|
||||||
|
$this->shareManager = $shareManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -63,16 +76,22 @@ class File implements \OCP\Encryption\IFile {
|
||||||
}
|
}
|
||||||
|
|
||||||
$ownerPath = substr($ownerPath, strlen('/files'));
|
$ownerPath = substr($ownerPath, strlen('/files'));
|
||||||
|
$userFolder = $this->rootFolder->getUserFolder($owner);
|
||||||
|
try {
|
||||||
|
$file = $userFolder->get($ownerPath);
|
||||||
|
} catch (NotFoundException $e) {
|
||||||
|
$file = null;
|
||||||
|
}
|
||||||
$ownerPath = $this->util->stripPartialFileExtension($ownerPath);
|
$ownerPath = $this->util->stripPartialFileExtension($ownerPath);
|
||||||
|
|
||||||
|
|
||||||
// first get the shares for the parent and cache the result so that we don't
|
// first get the shares for the parent and cache the result so that we don't
|
||||||
// need to check all parents for every file
|
// need to check all parents for every file
|
||||||
$parent = dirname($ownerPath);
|
$parent = dirname($ownerPath);
|
||||||
|
$parentNode = $userFolder->get($parent);
|
||||||
if (isset($this->cache[$parent])) {
|
if (isset($this->cache[$parent])) {
|
||||||
$resultForParents = $this->cache[$parent];
|
$resultForParents = $this->cache[$parent];
|
||||||
} else {
|
} else {
|
||||||
$resultForParents = \OCP\Share::getUsersSharingFile($parent, $owner);
|
$resultForParents = $this->shareManager->getAccessList($parentNode);
|
||||||
$this->cache[$parent] = $resultForParents;
|
$this->cache[$parent] = $resultForParents;
|
||||||
}
|
}
|
||||||
$userIds = \array_merge($userIds, $resultForParents['users']);
|
$userIds = \array_merge($userIds, $resultForParents['users']);
|
||||||
|
@ -80,9 +99,11 @@ class File implements \OCP\Encryption\IFile {
|
||||||
|
|
||||||
|
|
||||||
// Find out who, if anyone, is sharing the file
|
// Find out who, if anyone, is sharing the file
|
||||||
$resultForFile = \OCP\Share::getUsersSharingFile($ownerPath, $owner, false, false, false);
|
if ($file !== null) {
|
||||||
$userIds = \array_merge($userIds, $resultForFile['users']);
|
$resultForFile = $this->shareManager->getAccessList($file, false);
|
||||||
$public = $resultForFile['public'] || $resultForFile['remote'] || $public;
|
$userIds = \array_merge($userIds, $resultForFile['users']);
|
||||||
|
$public = $resultForFile['public'] || $resultForFile['remote'] || $public;
|
||||||
|
}
|
||||||
|
|
||||||
// check if it is a group mount
|
// check if it is a group mount
|
||||||
if (\OCP\App::isEnabled("files_external")) {
|
if (\OCP\App::isEnabled("files_external")) {
|
||||||
|
|
|
@ -173,7 +173,11 @@ class Server extends ServerContainer implements IServerContainer {
|
||||||
$c->getGroupManager(),
|
$c->getGroupManager(),
|
||||||
$c->getConfig()
|
$c->getConfig()
|
||||||
);
|
);
|
||||||
return new Encryption\File($util);
|
return new Encryption\File(
|
||||||
|
$util,
|
||||||
|
$c->getRootFolder(),
|
||||||
|
$c->getShareManager()
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->registerService('EncryptionKeyStorage', function (Server $c) {
|
$this->registerService('EncryptionKeyStorage', function (Server $c) {
|
||||||
|
|
Loading…
Reference in New Issue