From 22a566f7326c57f176b3d3360379fab92b58f39d Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 28 Nov 2016 09:17:26 -0800 Subject: [PATCH] Ignore Calendar date edits which just change the internal date timezone without rescheduling it Summary: Ref T11816. Currently, if someone in California creates an event and then someone in New York edits it, we generate a no-op " changed the start time from 3PM to 3PM." transaction. This is because the internal timezone of the event is changing, but the actual absolute time is not. Instead, when an edit wouldn't reschedule an event and would only change the internal timezone, ignore the edit. Test Plan: - Edited non-all-day events in PST / EST with out making changes (ignored). - Edited non-all-day events in PST / EST with changes (changes worked). - Performed the same edits with all-day events, which also were ignored and worked, respectively. - Pulled events in and out of all-day mode in different timezones, behavior seemeed reasonable. Reviewers: chad Reviewed By: chad Maniphest Tasks: T11816 Differential Revision: https://secure.phabricator.com/D16955 --- ...habricatorCalendarEventDateTransaction.php | 29 +++++++++++++++++++ ...habricatorApplicationTransactionEditor.php | 9 ++++++ .../PhabricatorModularTransactionType.php | 4 +++ 3 files changed, 42 insertions(+) diff --git a/src/applications/calendar/xaction/PhabricatorCalendarEventDateTransaction.php b/src/applications/calendar/xaction/PhabricatorCalendarEventDateTransaction.php index 253609a99e..38e044b3d6 100644 --- a/src/applications/calendar/xaction/PhabricatorCalendarEventDateTransaction.php +++ b/src/applications/calendar/xaction/PhabricatorCalendarEventDateTransaction.php @@ -22,6 +22,35 @@ abstract class PhabricatorCalendarEventDateTransaction ->toDictionary(); } + public function getTransactionHasEffect($object, $old, $new) { + $editor = $this->getEditor(); + + $actor = $this->getActor(); + $actor_timezone = $actor->getTimezoneIdentifier(); + + // When an edit only changes the timezone of an event without materially + // changing the absolute time, discard it. This can happen if two users in + // different timezones edit an event without rescheduling it. + + // Eventually, after T11073, there may be a UI control to adjust timezones. + // If a user explicitly changed the timezone, we should respect that. + // However, there is no way for users to intentionally apply this kind of + // edit today. + + $old_datetime = PhutilCalendarAbsoluteDateTime::newFromDictionary($old) + ->setIsAllDay($editor->getNewIsAllDay()) + ->setViewerTimezone($actor_timezone); + + $new_datetime = PhutilCalendarAbsoluteDateTime::newFromDictionary($new) + ->setIsAllDay($editor->getNewIsAllDay()) + ->setViewerTimezone($actor_timezone); + + $old_epoch = $old_datetime->getEpoch(); + $new_epoch = $new_datetime->getEpoch(); + + return ($old_epoch !== $new_epoch); + } + public function validateTransactions($object, array $xactions) { $errors = array(); diff --git a/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php b/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php index 10db361837..575972104b 100644 --- a/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php +++ b/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php @@ -502,6 +502,15 @@ abstract class PhabricatorApplicationTransactionEditor return false; } + $type = $xaction->getTransactionType(); + $xtype = $this->getModularTransactionType($type); + if ($xtype) { + return $xtype->getTransactionHasEffect( + $object, + $xaction->getOldValue(), + $xaction->getNewValue()); + } + return ($xaction->getOldValue() !== $xaction->getNewValue()); } diff --git a/src/applications/transactions/storage/PhabricatorModularTransactionType.php b/src/applications/transactions/storage/PhabricatorModularTransactionType.php index 3c9ef6b182..84bc4a07ec 100644 --- a/src/applications/transactions/storage/PhabricatorModularTransactionType.php +++ b/src/applications/transactions/storage/PhabricatorModularTransactionType.php @@ -35,6 +35,10 @@ abstract class PhabricatorModularTransactionType return; } + public function getTransactionHasEffect($object, $old, $new) { + return ($old !== $new); + } + public function extractFilePHIDs($object, $value) { return array(); }