diff --git a/lib/private/files/storage/common.php b/lib/private/files/storage/common.php
index 77a70226b37cb1e44409e7ae8337e78fcb9b3412..8e4958a930d6dab5b57b0f592b79d533c02e86bd 100644
--- a/lib/private/files/storage/common.php
+++ b/lib/private/files/storage/common.php
@@ -137,7 +137,7 @@ abstract class Common implements Storage {
 	}
 
 	public function isSharable($path) {
-		if (\OC_Util::isSharingDisabledForUser()) {
+		if (\OCP\Util::isSharingDisabledForUser()) {
 			return false;
 		}
 
diff --git a/lib/private/group.php b/lib/private/group.php
index 4eed2a8545007570960e2f14dcdaa1ce8d5ebf63..fdf8086f1e84c37b74457e3027a656bea190f981 100644
--- a/lib/private/group.php
+++ b/lib/private/group.php
@@ -183,7 +183,7 @@ class OC_Group {
 	 *
 	 * This function fetches all groups a user belongs to. It does not check
 	 * if the user exists at all.
-	 * @deprecated Use \OC::$server->getGroupManager->getuserGroupIds($user)
+	 * @deprecated Use \OC::$server->getGroupManager->getUserGroupIds($user)
 	 */
 	public static function getUserGroups($uid) {
 		$user = self::getUserManager()->get($uid);
diff --git a/lib/private/group/manager.php b/lib/private/group/manager.php
index 73ff0e537c6763a8c6eb6df9b3e960e80a2769b2..7387b423643598f8ff4a466d23d89f022a4beba0 100644
--- a/lib/private/group/manager.php
+++ b/lib/private/group/manager.php
@@ -210,10 +210,13 @@ class Manager extends PublicEmitter implements IGroupManager {
 	}
 
 	/**
-	 * @param \OC\User\User $user
+	 * @param \OC\User\User|null $user
 	 * @return \OC\Group\Group[]
 	 */
 	public function getUserGroups($user) {
+		if (is_null($user)) {
+			return false;
+		}
 		return $this->getUserIdGroups($user->getUID());
 	}
 
diff --git a/lib/private/share/share.php b/lib/private/share/share.php
index 4503818a9ecebaa91b0bbcaa7137b68a13815711..d377708a2681bf4b0b785533d18521876ad1a308 100644
--- a/lib/private/share/share.php
+++ b/lib/private/share/share.php
@@ -1811,7 +1811,7 @@ class Share extends Constants {
 				}
 			}
 			// Check if resharing is allowed, if not remove share permission
-			if (isset($row['permissions']) && (!self::isResharingAllowed() | \OC_Util::isSharingDisabledForUser())) {
+			if (isset($row['permissions']) && (!self::isResharingAllowed() | \OCP\Util::isSharingDisabledForUser())) {
 				$row['permissions'] &= ~\OCP\Constants::PERMISSION_SHARE;
 			}
 			// Add display names to result
diff --git a/lib/private/util.php b/lib/private/util.php
index 4c151d6363908f7dd258f3dfee9826482023f586..e48cdd4d9fc6b1f2f5188b4b775a38267e40158e 100644
--- a/lib/private/util.php
+++ b/lib/private/util.php
@@ -54,6 +54,11 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>
  *
  */
+
+use OCP\IConfig;
+use OCP\IGroupManager;
+use OCP\IUser;
+
 class OC_Util {
 	public static $scripts = array();
 	public static $styles = array();
@@ -218,20 +223,21 @@ class OC_Util {
 
 	/**
 	 * check if sharing is disabled for the current user
-	 *
-	 * @return boolean
+	 * @param IConfig $config
+	 * @param IGroupManager $groupManager
+	 * @param IUser|null $user
+	 * @return bool
 	 */
-	public static function isSharingDisabledForUser() {
-		if (\OC::$server->getAppConfig()->getValue('core', 'shareapi_exclude_groups', 'no') === 'yes') {
-			$user = \OCP\User::getUser();
-			$groupsList = \OC::$server->getAppConfig()->getValue('core', 'shareapi_exclude_groups_list', '');
+	public static function isSharingDisabledForUser(IConfig $config, IGroupManager $groupManager, $user) {
+		if ($config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes') {
+			$groupsList = $config->getAppValue('core', 'shareapi_exclude_groups_list', '');
 			$excludedGroups = json_decode($groupsList);
 			if (is_null($excludedGroups)) {
 				$excludedGroups = explode(',', $groupsList);
 				$newValue = json_encode($excludedGroups);
-				\OC::$server->getAppConfig()->setValue('core', 'shareapi_exclude_groups_list', $newValue);
+				$config->setAppValue('core', 'shareapi_exclude_groups_list', $newValue);
 			}
-			$usersGroups = \OC_Group::getUserGroups($user);
+			$usersGroups = $groupManager->getUserGroupIds($user);
 			if (!empty($usersGroups)) {
 				$remainingGroups = array_diff($usersGroups, $excludedGroups);
 				// if the user is only in groups which are disabled for sharing then
diff --git a/lib/public/igroupmanager.php b/lib/public/igroupmanager.php
index 862c77218de9470ee4281cf9350c4a7e4ecf096c..da80cfdd374e8a08ae9bf028ee042416032d17b7 100644
--- a/lib/public/igroupmanager.php
+++ b/lib/public/igroupmanager.php
@@ -93,7 +93,7 @@ interface IGroupManager {
 	public function search($search, $limit = null, $offset = null);
 
 	/**
-	 * @param \OCP\IUser $user
+	 * @param \OCP\IUser|null $user
 	 * @return \OCP\IGroup[]
 	 * @since 8.0.0
 	 */
diff --git a/lib/public/util.php b/lib/public/util.php
index 76b61347d46649b34c32a86954b6945a95b0f6df..07bc47c18b4cd22ac7f96e037b2d01350054c2a5 100644
--- a/lib/public/util.php
+++ b/lib/public/util.php
@@ -173,7 +173,11 @@ class Util {
 	 * @since 7.0.0
 	 */
 	public static function isSharingDisabledForUser() {
-		return \OC_Util::isSharingDisabledForUser();
+		return \OC_Util::isSharingDisabledForUser(
+				\OC::$server->getConfig(),
+				\OC::$server->getGroupManager(),
+				\OC::$server->getUserSession()->getUser()
+		);
 	}
 
 	/**
diff --git a/tests/lib/util.php b/tests/lib/util.php
index 9974e799d08aca5ee6eeb52dac1c3916c28bd254..a328b1923e961566430ac9d79740d4e30ec0feb9 100644
--- a/tests/lib/util.php
+++ b/tests/lib/util.php
@@ -289,38 +289,30 @@ class Test_Util extends \Test\TestCase {
 	 * @param bool $expected expected result
 	 */
 	function testIsSharingDisabledForUser($groups, $membership, $excludedGroups, $expected) {
-		$uid = "user1";
-		\OC_User::setUserId($uid);
-
-		\OC_User::createUser($uid, "passwd");
-
-		foreach ($groups as $group) {
-			\OC_Group::createGroup($group);
-		}
-
-		foreach ($membership as $group) {
-			\OC_Group::addToGroup($uid, $group);
-		}
-
-		$appConfig = \OC::$server->getAppConfig();
-		$appConfig->setValue('core', 'shareapi_exclude_groups_list', json_encode($excludedGroups));
-		$appConfig->setValue('core', 'shareapi_exclude_groups', 'yes');
-
-		$result = \OCP\Util::isSharingDisabledForUser();
+		$config = $this->getMockBuilder('OCP\IConfig')->disableOriginalConstructor()->getMock();
+		$groupManager = $this->getMockBuilder('OCP\IGroupManager')->disableOriginalConstructor()->getMock();
+		$user = $this->getMockBuilder('OCP\IUser')->disableOriginalConstructor()->getMock();
+
+		$config
+				->expects($this->at(0))
+				->method('getAppValue')
+				->with('core', 'shareapi_exclude_groups', 'no')
+				->will($this->returnValue('yes'));
+		$config
+				->expects($this->at(1))
+				->method('getAppValue')
+				->with('core', 'shareapi_exclude_groups_list')
+				->will($this->returnValue(json_encode($excludedGroups)));
+
+		$groupManager
+				->expects($this->at(0))
+				->method('getUserGroupIds')
+				->with($user)
+				->will($this->returnValue($membership));
+
+		$result = \OC_Util::isSharingDisabledForUser($config, $groupManager, $user);
 
 		$this->assertSame($expected, $result);
-
-		// cleanup
-		\OC_User::deleteUser($uid);
-		\OC_User::setUserId('');
-
-		foreach ($groups as $group) {
-			\OC_Group::deleteGroup($group);
-		}
-
-		$appConfig->setValue('core', 'shareapi_exclude_groups_list', '');
-		$appConfig->setValue('core', 'shareapi_exclude_groups', 'no');
-
 	}
 
 	public function dataProviderForTestIsSharingDisabledForUser() {