/** * @name GetUser * @description Loads the requested user by Id * @response UserResponse * @param int $userId * @return void */ public function GetUser($userId) { $responseCode = RestResponse::OK_CODE; $hideUsers = Configuration::Instance()->GetSectionKey(ConfigSection::PRIVACY, ConfigKeys::PRIVACY_HIDE_USER_DETAILS, new BooleanConverter()); $userSession = $this->server->GetSession(); $repository = $this->repositoryFactory->Create($userSession); $user = $repository->LoadById($userId); $loadedUserId = $user->Id(); if (empty($loadedUserId)) { $this->server->WriteResponse(RestResponse::NotFound(), RestResponse::NOT_FOUND_CODE); return; } $attributes = $this->attributeService->GetAttributes(CustomAttributeCategory::USER, array($userId)); if ($userId == $userSession->UserId || !$hideUsers || $userSession->IsAdmin) { $response = new UserResponse($this->server, $user, $attributes); } else { $me = $repository->LoadById($userSession->UserId); if ($me->IsAdminFor($user)) { $response = new UserResponse($this->server, $user, $attributes); } else { $response = RestResponse::Unauthorized(); $responseCode = RestResponse::UNAUTHORIZED_CODE; } } $this->server->WriteResponse($response, $responseCode); }
public function testWhenNotHidingUserDetails() { $this->HideUsers(false); $userId = 999; $user = new FakeUser($userId); $attributes = $this->getMock('IEntityAttributeList'); $this->userRepositoryFactory->expects($this->once())->method('Create')->with($this->equalTo($this->server->GetSession()))->will($this->returnValue($this->userRepository)); $this->userRepository->expects($this->at(0))->method('LoadById')->with($this->equalTo($userId))->will($this->returnValue($user)); $this->attributeService->expects($this->once())->method('GetAttributes')->with($this->equalTo(CustomAttributeCategory::USER), $this->equalTo(array($userId)))->will($this->returnValue($attributes)); $expectedResponse = new UserResponse($this->server, $user, $attributes); $this->service->GetUser($userId); $this->assertEquals($expectedResponse, $this->server->_LastResponse); }