Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjörn Schießle <schiessle@owncloud.com>2013-05-24 14:45:30 +0400
committerBjörn Schießle <schiessle@owncloud.com>2013-05-24 14:45:30 +0400
commit8fa5f35e4ff9821bd26c0c00d1bb01a573002f6f (patch)
tree4a15130ea6a11228f7e1ed17fc38bb6fb9549462 /lib/public
parentc4b40af602105284d88af01b53f067fc9eefe476 (diff)
backport changes to share.php to enable the encryption app to get all users with access to a given file
Diffstat (limited to 'lib/public')
-rw-r--r--lib/public/share.php106
1 files changed, 106 insertions, 0 deletions
diff --git a/lib/public/share.php b/lib/public/share.php
index 092f83e96db..dbe3c7193e4 100644
--- a/lib/public/share.php
+++ b/lib/public/share.php
@@ -107,6 +107,112 @@ class Share {
return false;
}
+
+ /**
+ * @brief Prepare a path to be passed to DB as file_target
+ * @return string Prepared path
+ */
+ public static function prepFileTarget( $path ) {
+
+ // Paths in DB are stored with leading slashes, so add one if necessary
+ if ( substr( $path, 0, 1 ) !== '/' ) {
+
+ $path = '/' . $path;
+
+ }
+
+ return $path;
+
+ }
+
+ /**
+ * @brief Find which users can access a shared item
+ * @param $path to the file
+ * @param $user owner of the file
+ * @param include owner to the list of users with access to the file
+ * @return array
+ * @note $path needs to be relative to user data dir, e.g. 'file.txt'
+ * not '/admin/data/file.txt'
+ */
+ public static function getUsersSharingFile($path, $user, $includeOwner = false, $removeDuplicates = true) {
+
+ $path_parts = explode(DIRECTORY_SEPARATOR, trim($path, DIRECTORY_SEPARATOR));
+ $path = '';
+ $shares = array();
+ $publicShare = false;
+ $view = new \OC\Files\View('/' . $user . '/files/');
+ foreach ($path_parts as $p) {
+ $path .= '/' . $p;
+ $meta = $view->getFileInfo(\OC_Filesystem::normalizePath($path));
+ $source = $meta['fileid'];
+
+ // Fetch all shares of this file path from DB
+ $query = \OC_DB::prepare(
+ 'SELECT share_with
+ FROM
+ `*PREFIX*share`
+ WHERE
+ item_source = ? AND share_type = ?'
+ );
+
+ $result = $query->execute(array($source, self::SHARE_TYPE_USER));
+
+ if (\OC_DB::isError($result)) {
+ \OC_Log::write('OCP\Share', \OC_DB::getErrorMessage($result), \OC_Log::ERROR);
+ }
+
+ while ($row = $result->fetchRow()) {
+ $shares[] = $row['share_with'];
+ }
+
+ // We also need to take group shares into account
+
+ $query = \OC_DB::prepare(
+ 'SELECT share_with
+ FROM
+ `*PREFIX*share`
+ WHERE
+ item_source = ? AND share_type = ?'
+ );
+
+ $result = $query->execute(array($source, self::SHARE_TYPE_GROUP));
+
+ if (\OC_DB::isError($result)) {
+ \OC_Log::write('OCP\Share', \OC_DB::getErrorMessage($result), \OC_Log::ERROR);
+ }
+
+ while ($row = $result->fetchRow()) {
+ $usersInGroup = \OC_Group::usersInGroup($row['share_with']);
+ $shares = array_merge($shares, $usersInGroup);
+ }
+
+ //check for public link shares
+ $query = \OC_DB::prepare(
+ 'SELECT share_with
+ FROM
+ `*PREFIX*share`
+ WHERE
+ item_source = ? AND share_type = ?'
+ );
+
+ $result = $query->execute(array($source, self::SHARE_TYPE_LINK));
+
+ if (\OC_DB::isError($result)) {
+ \OC_Log::write('OCP\Share', \OC_DB::getErrorMessage($result), \OC_Log::ERROR);
+ }
+
+ if ($result->fetchRow()) {
+ $publicShare = true;
+ }
+ }
+ // Include owner in list of users, if requested
+ if ($includeOwner) {
+ $shares[] = $user;
+ }
+
+ return array("users" => array_unique($shares), "public" => $publicShare);
+ }
+
/**
* @brief Get the items of item type shared with the current user
* @param string Item type