diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2015-11-20 15:22:52 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2015-11-20 15:22:52 +0100 |
commit | 427d107b9f375f5667a3e8f40191edd46924fdb8 (patch) | |
tree | a23de8dcbea7e7d66e842c9e15fc600350c9d49c /lib/private | |
parent | 308aaf89cd916a0c26c219650e09b8612a50fc47 (diff) | |
parent | c86483f3edb931d58477e4003490fb02fee6369f (diff) | |
download | nextcloud-server-427d107b9f375f5667a3e8f40191edd46924fdb8.tar.gz nextcloud-server-427d107b9f375f5667a3e8f40191edd46924fdb8.zip |
Merge pull request #20614 from owncloud/use-mocks-when-testing-isSharingDisabledForUser
Use mocks when testing isSharingDisabledForUser
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/files/storage/common.php | 2 | ||||
-rw-r--r-- | lib/private/group.php | 2 | ||||
-rw-r--r-- | lib/private/group/manager.php | 5 | ||||
-rw-r--r-- | lib/private/share/share.php | 2 | ||||
-rw-r--r-- | lib/private/util.php | 22 |
5 files changed, 21 insertions, 12 deletions
diff --git a/lib/private/files/storage/common.php b/lib/private/files/storage/common.php index 77a70226b37..8e4958a930d 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 4eed2a85450..fdf8086f1e8 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 73ff0e537c6..7387b423643 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 4503818a9ec..d377708a268 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 4c151d63639..e48cdd4d9fc 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 |