This repository has been archived by the owner on Oct 30, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Shared files #121
Open
georgehrke
wants to merge
12
commits into
master
Choose a base branch
from
shared-files
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Shared files #121
Changes from 7 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
dbb99c7
Add the names of everyone who has read permissions to the file's index
NacreData ca087ad
consolidate into one master index; use user-name attributes to filter…
NacreData be97b0a
Discover path to data directory from $CONFIG array. Thanks @scolebrook
NacreData 28c2262
update index when sharing status changes on a file; update returned l…
NacreData d7e51f4
Return link to found file in manner which appears to be preferred, as…
NacreData fb82520
fix code style
georgehrke 4b0369e
read data dir from getConfig insteaf of including config
georgehrke 385963b
use proper logger
georgehrke c00ad36
remove debugging code
georgehrke 72a0243
get user's home from userSession
georgehrke 6280aa3
check another user object before using it
georgehrke 403cdf7
use === instead of simple ==
georgehrke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
/** | ||
* ownCloud - search_lucene | ||
* | ||
* This file is licensed under the Affero General Public License version 3 or | ||
* later. See the COPYING file. | ||
* | ||
* @author Devin M. Ceartas <[email protected]> | ||
* @copyright Devin M. Ceartas 2016 | ||
*/ | ||
|
||
namespace OCA\Search_Lucene\Db; | ||
|
||
use OCP\IDb; | ||
|
||
class FilesInFolder { | ||
|
||
private $db; | ||
private $files; | ||
|
||
public function __construct(IDb $db) { | ||
$this->db = $db; | ||
$this->files = array(); | ||
} | ||
|
||
public function files($folder_id) { | ||
$sth = $this->db->prepare('SELECT fileid FROM `*PREFIX*filecache` WHERE `parent` = ?'); | ||
$sth->bindValue(1, $folder_id, \PDO::PARAM_INT); | ||
$sth->execute(); | ||
$result = $sth->fetchAll(); | ||
|
||
foreach ($result as $row) { | ||
if ($this->is_sub_folder($row['fileid'])) { | ||
return $this->files($row['fileid']); | ||
} else { | ||
$this->files[] = $row['fileid']; | ||
} | ||
} | ||
|
||
return array_unique($this->files); | ||
} | ||
|
||
private function is_sub_folder($folder_id) { | ||
$inner = $this->db->prepare('SELECT count(fileid) AS `is_sub` FROM `*PREFIX*filecache` WHERE `parent` = ?'); | ||
$inner->bindValue(1, $folder_id, \PDO::PARAM_INT); | ||
$inner->execute(); | ||
$sub_result = $inner->fetchAll(); | ||
return ($sub_result['is_sub'] > 0); | ||
} | ||
|
||
public function logit($text) { | ||
$FH = fopen('/var/www/html/data/borealis.log', 'a'); | ||
if(is_string($text) || is_numeric($text) || is_bool($text)) { | ||
fwrite($FH, $text . "\n"); | ||
} else { | ||
fwrite($FH, print_r($text, true)); | ||
} | ||
fclose($FH); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
/** | ||
* ownCloud - search_lucene | ||
* | ||
* This file is licensed under the Affero General Public License version 3 or | ||
* later. See the COPYING file. | ||
* | ||
* @author Devin M. Ceartas <[email protected]> | ||
* @copyright Devin M. Ceartas 2016 | ||
*/ | ||
|
||
namespace OCA\Search_Lucene\Hooks; | ||
|
||
use OCA\Search_Lucene\AppInfo\Application; | ||
|
||
class Share { | ||
|
||
private static function reIndex($fileIds) { | ||
$app = new Application(); | ||
$container = $app->getContainer(); | ||
self::logit(get_class($container)); | ||
$container->query('Indexer')->indexFiles($fileIds); | ||
} | ||
|
||
public static function postShareHook(array $param) { | ||
if ('file' == $param['itemType']) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
self::reIndex(array($param['itemSource'])); | ||
} else { | ||
$app = new Application(); | ||
$container = $app->getContainer(); | ||
$files = $container->query('FilesInFolder')->files($param['itemSource']); | ||
self::reIndex($files); | ||
} | ||
} | ||
|
||
public static function postUnshareHook(array $param) { | ||
if ('file' == $param['itemType']) { | ||
self::reIndex(array($param['itemSource'])); | ||
} else { | ||
$app = new Application(); | ||
$container = $app->getContainer(); | ||
$files = $container->query('FilesInFolder')->files($param['itemSource']); | ||
self::reIndex($files); | ||
} | ||
} | ||
|
||
public static function logit($text) { | ||
$FH = fopen( '/var/www/html/data/borealis.log', 'a' ); | ||
if(is_string($text) || is_numeric($text) || is_bool($text)) { | ||
fwrite($FH, $text . "\n"); | ||
} else { | ||
fwrite($FH, print_r($text, true)); | ||
} | ||
fclose( $FH ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
namespace OCA\Search_Lucene\Lucene; | ||
|
||
use OCP\Files\File; | ||
use OCP\Share; | ||
use OCA\Search_Lucene\Core\Files; | ||
use OCA\Search_Lucene\Db\StatusMapper; | ||
use OCA\Search_Lucene\Document\Ods; | ||
|
@@ -236,6 +237,18 @@ public function indexFile(File $file, $commit = true) { | |
|
||
// Store filecache id as unique id to lookup by when deleting | ||
$doc->addField(Document\Field::Keyword('fileId', $file->getId())); | ||
|
||
// Store names of individuals who have read permissions | ||
// FIXME: this next four lines seem a bit awkward. The goal is to get the "path" as | ||
// getUsersSharingFile() method expects it, which is relative to the user's dir | ||
// of files, without assuming the data directory is the same as the user name. | ||
$full_home_dir = \OC::$server->getUserManager()->get(\OC_User::getUser())->getHome(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
$datadirectory = \OC::$server->getConfig()->getSystemValue('datadirectory'); | ||
$prefix = preg_replace( "!^" . $datadirectory . "!", "", $full_home_dir ) . '/files/'; | ||
$path = preg_replace( '!'.$prefix.'!', "", $file->getPath()); | ||
$canReadIndiv = Share::getUsersSharingFile($path, \OC_User::getUser(), true, false); | ||
$concatenated = '_' . implode('_', $canReadIndiv['users']) . '_'; | ||
$doc->addField(Document\Field::Text('can_read', $concatenated, 'UTF-8')); | ||
|
||
// Store document path for the search results | ||
$doc->addField(Document\Field::Text('path', $file->getPath(), 'UTF-8')); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @NacreData
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will just use logger instead