From b6b713eb765cee05cec434cce2f79749c6c2755f Mon Sep 17 00:00:00 2001
From: Michael Gapczynski <mtgap@owncloud.com>
Date: Mon, 6 Aug 2012 20:43:08 -0400
Subject: [PATCH] Only show the user's groups in the share with autocomplete

---
 core/ajax/share.php | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/core/ajax/share.php b/core/ajax/share.php
index f7a41aa3a4..2cfbb5f320 100644
--- a/core/ajax/share.php
+++ b/core/ajax/share.php
@@ -100,18 +100,15 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['item']
 					}
 				}
 				$count = 0;
-				$groups = array();
-				$limit = 0;
-				$offset = 0;
-				while ($count < 4 && count($groups) == $limit) {
-					$limit = 4 - $count;
-					$groups = OC_Group::getGroups($_GET['search'], $limit, $offset);
-					$offset += $limit;
-					foreach ($groups as $group) {
-						if (!isset($_GET['itemShares'][OCP\Share::SHARE_TYPE_GROUP]) || !in_array($group, $_GET['itemShares'][OCP\Share::SHARE_TYPE_GROUP])) {
+				$groups = OC_Group::getUserGroups(OC_User::getUser());
+				foreach ($groups as $group) {
+					if ($count < 4) {
+						if (stripos($group, $_GET['search']) !== false && (!isset($_GET['itemShares'][OCP\Share::SHARE_TYPE_GROUP]) || !in_array($group, $_GET['itemShares'][OCP\Share::SHARE_TYPE_GROUP]))) {
 							$shareWith[] = array('label' => $group.' (group)', 'value' => array('shareType' => OCP\Share::SHARE_TYPE_GROUP, 'shareWith' => $group));
 							$count++;
 						}
+					} else {
+						break;
 					}
 				}
 				OC_JSON::success(array('data' => $shareWith));
-- 
GitLab