Exemple #1
0
 /**
  * @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 testWhenScheduleNotFound()
 {
     $scheduleId = 89181;
     $this->scheduleRepository->expects($this->once())->method('LoadById')->with($this->equalTo($scheduleId))->will($this->returnValue(null));
     $this->service->GetSchedule($scheduleId);
     $this->assertEquals(RestResponse::NotFound(), $this->server->_LastResponse);
 }
 public function testWhenAttributeNotFound()
 {
     $attributeId = 123;
     $this->attributeService->expects($this->once())->method('GetById')->with($this->equalTo($attributeId))->will($this->returnValue(null));
     $this->service->GetAttribute($attributeId);
     $this->assertEquals(RestResponse::NotFound(), $this->server->_LastResponse);
 }
 public function testWhenNotFound()
 {
     $resourceId = 8282;
     $this->repository->expects($this->once())->method('LoadById')->with($this->equalTo($resourceId))->will($this->returnValue(BookableResource::Null()));
     $this->service->GetResource($resourceId);
     $this->assertEquals(RestResponse::NotFound(), $this->server->_LastResponse);
 }
 public function testWhenAccessoryNotFound()
 {
     $accessoryId = 1233;
     $this->accessoryRepository->expects($this->once())->method('LoadById')->with($this->equalTo($accessoryId))->will($this->returnValue(null));
     $this->service->GetAccessory($accessoryId);
     $this->assertEquals(RestResponse::NotFound(), $this->server->_LastResponse);
     $this->assertEquals(RestResponse::NOT_FOUND_CODE, $this->server->_LastResponseCode);
 }
 /**
  * @name GetAttribute
  * @description Gets all custom attribute definitions for the requested attribute
  * @response CustomAttributeDefinitionResponse
  * @return void
  * @param int $attributeId
  */
 public function GetAttribute($attributeId)
 {
     $attribute = $this->attributeService->GetById($attributeId);
     if ($attribute != null) {
         $this->server->WriteResponse(new CustomAttributeDefinitionResponse($this->server, $attribute));
     } else {
         $this->server->WriteResponse(RestResponse::NotFound(), RestResponse::NOT_FOUND_CODE);
     }
 }
Exemple #7
0
 /**
  * @name GetGroup
  * @description Loads a specific group by id
  * @response GroupResponse
  * @param int $groupId
  * @return void
  */
 public function GetGroup($groupId)
 {
     $group = $this->groupRepository->LoadById($groupId);
     if ($group != null) {
         $this->server->WriteResponse(new GroupResponse($this->server, $group));
     } else {
         $this->server->WriteResponse(RestResponse::NotFound(), RestResponse::NOT_FOUND_CODE);
     }
 }
 /**
  * @name GetAccessory
  * @description Loads a specific accessory by id
  * @param int $accessoryId
  * @response AccessoryResponse
  * @return void
  */
 public function GetAccessory($accessoryId)
 {
     $accessory = $this->accessoryRepository->LoadById($accessoryId);
     if (empty($accessory)) {
         $this->server->WriteResponse(RestResponse::NotFound(), RestResponse::NOT_FOUND_CODE);
     } else {
         $this->server->WriteResponse(new AccessoryResponse($this->server, $accessory));
     }
 }
 public function testWhenGroupIsNotFound()
 {
     $groupId = 999;
     $this->groupRepository->expects($this->once())->method('LoadById')->with($this->equalTo($groupId))->will($this->returnValue(null));
     $expectedResponse = RestResponse::NotFound();
     $this->service->GetGroup($groupId);
     $this->assertEquals($expectedResponse, $this->server->_LastResponse);
     $this->assertEquals(RestResponse::NOT_FOUND_CODE, $this->server->_LastResponseCode);
 }
 /**
  * @name GetSchedule
  * @description Loads a specific schedule by id
  * @response ScheduleResponse
  * @param $scheduleId
  * @return void
  */
 public function GetSchedule($scheduleId)
 {
     $schedule = $this->scheduleRepository->LoadById($scheduleId);
     if ($schedule != null) {
         $layout = $this->scheduleRepository->GetLayout($schedule->GetId(), new ScheduleLayoutFactory($this->server->GetSession()->Timezone));
         $this->server->WriteResponse(new ScheduleResponse($this->server, $schedule, $layout));
     } else {
         $this->server->WriteResponse(RestResponse::NotFound(), RestResponse::NOT_FOUND_CODE);
     }
 }
 /**
  * @name GetResource
  * @description Loads a specific resource by id
  * @param int $resourceId
  * @response ResourceResponse
  * @return void
  */
 public function GetResource($resourceId)
 {
     $resource = $this->resourceRepository->LoadById($resourceId);
     $resourceId = $resource->GetResourceId();
     if (empty($resourceId)) {
         $this->server->WriteResponse(RestResponse::NotFound(), RestResponse::NOT_FOUND_CODE);
     } else {
         $attributes = $this->attributeService->GetAttributes(CustomAttributeCategory::RESOURCE, array($resourceId));
         $this->server->WriteResponse(new ResourceResponse($this->server, $resource, $attributes));
     }
 }
 /**
  * @name GetReservation
  * @param string $referenceNumber
  * @description Loads a specific reservation by reference number
  * @response ReservationResponse
  * @return void
  */
 public function GetReservation($referenceNumber)
 {
     Log::Debug('GetReservation called. $referenceNumber=%s', $referenceNumber);
     $reservation = $this->reservationViewRepository->GetReservationForEditing($referenceNumber);
     if (!empty($reservation->ReferenceNumber)) {
         $attributes = $this->attributeService->GetByCategory(CustomAttributeCategory::RESERVATION);
         $response = new ReservationResponse($this->server, $reservation, $this->privacyFilter, $attributes);
         $this->server->WriteResponse($response);
     } else {
         $this->server->WriteResponse($response = RestResponse::NotFound(), RestResponse::NOT_FOUND_CODE);
     }
 }
 public function testWhenReservationIsNotFound()
 {
     $reservation = NullReservationView::Instance();
     $referenceNumber = '12323';
     $this->reservationViewRepository->expects($this->once())->method('GetReservationForEditing')->with($this->equalTo($referenceNumber))->will($this->returnValue($reservation));
     $this->service->GetReservation($referenceNumber);
     $expectedResponse = RestResponse::NotFound();
     $this->assertEquals($expectedResponse, $this->server->_LastResponse);
 }
 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);
 }