diff --git a/src/applications/calendar/controller/PhabricatorCalendarImportEditController.php b/src/applications/calendar/controller/PhabricatorCalendarImportEditController.php --- a/src/applications/calendar/controller/PhabricatorCalendarImportEditController.php +++ b/src/applications/calendar/controller/PhabricatorCalendarImportEditController.php @@ -4,11 +4,27 @@ extends PhabricatorCalendarController { public function handleRequest(AphrontRequest $request) { + $engine = id(new PhabricatorCalendarImportEditEngine()) ->setController($this); $id = $request->getURIData('id'); - if (!$id) { + if ($id) { + + // edit a specific entry + + $calendar_import = self::querySingleCalendarImportByID($request, $id); + if (!$calendar_import) { + return new Aphront404Response(); + } + + // pass the correct import engine to build the response + $engine->setImportEngine($calendar_import->getEngine()); + + } else { + + // create an entry + $list_uri = $this->getApplicationURI('import/'); $import_type = $request->getStr('importType'); @@ -27,6 +43,18 @@ return $engine->buildResponse(); } + private static function querySingleCalendarImportByID(AphrontRequest $request, int $id) { + return id(new PhabricatorCalendarImportQuery()) + ->setViewer($request->getViewer()) + ->withIDs(array($id)) + ->requireCapabilities( + array( + PhabricatorPolicyCapability::CAN_VIEW, + PhabricatorPolicyCapability::CAN_EDIT, + )) + ->executeOne(); + } + private function buildEngineTypeResponse($cancel_uri) { $import_engines = PhabricatorCalendarImportEngine::getAllImportEngines(); diff --git a/src/applications/calendar/editor/PhabricatorCalendarImportEditEngine.php b/src/applications/calendar/editor/PhabricatorCalendarImportEditEngine.php --- a/src/applications/calendar/editor/PhabricatorCalendarImportEditEngine.php +++ b/src/applications/calendar/editor/PhabricatorCalendarImportEditEngine.php @@ -83,6 +83,12 @@ $engine = $object->getEngine(); $can_trigger = $engine->supportsTriggers($object); + // calendar URI import + // note that it can contains a secret token + // if we are here the user has enough privileges to edit this page and see the value + $uri_key = PhabricatorCalendarImportICSURITransaction::PARAMKEY_URI; + $uri = $object->getParameter($uri_key); + $fields = array( id(new PhabricatorTextEditField()) ->setKey('name') @@ -94,6 +100,15 @@ ->setConduitTypeDescription(pht('New import name.')) ->setPlaceholder($object->getDisplayName()) ->setValue($object->getName()), + id(new PhabricatorTextEditField()) + ->setKey('uri') + ->setLabel(pht('URI')) + ->setDescription(pht('URI to import.')) + ->setTransactionType( + PhabricatorCalendarImportICSURITransaction::TRANSACTIONTYPE) + ->setConduitDescription(pht('URI to import.')) + ->setConduitTypeDescription(pht('New URI.')) + ->setValue($uri), id(new PhabricatorBoolEditField()) ->setKey('disabled') ->setOptions(pht('Active'), pht('Disabled')) diff --git a/src/applications/calendar/query/PhabricatorCalendarEventQuery.php b/src/applications/calendar/query/PhabricatorCalendarEventQuery.php --- a/src/applications/calendar/query/PhabricatorCalendarEventQuery.php +++ b/src/applications/calendar/query/PhabricatorCalendarEventQuery.php @@ -222,12 +222,16 @@ $limit = $this->getRecurrenceLimit($event, $raw_limit); + // note that this can be NULL for some imported events $set = $event->newRecurrenceSet(); - $recurrences = $set->getEventsBetween( - $start_date, - $end_date, - $limit + 1); + $recurrences = []; + if ($set) { + $recurrences = $set->getEventsBetween( + $start_date, + $end_date, + $limit + 1); + } // We're generating events from the beginning and then filtering them // here (instead of only generating events starting at the start date)