1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 00:42:41 +01:00

Make .ics export less scary and attach .ics files to event mail

Summary:
Ref T10747.

  - Remove the warning dialog since these files don't seem to do anything confusing/problematic in Calendar.app or Google Calendar. Those importers generally need to be defensive about how they handle random ".ics" files from arbitrary third parties anyway, and this makes testing imports easier since we have a GET-table ".ics" URI for public events.
  - Attach ".ics" files to email.

Test Plan:
  - Clicked "Export as .ics", got an ICS file.
  - Used "bin/mail show-outbound" to review an ICS attachment, although I don't actually have real mail set up locally so this may still be a little funky.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10747

Differential Revision: https://secure.phabricator.com/D16559
This commit is contained in:
epriestley 2016-09-15 06:27:20 -07:00
parent 96f800249b
commit 3d6c3c2c45
5 changed files with 43 additions and 30 deletions

View file

@ -59,7 +59,7 @@ final class PhabricatorCalendarApplication extends PhabricatorApplication {
=> 'PhabricatorCalendarEventCancelController',
'(?P<action>join|decline|accept)/(?P<id>[1-9]\d*)/'
=> 'PhabricatorCalendarEventJoinController',
'export/(?P<id>[1-9]\d*)/'
'export/(?P<id>[1-9]\d*)/(?P<filename>[^/]*)'
=> 'PhabricatorCalendarEventExportController',
),
),

View file

@ -19,36 +19,22 @@ final class PhabricatorCalendarEventExportController
return new Aphront404Response();
}
if ($request->isFormPost()) {
$file_name = $event->getMonogram().'.ics';
$file_name = $event->getICSFilename();
$event_node = $event->newIntermediateEventNode($viewer);
$event_node = $event->newIntermediateEventNode($viewer);
$document_node = id(new PhutilCalendarDocumentNode())
->appendChild($event_node);
$document_node = id(new PhutilCalendarDocumentNode())
->appendChild($event_node);
$root_node = id(new PhutilCalendarRootNode())
->appendChild($document_node);
$root_node = id(new PhutilCalendarRootNode())
->appendChild($document_node);
$ics_data = id(new PhutilICSWriter())
->writeICSDocument($root_node);
return id(new AphrontFileResponse())
->setDownload($file_name)
->setMimeType('text/calendar')
->setContent($ics_data);
}
return $this->newDialog()
->setDisableWorkflowOnSubmit(true)
->setTitle(pht('Export as .ics'))
->appendParagraph(
pht(
'WARNING: This feature is a prototype and only supports a limited '.
'set of features. Keep your expectations low!'))
->addSubmitButton(pht('Download .ics'))
->addCancelButton($event->getURI(), pht('Close'));
$ics_data = id(new PhutilICSWriter())
->writeICSDocument($root_node);
return id(new AphrontFileResponse())
->setDownload($file_name)
->setMimeType('text/calendar')
->setContent($ics_data);
}
}

View file

@ -193,14 +193,14 @@ final class PhabricatorCalendarEventViewController
->setWorkflow(true));
}
$export_uri = $this->getApplicationURI("event/export/{$id}/");
$ics_name = $event->getICSFilename();
$export_uri = $this->getApplicationURI("event/export/{$id}/{$ics_name}");
$curtain->addAction(
id(new PhabricatorActionView())
->setName(pht('Export as .ics'))
->setIcon('fa-download')
->setHref($export_uri)
->setWorkflow(true));
->setHref($export_uri));
return $curtain;
}

View file

@ -285,6 +285,8 @@ final class PhabricatorCalendarEventEditor
pht('EVENT DETAIL'),
PhabricatorEnv::getProductionURI('/E'.$object->getID()));
$ics_attachment = $this->newICSAttachment($object);
$body->addAttachment($ics_attachment);
return $body;
}
@ -303,5 +305,27 @@ final class PhabricatorCalendarEventEditor
->setObject($object);
}
private function newICSAttachment(
PhabricatorCalendarEvent $event) {
$actor = $this->getActor();
$event_node = $event->newIntermediateEventNode($actor);
$document_node = id(new PhutilCalendarDocumentNode())
->appendChild($event_node);
$root_node = id(new PhutilCalendarRootNode())
->appendChild($document_node);
$ics_data = id(new PhutilICSWriter())
->writeICSDocument($root_node);
$ics_attachment = new PhabricatorMetaMTAAttachment(
$ics_data,
$event->getICSFilename(),
'text/calendar');
return $ics_attachment;
}
}

View file

@ -625,6 +625,9 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
return null;
}
public function getICSFilename() {
return $this->getMonogram().'.ics';
}
public function newIntermediateEventNode(PhabricatorUser $viewer) {
$base_uri = new PhutilURI(PhabricatorEnv::getProductionURI('/'));