summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/appframework/dependencyinjection/dicontainer.php4
-rw-r--r--lib/private/comments/comment.php4
-rw-r--r--lib/private/comments/manager.php56
-rw-r--r--lib/private/comments/managerfactory.php3
-rw-r--r--lib/private/console/application.php21
-rw-r--r--lib/private/db/mdb2schemamanager.php3
-rw-r--r--lib/private/db/querybuilder/expressionbuilder/expressionbuilder.php (renamed from lib/private/db/querybuilder/expressionbuilder.php)19
-rw-r--r--lib/private/db/querybuilder/expressionbuilder/ociexpressionbuilder.php (renamed from lib/private/db/querybuilder/ociexpressionbuilder.php)25
-rw-r--r--lib/private/db/querybuilder/expressionbuilder/pgsqlexpressionbuilder.php (renamed from lib/private/share20/exception/sharenotfound.php)26
-rw-r--r--lib/private/db/querybuilder/querybuilder.php6
-rw-r--r--lib/private/diagnostics/querylogger.php2
-rw-r--r--lib/private/files.php10
-rw-r--r--lib/private/files/cache/cache.php91
-rw-r--r--lib/private/files/cache/wrapper/cachejail.php7
-rw-r--r--lib/private/files/cache/wrapper/cachewrapper.php23
-rw-r--r--lib/private/files/node/root.php2
-rw-r--r--lib/private/files/storage/common.php8
-rw-r--r--lib/private/files/storage/wrapper/availability.php11
-rw-r--r--lib/private/files/storage/wrapper/jail.php11
-rw-r--r--lib/private/files/storage/wrapper/wrapper.php11
-rw-r--r--lib/private/files/stream/dir.php1
-rw-r--r--lib/private/files/type/detection.php4
-rw-r--r--lib/private/integritycheck/checker.php22
-rw-r--r--lib/private/integritycheck/iterator/excludefoldersbypathfilteriterator.php9
-rw-r--r--lib/private/repair/dropoldjobs.php1
-rw-r--r--lib/private/repair/repairmimetypes.php17
-rw-r--r--lib/private/server.php4
-rw-r--r--lib/private/share/hooks.php2
-rw-r--r--lib/private/share20/defaultshareprovider.php141
-rw-r--r--lib/private/share20/manager.php174
-rw-r--r--lib/private/share20/share.php98
-rw-r--r--lib/private/user/manager.php4
-rw-r--r--lib/private/user/user.php2
33 files changed, 530 insertions, 292 deletions
diff --git a/lib/private/appframework/dependencyinjection/dicontainer.php b/lib/private/appframework/dependencyinjection/dicontainer.php
index 5fc45fdd2e8..f74fe4aeb99 100644
--- a/lib/private/appframework/dependencyinjection/dicontainer.php
+++ b/lib/private/appframework/dependencyinjection/dicontainer.php
@@ -104,6 +104,10 @@ class DIContainer extends SimpleContainer implements IAppContainer {
return $this->getServer()->getCapabilitiesManager();
});
+ $this->registerService('OCP\Comments\ICommentsManager', function($c) {
+ return $this->getServer()->getCommentsManager();
+ });
+
$this->registerService('OCP\\IConfig', function($c) {
return $this->getServer()->getConfig();
});
diff --git a/lib/private/comments/comment.php b/lib/private/comments/comment.php
index 75964603f9f..36189d9523b 100644
--- a/lib/private/comments/comment.php
+++ b/lib/private/comments/comment.php
@@ -242,7 +242,7 @@ class Comment implements IComment {
/**
* sets (overwrites) the actor type and id
*
- * @param string $actorType e.g. 'user'
+ * @param string $actorType e.g. 'users'
* @param string $actorId e.g. 'zombie234'
* @return IComment
* @since 9.0.0
@@ -328,7 +328,7 @@ class Comment implements IComment {
/**
* sets (overwrites) the object of the comment
*
- * @param string $objectType e.g. 'file'
+ * @param string $objectType e.g. 'files'
* @param string $objectId e.g. '16435'
* @return IComment
* @since 9.0.0
diff --git a/lib/private/comments/manager.php b/lib/private/comments/manager.php
index 28bd3b0916a..36b2d9d08b8 100644
--- a/lib/private/comments/manager.php
+++ b/lib/private/comments/manager.php
@@ -21,6 +21,7 @@
namespace OC\Comments;
use Doctrine\DBAL\Exception\DriverException;
+use OCP\Comments\CommentsEvent;
use OCP\Comments\IComment;
use OCP\Comments\ICommentsManager;
use OCP\Comments\NotFoundException;
@@ -28,6 +29,7 @@ use OCP\IDBConnection;
use OCP\IConfig;
use OCP\ILogger;
use OCP\IUser;
+use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class Manager implements ICommentsManager {
@@ -37,20 +39,33 @@ class Manager implements ICommentsManager {
/** @var ILogger */
protected $logger;
- /** @var IComment[] */
- protected $commentsCache = [];
-
/** @var IConfig */
protected $config;
+ /** @var EventDispatcherInterface */
+ protected $dispatcher;
+
+ /** @var IComment[] */
+ protected $commentsCache = [];
+
+ /**
+ * Manager constructor.
+ *
+ * @param IDBConnection $dbConn
+ * @param ILogger $logger
+ * @param IConfig $config
+ * @param EventDispatcherInterface $dispatcher
+ */
public function __construct(
IDBConnection $dbConn,
ILogger $logger,
- IConfig $config
+ IConfig $config,
+ EventDispatcherInterface $dispatcher
) {
$this->dbConn = $dbConn;
$this->logger = $logger;
$this->config = $config;
+ $this->dispatcher = $dispatcher;
}
/**
@@ -384,7 +399,7 @@ class Manager implements ICommentsManager {
* saved in the used data storage. Use save() after setting other fields
* of the comment (e.g. message or verb).
*
- * @param string $actorType the actor type (e.g. 'user')
+ * @param string $actorType the actor type (e.g. 'users')
* @param string $actorId a user id
* @param string $objectType the object type the comment is attached to
* @param string $objectId the object id the comment is attached to
@@ -415,6 +430,13 @@ class Manager implements ICommentsManager {
throw new \InvalidArgumentException('Parameter must be string');
}
+ try {
+ $comment = $this->get($id);
+ } catch (\Exception $e) {
+ // Ignore exceptions, we just don't fire a hook then
+ $comment = null;
+ }
+
$qb = $this->dbConn->getQueryBuilder();
$query = $qb->delete('comments')
->where($qb->expr()->eq('id', $qb->createParameter('id')))
@@ -427,11 +449,19 @@ class Manager implements ICommentsManager {
$this->logger->logException($e, ['app' => 'core_comments']);
return false;
}
+
+ if ($affectedRows > 0 && $comment instanceof IComment) {
+ $this->dispatcher->dispatch(CommentsEvent::EVENT_DELETE, new CommentsEvent(
+ CommentsEvent::EVENT_DELETE,
+ $comment
+ ));
+ }
+
return ($affectedRows > 0);
}
/**
- * saves the comment permanently and returns it
+ * saves the comment permanently
*
* if the supplied comment has an empty ID, a new entry comment will be
* saved and the instance updated with the new ID.
@@ -493,6 +523,11 @@ class Manager implements ICommentsManager {
$comment->setId(strval($qb->getLastInsertId()));
}
+ $this->dispatcher->dispatch(CommentsEvent::EVENT_ADD, new CommentsEvent(
+ CommentsEvent::EVENT_ADD,
+ $comment
+ ));
+
return $affectedRows > 0;
}
@@ -526,6 +561,11 @@ class Manager implements ICommentsManager {
throw new NotFoundException('Comment to update does ceased to exist');
}
+ $this->dispatcher->dispatch(CommentsEvent::EVENT_UPDATE, new CommentsEvent(
+ CommentsEvent::EVENT_UPDATE,
+ $comment
+ ));
+
return $affectedRows > 0;
}
@@ -533,7 +573,7 @@ class Manager implements ICommentsManager {
* removes references to specific actor (e.g. on user delete) of a comment.
* The comment itself must not get lost/deleted.
*
- * @param string $actorType the actor type (e.g. 'user')
+ * @param string $actorType the actor type (e.g. 'users')
* @param string $actorId a user id
* @return boolean
* @since 9.0.0
@@ -560,7 +600,7 @@ class Manager implements ICommentsManager {
/**
* deletes all comments made of a specific object (e.g. on file delete)
*
- * @param string $objectType the object type (e.g. 'file')
+ * @param string $objectType the object type (e.g. 'files')
* @param string $objectId e.g. the file id
* @return boolean
* @since 9.0.0
diff --git a/lib/private/comments/managerfactory.php b/lib/private/comments/managerfactory.php
index d3f6c44e539..b8e77c64fae 100644
--- a/lib/private/comments/managerfactory.php
+++ b/lib/private/comments/managerfactory.php
@@ -52,7 +52,8 @@ class ManagerFactory implements ICommentsManagerFactory {
return new Manager(
$this->serverContainer->getDatabaseConnection(),
$this->serverContainer->getLogger(),
- $this->serverContainer->getConfig()
+ $this->serverContainer->getConfig(),
+ $this->serverContainer->getEventDispatcher()
);
}
}
diff --git a/lib/private/console/application.php b/lib/private/console/application.php
index c7d9c24d7cb..10ff69b1c80 100644
--- a/lib/private/console/application.php
+++ b/lib/private/console/application.php
@@ -25,25 +25,34 @@ namespace OC\Console;
use OC_App;
use OC_Defaults;
+use OCP\Console\ConsoleEvent;
use OCP\IConfig;
+use OCP\IRequest;
use Symfony\Component\Console\Application as SymfonyApplication;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
+use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class Application {
- /**
- * @var IConfig
- */
+ /** @var IConfig */
private $config;
+ /** @var EventDispatcherInterface */
+ private $dispatcher;
+ /** @var IRequest */
+ private $request;
/**
* @param IConfig $config
+ * @param EventDispatcherInterface $dispatcher
+ * @param IRequest $request
*/
- public function __construct(IConfig $config) {
+ public function __construct(IConfig $config, EventDispatcherInterface $dispatcher, IRequest $request) {
$defaults = new OC_Defaults;
$this->config = $config;
$this->application = new SymfonyApplication($defaults->getName(), \OC_Util::getVersionString());
+ $this->dispatcher = $dispatcher;
+ $this->request = $request;
}
/**
@@ -107,6 +116,10 @@ class Application {
* @throws \Exception
*/
public function run(InputInterface $input = null, OutputInterface $output = null) {
+ $this->dispatcher->dispatch(ConsoleEvent::EVENT_RUN, new ConsoleEvent(
+ ConsoleEvent::EVENT_RUN,
+ $this->request->server['argv']
+ ));
return $this->application->run($input, $output);
}
}
diff --git a/lib/private/db/mdb2schemamanager.php b/lib/private/db/mdb2schemamanager.php
index 495ccb902d6..bcabb6fe57a 100644
--- a/lib/private/db/mdb2schemamanager.php
+++ b/lib/private/db/mdb2schemamanager.php
@@ -49,7 +49,6 @@ class MDB2SchemaManager {
/**
* saves database scheme to xml file
* @param string $file name of file
- * @param int|string $mode
* @return bool
*
* TODO: write more documentation
@@ -123,7 +122,7 @@ class MDB2SchemaManager {
/**
* update the database scheme
* @param string $file file to read structure from
- * @return string|boolean
+ * @return boolean
*/
public function simulateUpdateDbFromStructure($file) {
$toSchema = $this->readSchemaFromFile($file);
diff --git a/lib/private/db/querybuilder/expressionbuilder.php b/lib/private/db/querybuilder/expressionbuilder/expressionbuilder.php
index b688ebfabbe..7ab4c03d97c 100644
--- a/lib/private/db/querybuilder/expressionbuilder.php
+++ b/lib/private/db/querybuilder/expressionbuilder/expressionbuilder.php
@@ -19,9 +19,13 @@
*
*/
-namespace OC\DB\QueryBuilder;
+namespace OC\DB\QueryBuilder\ExpressionBuilder;
use Doctrine\DBAL\Query\Expression\ExpressionBuilder as DoctrineExpressionBuilder;
+use OC\DB\QueryBuilder\CompositeExpression;
+use OC\DB\QueryBuilder\Literal;
+use OC\DB\QueryBuilder\QueryFunction;
+use OC\DB\QueryBuilder\QuoteHelper;
use OCP\DB\QueryBuilder\IExpressionBuilder;
use OCP\IDBConnection;
@@ -331,4 +335,17 @@ class ExpressionBuilder implements IExpressionBuilder {
public function literal($input, $type = null) {
return new Literal($this->expressionBuilder->literal($input, $type));
}
+
+ /**
+ * Returns a IQueryFunction that casts the column to the given type
+ *
+ * @param string $column
+ * @param mixed $type One of IQueryBuilder::PARAM_*
+ * @return string
+ */
+ public function castColumn($column, $type) {
+ return new QueryFunction(
+ $this->helper->quoteColumnName($column)
+ );
+ }
}
diff --git a/lib/private/db/querybuilder/ociexpressionbuilder.php b/lib/private/db/querybuilder/expressionbuilder/ociexpressionbuilder.php
index 4c127bd752d..6a6d0f455f6 100644
--- a/lib/private/db/querybuilder/ociexpressionbuilder.php
+++ b/lib/private/db/querybuilder/expressionbuilder/ociexpressionbuilder.php
@@ -19,24 +19,25 @@
*
*/
-namespace OC\DB\QueryBuilder;
+namespace OC\DB\QueryBuilder\ExpressionBuilder;
+use OC\DB\QueryBuilder\QueryFunction;
use OCP\DB\QueryBuilder\ILiteral;
use OCP\DB\QueryBuilder\IParameter;
use OCP\DB\QueryBuilder\IQueryBuilder;
+use OCP\DB\QueryBuilder\IQueryFunction;
class OCIExpressionBuilder extends ExpressionBuilder {
/**
* @param mixed $column
* @param mixed|null $type
- * @return array|QueryFunction|string
+ * @return array|IQueryFunction|string
*/
protected function prepareColumn($column, $type) {
if ($type === IQueryBuilder::PARAM_STR && !is_array($column) && !($column instanceof IParameter) && !($column instanceof ILiteral)) {
- $column = $this->helper->quoteColumnName($column);
- $column = new QueryFunction('to_char(' . $column . ')');
+ $column = $this->castColumn($column, $type);
} else {
$column = $this->helper->quoteColumnNames($column);
}
@@ -132,4 +133,20 @@ class OCIExpressionBuilder extends ExpressionBuilder {
return $this->expressionBuilder->notIn($x, $y);
}
+
+ /**
+ * Returns a IQueryFunction that casts the column to the given type
+ *
+ * @param string $column
+ * @param mixed $type One of IQueryBuilder::PARAM_*
+ * @return IQueryFunction
+ */
+ public function castColumn($column, $type) {
+ if ($type === IQueryBuilder::PARAM_STR) {
+ $column = $this->helper->quoteColumnName($column);
+ return new QueryFunction('to_char(' . $column . ')');
+ }
+
+ return parent::castColumn($column, $type);
+ }
}
diff --git a/lib/private/share20/exception/sharenotfound.php b/lib/private/db/querybuilder/expressionbuilder/pgsqlexpressionbuilder.php
index b59f185939a..8a0b68db998 100644
--- a/lib/private/share20/exception/sharenotfound.php
+++ b/lib/private/db/querybuilder/expressionbuilder/pgsqlexpressionbuilder.php
@@ -1,6 +1,6 @@
<?php
/**
- * @author Roeland Jago Douma <rullzer@owncloud.com>
+ * @author Joas Schilling <nickvergessen@owncloud.com>
*
* @copyright Copyright (c) 2016, ownCloud, Inc.
* @license AGPL-3.0
@@ -18,8 +18,28 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
-namespace OC\Share20\Exception;
-class ShareNotFound extends \Exception {
+namespace OC\DB\QueryBuilder\ExpressionBuilder;
+
+use OC\DB\QueryBuilder\QueryFunction;
+use OCP\DB\QueryBuilder\IQueryBuilder;
+
+class PgSqlExpressionBuilder extends ExpressionBuilder {
+
+ /**
+ * Returns a IQueryFunction that casts the column to the given type
+ *
+ * @param string $column
+ * @param mixed $type One of IQueryBuilder::PARAM_*
+ * @return string
+ */
+ public function castColumn($column, $type) {
+ if ($type === IQueryBuilder::PARAM_INT) {
+ $column = $this->helper->quoteColumnName($column);
+ return new QueryFunction('CAST(' . $column . ' AS INT)');
+ }
+
+ return parent::castColumn($column, $type);
+ }
}
diff --git a/lib/private/db/querybuilder/querybuilder.php b/lib/private/db/querybuilder/querybuilder.php
index 42b290b90e7..ff31ffbc043 100644
--- a/lib/private/db/querybuilder/querybuilder.php
+++ b/lib/private/db/querybuilder/querybuilder.php
@@ -21,7 +21,11 @@
namespace OC\DB\QueryBuilder;
+use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
use OC\DB\OracleConnection;
+use OC\DB\QueryBuilder\ExpressionBuilder\ExpressionBuilder;
+use OC\DB\QueryBuilder\ExpressionBuilder\OCIExpressionBuilder;
+use OC\DB\QueryBuilder\ExpressionBuilder\PgSqlExpressionBuilder;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\DB\QueryBuilder\IQueryFunction;
use OCP\DB\QueryBuilder\IParameter;
@@ -85,6 +89,8 @@ class QueryBuilder implements IQueryBuilder {
public function expr() {
if ($this->connection instanceof OracleConnection) {
return new OCIExpressionBuilder($this->connection);
+ } else if ($this->connection->getDatabasePlatform() instanceof PostgreSqlPlatform) {
+ return new PgSqlExpressionBuilder($this->connection);
} else {
return new ExpressionBuilder($this->connection);
}
diff --git a/lib/private/diagnostics/querylogger.php b/lib/private/diagnostics/querylogger.php
index 794e7a5e263..66a65b71d04 100644
--- a/lib/private/diagnostics/querylogger.php
+++ b/lib/private/diagnostics/querylogger.php
@@ -53,7 +53,7 @@ class QueryLogger implements IQueryLogger {
}
/**
- * @return \OCP\Diagnostics\IQuery[]
+ * @return Query[]
*/
public function getQueries() {
return $this->queries;
diff --git a/lib/private/files.php b/lib/private/files.php
index 7b451ac19be..a18bcc76519 100644
--- a/lib/private/files.php
+++ b/lib/private/files.php
@@ -160,6 +160,8 @@ class OC_Files {
/**
* @param View $view
* @param string $name
+ * @param string $dir
+ * @param boolean $onlyHeader
*/
private static function getSingleFile($view, $dir, $name, $onlyHeader) {
$filename = $dir . '/' . $name;
@@ -185,7 +187,7 @@ class OC_Files {
/**
* @param View $view
- * @param $dir
+ * @param string $dir
* @param string[]|string $files
*/
public static function lockFiles($view, $dir, $files) {
@@ -290,11 +292,11 @@ class OC_Files {
}
/**
- * @param $dir
+ * @param string $dir
* @param $files
- * @param $getType
+ * @param integer $getType
* @param View $view
- * @param $filename
+ * @param string $filename
*/
private static function unlockAllTheFiles($dir, $files, $getType, $view, $filename) {
if ($getType === self::FILE) {
diff --git a/lib/private/files/cache/cache.php b/lib/private/files/cache/cache.php
index cbe48f21bd8..22b9f49e528 100644
--- a/lib/private/files/cache/cache.php
+++ b/lib/private/files/cache/cache.php
@@ -201,7 +201,7 @@ class Cache implements ICache {
}
/**
- * store meta data for a file or folder
+ * insert or update meta data for a file or folder
*
* @param string $file
* @param array $data
@@ -214,49 +214,62 @@ class Cache implements ICache {
$this->update($id, $data);
return $id;
} else {
- // normalize file
- $file = $this->normalize($file);
+ return $this->insert($file, $data);
+ }
+ }
- if (isset($this->partial[$file])) { //add any saved partial data
- $data = array_merge($this->partial[$file], $data);
- unset($this->partial[$file]);
- }
+ /**
+ * insert meta data for a new file or folder
+ *
+ * @param string $file
+ * @param array $data
+ *
+ * @return int file id
+ * @throws \RuntimeException
+ */
+ public function insert($file, array $data) {
+ // normalize file
+ $file = $this->normalize($file);
- $requiredFields = array('size', 'mtime', 'mimetype');
- foreach ($requiredFields as $field) {
- if (!isset($data[$field])) { //data not complete save as partial and return
- $this->partial[$file] = $data;
- return -1;
- }
- }
+ if (isset($this->partial[$file])) { //add any saved partial data
+ $data = array_merge($this->partial[$file], $data);
+ unset($this->partial[$file]);
+ }
- $data['path'] = $file;
- $data['parent'] = $this->getParentId($file);
- $data['name'] = \OC_Util::basename($file);
-
- list($queryParts, $params) = $this->buildParts($data);
- $queryParts[] = '`storage`';
- $params[] = $this->getNumericStorageId();
-
- $queryParts = array_map(function ($item) {
- return trim($item, "`");
- }, $queryParts);
- $values = array_combine($queryParts, $params);
- if (\OC::$server->getDatabaseConnection()->insertIfNotExist('*PREFIX*filecache', $values, [
- 'storage',
- 'path_hash',
- ])
- ) {
- return (int)$this->connection->lastInsertId('*PREFIX*filecache');
+ $requiredFields = array('size', 'mtime', 'mimetype');
+ foreach ($requiredFields as $field) {
+ if (!isset($data[$field])) { //data not complete save as partial and return
+ $this->partial[$file] = $data;
+ return -1;
}
+ }
- // The file was created in the mean time
- if (($id = $this->getId($file)) > -1) {
- $this->update($id, $data);
- return $id;
- } else {
- throw new \RuntimeException('File entry could not be inserted with insertIfNotExist() but could also not be selected with getId() in order to perform an update. Please try again.');
- }
+ $data['path'] = $file;
+ $data['parent'] = $this->getParentId($file);
+ $data['name'] = \OC_Util::basename($file);
+
+ list($queryParts, $params) = $this->buildParts($data);
+ $queryParts[] = '`storage`';
+ $params[] = $this->getNumericStorageId();
+
+ $queryParts = array_map(function ($item) {
+ return trim($item, "`");
+ }, $queryParts);
+ $values = array_combine($queryParts, $params);
+ if (\OC::$server->getDatabaseConnection()->insertIfNotExist('*PREFIX*filecache', $values, [
+ 'storage',
+ 'path_hash',
+ ])
+ ) {
+ return (int)$this->connection->lastInsertId('*PREFIX*filecache');
+ }
+
+ // The file was created in the mean time
+ if (($id = $this->getId($file)) > -1) {
+ $this->update($id, $data);
+ return $id;
+ } else {
+ throw new \RuntimeException('File entry could not be inserted with insertIfNotExist() but could also not be selected with getId() in order to perform an update. Please try again.');
}
}
diff --git a/lib/private/files/cache/wrapper/cachejail.php b/lib/private/files/cache/wrapper/cachejail.php
index 32bd3626fcb..868e63cdf81 100644
--- a/lib/private/files/cache/wrapper/cachejail.php
+++ b/lib/private/files/cache/wrapper/cachejail.php
@@ -95,15 +95,16 @@ class CacheJail extends CacheWrapper {
}
/**
- * store meta data for a file or folder
+ * insert meta data for a new file or folder
*
* @param string $file
* @param array $data
*
* @return int file id
+ * @throws \RuntimeException
*/
- public function put($file, array $data) {
- return $this->cache->put($this->getSourcePath($file), $data);
+ public function insert($file, array $data) {
+ return $this->cache->insert($this->getSourcePath($file), $data);
}
/**
diff --git a/lib/private/files/cache/wrapper/cachewrapper.php b/lib/private/files/cache/wrapper/cachewrapper.php
index 1ce4f028c75..4080883419e 100644
--- a/lib/private/files/cache/wrapper/cachewrapper.php
+++ b/lib/private/files/cache/wrapper/cachewrapper.php
@@ -90,15 +90,34 @@ class CacheWrapper extends Cache {
}
/**
- * store meta data for a file or folder
+ * insert or update meta data for a file or folder
*
* @param string $file
* @param array $data
*
* @return int file id
+ * @throws \RuntimeException
*/
public function put($file, array $data) {
- return $this->cache->put($file, $data);
+ if (($id = $this->getId($file)) > -1) {
+ $this->update($id, $data);
+ return $id;
+ } else {
+ return $this->insert($file, $data);
+ }
+ }
+
+ /**
+ * insert meta data for a new file or folder
+ *
+ * @param string $file
+ * @param array $data
+ *
+ * @return int file id
+ * @throws \RuntimeException
+ */
+ public function insert($file, array $data) {
+ return $this->cache->insert($file, $data);
}
/**
diff --git a/lib/private/files/node/root.php b/lib/private/files/node/root.php
index 35163be0a0d..40ed531d5df 100644
--- a/lib/private/files/node/root.php
+++ b/lib/private/files/node/root.php
@@ -169,7 +169,7 @@ class Root extends Folder implements IRootFolder {
* @param string $path
* @throws \OCP\Files\NotFoundException
* @throws \OCP\Files\NotPermittedException
- * @return \OCP\Files\Node
+ * @return string
*/
public function get($path) {
$path = $this->normalizePath($path);
diff --git a/lib/private/files/storage/common.php b/lib/private/files/storage/common.php
index 95bb3f74ba7..3d5898dcd80 100644
--- a/lib/private/files/storage/common.php
+++ b/lib/private/files/storage/common.php
@@ -248,12 +248,6 @@ abstract class Common implements Storage, ILockingStorage {
return $this->getCachedFile($path);
}
- public function getLocalFolder($path) {
- $baseDir = \OC::$server->getTempManager()->getTemporaryFolder();
- $this->addLocalFolder($path, $baseDir);
- return $baseDir;
- }
-
/**
* @param string $path
* @param string $target
@@ -396,7 +390,7 @@ abstract class Common implements Storage, ILockingStorage {
* get the ETag for a file or folder
*
* @param string $path
- * @return string|false
+ * @return string
*/
public function getETag($path) {
return uniqid();
diff --git a/lib/private/files/storage/wrapper/availability.php b/lib/private/files/storage/wrapper/availability.php
index 1550c318ce3..55ddb0d5e8f 100644
--- a/lib/private/files/storage/wrapper/availability.php
+++ b/lib/private/files/storage/wrapper/availability.php
@@ -377,17 +377,6 @@ class Availability extends Wrapper {
}
/** {@inheritdoc} */
- public function getLocalFolder($path) {
- $this->checkAvailability();
- try {
- return parent::getLocalFolder($path);
- } catch (\OCP\Files\StorageNotAvailableException $e) {
- $this->setAvailability(false);
- throw $e;
- }
- }
-
- /** {@inheritdoc} */
public function hasUpdated($path, $time) {
$this->checkAvailability();
try {
diff --git a/lib/private/files/storage/wrapper/jail.php b/lib/private/files/storage/wrapper/jail.php
index 40738befd93..e5f5ab90359 100644
--- a/lib/private/files/storage/wrapper/jail.php
+++ b/lib/private/files/storage/wrapper/jail.php
@@ -353,17 +353,6 @@ class Jail extends Wrapper {
}
/**
- * get the path to a local version of the folder.
- * The local version of the folder can be temporary and doesn't have to be persistent across requests
- *
- * @param string $path
- * @return string
- */
- public function getLocalFolder($path) {
- return $this->storage->getLocalFolder($this->getSourcePath($path));
- }
-
- /**
* check if a file or folder has been updated since $time
*
* @param string $path
diff --git a/lib/private/files/storage/wrapper/wrapper.php b/lib/private/files/storage/wrapper/wrapper.php
index c632aa399e1..12914e7a1b8 100644
--- a/lib/private/files/storage/wrapper/wrapper.php
+++ b/lib/private/files/storage/wrapper/wrapper.php
@@ -354,17 +354,6 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage {
}
/**
- * get the path to a local version of the folder.
- * The local version of the folder can be temporary and doesn't have to be persistent across requests
- *
- * @param string $path
- * @return string
- */
- public function getLocalFolder($path) {
- return $this->storage->getLocalFolder($path);
- }
-
- /**
* check if a file or folder has been updated since $time
*
* @param string $path
diff --git a/lib/private/files/stream/dir.php b/lib/private/files/stream/dir.php
index fabadb0d596..7489ee683a2 100644
--- a/lib/private/files/stream/dir.php
+++ b/lib/private/files/stream/dir.php
@@ -58,6 +58,7 @@ class Dir {
/**
* @param string $path
+ * @param string[] $content
*/
public static function register($path, $content) {
self::$dirs[$path] = $content;
diff --git a/lib/private/files/type/detection.php b/lib/private/files/type/detection.php
index 9cc2e97c3cc..f106a98064f 100644
--- a/lib/private/files/type/detection.php
+++ b/lib/private/files/type/detection.php
@@ -121,7 +121,7 @@ class Detection implements IMimeTypeDetector {
}
/**
- * @return array
+ * @return string[]
*/
public function getAllAliases() {
$this->loadAliases();
@@ -264,7 +264,7 @@ class Detection implements IMimeTypeDetector {
/**
* Get path to the icon of a file type
- * @param string $mimeType the MIME type
+ * @param string $mimetype the MIME type
* @return string the url
*/
public function mimeTypeIcon($mimetype) {
diff --git a/lib/private/integritycheck/checker.php b/lib/private/integritycheck/checker.php
index c256fe66d32..e6f9f9a1457 100644
--- a/lib/private/integritycheck/checker.php
+++ b/lib/private/integritycheck/checker.php
@@ -90,6 +90,8 @@ class Checker {
// FIXME: Once the signing server is instructed to sign daily, beta and
// RCs as well these need to be included also.
$signedChannels = [
+ 'daily',
+ 'testing',
'stable',
];
if(!in_array($this->environmentHelper->getChannel(), $signedChannels, true)) {
@@ -113,16 +115,22 @@ class Checker {
* Enumerates all files belonging to the folder. Sensible defaults are excluded.
*
* @param string $folderToIterate
+ * @param string $root
* @return \RecursiveIteratorIterator
* @throws \Exception
*/
- private function getFolderIterator($folderToIterate) {
+ private function getFolderIterator($folderToIterate, $root = '') {
$dirItr = new \RecursiveDirectoryIterator(
$folderToIterate,
\RecursiveDirectoryIterator::SKIP_DOTS
);
+ if($root === '') {
+ $root = \OC::$SERVERROOT;
+ }
+ $root = rtrim($root, '/');
+
$excludeGenericFilesIterator = new ExcludeFileByNameFilterIterator($dirItr);
- $excludeFoldersIterator = new ExcludeFoldersByPathFilterIterator($excludeGenericFilesIterator);
+ $excludeFoldersIterator = new ExcludeFoldersByPathFilterIterator($excludeGenericFilesIterator, $root);
return new \RecursiveIteratorIterator(
$excludeFoldersIterator,
@@ -234,14 +242,16 @@ class Checker {
*
* @param X509 $certificate
* @param RSA $rsa
+ * @param string $path
*/
public function writeCoreSignature(X509 $certificate,
- RSA $rsa) {
- $iterator = $this->getFolderIterator($this->environmentHelper->getServerRoot());
- $hashes = $this->generateHashes($iterator, $this->environmentHelper->getServerRoot());
+ RSA $rsa,
+ $path) {
+ $iterator = $this->getFolderIterator($path, $path);
+ $hashes = $this->generateHashes($iterator, $path);
$signatureData = $this->createSignatureData($hashes, $certificate, $rsa);
$this->fileAccessHelper->file_put_contents(
- $this->environmentHelper->getServerRoot() . '/core/signature.json',
+ $path . '/core/signature.json',
json_encode($signatureData, JSON_PRETTY_PRINT)
);
}
diff --git a/lib/private/integritycheck/iterator/excludefoldersbypathfilteriterator.php b/lib/private/integritycheck/iterator/excludefoldersbypathfilteriterator.php
index c3994197fc6..67bcd423b68 100644
--- a/lib/private/integritycheck/iterator/excludefoldersbypathfilteriterator.php
+++ b/lib/private/integritycheck/iterator/excludefoldersbypathfilteriterator.php
@@ -24,7 +24,7 @@ namespace OC\IntegrityCheck\Iterator;
class ExcludeFoldersByPathFilterIterator extends \RecursiveFilterIterator {
private $excludedFolders = [];
- public function __construct(\RecursiveIterator $iterator) {
+ public function __construct(\RecursiveIterator $iterator, $root = '') {
parent::__construct($iterator);
$appFolders = \OC::$APPSROOTS;
@@ -33,9 +33,10 @@ class ExcludeFoldersByPathFilterIterator extends \RecursiveFilterIterator {
}
$this->excludedFolders = array_merge([
- rtrim(\OC::$server->getConfig()->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data'), '/'),
- rtrim(\OC::$SERVERROOT.'/themes', '/'),
- rtrim(\OC::$SERVERROOT.'/config', '/'),
+ rtrim($root . '/data', '/'),
+ rtrim($root .'/themes', '/'),
+ rtrim($root.'/config', '/'),
+ rtrim($root.'/apps', '/'),
], $appFolders);
}
diff --git a/lib/private/repair/dropoldjobs.php b/lib/private/repair/dropoldjobs.php
index 2d6172047c2..b2e9b05caa2 100644
--- a/lib/private/repair/dropoldjobs.php
+++ b/lib/private/repair/dropoldjobs.php
@@ -71,6 +71,7 @@ class DropOldJobs extends BasicEmitter implements RepairStep {
return [
['class' => 'OC_Cache_FileGlobalGC', 'arguments' => null],
['class' => 'OC\Cache\FileGlobalGC', 'arguments' => null],
+ ['class' => 'OCA\Files\BackgroundJob\DeleteOrphanedTagsJob', 'arguments' => null],
];
}
diff --git a/lib/private/repair/repairmimetypes.php b/lib/private/repair/repairmimetypes.php
index 692a7120a63..b84f19a3082 100644
--- a/lib/private/repair/repairmimetypes.php
+++ b/lib/private/repair/repairmimetypes.php
@@ -293,6 +293,17 @@ class RepairMimeTypes extends BasicEmitter implements \OC\RepairStep {
self::updateMimetypes($updatedMimetypes);
}
+ private function introduceRichDocumentsMimeTypes() {
+ $updatedMimetypes = array(
+ 'lwp' => 'application/vnd.lotus-wordpro',
+ 'one' => 'application/msonenote',
+ 'vsd' => 'application/vnd.visio',
+ 'wpd' => 'application/vnd.wordperfect',
+ );
+
+ self::updateMimetypes($updatedMimetypes);
+ }
+
/**
* Fix mime types
*/
@@ -356,5 +367,11 @@ class RepairMimeTypes extends BasicEmitter implements \OC\RepairStep {
$this->emit('\OC\Repair', 'info', array('Fixed rtf mime type'));
}
}
+
+ if (version_compare($ocVersionFromBeforeUpdate, '9.0.0.10', '<')) {
+ if ($this->introduceRichDocumentsMimeTypes()) {
+ $this->emit('\OC\Repair', 'info', array('Fixed richdocuments additional office mime types'));
+ }
+ }
}
}
diff --git a/lib/private/server.php b/lib/private/server.php
index d3dbcba86ba..55ac64a0c2d 100644
--- a/lib/private/server.php
+++ b/lib/private/server.php
@@ -617,7 +617,9 @@ class Server extends ServerContainer implements IServerContainer {
$c->getMountManager(),
$c->getGroupManager(),
$c->getL10N('core'),
- $factory
+ $factory,
+ $c->getUserManager(),
+ $c->getRootFolder()
);
return $manager;
diff --git a/lib/private/share/hooks.php b/lib/private/share/hooks.php
index 1fa233916d1..c939164e39e 100644
--- a/lib/private/share/hooks.php
+++ b/lib/private/share/hooks.php
@@ -38,7 +38,7 @@ class Hooks extends \OC\Share\Constants {
public static function post_deleteUser($arguments) {
// Delete any items shared with the deleted user
$query = \OC_DB::prepare('DELETE FROM `*PREFIX*share`'
- .' WHERE `share_with` = ? AND `share_type` = ? OR `share_type` = ?');
+ .' WHERE `share_with` = ? AND (`share_type` = ? OR `share_type` = ?)');
$query->execute(array($arguments['uid'], self::SHARE_TYPE_USER, self::$shareTypeGroupUserUnique));
// Delete any items the deleted user shared
$query = \OC_DB::prepare('SELECT `id` FROM `*PREFIX*share` WHERE `uid_owner` = ?');
diff --git a/lib/private/share20/defaultshareprovider.php b/lib/private/share20/defaultshareprovider.php
index 224dddf4019..0ab0dc81fa7 100644
--- a/lib/private/share20/defaultshareprovider.php
+++ b/lib/private/share20/defaultshareprovider.php
@@ -24,12 +24,11 @@ use OCP\Files\File;
use OCP\Share\IShareProvider;
use OC\Share20\Exception\InvalidShare;
use OC\Share20\Exception\ProviderException;
-use OC\Share20\Exception\ShareNotFound;
+use OCP\Share\Exceptions\ShareNotFound;
use OC\Share20\Exception\BackendError;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Files\NotFoundException;
use OCP\IGroup;
-use OCP\IUser;
use OCP\IGroupManager;
use OCP\IUserManager;
use OCP\Files\IRootFolder;
@@ -102,14 +101,10 @@ class DefaultShareProvider implements IShareProvider {
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
//Set the UID of the user we share with
- /** @var IUser $sharedWith */
- $sharedWith = $share->getSharedWith();
- $qb->setValue('share_with', $qb->createNamedParameter($sharedWith->getUID()));
+ $qb->setValue('share_with', $qb->createNamedParameter($share->getSharedWith()));
} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
//Set the GID of the group we share with
- /** @var IGroup $sharedWith */
- $sharedWith = $share->getSharedWith();
- $qb->setValue('share_with', $qb->createNamedParameter($sharedWith->getGID()));
+ $qb->setValue('share_with', $qb->createNamedParameter($share->getSharedWith()));
} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
//Set the token of the share
$qb->setValue('token', $qb->createNamedParameter($share->getToken()));
@@ -143,10 +138,10 @@ class DefaultShareProvider implements IShareProvider {
$qb->setValue('permissions', $qb->createNamedParameter($share->getPermissions()));
// Set who created this share
- $qb->setValue('uid_initiator', $qb->createNamedParameter($share->getSharedBy()->getUID()));
+ $qb->setValue('uid_initiator', $qb->createNamedParameter($share->getSharedBy()));
// Set who is the owner of this file/folder (and this the owner of the share)
- $qb->setValue('uid_owner', $qb->createNamedParameter($share->getShareOwner()->getUID()));
+ $qb->setValue('uid_owner', $qb->createNamedParameter($share->getShareOwner()));
// Set the file target
$qb->setValue('file_target', $qb->createNamedParameter($share->getTarget()));
@@ -192,9 +187,9 @@ class DefaultShareProvider implements IShareProvider {
$qb = $this->dbConn->getQueryBuilder();
$qb->update('share')
->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))
- ->set('share_with', $qb->createNamedParameter($share->getSharedWith()->getUID()))
- ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()->getUID()))
- ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()->getUID()))
+ ->set('share_with', $qb->createNamedParameter($share->getSharedWith()))
+ ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
+ ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
->set('permissions', $qb->createNamedParameter($share->getPermissions()))
->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
@@ -203,8 +198,8 @@ class DefaultShareProvider implements IShareProvider {
$qb = $this->dbConn->getQueryBuilder();
$qb->update('share')
->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))
- ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()->getUID()))
- ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()->getUID()))
+ ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
+ ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
->set('permissions', $qb->createNamedParameter($share->getPermissions()))
->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
@@ -216,8 +211,8 @@ class DefaultShareProvider implements IShareProvider {
$qb = $this->dbConn->getQueryBuilder();
$qb->update('share')
->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
- ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()->getUID()))
- ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()->getUID()))
+ ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
+ ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
->execute();
@@ -237,8 +232,8 @@ class DefaultShareProvider implements IShareProvider {
$qb->update('share')
->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))
->set('share_with', $qb->createNamedParameter($share->getPassword()))
- ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()->getUID()))
- ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()->getUID()))
+ ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
+ ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
->set('permissions', $qb->createNamedParameter($share->getPermissions()))
->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
@@ -255,7 +250,7 @@ class DefaultShareProvider implements IShareProvider {
* FIXME: remove once https://github.com/owncloud/core/pull/21660 is in
*
* @param \OCP\Share\IShare $parent
- * @return IShare[]
+ * @return \OCP\Share\IShare[]
*/
public function getChildren(\OCP\Share\IShare $parent) {
$children = [];
@@ -311,17 +306,17 @@ class DefaultShareProvider implements IShareProvider {
* this means we need a special entry in the share db.
*
* @param \OCP\Share\IShare $share
- * @param IUser $recipient
+ * @param string $recipient UserId of recipient
* @throws BackendError
* @throws ProviderException
*/
- public function deleteFromSelf(\OCP\Share\IShare $share, IUser $recipient) {
+ public function deleteFromSelf(\OCP\Share\IShare $share, $recipient) {
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
- /** @var IGroup $group */
- $group = $share->getSharedWith();
+ $group = $this->groupManager->get($share->getSharedWith());
+ $user = $this->userManager->get($recipient);
- if (!$group->inGroup($recipient)) {
+ if (!$group->inGroup($user)) {
throw new ProviderException('Recipient not in receiving group');
}
@@ -330,7 +325,7 @@ class DefaultShareProvider implements IShareProvider {
$stmt = $qb->select('*')
->from('share')
->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)))
- ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient->getUID())))
+ ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient)))
->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
->execute();
@@ -349,9 +344,9 @@ class DefaultShareProvider implements IShareProvider {
$qb->insert('share')
->values([
'share_type' => $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP),
- 'share_with' => $qb->createNamedParameter($recipient->getUID()),
- 'uid_owner' => $qb->createNamedParameter($share->getShareOwner()->getUID()),
- 'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()->getUID()),
+ '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->getNode()->getId()),
@@ -387,7 +382,7 @@ class DefaultShareProvider implements IShareProvider {
/**
* @inheritdoc
*/
- public function move(\OCP\Share\IShare $share, IUser $recipient) {
+ public function move(\OCP\Share\IShare $share, $recipient) {
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
// Just update the target
$qb = $this->dbConn->getQueryBuilder();
@@ -403,7 +398,7 @@ class DefaultShareProvider implements IShareProvider {
$stmt = $qb->select('id')
->from('share')
->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)))
- ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient->getUID())))
+ ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient)))
->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
->setMaxResults(1)
->execute();
@@ -417,9 +412,9 @@ class DefaultShareProvider implements IShareProvider {
$qb->insert('share')
->values([
'share_type' => $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP),
- 'share_with' => $qb->createNamedParameter($recipient->getUID()),
- 'uid_owner' => $qb->createNamedParameter($share->getShareOwner()->getUID()),
- 'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()->getUID()),
+ '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($share->getNode() instanceof File ? 'file' : 'folder'),
'item_source' => $qb->createNamedParameter($share->getNode()->getId()),
@@ -444,7 +439,7 @@ class DefaultShareProvider implements IShareProvider {
/**
* Get all shares by the given user. Sharetype and path can be used to filter.
*
- * @param IUser $user
+ * @param string $userId
* @param int $shareType
* @param \OCP\Files\File|\OCP\Files\Folder $node
* @param bool $reshares Also get the shares where $user is the owner instead of just the shares where $user is the initiator
@@ -452,7 +447,7 @@ class DefaultShareProvider implements IShareProvider {
* @param int $offset
* @return Share[]
*/
- public function getSharesBy(IUser $user, $shareType, $node, $reshares, $limit, $offset) {
+ public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) {
$qb = $this->dbConn->getQueryBuilder();
$qb->select('*')
->from('share');
@@ -465,21 +460,21 @@ class DefaultShareProvider implements IShareProvider {
if ($reshares === false) {
//Special case for old shares created via the web UI
$or1 = $qb->expr()->andX(
- $qb->expr()->eq('uid_owner', $qb->createNamedParameter($user->getUID())),
+ $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)),
$qb->expr()->isNull('uid_initiator')
);
$qb->andWhere(
$qb->expr()->orX(
- $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($user->getUID())),
+ $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)),
$or1
)
);
} else {
$qb->andWhere(
$qb->expr()->orX(
- $qb->expr()->eq('uid_owner', $qb->createNamedParameter($user->getUID())),
- $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($user->getUID()))
+ $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)),
+ $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))
)
);
}
@@ -508,7 +503,7 @@ class DefaultShareProvider implements IShareProvider {
/**
* @inheritdoc
*/
- public function getShareById($id, $recipient = null) {
+ public function getShareById($id, $recipientId = null) {
$qb = $this->dbConn->getQueryBuilder();
$qb->select('*')
@@ -540,8 +535,8 @@ class DefaultShareProvider implements IShareProvider {
}
// If the recipient is set for a group share resolve to that user
- if ($recipient !== null && $share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
- $share = $this->resolveGroupShare($share, $recipient);
+ if ($recipientId !== null && $share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
+ $share = $this->resolveGroupShare($share, $recipientId);
}
return $share;
@@ -551,7 +546,7 @@ class DefaultShareProvider implements IShareProvider {
* Get shares for a given path
*
* @param \OCP\Files\Node $path
- * @return IShare[]
+ * @return \OCP\Share\IShare[]
*/
public function getSharesByPath(Node $path) {
$qb = $this->dbConn->getQueryBuilder();
@@ -578,7 +573,7 @@ class DefaultShareProvider implements IShareProvider {
/**
* @inheritdoc
*/
- public function getSharedWith(IUser $user, $shareType, $node, $limit, $offset) {
+ public function getSharedWith($userId, $shareType, $node, $limit, $offset) {
/** @var Share[] $shares */
$shares = [];
@@ -598,7 +593,7 @@ class DefaultShareProvider implements IShareProvider {
$qb->setFirstResult($offset);
$qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)));
- $qb->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($user->getUID())));
+ $qb->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId)));
// Filter by node if provided
if ($node !== null) {
@@ -613,6 +608,7 @@ class DefaultShareProvider implements IShareProvider {
$cursor->closeCursor();
} else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) {
+ $user = $this->userManager->get($userId);
$allGroups = $this->groupManager->getUserGroups($user);
/** @var Share[] $shares2 */
@@ -666,7 +662,7 @@ class DefaultShareProvider implements IShareProvider {
* TODO: Optmize this!
*/
foreach($shares2 as $share) {
- $shares[] = $this->resolveGroupShare($share, $user);
+ $shares[] = $this->resolveGroupShare($share, $userId);
}
} else {
throw new BackendError('Invalid backend');
@@ -680,7 +676,7 @@ class DefaultShareProvider implements IShareProvider {
* Get a share by token
*
* @param string $token
- * @return IShare
+ * @return \OCP\Share\IShare
* @throws ShareNotFound
*/
public function getShareByToken($token) {
@@ -715,7 +711,7 @@ class DefaultShareProvider implements IShareProvider {
* @throws InvalidShare
*/
private function createShare($data) {
- $share = new Share();
+ $share = new Share($this->rootFolder);
$share->setId((int)$data['id'])
->setShareType((int)$data['share_type'])
->setPermissions((int)$data['permissions'])
@@ -727,17 +723,9 @@ class DefaultShareProvider implements IShareProvider {
$share->setShareTime($shareTime);
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
- $sharedWith = $this->userManager->get($data['share_with']);
- if ($sharedWith === null) {
- throw new InvalidShare();
- }
- $share->setSharedWith($sharedWith);
+ $share->setSharedWith($data['share_with']);
} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
- $sharedWith = $this->groupManager->get($data['share_with']);
- if ($sharedWith === null) {
- throw new InvalidShare();
- }
- $share->setSharedWith($sharedWith);
+ $share->setSharedWith($data['share_with']);
} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
$share->setPassword($data['share_with']);
$share->setToken($data['token']);
@@ -745,28 +733,19 @@ class DefaultShareProvider implements IShareProvider {
if ($data['uid_initiator'] === null) {
//OLD SHARE
- $sharedBy = $this->userManager->get($data['uid_owner']);
- if ($sharedBy === null) {
- throw new InvalidShare();
- }
- $share->setSharedBy($sharedBy);
+ $share->setSharedBy($data['uid_owner']);
$path = $this->getNode($share->getSharedBy(), (int)$data['file_source']);
$owner = $path->getOwner();
- $share->setShareOwner($owner);
+ $share->setShareOwner($owner->getUID());
} else {
//New share!
- $sharedBy = $this->userManager->get($data['uid_initiator']);
- $shareOwner = $this->userManager->get($data['uid_owner']);
- if ($sharedBy === null || $shareOwner === null) {
- throw new InvalidShare();
- }
- $share->setSharedBy($sharedBy);
- $share->setShareOwner($shareOwner);
+ $share->setSharedBy($data['uid_initiator']);
+ $share->setShareOwner($data['uid_owner']);
}
- $path = $this->getNode($share->getShareOwner(), (int)$data['file_source']);
- $share->setNode($path);
+ $share->setNodeId((int)$data['file_source']);
+ $share->setNodeType($data['item_type']);
if ($data['expiration'] !== null) {
$expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']);
@@ -781,14 +760,14 @@ class DefaultShareProvider implements IShareProvider {
/**
* Get the node with file $id for $user
*
- * @param IUser $user
+ * @param string $user The userId
* @param int $id
* @return \OCP\Files\File|\OCP\Files\Folder
* @throws InvalidShare
*/
- private function getNode(IUser $user, $id) {
+ private function getNode($user, $id) {
try {
- $userFolder = $this->rootFolder->getUserFolder($user->getUID());
+ $userFolder = $this->rootFolder->getUserFolder($user);
} catch (NotFoundException $e) {
throw new InvalidShare();
}
@@ -806,18 +785,18 @@ class DefaultShareProvider implements IShareProvider {
* Resolve a group share to a user specific share
* Thus if the user moved their group share make sure this is properly reflected here.
*
- * @param Share $share
- * @param IUser $user
+ * @param \OCP\Share\IShare $share
+ * @param string $userId
* @return Share Returns the updated share if one was found else return the original share.
*/
- private function resolveGroupShare(Share $share, IUser $user) {
+ private function resolveGroupShare(\OCP\Share\IShare $share, $userId) {
$qb = $this->dbConn->getQueryBuilder();
$stmt = $qb->select('*')
->from('share')
->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)))
- ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($user->getUID())))
+ ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId)))
->setMaxResults(1)
->execute();
diff --git a/lib/private/share20/manager.php b/lib/private/share20/manager.php
index b22b81bb404..d65fb927f9b 100644
--- a/lib/private/share20/manager.php
+++ b/lib/private/share20/manager.php
@@ -21,7 +21,8 @@
namespace OC\Share20;
-use OCP\Files\Node;
+use OCP\Files\IRootFolder;
+use OCP\IUserManager;
use OCP\Share\IManager;
use OCP\Share\IProviderFactory;
use OC\Share20\Exception\BackendError;
@@ -34,10 +35,9 @@ use OCP\Files\Mount\IMountManager;
use OCP\IGroupManager;
use OCP\Files\File;
use OCP\Files\Folder;
-use OCP\IUser;
-use OC\Share20\Exception\ShareNotFound;
-use OC\HintException;
+use OCP\Share\Exceptions\ShareNotFound;
+use OCP\Share\Exceptions\GenericShareException;
/**
* This class is the communication hub for all sharing related operations.
@@ -46,27 +46,24 @@ class Manager implements IManager {
/** @var IProviderFactory */
private $factory;
-
/** @var ILogger */
private $logger;
-
/** @var IConfig */
private $config;
-
/** @var ISecureRandom */
private $secureRandom;
-
/** @var IHasher */
private $hasher;
-
/** @var IMountManager */
private $mountManager;
-
/** @var IGroupManager */
private $groupManager;
-
/** @var IL10N */
private $l;
+ /** @var IUserManager */
+ private $userManager;
+ /** @var IRootFolder */
+ private $rootFolder;
/**
* Manager constructor.
@@ -79,6 +76,8 @@ class Manager implements IManager {
* @param IGroupManager $groupManager
* @param IL10N $l
* @param IProviderFactory $factory
+ * @param IUserManager $userManager
+ * @param IRootFolder $rootFolder
*/
public function __construct(
ILogger $logger,
@@ -88,7 +87,9 @@ class Manager implements IManager {
IMountManager $mountManager,
IGroupManager $groupManager,
IL10N $l,
- IProviderFactory $factory
+ IProviderFactory $factory,
+ IUserManager $userManager,
+ IRootFolder $rootFolder
) {
$this->logger = $logger;
$this->config = $config;
@@ -98,6 +99,8 @@ class Manager implements IManager {
$this->groupManager = $groupManager;
$this->l = $l;
$this->factory = $factory;
+ $this->userManager = $userManager;
+ $this->rootFolder = $rootFolder;
}
/**
@@ -144,18 +147,19 @@ class Manager implements IManager {
* Check for generic requirements before creating a share
*
* @param \OCP\Share\IShare $share
- * @throws \Exception
+ * @throws \InvalidArgumentException
+ * @throws GenericShareException
*/
protected function generalCreateChecks(\OCP\Share\IShare $share) {
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
// We expect a valid user as sharedWith for user shares
- if (!($share->getSharedWith() instanceof \OCP\IUser)) {
- throw new \InvalidArgumentException('SharedWith should be an IUser');
+ if (!$this->userManager->userExists($share->getSharedWith())) {
+ throw new \InvalidArgumentException('SharedWith is not a valid user');
}
} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
// We expect a valid group as sharedWith for group shares
- if (!($share->getSharedWith() instanceof \OCP\IGroup)) {
- throw new \InvalidArgumentException('SharedWith should be an IGroup');
+ if (!$this->groupManager->groupExists($share->getSharedWith())) {
+ throw new \InvalidArgumentException('SharedWith is not a valid group');
}
} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
if ($share->getSharedWith() !== null) {
@@ -172,7 +176,8 @@ class Manager implements IManager {
}
// Cannot share with yourself
- if ($share->getSharedWith() === $share->getSharedBy()) {
+ if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER &&
+ $share->getSharedWith() === $share->getSharedBy()) {
throw new \InvalidArgumentException('Can\'t share with yourself');
}
@@ -190,7 +195,7 @@ class Manager implements IManager {
// Check if we actually have share permissions
if (!$share->getNode()->isShareable()) {
$message_t = $this->l->t('You are not allowed to share %s', [$share->getNode()->getPath()]);
- throw new HintException($message_t, $message_t, 404);
+ throw new GenericShareException($message_t, $message_t, 404);
}
// Permissions should be set
@@ -201,7 +206,7 @@ class Manager implements IManager {
// Check that we do not share with more permissions than we have
if ($share->getPermissions() & ~$share->getNode()->getPermissions()) {
$message_t = $this->l->t('Cannot increase permissions of %s', [$share->getNode()->getPath()]);
- throw new HintException($message_t, $message_t, 404);
+ throw new GenericShareException($message_t, $message_t, 404);
}
// Check that read permissions are always set
@@ -213,9 +218,11 @@ class Manager implements IManager {
/**
* Validate if the expiration date fits the system settings
*
- * @param \DateTime $expirationDate The current expiration date (can be null)
- * @return \DateTime|null The expiration date or null if $expireDate was null and it is not required
- * @throws \OC\HintException
+ * @param \OCP\Share\IShare $share The share to validate the expiration date of
+ * @return \OCP\Share\IShare The expiration date or null if $expireDate was null and it is not required
+ * @throws GenericShareException
+ * @throws \InvalidArgumentException
+ * @throws \Exception
*/
protected function validateExpirationDate(\OCP\Share\IShare $share) {
@@ -229,7 +236,7 @@ class Manager implements IManager {
$date->setTime(0, 0, 0);
if ($date >= $expirationDate) {
$message = $this->l->t('Expiration date is in the past');
- throw new \OC\HintException($message, $message, 404);
+ throw new GenericShareException($message, $message, 404);
}
}
@@ -244,7 +251,7 @@ class Manager implements IManager {
$date->add(new \DateInterval('P' . $this->shareApiLinkDefaultExpireDays() . 'D'));
if ($date < $expirationDate) {
$message = $this->l->t('Cannot set expiration date more than %s days in the future', [$this->shareApiLinkDefaultExpireDays()]);
- throw new \OC\HintException($message, $message, 404);
+ throw new GenericShareException($message, $message, 404);
}
}
@@ -282,10 +289,12 @@ class Manager implements IManager {
protected function userCreateChecks(\OCP\Share\IShare $share) {
// Check if we can share with group members only
if ($this->shareWithGroupMembersOnly()) {
+ $sharedBy = $this->userManager->get($share->getSharedBy());
+ $sharedWith = $this->userManager->get($share->getSharedWith());
// Verify we can share with this user
$groups = array_intersect(
- $this->groupManager->getUserGroupIds($share->getSharedBy()),
- $this->groupManager->getUserGroupIds($share->getSharedWith())
+ $this->groupManager->getUserGroupIds($sharedBy),
+ $this->groupManager->getUserGroupIds($sharedWith)
);
if (empty($groups)) {
throw new \Exception('Only sharing with group members is allowed');
@@ -311,10 +320,13 @@ class Manager implements IManager {
}
// The share is already shared with this user via a group share
- if ($existingShare->getShareType() === \OCP\Share::SHARE_TYPE_GROUP &&
- $existingShare->getSharedWith()->inGroup($share->getSharedWith()) &&
- $existingShare->getShareOwner() !== $share->getShareOwner()) {
- throw new \Exception('Path already shared with this user');
+ if ($existingShare->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
+ $group = $this->groupManager->get($existingShare->getSharedWith());
+ $user = $this->userManager->get($share->getSharedWith());
+
+ if ($group->inGroup($user) && $existingShare->getShareOwner() !== $share->getShareOwner()) {
+ throw new \Exception('Path already shared with this user');
+ }
}
}
}
@@ -328,7 +340,9 @@ class Manager implements IManager {
protected function groupCreateChecks(\OCP\Share\IShare $share) {
// Verify if the user can share with this group
if ($this->shareWithGroupMembersOnly()) {
- if (!$share->getSharedWith()->inGroup($share->getSharedBy())) {
+ $sharedBy = $this->userManager->get($share->getSharedBy());
+ $sharedWith = $this->groupManager->get($share->getSharedWith());
+ if (!$sharedWith->inGroup($sharedBy)) {
throw new \Exception('Only sharing within your own groups is allowed');
}
}
@@ -465,10 +479,11 @@ class Manager implements IManager {
$this->pathCreateChecks($share->getNode());
// On creation of a share the owner is always the owner of the path
- $share->setShareOwner($share->getNode()->getOwner());
+ $share->setShareOwner($share->getNode()->getOwner()->getUID());
// Cannot share with the owner
- if ($share->getSharedWith() === $share->getShareOwner()) {
+ if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER &&
+ $share->getSharedWith() === $share->getShareOwner()) {
throw new \InvalidArgumentException('Can\'t share with the share owner');
}
@@ -477,16 +492,6 @@ class Manager implements IManager {
$target = \OC\Files\Filesystem::normalizePath($target);
$share->setTarget($target);
- //Get sharewith for hooks
- $sharedWith = null;
- if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
- $sharedWith = $share->getSharedWith()->getUID();
- } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
- $sharedWith = $share->getSharedWith()->getGID();
- } else {
- $sharedWith = $share->getSharedWith();
- }
-
// Pre share hook
$run = true;
$error = '';
@@ -494,13 +499,13 @@ class Manager implements IManager {
'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder',
'itemSource' => $share->getNode()->getId(),
'shareType' => $share->getShareType(),
- 'uidOwner' => $share->getSharedBy()->getUID(),
+ 'uidOwner' => $share->getSharedBy(),
'permissions' => $share->getPermissions(),
'fileSource' => $share->getNode()->getId(),
'expiration' => $share->getExpirationDate(),
'token' => $share->getToken(),
'itemTarget' => $share->getTarget(),
- 'shareWith' => $sharedWith,
+ 'shareWith' => $share->getSharedWith(),
'run' => &$run,
'error' => &$error,
];
@@ -518,13 +523,13 @@ class Manager implements IManager {
'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder',
'itemSource' => $share->getNode()->getId(),
'shareType' => $share->getShareType(),
- 'uidOwner' => $share->getSharedBy()->getUID(),
+ 'uidOwner' => $share->getSharedBy(),
'permissions' => $share->getPermissions(),
'fileSource' => $share->getNode()->getId(),
'expiration' => $share->getExpirationDate(),
'token' => $share->getToken(),
'id' => $share->getId(),
- 'shareWith' => $sharedWith,
+ 'shareWith' => $share->getSharedWith(),
'itemTarget' => $share->getTarget(),
'fileTarget' => $share->getTarget(),
];
@@ -539,6 +544,7 @@ class Manager implements IManager {
*
* @param \OCP\Share\IShare $share
* @return \OCP\Share\IShare The share object
+ * @throws \InvalidArgumentException
*/
public function updateShare(\OCP\Share\IShare $share) {
$expirationDateUpdated = false;
@@ -561,7 +567,8 @@ class Manager implements IManager {
}
// Cannot share with the owner
- if ($share->getSharedWith() === $share->getShareOwner()) {
+ if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER &&
+ $share->getSharedWith() === $share->getShareOwner()) {
throw new \InvalidArgumentException('Can\'t share with the share owner');
}
@@ -603,10 +610,23 @@ class Manager implements IManager {
'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder',
'itemSource' => $share->getNode()->getId(),
'date' => $share->getExpirationDate(),
- 'uidOwner' => $share->getSharedBy()->getUID(),
+ 'uidOwner' => $share->getSharedBy(),
]);
}
+ if ($share->getPermissions() !== $originalShare->getPermissions()) {
+ $userFolder = $this->rootFolder->getUserFolder($share->getShareOwner());
+ \OC_Hook::emit('OCP\Share', 'post_update_permissions', array(
+ 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder',
+ 'itemSource' => $share->getNode()->getId(),
+ 'shareType' => $share->getShareType(),
+ 'shareWith' => $share->getSharedWith(),
+ 'uidOwner' => $share->getSharedBy(),
+ 'permissions' => $share->getPermissions(),
+ 'path' => $userFolder->getRelativePath($share->getNode()->getPath()),
+ ));
+ }
+
return $share;
}
@@ -638,8 +658,6 @@ class Manager implements IManager {
*
* @param \OCP\Share\IShare $share
* @throws ShareNotFound
- * @throws BackendError
- * @throws ShareNotFound
*/
public function deleteShare(\OCP\Share\IShare $share) {
// Just to make sure we have all the info
@@ -650,22 +668,22 @@ class Manager implements IManager {
$shareType = $share->getShareType();
$sharedWith = '';
if ($shareType === \OCP\Share::SHARE_TYPE_USER) {
- $sharedWith = $share->getSharedWith()->getUID();
+ $sharedWith = $share->getSharedWith();
} else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) {
- $sharedWith = $share->getSharedWith()->getGID();
+ $sharedWith = $share->getSharedWith();
} else if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) {
$sharedWith = $share->getSharedWith();
}
$hookParams = [
'id' => $share->getId(),
- 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder',
- 'itemSource' => $share->getNode()->getId(),
+ 'itemType' => $share->getNodeType(),
+ 'itemSource' => $share->getNodeId(),
'shareType' => $shareType,
'shareWith' => $sharedWith,
'itemparent' => $share->getParent(),
- 'uidOwner' => $share->getSharedBy()->getUID(),
- 'fileSource' => $share->getNode()->getId(),
+ 'uidOwner' => $share->getSharedBy(),
+ 'fileSource' => $share->getNodeId(),
'fileTarget' => $share->getTarget()
];
return $hookParams;
@@ -705,38 +723,45 @@ class Manager implements IManager {
* handle this.
*
* @param \OCP\Share\IShare $share
- * @param IUser $recipient
+ * @param string $recipientId
*/
- public function deleteFromSelf(\OCP\Share\IShare $share, IUser $recipient) {
- list($providerId, $id) = $this->splitFullId($share->getId());
+ public function deleteFromSelf(\OCP\Share\IShare $share, $recipientId) {
+ list($providerId, ) = $this->splitFullId($share->getId());
$provider = $this->factory->getProvider($providerId);
- $provider->deleteFromSelf($share, $recipient);
+ $provider->deleteFromSelf($share, $recipientId);
}
/**
* @inheritdoc
*/
- public function moveShare(\OCP\Share\IShare $share, IUser $recipient) {
+ public function moveShare(\OCP\Share\IShare $share, $recipientId) {
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
throw new \InvalidArgumentException('Can\'t change target of link share');
}
- if (($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && $share->getSharedWith() !== $recipient) ||
- ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP && !$share->getSharedWith()->inGroup($recipient))) {
+ if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && $share->getSharedWith() !== $recipientId) {
throw new \InvalidArgumentException('Invalid recipient');
}
+ if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
+ $sharedWith = $this->groupManager->get($share->getSharedWith());
+ $recipient = $this->userManager->get($recipientId);
+ if (!$sharedWith->inGroup($recipient)) {
+ throw new \InvalidArgumentException('Invalid recipient');
+ }
+ }
+
list($providerId, ) = $this->splitFullId($share->getId());
$provider = $this->factory->getProvider($providerId);
- $provider->move($share, $recipient);
+ $provider->move($share, $recipientId);
}
/**
* Get shares shared by (initiated) by the provided user.
*
- * @param IUser $user
+ * @param string $userId
* @param int $shareType
* @param \OCP\Files\File|\OCP\Files\Folder $path
* @param bool $reshares
@@ -744,7 +769,7 @@ class Manager implements IManager {
* @param int $offset
* @return \OCP\Share\IShare[]
*/
- public function getSharesBy(IUser $user, $shareType, $path = null, $reshares = false, $limit = 50, $offset = 0) {
+ public function getSharesBy($userId, $shareType, $path = null, $reshares = false, $limit = 50, $offset = 0) {
if ($path !== null &&
!($path instanceof \OCP\Files\File) &&
!($path instanceof \OCP\Files\Folder)) {
@@ -753,16 +778,16 @@ class Manager implements IManager {
$provider = $this->factory->getProviderForType($shareType);
- return $provider->getSharesBy($user, $shareType, $path, $reshares, $limit, $offset);
+ return $provider->getSharesBy($userId, $shareType, $path, $reshares, $limit, $offset);
}
/**
* @inheritdoc
*/
- public function getSharedWith(IUser $user, $shareType, $node = null, $limit = 50, $offset = 0) {
+ public function getSharedWith($userId, $shareType, $node = null, $limit = 50, $offset = 0) {
$provider = $this->factory->getProviderForType($shareType);
- return $provider->getSharedWith($user, $shareType, $node, $limit, $offset);
+ return $provider->getSharedWith($userId, $shareType, $node, $limit, $offset);
}
/**
@@ -874,7 +899,7 @@ class Manager implements IManager {
* @return \OCP\Share\IShare;
*/
public function newShare() {
- return new \OC\Share20\Share();
+ return new \OC\Share20\Share($this->rootFolder);
}
/**
@@ -954,10 +979,10 @@ class Manager implements IManager {
*
* TODO: Deprecate fuction from OC_Util
*
- * @param IUser $user
+ * @param string $userId
* @return bool
*/
- public function sharingDisabledForUser(IUser $user) {
+ public function sharingDisabledForUser($userId) {
if ($this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes') {
$groupsList = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', '');
$excludedGroups = json_decode($groupsList);
@@ -966,6 +991,7 @@ class Manager implements IManager {
$newValue = json_encode($excludedGroups);
$this->config->setAppValue('core', 'shareapi_exclude_groups_list', $newValue);
}
+ $user = $this->userManager->get($userId);
$usersGroups = $this->groupManager->getUserGroupIds($user);
if (!empty($usersGroups)) {
$remainingGroups = array_diff($usersGroups, $excludedGroups);
diff --git a/lib/private/share20/share.php b/lib/private/share20/share.php
index f9cba10a07a..cd30f24c42e 100644
--- a/lib/private/share20/share.php
+++ b/lib/private/share20/share.php
@@ -20,7 +20,10 @@
*/
namespace OC\Share20;
+use OCP\Files\File;
+use OCP\Files\IRootFolder;
use OCP\Files\Node;
+use OCP\Files\NotFoundException;
use OCP\IUser;
use OCP\IGroup;
@@ -31,14 +34,18 @@ class Share implements \OCP\Share\IShare {
/** @var string */
private $providerId;
/** @var Node */
- private $path;
+ private $node;
+ /** @var int */
+ private $fileId;
+ /** @var string */
+ private $nodeType;
/** @var int */
private $shareType;
- /** @var IUser|IGroup */
+ /** @var string */
private $sharedWith;
- /** @var IUser */
+ /** @var string */
private $sharedBy;
- /** @var IUser */
+ /** @var string */
private $shareOwner;
/** @var int */
private $permissions;
@@ -57,6 +64,13 @@ class Share implements \OCP\Share\IShare {
/** @var bool */
private $mailSend;
+ /** @var IRootFolder */
+ private $rootFolder;
+
+ public function __construct(IRootFolder $rootFolder) {
+ $this->rootFolder = $rootFolder;
+ }
+
/**
* @inheritdoc
*/
@@ -90,8 +104,10 @@ class Share implements \OCP\Share\IShare {
/**
* @inheritdoc
*/
- public function setNode(Node $path) {
- $this->path = $path;
+ public function setNode(Node $node) {
+ $this->fileId = null;
+ $this->nodeType = null;
+ $this->node = $node;
return $this;
}
@@ -99,7 +115,66 @@ class Share implements \OCP\Share\IShare {
* @inheritdoc
*/
public function getNode() {
- return $this->path;
+ if ($this->node === null) {
+
+ if ($this->shareOwner === null || $this->fileId === null) {
+ throw new NotFoundException();
+ }
+
+ $userFolder = $this->rootFolder->getUserFolder($this->shareOwner);
+
+ $nodes = $userFolder->getById($this->fileId);
+ if (empty($nodes)) {
+ throw new NotFoundException();
+ }
+
+ $this->node = $nodes[0];
+ }
+
+ return $this->node;
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function setNodeId($fileId) {
+ $this->node = null;
+ $this->fileId = $fileId;
+ return $this;
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function getNodeId() {
+ if ($this->fileId === null) {
+ $this->fileId = $this->getNode()->getId();
+ }
+
+ return $this->fileId;
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function setNodeType($type) {
+ if ($type !== 'file' && $type !== 'folder') {
+ throw new \InvalidArgumentException();
+ }
+
+ $this->nodeType = $type;
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function getNodeType() {
+ if ($this->nodeType === null) {
+ $node = $this->getNode();
+ $this->nodeType = $node instanceof File ? 'file' : 'folder';
+ }
+
+ return $this->nodeType;
}
/**
@@ -121,6 +196,9 @@ class Share implements \OCP\Share\IShare {
* @inheritdoc
*/
public function setSharedWith($sharedWith) {
+ if (!is_string($sharedWith)) {
+ throw new \InvalidArgumentException();
+ }
$this->sharedWith = $sharedWith;
return $this;
}
@@ -170,6 +248,9 @@ class Share implements \OCP\Share\IShare {
* @inheritdoc
*/
public function setSharedBy($sharedBy) {
+ if (!is_string($sharedBy)) {
+ throw new \InvalidArgumentException();
+ }
//TODO checks
$this->sharedBy = $sharedBy;
@@ -188,6 +269,9 @@ class Share implements \OCP\Share\IShare {
* @inheritdoc
*/
public function setShareOwner($shareOwner) {
+ if (!is_string($shareOwner)) {
+ throw new \InvalidArgumentException();
+ }
//TODO checks
$this->shareOwner = $shareOwner;
diff --git a/lib/private/user/manager.php b/lib/private/user/manager.php
index 86750dcd994..6798a7340c3 100644
--- a/lib/private/user/manager.php
+++ b/lib/private/user/manager.php
@@ -265,6 +265,10 @@ class Manager extends PublicEmitter implements IUserManager {
if (trim($uid) == '') {
throw new \Exception($l->t('A valid username must be provided'));
}
+ // No whitespace at the beginning or at the end
+ if (strlen(trim($uid, "\t\n\r\0\x0B\xe2\x80\x8b")) !== strlen(trim($uid))) {
+ throw new \Exception($l->t('Username contains whitespace at the beginning or at the end'));
+ }
// No empty password
if (trim($password) == '') {
throw new \Exception($l->t('A valid password must be provided'));
diff --git a/lib/private/user/user.php b/lib/private/user/user.php
index 5e556575118..516c1d443c6 100644
--- a/lib/private/user/user.php
+++ b/lib/private/user/user.php
@@ -210,7 +210,7 @@ class User implements IUser {
// Delete the users entry in the storage table
\OC\Files\Cache\Storage::remove('home::' . $this->uid);
- \OC::$server->getCommentsManager()->deleteReferencesOfActor('user', $this->uid);
+ \OC::$server->getCommentsManager()->deleteReferencesOfActor('users', $this->uid);
\OC::$server->getCommentsManager()->deleteReadMarksFromUser($this);
}