Page MenuHomePhabricator

D12618.diff
No OneTemporary

D12618.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -1488,6 +1488,7 @@
'PhabricatorCalendarEventInvalidEpochException' => 'applications/calendar/exception/PhabricatorCalendarEventInvalidEpochException.php',
'PhabricatorCalendarEventInvitee' => 'applications/calendar/storage/PhabricatorCalendarEventInvitee.php',
'PhabricatorCalendarEventInviteeQuery' => 'applications/calendar/query/PhabricatorCalendarEventInviteeQuery.php',
+ 'PhabricatorCalendarEventJoinController' => 'applications/calendar/controller/PhabricatorCalendarEventJoinController.php',
'PhabricatorCalendarEventListController' => 'applications/calendar/controller/PhabricatorCalendarEventListController.php',
'PhabricatorCalendarEventPHIDType' => 'applications/calendar/phid/PhabricatorCalendarEventPHIDType.php',
'PhabricatorCalendarEventQuery' => 'applications/calendar/query/PhabricatorCalendarEventQuery.php',
@@ -4824,6 +4825,7 @@
'PhabricatorPolicyInterface',
),
'PhabricatorCalendarEventInviteeQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
+ 'PhabricatorCalendarEventJoinController' => 'PhabricatorCalendarController',
'PhabricatorCalendarEventListController' => 'PhabricatorCalendarController',
'PhabricatorCalendarEventPHIDType' => 'PhabricatorPHIDType',
'PhabricatorCalendarEventQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
diff --git a/src/applications/calendar/application/PhabricatorCalendarApplication.php b/src/applications/calendar/application/PhabricatorCalendarApplication.php
--- a/src/applications/calendar/application/PhabricatorCalendarApplication.php
+++ b/src/applications/calendar/application/PhabricatorCalendarApplication.php
@@ -53,6 +53,8 @@
=> 'PhabricatorCalendarEventEditController',
'cancel/(?P<id>[1-9]\d*)/'
=> 'PhabricatorCalendarEventCancelController',
+ 'join/(?P<id>[1-9]\d*)/'
+ => 'PhabricatorCalendarEventJoinController',
),
),
);
diff --git a/src/applications/calendar/controller/PhabricatorCalendarEventJoinController.php b/src/applications/calendar/controller/PhabricatorCalendarEventJoinController.php
new file mode 100644
--- /dev/null
+++ b/src/applications/calendar/controller/PhabricatorCalendarEventJoinController.php
@@ -0,0 +1,74 @@
+<?php
+
+final class PhabricatorCalendarEventJoinController
+ extends PhabricatorCalendarController {
+
+ private $id;
+
+ public function handleRequest(AphrontRequest $request) {
+ $this->id = $request->getURIData('id');
+ $request = $this->getRequest();
+ $viewer = $request->getViewer();
+ $declined_status = PhabricatorCalendarEventInvitee::STATUS_DECLINED;
+ $attending_status = PhabricatorCalendarEventInvitee::STATUS_ATTENDING;
+
+ $event = id(new PhabricatorCalendarEventQuery())
+ ->setViewer($viewer)
+ ->withIDs(array($this->id))
+ ->executeOne();
+
+ if (!$event) {
+ return new Aphront404Response();
+ }
+
+ $cancel_uri = '/E'.$event->getID();
+ $validation_exception = null;
+
+ $is_attending = $event->getIsUserAttending($viewer->getPHID());
+
+ if ($request->isFormPost()) {
+ $new_status = null;
+
+ if ($is_attending) {
+ $new_status = array($viewer->getPHID() => $declined_status);
+ } else {
+ $new_status = array($viewer->getPHID() => $attending_status);
+ }
+
+ $xaction = id(new PhabricatorCalendarEventTransaction())
+ ->setTransactionType(
+ PhabricatorCalendarEventTransaction::TYPE_INVITE)
+ ->setNewValue($new_status);
+
+ $editor = id(new PhabricatorCalendarEventEditor())
+ ->setActor($viewer)
+ ->setContentSourceFromRequest($request)
+ ->setContinueOnNoEffect(true)
+ ->setContinueOnMissingFields(true);
+
+ try {
+ $editor->applyTransactions($event, array($xaction));
+ return id(new AphrontRedirectResponse())->setURI($cancel_uri);
+ } catch (PhabricatorApplicationTransactionValidationException $ex) {
+ $validation_exception = $ex;
+ }
+ }
+
+ if (!$is_attending) {
+ $title = pht('Join Event');
+ $paragraph = pht('Would you like to join this event?');
+ $submit = pht('Join');
+ } else {
+ $title = pht('Decline Event');
+ $paragraph = pht('Would you like to decline this event?');
+ $submit = pht('Decline');
+ }
+
+ return $this->newDialog()
+ ->setTitle($title)
+ ->setValidationException($validation_exception)
+ ->appendParagraph($paragraph)
+ ->addCancelButton($cancel_uri)
+ ->addSubmitButton($submit);
+ }
+}
diff --git a/src/applications/calendar/controller/PhabricatorCalendarEventViewController.php b/src/applications/calendar/controller/PhabricatorCalendarEventViewController.php
--- a/src/applications/calendar/controller/PhabricatorCalendarEventViewController.php
+++ b/src/applications/calendar/controller/PhabricatorCalendarEventViewController.php
@@ -72,6 +72,7 @@
$viewer = $this->getRequest()->getUser();
$id = $event->getID();
$is_cancelled = $event->getIsCancelled();
+ $is_attending = $event->getIsUserAttending($viewer->getPHID());
$actions = id(new PhabricatorActionListView())
->setObjectURI($this->getApplicationURI('event/'.$id.'/'))
@@ -91,6 +92,22 @@
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit));
+ if ($is_attending) {
+ $actions->addAction(
+ id(new PhabricatorActionView())
+ ->setName(pht('Decline Event'))
+ ->setIcon('fa-user-times')
+ ->setHref($this->getApplicationURI("event/join/{$id}/"))
+ ->setWorkflow(true));
+ } else {
+ $actions->addAction(
+ id(new PhabricatorActionView())
+ ->setName(pht('Join Event'))
+ ->setIcon('fa-user-plus')
+ ->setHref($this->getApplicationURI("event/join/{$id}/"))
+ ->setWorkflow(true));
+ }
+
if ($is_cancelled) {
$actions->addAction(
id(new PhabricatorActionView())
diff --git a/src/applications/calendar/storage/PhabricatorCalendarEvent.php b/src/applications/calendar/storage/PhabricatorCalendarEvent.php
--- a/src/applications/calendar/storage/PhabricatorCalendarEvent.php
+++ b/src/applications/calendar/storage/PhabricatorCalendarEvent.php
@@ -130,6 +130,27 @@
return $this;
}
+ public function getUserInviteStatus($phid) {
+ $invitees = $this->getInvitees();
+ $invitees = mpull($invitees, null, 'getInviteePHID');
+
+ $invited = idx($invitees, $phid);
+ if (!$invited) {
+ return PhabricatorCalendarEventInvitee::STATUS_UNINVITED;
+ }
+ $invited = $invited->getStatus();
+ return $invited;
+ }
+
+ public function getIsUserAttending($phid) {
+ $attending_status = PhabricatorCalendarEventInvitee::STATUS_ATTENDING;
+
+ $old_status = $this->getUserInviteStatus($phid);
+ $is_attending = ($old_status == $attending_status);
+
+ return $is_attending;
+ }
+
/**
* Validates data and throws exceptions for non-sensical status
* windows
diff --git a/src/applications/calendar/storage/PhabricatorCalendarEventTransaction.php b/src/applications/calendar/storage/PhabricatorCalendarEventTransaction.php
--- a/src/applications/calendar/storage/PhabricatorCalendarEventTransaction.php
+++ b/src/applications/calendar/storage/PhabricatorCalendarEventTransaction.php
@@ -66,9 +66,11 @@
case self::TYPE_STATUS:
case self::TYPE_DESCRIPTION:
case self::TYPE_CANCEL:
- case self::TYPE_INVITE:
return 'fa-pencil';
break;
+ case self::TYPE_INVITE:
+ return 'fa-user-plus';
+ break;
}
return parent::getIcon();
}

File Metadata

Mime Type
text/plain
Expires
Mon, Oct 28, 7:58 PM (3 w, 10 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6730988
Default Alt Text
D12618.diff (7 KB)

Event Timeline