@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Ability to join or decline an event

Summary: Ref T7986, Ability to join or decline an event.

Test Plan: Open Calendar event, join event, Invitee list should update. Decline event, invitee list should remove you.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: Korvin, epriestley

Maniphest Tasks: T7986

Differential Revision: https://secure.phabricator.com/D12618

+119 -1
+2
src/__phutil_library_map__.php
··· 1488 1488 'PhabricatorCalendarEventInvalidEpochException' => 'applications/calendar/exception/PhabricatorCalendarEventInvalidEpochException.php', 1489 1489 'PhabricatorCalendarEventInvitee' => 'applications/calendar/storage/PhabricatorCalendarEventInvitee.php', 1490 1490 'PhabricatorCalendarEventInviteeQuery' => 'applications/calendar/query/PhabricatorCalendarEventInviteeQuery.php', 1491 + 'PhabricatorCalendarEventJoinController' => 'applications/calendar/controller/PhabricatorCalendarEventJoinController.php', 1491 1492 'PhabricatorCalendarEventListController' => 'applications/calendar/controller/PhabricatorCalendarEventListController.php', 1492 1493 'PhabricatorCalendarEventPHIDType' => 'applications/calendar/phid/PhabricatorCalendarEventPHIDType.php', 1493 1494 'PhabricatorCalendarEventQuery' => 'applications/calendar/query/PhabricatorCalendarEventQuery.php', ··· 4824 4825 'PhabricatorPolicyInterface', 4825 4826 ), 4826 4827 'PhabricatorCalendarEventInviteeQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 4828 + 'PhabricatorCalendarEventJoinController' => 'PhabricatorCalendarController', 4827 4829 'PhabricatorCalendarEventListController' => 'PhabricatorCalendarController', 4828 4830 'PhabricatorCalendarEventPHIDType' => 'PhabricatorPHIDType', 4829 4831 'PhabricatorCalendarEventQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
+2
src/applications/calendar/application/PhabricatorCalendarApplication.php
··· 53 53 => 'PhabricatorCalendarEventEditController', 54 54 'cancel/(?P<id>[1-9]\d*)/' 55 55 => 'PhabricatorCalendarEventCancelController', 56 + 'join/(?P<id>[1-9]\d*)/' 57 + => 'PhabricatorCalendarEventJoinController', 56 58 ), 57 59 ), 58 60 );
+74
src/applications/calendar/controller/PhabricatorCalendarEventJoinController.php
··· 1 + <?php 2 + 3 + final class PhabricatorCalendarEventJoinController 4 + extends PhabricatorCalendarController { 5 + 6 + private $id; 7 + 8 + public function handleRequest(AphrontRequest $request) { 9 + $this->id = $request->getURIData('id'); 10 + $request = $this->getRequest(); 11 + $viewer = $request->getViewer(); 12 + $declined_status = PhabricatorCalendarEventInvitee::STATUS_DECLINED; 13 + $attending_status = PhabricatorCalendarEventInvitee::STATUS_ATTENDING; 14 + 15 + $event = id(new PhabricatorCalendarEventQuery()) 16 + ->setViewer($viewer) 17 + ->withIDs(array($this->id)) 18 + ->executeOne(); 19 + 20 + if (!$event) { 21 + return new Aphront404Response(); 22 + } 23 + 24 + $cancel_uri = '/E'.$event->getID(); 25 + $validation_exception = null; 26 + 27 + $is_attending = $event->getIsUserAttending($viewer->getPHID()); 28 + 29 + if ($request->isFormPost()) { 30 + $new_status = null; 31 + 32 + if ($is_attending) { 33 + $new_status = array($viewer->getPHID() => $declined_status); 34 + } else { 35 + $new_status = array($viewer->getPHID() => $attending_status); 36 + } 37 + 38 + $xaction = id(new PhabricatorCalendarEventTransaction()) 39 + ->setTransactionType( 40 + PhabricatorCalendarEventTransaction::TYPE_INVITE) 41 + ->setNewValue($new_status); 42 + 43 + $editor = id(new PhabricatorCalendarEventEditor()) 44 + ->setActor($viewer) 45 + ->setContentSourceFromRequest($request) 46 + ->setContinueOnNoEffect(true) 47 + ->setContinueOnMissingFields(true); 48 + 49 + try { 50 + $editor->applyTransactions($event, array($xaction)); 51 + return id(new AphrontRedirectResponse())->setURI($cancel_uri); 52 + } catch (PhabricatorApplicationTransactionValidationException $ex) { 53 + $validation_exception = $ex; 54 + } 55 + } 56 + 57 + if (!$is_attending) { 58 + $title = pht('Join Event'); 59 + $paragraph = pht('Would you like to join this event?'); 60 + $submit = pht('Join'); 61 + } else { 62 + $title = pht('Decline Event'); 63 + $paragraph = pht('Would you like to decline this event?'); 64 + $submit = pht('Decline'); 65 + } 66 + 67 + return $this->newDialog() 68 + ->setTitle($title) 69 + ->setValidationException($validation_exception) 70 + ->appendParagraph($paragraph) 71 + ->addCancelButton($cancel_uri) 72 + ->addSubmitButton($submit); 73 + } 74 + }
+17
src/applications/calendar/controller/PhabricatorCalendarEventViewController.php
··· 72 72 $viewer = $this->getRequest()->getUser(); 73 73 $id = $event->getID(); 74 74 $is_cancelled = $event->getIsCancelled(); 75 + $is_attending = $event->getIsUserAttending($viewer->getPHID()); 75 76 76 77 $actions = id(new PhabricatorActionListView()) 77 78 ->setObjectURI($this->getApplicationURI('event/'.$id.'/')) ··· 90 91 ->setHref($this->getApplicationURI("event/edit/{$id}/")) 91 92 ->setDisabled(!$can_edit) 92 93 ->setWorkflow(!$can_edit)); 94 + 95 + if ($is_attending) { 96 + $actions->addAction( 97 + id(new PhabricatorActionView()) 98 + ->setName(pht('Decline Event')) 99 + ->setIcon('fa-user-times') 100 + ->setHref($this->getApplicationURI("event/join/{$id}/")) 101 + ->setWorkflow(true)); 102 + } else { 103 + $actions->addAction( 104 + id(new PhabricatorActionView()) 105 + ->setName(pht('Join Event')) 106 + ->setIcon('fa-user-plus') 107 + ->setHref($this->getApplicationURI("event/join/{$id}/")) 108 + ->setWorkflow(true)); 109 + } 93 110 94 111 if ($is_cancelled) { 95 112 $actions->addAction(
+21
src/applications/calendar/storage/PhabricatorCalendarEvent.php
··· 130 130 return $this; 131 131 } 132 132 133 + public function getUserInviteStatus($phid) { 134 + $invitees = $this->getInvitees(); 135 + $invitees = mpull($invitees, null, 'getInviteePHID'); 136 + 137 + $invited = idx($invitees, $phid); 138 + if (!$invited) { 139 + return PhabricatorCalendarEventInvitee::STATUS_UNINVITED; 140 + } 141 + $invited = $invited->getStatus(); 142 + return $invited; 143 + } 144 + 145 + public function getIsUserAttending($phid) { 146 + $attending_status = PhabricatorCalendarEventInvitee::STATUS_ATTENDING; 147 + 148 + $old_status = $this->getUserInviteStatus($phid); 149 + $is_attending = ($old_status == $attending_status); 150 + 151 + return $is_attending; 152 + } 153 + 133 154 /** 134 155 * Validates data and throws exceptions for non-sensical status 135 156 * windows
+3 -1
src/applications/calendar/storage/PhabricatorCalendarEventTransaction.php
··· 66 66 case self::TYPE_STATUS: 67 67 case self::TYPE_DESCRIPTION: 68 68 case self::TYPE_CANCEL: 69 - case self::TYPE_INVITE: 70 69 return 'fa-pencil'; 70 + break; 71 + case self::TYPE_INVITE: 72 + return 'fa-user-plus'; 71 73 break; 72 74 } 73 75 return parent::getIcon();