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

Make event hosts editable

Summary:
Fixes T10909. I think this is a generally reasonable sort of capability to expose, although I've made it edit-only for now (when creating an event, you're always the host).

Also clean up some minor leftovers in the code, and a couple of little bugs with recurrence frequencies.

Test Plan: Created an event, edited the host of an event.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10909

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

+101 -25
+2
src/__phutil_library_map__.php
··· 2036 2036 'PhabricatorCalendarEventEndDateTransaction' => 'applications/calendar/xaction/PhabricatorCalendarEventEndDateTransaction.php', 2037 2037 'PhabricatorCalendarEventFrequencyTransaction' => 'applications/calendar/xaction/PhabricatorCalendarEventFrequencyTransaction.php', 2038 2038 'PhabricatorCalendarEventFulltextEngine' => 'applications/calendar/search/PhabricatorCalendarEventFulltextEngine.php', 2039 + 'PhabricatorCalendarEventHostTransaction' => 'applications/calendar/xaction/PhabricatorCalendarEventHostTransaction.php', 2039 2040 'PhabricatorCalendarEventIconTransaction' => 'applications/calendar/xaction/PhabricatorCalendarEventIconTransaction.php', 2040 2041 'PhabricatorCalendarEventInviteTransaction' => 'applications/calendar/xaction/PhabricatorCalendarEventInviteTransaction.php', 2041 2042 'PhabricatorCalendarEventInvitee' => 'applications/calendar/storage/PhabricatorCalendarEventInvitee.php', ··· 6663 6664 'PhabricatorCalendarEventEndDateTransaction' => 'PhabricatorCalendarEventDateTransaction', 6664 6665 'PhabricatorCalendarEventFrequencyTransaction' => 'PhabricatorCalendarEventTransactionType', 6665 6666 'PhabricatorCalendarEventFulltextEngine' => 'PhabricatorFulltextEngine', 6667 + 'PhabricatorCalendarEventHostTransaction' => 'PhabricatorCalendarEventTransactionType', 6666 6668 'PhabricatorCalendarEventIconTransaction' => 'PhabricatorCalendarEventTransactionType', 6667 6669 'PhabricatorCalendarEventInviteTransaction' => 'PhabricatorCalendarEventTransactionType', 6668 6670 'PhabricatorCalendarEventInvitee' => array(
+13 -3
src/applications/calendar/editor/PhabricatorCalendarEventEditEngine.php
··· 23 23 24 24 protected function newEditableObject() { 25 25 return PhabricatorCalendarEvent::initializeNewCalendarEvent( 26 - $this->getViewer(), 27 - $mode = null); 26 + $this->getViewer()); 28 27 } 29 28 30 29 protected function newObjectQuery() { ··· 106 105 ->setConduitDescription(pht('Cancel or restore the event.')) 107 106 ->setConduitTypeDescription(pht('True to cancel the event.')) 108 107 ->setValue($object->getIsCancelled()), 108 + id(new PhabricatorUsersEditField()) 109 + ->setKey('hostPHID') 110 + ->setAliases(array('host')) 111 + ->setLabel(pht('Host')) 112 + ->setDescription(pht('Host of the event.')) 113 + ->setTransactionType( 114 + PhabricatorCalendarEventHostTransaction::TRANSACTIONTYPE) 115 + ->setIsConduitOnly($this->getIsCreate()) 116 + ->setConduitDescription(pht('Change the host of the event.')) 117 + ->setConduitTypeDescription(pht('New event host.')) 118 + ->setSingleValue($object->getHostPHID()), 109 119 id(new PhabricatorDatasourceEditField()) 110 120 ->setKey('inviteePHIDs') 111 121 ->setAliases(array('invite', 'invitee', 'invitees', 'inviteePHID')) ··· 141 151 ->setDescription(pht('Recurring event frequency.')) 142 152 ->setConduitDescription(pht('Change the event frequency.')) 143 153 ->setConduitTypeDescription(pht('New event frequency.')) 144 - ->setValue($object->getFrequencyUnit()); 154 + ->setValue($object->getFrequencyRule()); 145 155 } 146 156 147 157 if ($this->getIsCreate() || $object->getIsRecurring()) {
+15 -18
src/applications/calendar/storage/PhabricatorCalendarEvent.php
··· 39 39 40 40 protected $spacePHID; 41 41 42 - const DEFAULT_ICON = 'fa-calendar'; 43 - 44 42 private $parentEvent = self::ATTACHABLE; 45 43 private $invitees = self::ATTACHABLE; 46 44 ··· 53 51 const FREQUENCY_MONTHLY = 'monthly'; 54 52 const FREQUENCY_YEARLY = 'yearly'; 55 53 56 - public static function initializeNewCalendarEvent( 57 - PhabricatorUser $actor, 58 - $mode) { 54 + public static function initializeNewCalendarEvent(PhabricatorUser $actor) { 59 55 $app = id(new PhabricatorApplicationQuery()) 60 56 ->setViewer($actor) 61 57 ->withClasses(array('PhabricatorCalendarApplication')) 62 58 ->executeOne(); 63 59 64 - $view_policy = null; 65 - $is_recurring = 0; 66 - 67 - if ($mode == 'public') { 68 - $view_policy = PhabricatorPolicies::getMostOpenPolicy(); 69 - } 70 - 71 - if ($mode == 'recurring') { 72 - $is_recurring = true; 73 - } 60 + $view_policy = PhabricatorPolicies::getMostOpenPolicy(); 74 61 75 62 $start = new DateTime('@'.PhabricatorTime::getNow()); 76 63 $start->setTimeZone($actor->getTimeZone()); ··· 82 69 $epoch_min = $start->format('U'); 83 70 $epoch_max = $end->format('U'); 84 71 72 + $default_icon = 'fa-calendar'; 73 + 85 74 return id(new PhabricatorCalendarEvent()) 86 75 ->setHostPHID($actor->getPHID()) 87 76 ->setIsCancelled(0) 88 77 ->setIsAllDay(0) 89 78 ->setIsStub(0) 90 - ->setIsRecurring($is_recurring) 91 - ->setIcon(self::DEFAULT_ICON) 79 + ->setIsRecurring(0) 80 + ->setRecurrenceFrequency( 81 + array( 82 + 'rule' => self::FREQUENCY_WEEKLY, 83 + )) 84 + ->setIcon($default_icon) 92 85 ->setViewPolicy($view_policy) 93 86 ->setEditPolicy($actor->getPHID()) 94 87 ->setSpacePHID($actor->getDefaultSpacePHID()) ··· 396 389 return $this; 397 390 } 398 391 392 + public function getFrequencyRule() { 393 + return idx($this->recurrenceFrequency, 'rule'); 394 + } 395 + 399 396 public function getFrequencyUnit() { 400 - $frequency = idx($this->recurrenceFrequency, 'rule'); 397 + $frequency = $this->getFrequencyRule(); 401 398 402 399 switch ($frequency) { 403 400 case 'daily':
+4 -4
src/applications/calendar/xaction/PhabricatorCalendarEventFrequencyTransaction.php
··· 6 6 const TRANSACTIONTYPE = 'calendar.frequency'; 7 7 8 8 public function generateOldValue($object) { 9 - return $object->getFrequencyUnit(); 9 + return $object->getFrequencyRule(); 10 10 } 11 11 12 12 public function applyInternalEffects($object, $value) { ··· 17 17 } 18 18 19 19 public function getTitle() { 20 - $frequency = $this->getFrequencyUnit($this->getNewValue()); 20 + $frequency = $this->getFrequencyRule($this->getNewValue()); 21 21 switch ($frequency) { 22 22 case PhabricatorCalendarEvent::FREQUENCY_DAILY: 23 23 return pht( ··· 39 39 } 40 40 41 41 public function getTitleForFeed() { 42 - $frequency = $this->getFrequencyUnit($this->getNewValue()); 42 + $frequency = $this->getFrequencyRule($this->getNewValue()); 43 43 switch ($frequency) { 44 44 case PhabricatorCalendarEvent::FREQUENCY_DAILY: 45 45 return pht( ··· 64 64 } 65 65 } 66 66 67 - private function getFrequencyUnit($value) { 67 + private function getFrequencyRule($value) { 68 68 if (is_array($value)) { 69 69 $value = idx($value, 'rule'); 70 70 } else {
+59
src/applications/calendar/xaction/PhabricatorCalendarEventHostTransaction.php
··· 1 + <?php 2 + 3 + final class PhabricatorCalendarEventHostTransaction 4 + extends PhabricatorCalendarEventTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'calendar.host'; 7 + 8 + public function generateOldValue($object) { 9 + return $object->getHostPHID(); 10 + } 11 + 12 + public function applyInternalEffects($object, $value) { 13 + $object->setHostPHID($value); 14 + } 15 + 16 + public function getTitle() { 17 + return pht( 18 + '%s changed the host of this event from %s to %s.', 19 + $this->renderAuthor(), 20 + $this->renderOldHandle(), 21 + $this->renderNewHandle()); 22 + } 23 + 24 + public function getTitleForFeed() { 25 + return pht( 26 + '%s changed the host of %s from %s to %s.', 27 + $this->renderAuthor(), 28 + $this->renderObject(), 29 + $this->renderOldHandle(), 30 + $this->renderNewHandle()); 31 + } 32 + 33 + public function validateTransactions($object, array $xactions) { 34 + $errors = array(); 35 + 36 + foreach ($xactions as $xaction) { 37 + $host_phid = $xaction->getNewValue(); 38 + if (!$host_phid) { 39 + $errors[] = $this->newRequiredError( 40 + pht('Event host is required.')); 41 + continue; 42 + } 43 + 44 + $user = id(new PhabricatorPeopleQuery()) 45 + ->setViewer($this->getActor()) 46 + ->withPHIDs(array($host_phid)) 47 + ->executeOne(); 48 + if (!$user) { 49 + $errors[] = $this->newInvalidError( 50 + pht( 51 + 'Host PHID "%s" is not a valid user PHID.', 52 + $host_phid)); 53 + } 54 + } 55 + 56 + return $errors; 57 + } 58 + 59 + }
+8
src/applications/transactions/storage/PhabricatorModularTransactionType.php
··· 148 148 return $display; 149 149 } 150 150 151 + final protected function renderOldHandle() { 152 + return $this->renderHandle($this->getOldValue()); 153 + } 154 + 155 + final protected function renderNewHandle() { 156 + return $this->renderHandle($this->getNewValue()); 157 + } 158 + 151 159 final protected function renderHandleList(array $phids) { 152 160 $viewer = $this->getViewer(); 153 161 $display = $viewer->renderHandleList($phids)