Add getOwner to FileInfo

This commit is contained in:
Robin Appelman 2015-11-02 14:56:38 +01:00
parent 422d29ae48
commit 331ef0e3c0
4 changed files with 44 additions and 7 deletions

View file

@ -28,6 +28,8 @@
namespace OC\Files; namespace OC\Files;
use OCP\IUser;
class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess { class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess {
/** /**
* @var array $data * @var array $data
@ -54,19 +56,26 @@ class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess {
*/ */
private $mount; private $mount;
/**
* @var IUser
*/
private $owner;
/** /**
* @param string|boolean $path * @param string|boolean $path
* @param Storage\Storage $storage * @param Storage\Storage $storage
* @param string $internalPath * @param string $internalPath
* @param array $data * @param array $data
* @param \OCP\Files\Mount\IMountPoint $mount * @param \OCP\Files\Mount\IMountPoint $mount
* @param \OCP\IUser|null $owner
*/ */
public function __construct($path, $storage, $internalPath, $data, $mount) { public function __construct($path, $storage, $internalPath, $data, $mount, $owner= null) {
$this->path = $path; $this->path = $path;
$this->storage = $storage; $this->storage = $storage;
$this->internalPath = $internalPath; $this->internalPath = $internalPath;
$this->data = $data; $this->data = $data;
$this->mount = $mount; $this->mount = $mount;
$this->owner = $owner;
} }
public function offsetSet($offset, $value) { public function offsetSet($offset, $value) {
@ -267,4 +276,13 @@ class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess {
public function getMountPoint() { public function getMountPoint() {
return $this->mount; return $this->mount;
} }
/**
* Get the owner of the file
*
* @return \OCP\IUser
*/
public function getOwner() {
return $this->owner;
}
} }

View file

@ -347,4 +347,8 @@ class Node implements \OCP\Files\Node {
public function getMountPoint() { public function getMountPoint() {
return $this->getFileInfo()->getMountPoint(); return $this->getFileInfo()->getMountPoint();
} }
public function getOwner() {
return $this->getFileInfo()->getOwner();
}
} }

View file

@ -1250,7 +1250,8 @@ class View {
$data['permissions'] |= \OCP\Constants::PERMISSION_DELETE; $data['permissions'] |= \OCP\Constants::PERMISSION_DELETE;
} }
return new FileInfo($path, $storage, $internalPath, $data, $mount); $owner = \OC::$server->getUserManager()->get($storage->getOwner($internalPath));
return new FileInfo($path, $storage, $internalPath, $data, $mount, $owner);
} }
/** /**
@ -1316,7 +1317,8 @@ class View {
if (\OCP\Util::isSharingDisabledForUser()) { if (\OCP\Util::isSharingDisabledForUser()) {
$content['permissions'] = $content['permissions'] & ~\OCP\Constants::PERMISSION_SHARE; $content['permissions'] = $content['permissions'] & ~\OCP\Constants::PERMISSION_SHARE;
} }
$files[] = new FileInfo($path . '/' . $content['name'], $storage, $content['path'], $content, $mount); $owner = \OC::$server->getUserManager()->get($storage->getOwner($content['path']));
$files[] = new FileInfo($path . '/' . $content['name'], $storage, $content['path'], $content, $mount, $owner);
} }
//add a folder for any mountpoint in this directory and add the sizes of other mountpoints to the folders //add a folder for any mountpoint in this directory and add the sizes of other mountpoints to the folders
@ -1385,7 +1387,8 @@ class View {
$rootEntry['permissions'] = $rootEntry['permissions'] & ~\OCP\Constants::PERMISSION_SHARE; $rootEntry['permissions'] = $rootEntry['permissions'] & ~\OCP\Constants::PERMISSION_SHARE;
} }
$files[] = new FileInfo($path . '/' . $rootEntry['name'], $subStorage, '', $rootEntry, $mount); $owner = \OC::$server->getUserManager()->get($subStorage->getOwner(''));
$files[] = new FileInfo($path . '/' . $rootEntry['name'], $subStorage, '', $rootEntry, $mount, $owner);
} }
} }
} }
@ -1507,7 +1510,8 @@ class View {
$internalPath = $result['path']; $internalPath = $result['path'];
$path = $mountPoint . $result['path']; $path = $mountPoint . $result['path'];
$result['path'] = substr($mountPoint . $result['path'], $rootLength); $result['path'] = substr($mountPoint . $result['path'], $rootLength);
$files[] = new FileInfo($path, $storage, $internalPath, $result, $mount); $owner = \OC::$server->getUserManager()->get($storage->getOwner($internalPath));
$files[] = new FileInfo($path, $storage, $internalPath, $result, $mount, $owner);
} }
} }
@ -1525,7 +1529,8 @@ class View {
$internalPath = $result['path']; $internalPath = $result['path'];
$result['path'] = rtrim($relativeMountPoint . $result['path'], '/'); $result['path'] = rtrim($relativeMountPoint . $result['path'], '/');
$path = rtrim($mountPoint . $internalPath, '/'); $path = rtrim($mountPoint . $internalPath, '/');
$files[] = new FileInfo($path, $storage, $internalPath, $result, $mount); $owner = \OC::$server->getUserManager()->get($storage->getOwner($internalPath));
$files[] = new FileInfo($path, $storage, $internalPath, $result, $mount, $owner);
} }
} }
} }
@ -1666,6 +1671,7 @@ class View {
$mount = $this->getMount($path); $mount = $this->getMount($path);
$storage = $mount->getStorage(); $storage = $mount->getStorage();
$internalPath = $mount->getInternalPath($this->getAbsolutePath($path)); $internalPath = $mount->getInternalPath($this->getAbsolutePath($path));
$owner = \OC::$server->getUserManager()->get($storage->getOwner($internalPath));
return new FileInfo( return new FileInfo(
$this->getAbsolutePath($path), $this->getAbsolutePath($path),
$storage, $storage,
@ -1680,7 +1686,8 @@ class View {
'encrypted' => false, 'encrypted' => false,
'permissions' => \OCP\Constants::PERMISSION_ALL 'permissions' => \OCP\Constants::PERMISSION_ALL
], ],
$mount $mount,
$owner
); );
} }

View file

@ -229,4 +229,12 @@ interface FileInfo {
* @since 8.0.0 * @since 8.0.0
*/ */
public function getMountPoint(); public function getMountPoint();
/**
* Get the owner of the file
*
* @return \OCP\IUser
* @since 9.0.0
*/
public function getOwner();
} }