Skip to content

Commit

Permalink
Merge pull request #26050 from owncloud/stable9.1-prefilter-inaccessi…
Browse files Browse the repository at this point in the history
…ble-shares

[stable9.1] Prefilter inaccessible shares in DefaultShareProvider::getSharedWith()
  • Loading branch information
Vincent Petry authored Sep 7, 2016
2 parents 6415170 + 39182a4 commit d614c12
Show file tree
Hide file tree
Showing 2 changed files with 195 additions and 31 deletions.
46 changes: 38 additions & 8 deletions lib/private/Share20/DefaultShareProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,25 @@ public function getSharesByPath(Node $path) {
return $shares;
}

/**
* Returns whether the given database result can be interpreted as
* a share with accessible file (not trashed, not deleted)
*/
private function isAccessibleResult($data) {
// exclude shares leading to deleted file entries
if ($data['fileid'] === null) {
return false;
}

// exclude shares leading to trashbin on home storages
$pathSections = explode('/', $data['path'], 2);
// FIXME: would not detect rare md5'd home storage case properly
if ($pathSections[0] !== 'files' && explode(':', $data['storage_string_id'], 2)[0] === 'home') {
return false;
}
return true;
}

/**
* @inheritdoc
*/
Expand All @@ -591,11 +610,14 @@ public function getSharedWith($userId, $shareType, $node, $limit, $offset) {
if ($shareType === \OCP\Share::SHARE_TYPE_USER) {
//Get shares directly with this user
$qb = $this->dbConn->getQueryBuilder();
$qb->select('*')
->from('share');
$qb->select('s.*', 'f.fileid', 'f.path')
->selectAlias('st.id', 'storage_string_id')
->from('share', 's')
->leftJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid'))
->leftJoin('f', 'storages', 'st', $qb->expr()->eq('f.storage', 'st.numeric_id'));

// Order by id
$qb->orderBy('id');
$qb->orderBy('s.id');

// Set limit and offset
if ($limit !== -1) {
Expand All @@ -618,7 +640,9 @@ public function getSharedWith($userId, $shareType, $node, $limit, $offset) {
$cursor = $qb->execute();

while($data = $cursor->fetch()) {
$shares[] = $this->createShare($data);
if ($this->isAccessibleResult($data)) {
$shares[] = $this->createShare($data);
}
}
$cursor->closeCursor();

Expand All @@ -639,9 +663,12 @@ public function getSharedWith($userId, $shareType, $node, $limit, $offset) {
}

$qb = $this->dbConn->getQueryBuilder();
$qb->select('*')
->from('share')
->orderBy('id')
$qb->select('s.*', 'f.fileid', 'f.path')
->selectAlias('st.id', 'storage_string_id')
->from('share', 's')
->leftJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid'))
->leftJoin('f', 'storages', 'st', $qb->expr()->eq('f.storage', 'st.numeric_id'))
->orderBy('s.id')
->setFirstResult(0);

if ($limit !== -1) {
Expand Down Expand Up @@ -671,7 +698,10 @@ public function getSharedWith($userId, $shareType, $node, $limit, $offset) {
$offset--;
continue;
}
$shares2[] = $this->createShare($data);

if ($this->isAccessibleResult($data)) {
$shares2[] = $this->createShare($data);
}
}
$cursor->closeCursor();
}
Expand Down
Loading

0 comments on commit d614c12

Please sign in to comment.