public function testShowList() { $template = new Template('activity', 'stream.app.navigation', ''); $template->assign('activeNavigation', 'all'); $template->assign('navigations', []); $template->assign('rssLink', ''); $this->navigation->expects($this->any())->method('getTemplate')->willReturn($template); $avatar = $this->getMockBuilder('OCP\\IAvatar')->disableOriginalConstructor()->getMock(); $this->avatarManager->expects($this->once())->method('getAvatar')->willReturn($avatar); $avatar->expects($this->once())->method('exists')->willReturn(false); $templateResponse = $this->controller->showList(); $this->assertInstanceOf('\\OCP\\AppFramework\\Http\\TemplateResponse', $templateResponse, 'Asserting type of return is \\OCP\\AppFramework\\Http\\TemplateResponse'); $renderedResponse = $templateResponse->render(); $this->assertNotEmpty($renderedResponse); }
/** * @NoAdminRequired * * @param array $crop * @return DataResponse */ public function postCroppedAvatar($crop) { $userId = $this->userSession->getUser()->getUID(); if (is_null($crop)) { return new DataResponse(['data' => ['message' => $this->l->t("No crop data provided")]], Http::STATUS_BAD_REQUEST); } if (!isset($crop['x'], $crop['y'], $crop['w'], $crop['h'])) { return new DataResponse(['data' => ['message' => $this->l->t("No valid crop data provided")]], Http::STATUS_BAD_REQUEST); } $tmpAvatar = $this->cache->get('tmpAvatar'); if (is_null($tmpAvatar)) { return new DataResponse(['data' => ['message' => $this->l->t("No temporary profile picture available, try again")]], Http::STATUS_BAD_REQUEST); } $image = new \OC_Image($tmpAvatar); $image->crop($crop['x'], $crop['y'], round($crop['w']), round($crop['h'])); try { $avatar = $this->avatarManager->getAvatar($userId); $avatar->set($image); // Clean up $this->cache->remove('tmpAvatar'); return new DataResponse(['status' => 'success']); } catch (\OC\NotSquareException $e) { return new DataResponse(['data' => ['message' => $this->l->t('Crop is not square')]], Http::STATUS_BAD_REQUEST); } catch (\Exception $e) { return new DataResponse(['data' => ['message' => $e->getMessage()]], Http::STATUS_BAD_REQUEST); } }
/** * get the avatar image if it exists * * @param int $size * @return IImage|null * @since 9.0.0 */ public function getAvatarImage($size) { // delay the initialization if (is_null($this->avatarManager)) { $this->avatarManager = \OC::$server->getAvatarManager(); } $avatar = $this->avatarManager->getAvatar($this->uid); $image = $avatar->get(-1); if ($image) { return $image; } return null; }
/** * @brief sets an image as ownCloud avatar * @return null */ private function setOwnCloudAvatar() { if (!$this->image->valid()) { $this->log->log('user_ldap', 'jpegPhoto data invalid for ' . $this->dn, \OCP\Util::ERROR); return; } //make sure it is a square and not bigger than 128x128 $size = min(array($this->image->width(), $this->image->height(), 128)); if (!$this->image->centerCrop($size)) { $this->log->log('user_ldap', 'croping image for avatar failed for ' . $this->dn, \OCP\Util::ERROR); return; } if (!$this->fs->isLoaded()) { $this->fs->setup($this->uid); } $avatar = $this->avatarManager->getAvatar($this->uid); $avatar->set($this->image); }
/** * @param IUser $user * @param array $userGroups * @return array */ private function formatUserForIndex(IUser $user, array $userGroups = null) { // TODO: eliminate this encryption specific code below and somehow // hook in additional user info from other apps // recovery isn't possible if admin or user has it disabled and encryption // is enabled - so we eliminate the else paths in the conditional tree // below $restorePossible = false; if ($this->isEncryptionAppEnabled) { if ($this->isRestoreEnabled) { // check for the users recovery setting $recoveryMode = $this->config->getUserValue($user->getUID(), 'encryption', 'recoveryEnabled', '0'); // method call inside empty is possible with PHP 5.5+ $recoveryModeEnabled = !empty($recoveryMode); if ($recoveryModeEnabled) { // user also has recovery mode enabled $restorePossible = true; } } } else { // recovery is possible if encryption is disabled (plain files are // available) $restorePossible = true; } $subAdminGroups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($user); foreach ($subAdminGroups as $key => $subAdminGroup) { $subAdminGroups[$key] = $subAdminGroup->getGID(); } $displayName = $user->getEMailAddress(); if (is_null($displayName)) { $displayName = ''; } $avatarAvailable = false; if ($this->config->getSystemValue('enable_avatars', true) === true) { try { $avatarAvailable = $this->avatarManager->getAvatar($user->getUID())->exists(); } catch (\Exception $e) { //No avatar yet } } return ['name' => $user->getUID(), 'displayname' => $user->getDisplayName(), 'groups' => empty($userGroups) ? $this->groupManager->getUserGroupIds($user) : $userGroups, 'subadmin' => $subAdminGroups, 'quota' => $user->getQuota(), 'storageLocation' => $user->getHome(), 'lastLogin' => $user->getLastLogin() * 1000, 'backend' => $user->getBackendClassName(), 'email' => $displayName, 'isRestoreDisabled' => !$restorePossible, 'isAvatarAvailable' => $avatarAvailable]; }
/** * @brief sets an image as ownCloud avatar * @return null */ private function setOwnCloudAvatar() { if (!$this->image->valid()) { $this->log->log('jpegPhoto data invalid for ' . $this->dn, \OCP\Util::ERROR); return; } //make sure it is a square and not bigger than 128x128 $size = min(array($this->image->width(), $this->image->height(), 128)); if (!$this->image->centerCrop($size)) { $this->log->log('croping image for avatar failed for ' . $this->dn, \OCP\Util::ERROR); return; } if (!$this->fs->isLoaded()) { $this->fs->setup($this->uid); } try { $avatar = $this->avatarManager->getAvatar($this->uid); $avatar->set($this->image); } catch (\Exception $e) { \OC::$server->getLogger()->notice('Could not set avatar for ' . $this->dn . ', because: ' . $e->getMessage(), ['app' => 'user_ldap']); } }