diff options
author | Michael Gapczynski <GapczynskiM@gmail.com> | 2011-08-14 12:16:14 -0400 |
---|---|---|
committer | Michael Gapczynski <GapczynskiM@gmail.com> | 2011-08-14 12:16:14 -0400 |
commit | 5cb687d168280a14ff10ff096d4d13dc76849e17 (patch) | |
tree | c0b6359706a58d28d7576e9814e2053af1a484ce /apps/files_sharing | |
parent | e1473cfe83c649627a7355d55665af44ce1fc936 (diff) | |
download | nextcloud-server-5cb687d168280a14ff10ff096d4d13dc76849e17.tar.gz nextcloud-server-5cb687d168280a14ff10ff096d4d13dc76849e17.zip |
Refactor getUserAndGroups() for new user group sharing standard - user@group
Diffstat (limited to 'apps/files_sharing')
-rw-r--r-- | apps/files_sharing/lib_share.php | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php index f4198702276..167a16b2754 100644 --- a/apps/files_sharing/lib_share.php +++ b/apps/files_sharing/lib_share.php @@ -105,9 +105,13 @@ class OC_Share { */ private static function getUserAndGroups() { $self = OC_User::getUser(); + $in = " IN('".$self."'"; $groups = OC_Group::getUserGroups($self); - array_unshift($groups, $self); - return $groups; + foreach ($groups as $group) { + $in .= ", '".$self."@".$group."'"; + } + $in .= ")"; + return $in; } /** @@ -171,9 +175,8 @@ class OC_Share { $folder .= "/"; } $length = strlen($folder); - $userAndGroups = self::getUserAndGroups(); - $query = OC_DB::prepare("SELECT uid_owner, source, target FROM *PREFIX*sharing WHERE SUBSTR(source, 1, ?) = ? OR SUBSTR(target, 1, ?) = ? AND uid_shared_with IN(".substr(str_repeat(",?", count($userAndGroups)), 1).")"); - return $query->execute(array_merge(array($length, $folder, $length, $folder), $userAndGroups))->fetchAll(); + $query = OC_DB::prepare("SELECT uid_owner, source, target FROM *PREFIX*sharing WHERE SUBSTR(source, 1, ?) = ? OR SUBSTR(target, 1, ?) = ? AND uid_shared_with ".self::getUserAndGroups()." "); + return $query->execute(array($length, $folder, $length, $folder))->fetchAll(); } /** @@ -183,14 +186,13 @@ class OC_Share { */ public static function getParentFolders($target) { $target = self::cleanPath($target); - $userAndGroups = self::getUserAndGroups(); - $query = OC_DB::prepare("SELECT source FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with IN(".substr(str_repeat(",?", count($userAndGroups)), 1).") LIMIT 1"); + $query = OC_DB::prepare("SELECT source FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with".self::getUserAndGroups()." LIMIT 1"); // Prevent searching for user directory e.g. '/MTGap/files' $userDirectory = substr($target, 0, strpos($target, "files") + 5); while ($target != "" && $target != "/" && $target != "." && $target != $userDirectory) { // Check if the parent directory of this target location is shared $target = dirname($target); - $result = $query->execute(array_merge(array($target), $userAndGroups))->fetchAll(); + $result = $query->execute(array($target))->fetchAll(); if (count($result) > 0) { break; } @@ -210,9 +212,8 @@ class OC_Share { */ public static function getSource($target) { $target = self::cleanPath($target); - $userAndGroups = self::getUserAndGroups(); - $query = OC_DB::prepare("SELECT source FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with IN(".substr(str_repeat(",?", count($userAndGroups)), 1).") LIMIT 1"); - $result = $query->execute(array_merge(array($target), $userAndGroups))->fetchAll(); + $query = OC_DB::prepare("SELECT source FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with ".self::getUserAndGroups()." LIMIT 1"); + $result = $query->execute(array($target))->fetchAll(); if (count($result) > 0) { return $result[0]['source']; } else { @@ -232,15 +233,14 @@ class OC_Share { */ public static function getPermissions($target) { $target = self::cleanPath($target); - $userAndGroups = self::getUserAndGroups(); - $query = OC_DB::prepare("SELECT permissions FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with IN(".substr(str_repeat(",?", count($userAndGroups)), 1).") LIMIT 1"); - $result = $query->execute(array_merge(array($target), $userAndGroups))->fetchAll(); + $query = OC_DB::prepare("SELECT permissions FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with ".self::getUserAndGroups()." LIMIT 1"); + $result = $query->execute(array($target))->fetchAll(); if (count($result) > 0) { return $result[0]['permissions']; } else { $folders =self::getParentFolders($target); if ($folders == true) { - $result = $query->execute(array_merge(array($folders), $userAndGroups))->fetchAll(); + $result = $query->execute(array($folders))->fetchAll(); if (count($result) > 0) { return $result[0]['permissions']; } |