Example #1
0
 public function Validate($reservationSeries)
 {
     if ($this->userSession->IsAdmin) {
         Log::Debug('User is application admin. Skipping check. UserId=%s', $this->userSession->UserId);
         return new ReservationRuleResult(true);
     }
     if ($this->userSession->IsGroupAdmin || $this->userSession->IsResourceAdmin || $this->userSession->IsScheduleAdmin) {
         if ($this->userSession->IsGroupAdmin) {
             $user = $this->userRepository->LoadById($this->userSession->UserId);
             $reservationUser = $this->userRepository->LoadById($reservationSeries->UserId());
             if ($user->IsAdminFor($reservationUser)) {
                 Log::Debug('User is admin for reservation user. Skipping check. UserId=%s', $this->userSession->UserId);
                 return new ReservationRuleResult(true);
             }
         }
         if ($this->userSession->IsResourceAdmin || $this->userSession->IsScheduleAdmin) {
             $user = $this->userRepository->LoadById($this->userSession->UserId);
             $isResourceAdmin = true;
             foreach ($reservationSeries->AllResources() as $resource) {
                 if (!$user->IsResourceAdminFor($resource)) {
                     $isResourceAdmin = false;
                     break;
                 }
             }
             if ($isResourceAdmin) {
                 Log::Debug('User is admin for all resources. Skipping check. UserId=%s', $this->userSession->UserId);
                 return new ReservationRuleResult(true);
             }
         }
     }
     return $this->rule->Validate($reservationSeries);
 }
 public function testIfUserIsNotAdminForAtLeastOneResource_InvokeBaseRule()
 {
     $expectedResult = new ReservationValidationResult(false, array('some error'));
     $this->fakeUser->IsAdmin = false;
     $this->userRepository->expects($this->once())->method('LoadById')->with($this->equalTo($this->fakeUser->UserId))->will($this->returnValue($this->user));
     $this->user->expects($this->at(0))->method('IsResourceAdminFor')->with($this->equalTo($this->resource1))->will($this->returnValue(true));
     $this->user->expects($this->at(1))->method('IsResourceAdminFor')->with($this->equalTo($this->resource2))->will($this->returnValue(false));
     $this->baseRule->expects($this->once())->method('Validate')->with($this->equalTo($this->reservationSeries))->will($this->returnValue($expectedResult));
     $result = $this->rule->Validate($this->reservationSeries);
     $this->assertEquals($expectedResult, $result);
 }