From 2725fdf80008c611e05a33762a3fa068af4e6ed7 Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 3 Jun 2016 05:22:40 -0700 Subject: [PATCH] When a user changes their timezone, clear their ignored timezone offset Summary: Ref T4103. We have a couple of settings like this where changing one setting changes another (e.g., enabling DarkConsole makes the console visible). Provide a mechanism to let changing timezone really mean "change timezone, and also clear the timezone offset". Test Plan: Swapped timezones, reconciled them by ignoring the offset, changed timezone again to another zone with the same offset, got asked to reconcile again. Reviewers: chad Reviewed By: chad Maniphest Tasks: T4103 Differential Revision: https://secure.phabricator.com/D16018 --- .../PhabricatorUserPreferencesEditor.php | 40 ++++++++++++++----- .../settings/setting/PhabricatorSetting.php | 14 +++++++ .../setting/PhabricatorTimezoneSetting.php | 12 ++++++ 3 files changed, 57 insertions(+), 9 deletions(-) diff --git a/src/applications/settings/editor/PhabricatorUserPreferencesEditor.php b/src/applications/settings/editor/PhabricatorUserPreferencesEditor.php index d320391091..918142f95c 100644 --- a/src/applications/settings/editor/PhabricatorUserPreferencesEditor.php +++ b/src/applications/settings/editor/PhabricatorUserPreferencesEditor.php @@ -19,6 +19,23 @@ final class PhabricatorUserPreferencesEditor return $types; } + protected function expandTransaction( + PhabricatorLiskDAO $object, + PhabricatorApplicationTransaction $xaction) { + + $setting_key = $xaction->getMetadataValue( + PhabricatorUserPreferencesTransaction::PROPERTY_SETTING); + + $settings = $this->getSettings(); + $setting = idx($settings, $setting_key); + if ($setting) { + return $setting->expandSettingTransaction($object, $xaction); + } + + return parent::expandTransaction($object, $xaction); + } + + protected function getCustomTransactionOldValue( PhabricatorLiskDAO $object, PhabricatorApplicationTransaction $xaction) { @@ -95,15 +112,7 @@ final class PhabricatorUserPreferencesEditor array $xactions) { $errors = parent::validateTransaction($object, $type, $xactions); - - $actor = $this->getActor(); - $settings = PhabricatorSetting::getAllEnabledSettings($actor); - - foreach ($settings as $key => $setting) { - $setting = clone $setting; - $setting->setViewer($actor); - $settings[$key] = $setting; - } + $settings = $this->getSettings(); switch ($type) { case PhabricatorUserPreferencesTransaction::TYPE_SETTING: @@ -157,4 +166,17 @@ final class PhabricatorUserPreferencesEditor return $xactions; } + private function getSettings() { + $actor = $this->getActor(); + $settings = PhabricatorSetting::getAllEnabledSettings($actor); + + foreach ($settings as $key => $setting) { + $setting = clone $setting; + $setting->setViewer($actor); + $settings[$key] = $setting; + } + + return $settings; + } + } diff --git a/src/applications/settings/setting/PhabricatorSetting.php b/src/applications/settings/setting/PhabricatorSetting.php index 517cc67317..8307d17082 100644 --- a/src/applications/settings/setting/PhabricatorSetting.php +++ b/src/applications/settings/setting/PhabricatorSetting.php @@ -111,4 +111,18 @@ abstract class PhabricatorSetting extends Phobject { return $value; } + public function expandSettingTransaction($object, $xaction) { + return array($xaction); + } + + protected function newSettingTransaction($object, $key, $value) { + $setting_property = PhabricatorUserPreferencesTransaction::PROPERTY_SETTING; + $xaction_type = PhabricatorUserPreferencesTransaction::TYPE_SETTING; + + return id(clone $object->getApplicationTransactionTemplate()) + ->setTransactionType($xaction_type) + ->setMetadataValue($setting_property, $key) + ->setNewValue($value); + } + } diff --git a/src/applications/settings/setting/PhabricatorTimezoneSetting.php b/src/applications/settings/setting/PhabricatorTimezoneSetting.php index e68849e2ae..b7a6b94e30 100644 --- a/src/applications/settings/setting/PhabricatorTimezoneSetting.php +++ b/src/applications/settings/setting/PhabricatorTimezoneSetting.php @@ -87,4 +87,16 @@ final class PhabricatorTimezoneSetting return $option_groups; } + public function expandSettingTransaction($object, $xaction) { + // When the user changes their timezone, we also clear any ignored + // timezone offset. + return array( + $xaction, + $this->newSettingTransaction( + $object, + PhabricatorTimezoneIgnoreOffsetSetting::SETTINGKEY, + null), + ); + } + }