/** * @param string $pattern which should match within the $searchProperties * @param array $searchProperties defines the properties within the query pattern should match * @param array $options - for future use. One should always have options! * @return array an array of contacts which are arrays of key-value-pairs */ public function search($pattern, $searchProperties, $options) { $users = array(); if ($pattern == '') { // Fetch all contacts $users = $this->userManager->search(''); } else { foreach ($searchProperties as $property) { $result = array(); if ($property === 'FN') { $result = $this->userManager->searchDisplayName($pattern); } else { if ($property === 'id') { $result = $this->userManager->search($pattern); } } if (is_array($result)) { $users = array_merge($users, $result); } } } $contacts = array(); foreach ($users as $user) { $contact = array("id" => $user->getUID(), "FN" => $user->getDisplayname(), "EMAIL" => array(), "IMPP" => array("x-owncloud-handle:" . $user->getUID())); $contacts[] = $contact; } return $contacts; }
/** * returns a list of users * * @return OC_OCS_Result */ public function getUsers() { $search = !empty($_GET['search']) ? $_GET['search'] : ''; $limit = !empty($_GET['limit']) ? $_GET['limit'] : null; $offset = !empty($_GET['offset']) ? $_GET['offset'] : null; // Check if user is logged in $user = $this->userSession->getUser(); if ($user === null) { return new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED); } // Admin? Or SubAdmin? if ($this->groupManager->isAdmin($user->getUID())) { $users = $this->userManager->search($search, $limit, $offset); } else { if (\OC_SubAdmin::isSubAdmin($user->getUID())) { $subAdminOfGroups = \OC_SubAdmin::getSubAdminsGroups($user->getUID()); if ($offset === null) { $offset = 0; } $users = []; foreach ($subAdminOfGroups as $group) { $users = array_merge($users, $this->groupManager->displayNamesInGroup($group, $search)); } $users = array_slice($users, $offset, $limit); } else { return new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED); } } $users = array_keys($users); return new OC_OCS_Result(['users' => $users]); }
public function testGetUsers() { $result = $this->api->getUsers(); $this->assertInstanceOf('OC_OCS_Result', $result); $this->assertTrue($result->succeeded()); $count = $result->getData(); $count = count($count['users']); $this->assertEquals(count($this->userManager->search('', null, null)), $count); $user = $this->generateUsers(); $_GET['search'] = $user->getUID(); $result = $this->api->getUsers(); $this->assertInstanceOf('OC_OCS_Result', $result); $this->assertTrue($result->succeeded()); $data = $result->getData(); $this->assertEquals($user->getUID(), reset($data['users'])); // Add several users $this->generateUsers(10); $this->resetParams(); $_GET['limit'] = 2; $result = $this->api->getUsers(); $this->assertInstanceOf('OC_OCS_Result', $result); $this->assertTrue($result->succeeded()); $count = $result->getData(); $count = count($count['users']); $this->assertEquals(2, $count); $this->resetParams(); $_GET['limit'] = 1; $_GET['offset'] = 1; $result = $this->api->getUsers(array()); $this->assertInstanceOf('OC_OCS_Result', $result); $this->assertTrue($result->succeeded()); $data = $result->getData(); $this->assertEquals(array_keys($this->userManager->search('', 1, 1)), $data['users']); }
/** * @param $argument * @throws \Exception */ protected function run($argument) { $maxAge = $this->expiration->getMaxAgeAsTimestamp(); if (!$maxAge) { return; } $offset = $this->config->getAppValue('files_trashbin', 'cronjob_user_offset', 0); $users = $this->userManager->search('', self::USERS_PER_SESSION, $offset); if (!count($users)) { // No users found, reset offset and retry $offset = 0; $users = $this->userManager->search('', self::USERS_PER_SESSION); } $offset += self::USERS_PER_SESSION; $this->config->setAppValue('files_trashbin', 'cronjob_user_offset', $offset); foreach ($users as $user) { $uid = $user->getUID(); if (!$this->setupFS($uid)) { continue; } $dirContent = Helper::getTrashFiles('/', $uid, 'mtime'); Trashbin::deleteExpiredFiles($dirContent, $uid); } \OC_Util::tearDownFS(); }
protected function execute(InputInterface $input, OutputInterface $output) { if (!$input->getOption('debug')) { $this->scanner->listen('\\OCA\\Music\\Utility\\Scanner', 'update', function ($path) use($output) { $output->writeln("Scanning <info>{$path}</info>"); }); } $inputPath = $input->getOption('path'); $path = false; if ($inputPath) { $path = '/' . trim($inputPath, '/'); list(, $user, ) = explode('/', $path, 3); $users = array($user); } else { if ($input->getOption('all')) { $users = $this->userManager->search(''); } else { $users = $input->getArgument('user_id'); } } foreach ($users as $user) { if (is_object($user)) { $user = $user->getUID(); } \OC_Util::tearDownFS(); \OC_Util::setupFS($user); $output->writeln("Start scan for <info>{$user}</info>"); $this->scanner->rescan($user, true, $path ? $path : $this->resolveUserFolder($user), $input->getOption('debug'), $output); } }
/** * returns a list of users * * @return OC_OCS_Result */ public function getUsers() { $search = !empty($_GET['search']) ? $_GET['search'] : ''; $limit = !empty($_GET['limit']) ? $_GET['limit'] : null; $offset = !empty($_GET['offset']) ? $_GET['offset'] : null; $users = $this->userManager->search($search, $limit, $offset); $users = array_keys($users); return new OC_OCS_Result(['users' => $users]); }
/** * Returns a list of principals based on a prefix. * * This prefix will often contain something like 'principals'. You are only * expected to return principals that are in this base path. * * You are expected to return at least a 'uri' for every user, you can * return any additional properties if you wish so. Common properties are: * {DAV:}displayname * * @param string $prefixPath * @return string[] */ public function getPrincipalsByPrefix($prefixPath) { $principals = []; if ($prefixPath === $this->principalPrefix) { foreach ($this->userManager->search('') as $user) { $principals[] = $this->userToPrincipal($user); } } return $principals; }
/** * become another user * @UseSession */ public function impersonate($userid) { $users = $this->userManager->search($userid, 1, 0); if (count($users) > 0) { $user = array_shift($users); if (strcasecmp($user->getUID(), $userid) === 0) { $this->userSession->setUser($user); } } return new JSONResponse(); }
/** * A hack to access files and views. Better than before. * * @return bool */ protected function initFS() { //Need any valid user to mount FS $results = $this->userManager->search('', 2, 0); $anyUser = array_pop($results); if (is_null($anyUser)) { \OC::$server->getLogger()->error("Failed to setup file system", ['app' => 'files_antivirus']); return false; } \OC_Util::tearDownFS(); \OC_Util::setupFS($anyUser->getUID()); return true; }
/** * A hack to access files and views. Better than before. */ protected function initFS() { //Need any valid user to mount FS $results = $this->userManager->search('', 2, 0); $anyUser = array_pop($results); if (is_null($anyUser)) { \OCP\Util::writeLog('files_antivirus', "Failed to setup file system", \OCP\Util::ERROR); return false; } \OC_Util::tearDownFS(); \OC_Util::setupFS($anyUser->getUID()); return true; }
/** * Returns a list of principals based on a prefix. * * This prefix will often contain something like 'principals'. You are only * expected to return principals that are in this base path. * * You are expected to return at least a 'uri' for every user, you can * return any additional properties if you wish so. Common properties are: * {DAV:}displayname * * @param string $prefixPath * @return string[] */ public function getPrincipalsByPrefix($prefixPath) { $principals = []; if ($prefixPath === 'principals') { foreach ($this->userManager->search('') as $user) { $principal = ['uri' => 'principals/' . $user->getUID(), '{DAV:}displayname' => $user->getUID()]; $email = $this->config->getUserValue($user->getUID(), 'settings', 'email'); if (!empty($email)) { $principal['{http://sabredav.org/ns}email-address'] = $email; } $principals[] = $principal; } } return $principals; }
/** * @NoAdminRequired * * @param int $offset * @param int $limit * @param string $gid GID to filter for * @param string $pattern Pattern to search for in the username * @param string $backend Backend to filter for (class-name) * @return DataResponse * * TODO: Tidy up and write unit tests - code is mainly static method calls */ public function index($offset = 0, $limit = 10, $gid = '', $pattern = '', $backend = '') { // FIXME: The JS sends the group '_everyone' instead of no GID for the "all users" group. if ($gid === '_everyone') { $gid = ''; } // Remove backends if (!empty($backend)) { $activeBackends = $this->userManager->getBackends(); $this->userManager->clearBackends(); foreach ($activeBackends as $singleActiveBackend) { if ($backend === get_class($singleActiveBackend)) { $this->userManager->registerBackend($singleActiveBackend); break; } } } $users = []; if ($this->isAdmin) { if ($gid !== '') { $batch = $this->getUsersForUID($this->groupManager->displayNamesInGroup($gid, $pattern, $limit, $offset)); } else { $batch = $this->userManager->search($pattern, $limit, $offset); } foreach ($batch as $user) { $users[] = $this->formatUserForIndex($user); } } else { $subAdminOfGroups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($this->userSession->getUser()); // New class returns IGroup[] so convert back $gids = []; foreach ($subAdminOfGroups as $group) { $gids[] = $group->getGID(); } $subAdminOfGroups = $gids; // Set the $gid parameter to an empty value if the subadmin has no rights to access a specific group if ($gid !== '' && !in_array($gid, $subAdminOfGroups)) { $gid = ''; } // Batch all groups the user is subadmin of when a group is specified $batch = []; if ($gid === '') { foreach ($subAdminOfGroups as $group) { $groupUsers = $this->groupManager->displayNamesInGroup($group, $pattern, $limit, $offset); foreach ($groupUsers as $uid => $displayName) { $batch[$uid] = $displayName; } } } else { $batch = $this->groupManager->displayNamesInGroup($gid, $pattern, $limit, $offset); } $batch = $this->getUsersForUID($batch); foreach ($batch as $user) { // Only add the groups, this user is a subadmin of $userGroups = array_values(array_intersect($this->groupManager->getUserGroupIds($user), $subAdminOfGroups)); $users[] = $this->formatUserForIndex($user, $userGroups); } } return new DataResponse($users); }
protected function run($argument) { $maxAge = $this->expiration->getMaxAgeAsTimestamp(); if (!$maxAge) { return; } $users = $this->userManager->search(''); $isFSready = false; foreach ($users as $user) { $uid = $user->getUID(); if (!$isFSready) { if (!$this->setupFS($uid)) { continue; } $isFSready = true; } Storage::expireOlderThanMaxForUser($uid); } \OC_Util::tearDownFS(); }
/** * @param $argument * @throws \Exception */ protected function run($argument) { $offset = $this->config->getAppValue('files', 'cronjob_scan_files', 0); $users = $this->userManager->search('', self::USERS_PER_SESSION, $offset); if (!count($users)) { // No users found, reset offset and retry $offset = 0; $users = $this->userManager->search('', self::USERS_PER_SESSION); } $offset += self::USERS_PER_SESSION; $this->config->setAppValue('files', 'cronjob_scan_files', $offset); foreach ($users as $user) { $this->runScanner($user); } }
/** * @param int $id * @param string $authorId * @param int $timeStamp */ protected function createPublicity($id, $authorId, $timeStamp) { $users = $this->userManager->search(''); $event = $this->activityManager->generateEvent(); $event->setApp('announcementcenter')->setType('announcementcenter')->setAuthor($authorId)->setTimestamp($timeStamp)->setSubject('announcementsubject#' . $id, [$authorId])->setMessage('announcementmessage#' . $id, [$authorId])->setObject('announcement', $id); $dateTime = new \DateTime(); $dateTime->setTimestamp($timeStamp); $notification = $this->notificationManager->createNotification(); $notification->setApp('announcementcenter')->setDateTime($dateTime)->setObject('announcement', $id)->setSubject('announced', [$authorId])->setLink($this->urlGenerator->linkToRoute('announcementcenter.page.index')); foreach ($users as $user) { $event->setAffectedUser($user->getUID()); $this->activityManager->publish($event); if ($authorId !== $user->getUID()) { $notification->setUser($user->getUID()); $this->notificationManager->notify($notification); } } }
protected function execute(InputInterface $input, OutputInterface $output) { $inputPath = $input->getOption('path'); if ($inputPath) { $inputPath = '/' . trim($inputPath, '/'); list(, $user, ) = explode('/', $inputPath, 3); $users = array($user); } else { if ($input->getOption('all')) { $users = $this->userManager->search(''); } else { $users = $input->getArgument('user_id'); } } # no messaging level option means: no full printout but statistics # $quiet means no print at all # $verbose means full printout including statistics # -q -v full stat # 0 0 no yes # 0 1 yes yes # 1 -- no no (quiet overrules verbose) $verbose = $input->getOption('verbose'); $quiet = $input->getOption('quiet'); # restrict the verbosity level to VERBOSITY_VERBOSE if ($output->getVerbosity() > OutputInterface::VERBOSITY_VERBOSE) { $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE); } if ($quiet) { $verbose = false; } # check quantity of users to be process and show it on the command line $users_total = count($users); if ($users_total === 0) { $output->writeln("<error>Please specify the user id to scan, \"--all\" to scan for all users or \"--path=...\"</error>"); return; } else { if ($users_total > 1) { $output->writeln("\nScanning files for {$users_total} users"); } } $this->initTools(); $user_count = 0; foreach ($users as $user) { if (is_object($user)) { $user = $user->getUID(); } $path = $inputPath ? $inputPath : '/' . $user; $user_count += 1; if ($this->userManager->userExists($user)) { # add an extra line when verbose is set to optical separate users if ($verbose) { $output->writeln(""); } $output->writeln("Starting scan for user {$user_count} out of {$users_total} ({$user})"); # full: printout data if $verbose was set $this->scanFiles($user, $path, $verbose, $output, $input->getOption('unscanned')); } else { $output->writeln("<error>Unknown user {$user_count} {$user}</error>"); } # check on each user if there was a user interrupt (ctrl-c) and exit foreach if ($this->hasBeenInterrupted()) { break; } } # stat: printout statistics if $quiet was not set if (!$quiet) { $this->presentStats($output); } }