/**
  * @param int $userId
  * @return User|void
  */
 public function LoadById($userId)
 {
     $user = parent::LoadById($userId);
     $me = parent::LoadById($this->userSession->UserId);
     if ($userId == $this->userSession->UserId || $me->IsAdminFor($user)) {
         return $user;
     }
     return User::Null();
 }
Example #2
0
 /**
  * @param $command SqlCommand
  * @return User
  */
 private function Load($command)
 {
     $reader = ServiceLocator::GetDatabase()->Query($command);
     if ($row = $reader->GetRow()) {
         $userId = $row[ColumnNames::USER_ID];
         $emailPreferences = $this->LoadEmailPreferences($userId);
         $permissions = $this->LoadPermissions($userId);
         $groups = $this->LoadGroups($userId);
         $user = User::FromRow($row);
         $user->WithEmailPreferences($emailPreferences);
         $user->WithPermissions($permissions);
         $user->WithGroups($groups);
         $this->LoadAttributes($userId, $user);
         if ($user->IsGroupAdmin()) {
             $ownedGroups = $this->LoadOwnedGroups($userId);
             $user->WithOwnedGroups($ownedGroups);
         }
         $preferences = $this->LoadPreferences($userId);
         $user->WithPreferences($preferences);
         $user->WithDefaultSchedule($row[ColumnNames::DEFAULT_SCHEDULE_ID]);
         $this->_cache->Add($userId, $user);
         return $user;
     } else {
         return User::Null();
     }
 }
 public function testWhenUserIsNotFound()
 {
     $userId = 999;
     $this->HideUsers(false);
     $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::Null()));
     $expectedResponse = RestResponse::NotFound();
     $this->service->GetUser($userId);
     $this->assertEquals($expectedResponse, $this->server->_LastResponse);
     $this->assertEquals(RestResponse::NOT_FOUND_CODE, $this->server->_LastResponseCode);
 }