/** * Read legacy config data * * @return array list of mount configs */ protected function readLegacyConfig() { // read global config $data = parent::readLegacyConfig(); $userId = $this->getUser()->getUID(); // don't use array_filter() with ARRAY_FILTER_USE_KEY, it's PHP 5.6+ if (isset($data[\OC_Mount_Config::MOUNT_TYPE_USER])) { $newData = []; foreach ($data[\OC_Mount_Config::MOUNT_TYPE_USER] as $key => $value) { if (strtolower($key) === strtolower($userId) || $key === 'all') { $newData[$key] = $value; } } $data[\OC_Mount_Config::MOUNT_TYPE_USER] = $newData; } if (isset($data[\OC_Mount_Config::MOUNT_TYPE_GROUP])) { $newData = []; foreach ($data[\OC_Mount_Config::MOUNT_TYPE_GROUP] as $key => $value) { if ($this->groupManager->isInGroup($userId, $key)) { $newData[$key] = $value; } } $data[\OC_Mount_Config::MOUNT_TYPE_GROUP] = $newData; } return $data; }
/** * Read legacy config data * * @return array list of mount configs */ protected function readLegacyConfig() { // read global config $data = parent::readLegacyConfig(); $userId = $this->getUser()->getUID(); if (isset($data[\OC_Mount_Config::MOUNT_TYPE_USER])) { $data[\OC_Mount_Config::MOUNT_TYPE_USER] = array_filter($data[\OC_Mount_Config::MOUNT_TYPE_USER], function ($key) use($userId) { return strtolower($key) === strtolower($userId) || $key === 'all'; }, ARRAY_FILTER_USE_KEY); } if (isset($data[\OC_Mount_Config::MOUNT_TYPE_GROUP])) { $data[\OC_Mount_Config::MOUNT_TYPE_GROUP] = array_filter($data[\OC_Mount_Config::MOUNT_TYPE_GROUP], function ($key) use($userId) { return $this->groupManager->isInGroup($userId, $key); }, ARRAY_FILTER_USE_KEY); } return $data; }
/** * @param string $gid * @param string $uid * @return bool */ protected function isMember($gid, $uid) { if (isset($this->memberships[$gid][$uid])) { return $this->memberships[$gid][$uid]; } $isMember = $this->groupManager->isInGroup($uid, $gid); if (!isset($this->memberships[$gid])) { $this->memberships[$gid] = []; } $this->memberships[$gid][$uid] = $isMember; return $isMember; }
/** * @param array $parameters * @return OC_OCS_Result */ public function removeFromGroup($parameters) { // Check if user is logged in $user = $this->userSession->getUser(); if ($user === null) { return new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED); } $group = !empty($parameters['_delete']['groupid']) ? $parameters['_delete']['groupid'] : null; if (is_null($group)) { return new OC_OCS_Result(null, 101); } // If they're not an admin, check they are a subadmin of the group in question if (!$this->groupManager->isInGroup($user->getUID(), 'admin') && !OC_SubAdmin::isSubAdminofGroup($user->getUID(), $group)) { return new OC_OCS_Result(null, 104); } // Check they aren't removing themselves from 'admin' or their 'subadmin; group if ($parameters['userid'] === $user->getUID()) { if ($this->groupManager->isInGroup($user->getUID(), 'admin')) { if ($group === 'admin') { return new OC_OCS_Result(null, 105, 'Cannot remove yourself from the admin group'); } } else { // Not an admin, check they are not removing themself from their subadmin group if (in_array($group, OC_SubAdmin::getSubAdminsGroups($user->getUID()))) { return new OC_OCS_Result(null, 105, 'Cannot remove yourself from this group as you are a SubAdmin'); } } } // Check if the group exists if (!$this->groupManager->groupExists($group)) { return new OC_OCS_Result(null, 102); } // Check if the user exists if (!$this->userManager->userExists($parameters['userid'])) { return new OC_OCS_Result(null, 103); } // Remove user from group $this->groupManager->get($group)->removeUser($this->userManager->get($parameters['userid'])); return new OC_OCS_Result(null, 100); }