/** * @Route("/{id}/event/create", name="oro_system_calendar_event_create", requirements={"id"="\d+"}) * @Template("OroCalendarBundle:SystemCalendarEvent:update.html.twig") */ public function createAction(SystemCalendar $calendar) { $this->checkPermissionByConfig($calendar); $securityFacade = $this->getSecurityFacade(); $isGranted = $calendar->isPublic() ? $securityFacade->isGranted('oro_public_calendar_event_management') : $securityFacade->isGranted('oro_system_calendar_event_management'); if (!$isGranted) { throw new AccessDeniedException(); } $entity = new CalendarEvent(); $startTime = new \DateTime('now', new \DateTimeZone('UTC')); $endTime = new \DateTime('now', new \DateTimeZone('UTC')); $endTime->add(new \DateInterval('PT1H')); $entity->setStart($startTime); $entity->setEnd($endTime); $entity->setSystemCalendar($calendar); return $this->update($entity, $this->get('router')->generate('oro_system_calendar_event_create', ['id' => $calendar->getId()])); }
/** * Links an event with a calendar by its alias and id * * @param CalendarEvent $event * @param string $calendarAlias * @param int $calendarId * * @throws \LogicException * @throws ForbiddenException */ public function setCalendar(CalendarEvent $event, $calendarAlias, $calendarId) { if ($calendarAlias === Calendar::CALENDAR_ALIAS) { $calendar = $event->getCalendar(); if (!$calendar || $calendar->getId() !== $calendarId) { $event->setCalendar($this->findCalendar($calendarId)); } } elseif (in_array($calendarAlias, [SystemCalendar::CALENDAR_ALIAS, SystemCalendar::PUBLIC_CALENDAR_ALIAS])) { $systemCalendar = $this->findSystemCalendar($calendarId); //@TODO: Added permission verification if ($systemCalendar->isPublic() && !$this->calendarConfig->isPublicCalendarEnabled()) { throw new ForbiddenException('Public calendars are disabled.'); } if (!$systemCalendar->isPublic() && !$this->calendarConfig->isSystemCalendarEnabled()) { throw new ForbiddenException('System calendars are disabled.'); } $event->setSystemCalendar($systemCalendar); } else { throw new \LogicException(sprintf('Unexpected calendar alias: "%s". CalendarId: %d.', $calendarAlias, $calendarId)); } }
public function testSetCalendar() { $calendar = new Calendar(); $systemCalendar = new SystemCalendar(); $obj = new CalendarEvent(); $this->assertNull($obj->getCalendar()); $this->assertNull($obj->getSystemCalendar()); $obj->setCalendar($calendar); $this->assertSame($calendar, $obj->getCalendar()); $this->assertNull($obj->getSystemCalendar()); $obj->setSystemCalendar($systemCalendar); $this->assertNull($obj->getCalendar()); $this->assertSame($systemCalendar, $obj->getSystemCalendar()); $obj->setCalendar($calendar); $this->assertSame($calendar, $obj->getCalendar()); $this->assertNull($obj->getSystemCalendar()); $obj->setCalendar(null); $this->assertNull($obj->getCalendar()); $obj->setSystemCalendar($systemCalendar); $this->assertNull($obj->getCalendar()); $this->assertSame($systemCalendar, $obj->getSystemCalendar()); $obj->setSystemCalendar(null); $this->assertNull($obj->getCalendar()); $this->assertNull($obj->getSystemCalendar()); }
/** * @expectedException \Oro\Bundle\SecurityBundle\Exception\ForbiddenException * @expectedExceptionMessage Access denied. */ public function testHandleDeleteWhenSystemCalendarEventManagementNotGranted() { $calendar = new SystemCalendar(); $event = new CalendarEvent(); $event->setSystemCalendar($calendar); $this->manager->expects($this->once())->method('find')->will($this->returnValue($event)); $this->calendarConfig->expects($this->once())->method('isSystemCalendarEnabled')->will($this->returnValue(true)); $this->securityFacade->expects($this->once())->method('isGranted')->with('oro_system_calendar_event_management')->will($this->returnValue(false)); $this->handler->handleDelete(1, $this->manager); }
/** * Adds an event to the calendar. * * @param CalendarEvent $event * * @return self */ public function addEvent(CalendarEvent $event) { $this->events[] = $event; $event->setSystemCalendar($this); return $this; }