/** * Check if an app is enabled for user * * @param string $appId * @param \OCP\IUser $user (optional) if not defined, the currently logged in user will be used * @return bool */ public function isEnabledForUser($appId, $user = null) { if (is_null($user)) { $user = $this->userSession->getUser(); } $installedApps = $this->getInstalledApps(); if (isset($installedApps[$appId])) { $enabled = $installedApps[$appId]; if ($enabled === 'yes') { return true; } elseif (is_null($user)) { return false; } else { $groupIds = json_decode($enabled); $userGroups = $this->groupManager->getUserGroupIds($user); foreach ($userGroups as $groupId) { if (array_search($groupId, $groupIds) !== false) { return true; } } return false; } } else { return false; } }
/** * @param ILogger $logger * @param IUserSession $userSession * @param IConfig $config */ public function __construct(ILogger $logger, IUserSession $userSession, IConfig $config) { $this->logger = $logger; $this->user = $userSession && $userSession->isLoggedIn() ? $userSession->getUser() : false; $this->config = $config; $this->supportedKeyFormats = ['hash', 'password']; }
/** * @NoAdminRequired * @UseSession * * @param string $oldPassword * @param string $newPassword * @return DataResponse */ public function updatePrivateKeyPassword($oldPassword, $newPassword) { $result = false; $uid = $this->userSession->getUser()->getUID(); $errorMessage = $this->l->t('Could not update the private key password.'); //check if password is correct $passwordCorrect = $this->userManager->checkPassword($uid, $newPassword); if ($passwordCorrect !== false) { $encryptedKey = $this->keyManager->getPrivateKey($uid); $decryptedKey = $this->crypt->decryptPrivateKey($encryptedKey, $oldPassword); if ($decryptedKey) { $encryptedKey = $this->crypt->symmetricEncryptFileContent($decryptedKey, $newPassword); $header = $this->crypt->generateHeader(); if ($encryptedKey) { $this->keyManager->setPrivateKey($uid, $header . $encryptedKey); $this->session->setPrivateKey($decryptedKey); $result = true; } } else { $errorMessage = $this->l->t('The old password was not correct, please try again.'); } } else { $errorMessage = $this->l->t('The current log-in password was not correct, please try again.'); } if ($result === true) { $this->session->setStatus(Session::INIT_SUCCESSFUL); return new DataResponse(['message' => (string) $this->l->t('Private key password successfully updated.')]); } else { return new DataResponse(['message' => (string) $errorMessage], Http::STATUS_BAD_REQUEST); } }
public function testTagManagerWithoutUserReturnsNull() { $this->userSession = $this->getMock('\\OCP\\IUserSession'); $this->userSession->expects($this->any())->method('getUser')->will($this->returnValue(null)); $this->tagMgr = new OC\TagManager($this->tagMapper, $this->userSession); $this->assertNull($this->tagMgr->load($this->objectType)); }
/** * @param ILogger $logger * @param IUserSession $userSession * @param Crypt $crypt * @param KeyManager $keyManager */ public function __construct(ILogger $logger, IUserSession $userSession, Crypt $crypt, KeyManager $keyManager) { $this->logger = $logger; $this->user = $userSession && $userSession->isLoggedIn() ? $userSession->getUser()->getUID() : false; $this->crypt = $crypt; $this->keyManager = $keyManager; }
/** * returns an array of users in the group specified * * @param array $parameters * @return OC_OCS_Result */ public function getGroup($parameters) { // Check if user is logged in $user = $this->userSession->getUser(); if ($user === null) { return new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED); } $groupId = $parameters['groupid']; // Check the group exists if (!$this->groupManager->groupExists($groupId)) { return new OC_OCS_Result(null, \OCP\API::RESPOND_NOT_FOUND, 'The requested group could not be found'); } $isSubadminOfGroup = false; $group = $this->groupManager->get($groupId); if ($group !== null) { $isSubadminOfGroup = $this->groupManager->getSubAdmin()->isSubAdminofGroup($user, $group); } // Check subadmin has access to this group if ($this->groupManager->isAdmin($user->getUID()) || $isSubadminOfGroup) { $users = $this->groupManager->get($groupId)->getUsers(); $users = array_map(function ($user) { /** @var IUser $user */ return $user->getUID(); }, $users); $users = array_values($users); return new OC_OCS_Result(['users' => $users]); } else { return new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED, 'User does not have access to specified group'); } }
/** * constructor of the controller * * @param string $appName * @param IRequest $request * @param ILogger $logger * @param IUserSession $userSession * @param CurrentUserSettings $userSettings */ public function __construct($appName, IRequest $request, ILogger $logger, IUserSession $userSession, CurrentUserSettings $userSettings) { parent::__construct($appName, $request); $this->logger = $logger; $this->user = $userSession->getUser(); $this->userSettings = $userSettings; }
/** * @return IUser|null */ protected function getUser() { if ($this->user) { return $this->user; } return $this->userSession->getUser(); }
/** * Create a new \OCP\ITags instance and load tags from db. * * @see \OCP\ITags * @param string $type The type identifier e.g. 'contact' or 'event'. * @param array $defaultTags An array of default tags to be used if none are stored. * @param boolean $includeShared Whether to include tags for items shared with this user by others. * @param string $userId user for which to retrieve the tags, defaults to the currently * logged in user * @return \OCP\ITags */ public function load($type, $defaultTags = array(), $includeShared = false, $userId = null) { if (is_null($userId)) { $userId = $this->userSession->getUser()->getUId(); } return new Tags($this->mapper, $userId, $type, $defaultTags, $includeShared); }
/** * @NoAdminRequired * @NoCSRFRequired * * @return TemplateResponse */ public function index() { $userId = $this->userSession->getUser()->getUID(); $appVersion = $this->config->getAppValue($this->appName, 'installed_version'); $defaultView = $this->config->getUserValue($userId, $this->appName, 'currentView', 'month'); return new TemplateResponse('calendar', 'main', ['appVersion' => $appVersion, 'defaultView' => $defaultView]); }
/** * Updates the tags of the specified file path. * The passed tags are absolute, which means they will * replace the actual tag selection. * * @param array $tagName tag name to filter by * @return FileInfo[] list of matching files * @throws \Exception if the tag does not exist */ public function getFilesByTag($tagName) { $nodes = $this->homeFolder->searchByTag($tagName, $this->userSession->getUser()->getUId()); foreach ($nodes as &$node) { $node = $node->getFileInfo(); } return $nodes; }
/** * Util constructor. * * @param View $files * @param Crypt $crypt * @param ILogger $logger * @param IUserSession $userSession * @param IConfig $config */ public function __construct(View $files, Crypt $crypt, ILogger $logger, IUserSession $userSession, IConfig $config) { $this->files = $files; $this->crypt = $crypt; $this->logger = $logger; $this->user = $userSession && $userSession->isLoggedIn() ? $userSession->getUser() : false; $this->config = $config; }
/** * @param ILogger $logger * @param IUserSession $userSession * @param IConfig $config * @param IL10N $l */ public function __construct(ILogger $logger, IUserSession $userSession, IConfig $config, IL10N $l) { $this->logger = $logger; $this->user = $userSession && $userSession->isLoggedIn() ? $userSession->getUser()->getUID() : '"no user given"'; $this->config = $config; $this->l = $l; $this->supportedKeyFormats = ['hash', 'password']; }
/** * Returns whether the currently logged in user is an administrator */ private function isAdmin() { $user = $this->userSession->getUser(); if ($user !== null) { return $this->groupManager->isAdmin($user->getUID()); } return false; }
/** * @NoAdminRequired * * @param string $pattern * @param bool $filterGroups * @return DataResponse */ public function index($pattern = '', $filterGroups = false) { $groupPattern = $filterGroups ? $pattern : ''; $groupsInfo = new \OC\Group\MetaData($this->userSession->getUser()->getUID(), $this->isAdmin, $this->groupManager); $groupsInfo->setSorting($groupsInfo::SORT_USERCOUNT); list($adminGroups, $groups) = $groupsInfo->get($groupPattern, $pattern); return new DataResponse(array('data' => array('adminGroups' => $adminGroups, 'groups' => $groups))); }
/** * @param \Sabre\DAV\Tree $tree tree * @param IUserSession $userSession user session * @param \OCP\Files\Folder $userFolder user home folder * @param \OCP\Share\IManager $shareManager share manager */ public function __construct(\Sabre\DAV\Tree $tree, IUserSession $userSession, \OCP\Files\Folder $userFolder, \OCP\Share\IManager $shareManager) { $this->tree = $tree; $this->shareManager = $shareManager; $this->userFolder = $userFolder; $this->userId = $userSession->getUser()->getUID(); $this->cachedShareTypes = []; }
/** * @param IUserSession $session * @return string */ protected function getCurrentUser(IUserSession $session) { $user = $session->getUser(); if ($user instanceof IUser) { $user = $user->getUID(); } return (string) $user; }
/** * @dataProvider usersProvider * @param $query * @param $uid */ public function testImpersonate($query, $uid) { $user = $this->getMock('\\OCP\\IUser'); $user->expects($this->once())->method('getUID')->will($this->returnValue($uid)); $this->userManager->expects($this->once())->method('search')->with($query, 1, 0)->will($this->returnValue([$user])); $this->userSession->expects($this->once())->method('setUser')->with($user); $this->assertEquals(new JSONResponse(), $this->controller->impersonate($query)); }
protected function manipulateStorageConfig(StorageConfig $storage) { /** @var AuthMechanism */ $authMechanism = $storage->getAuthMechanism(); $authMechanism->manipulateStorageConfig($storage, $this->userSession->getUser()); /** @var Backend */ $backend = $storage->getBackend(); $backend->manipulateStorageConfig($storage, $this->userSession->getUser()); }
public function __construct($AppName, IRequest $request, IUserSession $session, IConfig $settings) { parent::__construct($AppName, $request); $this->request = $request; $this->current_user = $session->getUser()->getUID(); $this->content = array(); $this->settings = $settings; $this->app = $AppName; }
protected function prepareForInitCollections() { $this->user->expects($this->any())->method('getUID')->will($this->returnValue('alice')); $this->userSession->expects($this->once())->method('getUser')->will($this->returnValue($this->user)); $this->dispatcher->addListener(CommentsEntityEvent::EVENT_ENTITY, function (CommentsEntityEvent $event) { $event->addEntityCollection('files', function () { return true; }); }); }
public function testGetApps() { $user = $this->generateUsers(); $this->groupManager->get('admin')->addUser($user); $this->userSession->setUser($user); $result = $this->api->getApps([]); $this->assertTrue($result->succeeded()); $data = $result->getData(); $this->assertEquals(count(\OC_App::listAllApps()), count($data['apps'])); }
/** * 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(); }
private function asSubAdminOfGroup($group) { $user = $this->createUser('subAdmin'); $this->userSession->method('getUser')->willReturn($user); $this->subAdminManager->method('isSubAdminOfGroup')->will($this->returnCallback(function ($_user, $_group) use($user, $group) { if ($_user === $user && $_group === $group) { return true; } return false; })); }
/** * test updatePrivateKeyPassword() if wrong new password was entered */ public function testUpdatePrivateKeyPasswordWrongNewPassword() { $oldPassword = '******'; $newPassword = '******'; $this->userSessionMock->expects($this->once())->method('getUID')->willReturn('uid'); $this->userManagerMock->expects($this->exactly(2))->method('checkPassword')->willReturn(false); $result = $this->controller->updatePrivateKeyPassword($oldPassword, $newPassword); $data = $result->getData(); $this->assertSame(Http::STATUS_BAD_REQUEST, $result->getStatus()); $this->assertSame('The current log-in password was not correct, please try again.', $data['message']); }
public function testGetApps() { $this->ocsClient->expects($this->any())->method($this->anything())->will($this->returnValue(null)); $user = $this->generateUsers(); $this->groupManager->get('admin')->addUser($user); $this->userSession->setUser($user); $result = $this->api->getApps([]); $this->assertTrue($result->succeeded()); $data = $result->getData(); $this->assertEquals(count(\OC_App::listAllApps(false, true, $this->ocsClient)), count($data['apps'])); }
/** * @param IUserSession $user * @param Crypt $crypt * @param ISecureRandom $random * @param KeyManager $keyManager * @param IConfig $config * @param IStorage $keyStorage * @param IFile $file * @param View $view */ public function __construct(IUserSession $user, Crypt $crypt, ISecureRandom $random, KeyManager $keyManager, IConfig $config, IStorage $keyStorage, IFile $file, View $view) { $this->user = $user && $user->isLoggedIn() ? $user->getUser() : false; $this->crypt = $crypt; $this->random = $random; $this->keyManager = $keyManager; $this->config = $config; $this->keyStorage = $keyStorage; $this->view = $view; $this->file = $file; }
/** * get a config value * * @return JSONResponse * * @NoAdminRequired */ public function getView() { $userId = $this->userSession->getUser()->getUID(); $app = $this->appName; try { $view = $this->config->getUserValue($userId, $app, 'currentView', 'month'); } catch (\Exception $e) { return new JSONResponse([], Http::STATUS_INTERNAL_SERVER_ERROR); } return new JSONResponse(['value' => $view]); }
/** * Create a new \OCP\ITags instance and load tags from db. * * @see \OCP\ITags * @param string $type The type identifier e.g. 'contact' or 'event'. * @param array $defaultTags An array of default tags to be used if none are stored. * @param boolean $includeShared Whether to include tags for items shared with this user by others. * @param string $userId user for which to retrieve the tags, defaults to the currently * logged in user * @return \OCP\ITags */ public function load($type, $defaultTags = array(), $includeShared = false, $userId = null) { if (is_null($userId)) { $user = $this->userSession->getUser(); if ($user === null) { // nothing we can do without a user return null; } $userId = $this->userSession->getUser()->getUId(); } return new Tags($this->mapper, $userId, $type, $defaultTags, $includeShared); }
/** * initializes the collection. At this point of time, we need the logged in * user. Since it is not the case when the instance is created, we cannot * have this in the constructor. * * @throws NotAuthenticated */ protected function initCollections() { if (!empty($this->entityTypeCollections)) { return; } $user = $this->userSession->getUser(); if (is_null($user)) { throw new NotAuthenticated(); } $userFolder = $this->rootFolder->getUserFolder($user->getUID()); $this->entityTypeCollections['files'] = new EntityTypeCollection('files', $this->commentsManager, $userFolder, $this->userManager, $this->logger); }