1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-21 21:10:56 +01:00

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
This commit is contained in:
epriestley 2016-06-03 05:22:40 -07:00
parent 2f936094d8
commit 2725fdf800
3 changed files with 57 additions and 9 deletions

View file

@ -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;
}
}

View file

@ -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);
}
}

View file

@ -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),
);
}
}