@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.

Simplify the TYPE_INVITE Calendar Event transaction for EditEngine

Summary:
Ref T9275. Now that TYPE_ACCEPT and TYPE_DECLINE have been separated out, we can simplify TYPE_INVITE.

This now just takes a list of invited PHIDs, uninvites ones that were removed and invites ones that were added. This is simpler, lets more logic live in the Editor, and makes EditEngine/API access easier.

Test Plan: Created events, added and removed invitees. Used comment stacked action and "pro" editor to adjust invitees.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T9275

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

+117 -61
+2 -45
src/applications/calendar/controller/PhabricatorCalendarEventEditController.php
··· 105 105 $subscribers = PhabricatorSubscribersQuery::loadSubscribersForPHID( 106 106 $event->getPHID()); 107 107 108 - $invitees = array(); 109 - foreach ($event->getInvitees() as $invitee) { 110 - if ($invitee->isUninvited()) { 111 - continue; 112 - } else { 113 - $invitees[] = $invitee->getInviteePHID(); 114 - } 115 - } 116 - 108 + $invitees = $event->getInviteePHIDsForEdit(); 117 109 $cancel_uri = $event->getURI(); 118 110 } 119 111 ··· 172 164 $icon = $request->getStr('icon'); 173 165 174 166 $invitees = $request->getArr('invitees'); 175 - $new_invitees = $this->getNewInviteeList($invitees, $event); 176 - $status_attending = PhabricatorCalendarEventInvitee::STATUS_ATTENDING; 177 - if ($this->isCreate()) { 178 - $status = idx($new_invitees, $viewer->getPHID()); 179 - if ($status) { 180 - $new_invitees[$viewer->getPHID()] = $status_attending; 181 - } 182 - } 183 167 184 168 $xactions[] = id(new PhabricatorCalendarEventTransaction()) 185 169 ->setTransactionType( ··· 236 220 $xactions[] = id(new PhabricatorCalendarEventTransaction()) 237 221 ->setTransactionType( 238 222 PhabricatorCalendarEventTransaction::TYPE_INVITE) 239 - ->setNewValue($new_invitees); 223 + ->setNewValue($invitees); 240 224 241 225 $xactions[] = id(new PhabricatorCalendarEventTransaction()) 242 226 ->setTransactionType( ··· 487 471 ->setUser($viewer) 488 472 ->setDatasource(new PhabricatorMetaMTAMailableDatasource()); 489 473 490 - 491 474 $icon = id(new PHUIFormIconSetControl()) 492 475 ->setLabel(pht('Icon')) 493 476 ->setName('icon') ··· 573 556 ->appendChild($view); 574 557 } 575 558 576 - 577 - public function getNewInviteeList(array $phids, $event) { 578 - $invitees = $event->getInvitees(); 579 - $invitees = mpull($invitees, null, 'getInviteePHID'); 580 - $invited_status = PhabricatorCalendarEventInvitee::STATUS_INVITED; 581 - $uninvited_status = PhabricatorCalendarEventInvitee::STATUS_UNINVITED; 582 - $phids = array_fuse($phids); 583 - 584 - $new = array(); 585 - foreach ($phids as $phid) { 586 - $old_status = $event->getUserInviteStatus($phid); 587 - if ($old_status != $uninvited_status) { 588 - continue; 589 - } 590 - $new[$phid] = $invited_status; 591 - } 592 - 593 - foreach ($invitees as $invitee) { 594 - $deleted_invitee = !idx($phids, $invitee->getInviteePHID()); 595 - if ($deleted_invitee) { 596 - $new[$invitee->getInviteePHID()] = $uninvited_status; 597 - } 598 - } 599 - 600 - return $new; 601 - } 602 559 603 560 private function getDefaultTimeValues($viewer) { 604 561 $start = new DateTime('@'.time());
+19
src/applications/calendar/editor/PhabricatorCalendarEditEngine.php
··· 60 60 } 61 61 62 62 protected function buildCustomEditFields($object) { 63 + $viewer = $this->getViewer(); 64 + 65 + if ($this->getIsCreate()) { 66 + $invitee_phids = array($viewer->getPHID()); 67 + } else { 68 + $invitee_phids = $object->getInviteePHIDsForEdit(); 69 + } 70 + 63 71 $fields = array( 64 72 id(new PhabricatorTextEditField()) 65 73 ->setKey('name') ··· 90 98 ->setConduitDescription(pht('Cancel or restore the event.')) 91 99 ->setConduitTypeDescription(pht('True to cancel the event.')) 92 100 ->setValue($object->getIsCancelled()), 101 + id(new PhabricatorDatasourceEditField()) 102 + ->setKey('inviteePHIDs') 103 + ->setAliases(array('invite', 'invitee', 'invitees', 'inviteePHID')) 104 + ->setLabel(pht('Invitees')) 105 + ->setDatasource(new PhabricatorMetaMTAMailableDatasource()) 106 + ->setTransactionType(PhabricatorCalendarEventTransaction::TYPE_INVITE) 107 + ->setDescription(pht('Users invited to the event.')) 108 + ->setConduitDescription(pht('Change invited users.')) 109 + ->setConduitTypeDescription(pht('New event invitees.')) 110 + ->setValue($invitee_phids) 111 + ->setCommentActionLabel(pht('Change Invitees')), 93 112 id(new PhabricatorIconSetEditField()) 94 113 ->setKey('icon') 95 114 ->setLabel(pht('Icon'))
+75 -15
src/applications/calendar/editor/PhabricatorCalendarEventEditor.php
··· 109 109 $actor_phid = $this->getActingAsPHID(); 110 110 return $object->getUserInviteStatus($actor_phid); 111 111 case PhabricatorCalendarEventTransaction::TYPE_INVITE: 112 - $map = $xaction->getNewValue(); 113 - $phids = array_keys($map); 114 - $invitees = mpull($object->getInvitees(), null, 'getInviteePHID'); 115 - 116 - $old = array(); 117 - foreach ($phids as $phid) { 118 - $invitee = idx($invitees, $phid); 119 - if ($invitee) { 120 - $old[$phid] = $invitee->getStatus(); 121 - } else { 122 - $old[$phid] = PhabricatorCalendarEventInvitee::STATUS_UNINVITED; 123 - } 124 - } 125 - return $old; 112 + $invitees = $object->getInvitees(); 113 + return mpull($invitees, 'getStatus', 'getInviteePHID'); 126 114 } 127 115 128 116 return parent::getCustomTransactionOldValue($object, $xaction); ··· 137 125 case PhabricatorCalendarEventTransaction::TYPE_NAME: 138 126 case PhabricatorCalendarEventTransaction::TYPE_DESCRIPTION: 139 127 case PhabricatorCalendarEventTransaction::TYPE_CANCEL: 140 - case PhabricatorCalendarEventTransaction::TYPE_INVITE: 141 128 case PhabricatorCalendarEventTransaction::TYPE_ICON: 142 129 return $xaction->getNewValue(); 143 130 case PhabricatorCalendarEventTransaction::TYPE_ACCEPT: ··· 150 137 case PhabricatorCalendarEventTransaction::TYPE_START_DATE: 151 138 case PhabricatorCalendarEventTransaction::TYPE_END_DATE: 152 139 return $xaction->getNewValue(); 140 + case PhabricatorCalendarEventTransaction::TYPE_INVITE: 141 + $status_invited = PhabricatorCalendarEventInvitee::STATUS_INVITED; 142 + $status_uninvited = PhabricatorCalendarEventInvitee::STATUS_UNINVITED; 143 + $status_attending = PhabricatorCalendarEventInvitee::STATUS_ATTENDING; 144 + 145 + $invitees = $object->getInvitees(); 146 + foreach ($invitees as $key => $invitee) { 147 + if ($invitee->getStatus() == $status_uninvited) { 148 + unset($invitees[$key]); 149 + } 150 + } 151 + $invitees = mpull($invitees, null, 'getInviteePHID'); 152 + 153 + $new = $xaction->getNewValue(); 154 + $new = array_fuse($new); 155 + 156 + $all = array_keys($invitees + $new); 157 + $map = array(); 158 + foreach ($all as $phid) { 159 + $is_old = isset($invitees[$phid]); 160 + $is_new = isset($new[$phid]); 161 + 162 + if ($is_old && !$is_new) { 163 + $map[$phid] = $status_uninvited; 164 + } else if (!$is_old && $is_new) { 165 + $map[$phid] = $status_invited; 166 + } 167 + } 168 + 169 + // If we're creating this event and the actor is inviting themselves, 170 + // mark them as attending. 171 + if ($this->getIsNewObject()) { 172 + $acting_phid = $this->getActingAsPHID(); 173 + if (isset($map[$acting_phid])) { 174 + $map[$acting_phid] = $status_attending; 175 + } 176 + } 177 + 178 + return $map; 153 179 } 154 180 155 181 return parent::getCustomTransactionNewValue($object, $xaction); ··· 398 424 399 425 $error->setIsMissingFieldError(true); 400 426 $errors[] = $error; 427 + } 428 + break; 429 + case PhabricatorCalendarEventTransaction::TYPE_INVITE: 430 + $old = $object->getInvitees(); 431 + $old = mpull($old, null, 'getInviteePHID'); 432 + foreach ($xactions as $xaction) { 433 + $new = $xaction->getNewValue(); 434 + $new = array_fuse($new); 435 + $add = array_diff_key($new, $old); 436 + if (!$add) { 437 + continue; 438 + } 439 + 440 + // In the UI, we only allow you to invite mailable objects, but there 441 + // is no definitive marker for "invitable object" today. Just allow 442 + // any valid object to be invited. 443 + $objects = id(new PhabricatorObjectQuery()) 444 + ->setViewer($this->getActor()) 445 + ->withPHIDs($add) 446 + ->execute(); 447 + $objects = mpull($objects, null, 'getPHID'); 448 + foreach ($add as $phid) { 449 + if (isset($objects[$phid])) { 450 + continue; 451 + } 452 + 453 + $errors[] = new PhabricatorApplicationTransactionValidationError( 454 + $type, 455 + pht('Invalid'), 456 + pht( 457 + 'Invitee "%s" identifies an object that does not exist or '. 458 + 'which you do not have permission to view.', 459 + $phid)); 460 + } 401 461 } 402 462 break; 403 463 }
+13
src/applications/calendar/storage/PhabricatorCalendarEvent.php
··· 329 329 return $this; 330 330 } 331 331 332 + public function getInviteePHIDsForEdit() { 333 + $invitees = array(); 334 + 335 + foreach ($this->getInvitees() as $invitee) { 336 + if ($invitee->isUninvited()) { 337 + continue; 338 + } 339 + $invitees[] = $invitee->getInviteePHID(); 340 + } 341 + 342 + return $invitees; 343 + } 344 + 332 345 public function getUserInviteStatus($phid) { 333 346 $invitees = $this->getInvitees(); 334 347 $invitees = mpull($invitees, null, 'getInviteePHID');
+8 -1
src/applications/calendar/storage/PhabricatorCalendarEventTransaction.php
··· 18 18 const TYPE_FREQUENCY = 'calendar.frequency'; 19 19 const TYPE_RECURRENCE_END_DATE = 'calendar.recurrenceenddate'; 20 20 21 - 22 21 const MAILTAG_RESCHEDULE = 'calendar-reschedule'; 23 22 const MAILTAG_CONTENT = 'calendar-content'; 24 23 const MAILTAG_OTHER = 'calendar-other'; ··· 176 175 $this->renderHandleLink($author_phid)); 177 176 case self::TYPE_INVITE: 178 177 $text = null; 178 + 179 + // Fill in any new invitees as "uninvited" in the old data, to make 180 + // some of the rendering logic a little easier. 181 + $status_uninvited = PhabricatorCalendarEventInvitee::STATUS_UNINVITED; 182 + $old = $old + array_fill_keys(array_keys($new), $status_uninvited); 179 183 180 184 if (count($old) === 1 181 185 && count($new) === 1 ··· 386 390 $this->renderHandleLink($object_phid)); 387 391 case self::TYPE_INVITE: 388 392 $text = null; 393 + 394 + $status_uninvited = PhabricatorCalendarEventInvitee::STATUS_UNINVITED; 395 + $old = $old + array_fill_keys(array_keys($new), $status_uninvited); 389 396 390 397 if (count($old) === 1 391 398 && count($new) === 1