1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-24 21:48:21 +01:00

Modularize all the mail preferences

Summary:
Ref T4103. This isn't completely perfect but should let us move forward without also expanding scope into "too much mail".

I split the existing "Mail Preferences" into two panels: a "Mail Delivery" panel for the EditEngine settings, and a "2000000 dropdowns" panel for the two million dropdowns. This one retains the old code more or less unmodified.

Test Plan:
  - Ran unit tests, which cover most of this stuff.
  - Grepped for all removed constants.
  - Ran migrations, inspected database results.
  - Changed settings in both modified panels.
  - This covers a lot of ground, but anything I missed will hopefully be fairly obvious.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T4103

Differential Revision: https://secure.phabricator.com/D16038
This commit is contained in:
epriestley 2016-06-04 15:16:12 -07:00
parent d326b239ae
commit 7ef6c0a523
14 changed files with 258 additions and 172 deletions

View file

@ -0,0 +1,47 @@
<?php
$table = new PhabricatorUserPreferences();
$conn_w = $table->establishConnection('w');
// Convert "Mail Format", "Re Prefix" and "Vary Subjects" mail settings to
// string constants to avoid weird stuff where we store "true" and "false" as
// strings in the database.
// Each of these keys will be converted to the first value if present and
// truthy, or the second value if present and falsey.
$remap = array(
'html-emails' => array('html', 'text'),
're-prefix' => array('re', 'none'),
'vary-subject' => array('vary', 'static'),
);
foreach (new LiskMigrationIterator($table) as $row) {
$dict = $row->getPreferences();
$should_update = false;
foreach ($remap as $key => $value) {
if (isset($dict[$key])) {
if ($dict[$key]) {
$dict[$key] = $value[0];
} else {
$dict[$key] = $value[1];
}
$should_update = true;
}
}
if (!$should_update) {
continue;
}
queryfx(
$conn_w,
'UPDATE %T SET preferences = %s WHERE id = %d',
$table->getTableName(),
phutil_json_encode($dict),
$row->getID());
}
$prefs_key = PhabricatorUserPreferencesCacheType::KEY_PREFERENCES;
PhabricatorUserCache::clearCacheForAllUsers($prefs_key);

View file

@ -2389,6 +2389,7 @@ phutil_register_library_map(array(
'PhabricatorElasticSearchSetupCheck' => 'applications/config/check/PhabricatorElasticSearchSetupCheck.php', 'PhabricatorElasticSearchSetupCheck' => 'applications/config/check/PhabricatorElasticSearchSetupCheck.php',
'PhabricatorEmailAddressesSettingsPanel' => 'applications/settings/panel/PhabricatorEmailAddressesSettingsPanel.php', 'PhabricatorEmailAddressesSettingsPanel' => 'applications/settings/panel/PhabricatorEmailAddressesSettingsPanel.php',
'PhabricatorEmailContentSource' => 'applications/metamta/contentsource/PhabricatorEmailContentSource.php', 'PhabricatorEmailContentSource' => 'applications/metamta/contentsource/PhabricatorEmailContentSource.php',
'PhabricatorEmailDeliverySettingsPanel' => 'applications/settings/panel/PhabricatorEmailDeliverySettingsPanel.php',
'PhabricatorEmailFormatSetting' => 'applications/settings/setting/PhabricatorEmailFormatSetting.php', 'PhabricatorEmailFormatSetting' => 'applications/settings/setting/PhabricatorEmailFormatSetting.php',
'PhabricatorEmailFormatSettingsPanel' => 'applications/settings/panel/PhabricatorEmailFormatSettingsPanel.php', 'PhabricatorEmailFormatSettingsPanel' => 'applications/settings/panel/PhabricatorEmailFormatSettingsPanel.php',
'PhabricatorEmailLoginController' => 'applications/auth/controller/PhabricatorEmailLoginController.php', 'PhabricatorEmailLoginController' => 'applications/auth/controller/PhabricatorEmailLoginController.php',
@ -2396,6 +2397,7 @@ phutil_register_library_map(array(
'PhabricatorEmailPreferencesSettingsPanel' => 'applications/settings/panel/PhabricatorEmailPreferencesSettingsPanel.php', 'PhabricatorEmailPreferencesSettingsPanel' => 'applications/settings/panel/PhabricatorEmailPreferencesSettingsPanel.php',
'PhabricatorEmailRePrefixSetting' => 'applications/settings/setting/PhabricatorEmailRePrefixSetting.php', 'PhabricatorEmailRePrefixSetting' => 'applications/settings/setting/PhabricatorEmailRePrefixSetting.php',
'PhabricatorEmailSelfActionsSetting' => 'applications/settings/setting/PhabricatorEmailSelfActionsSetting.php', 'PhabricatorEmailSelfActionsSetting' => 'applications/settings/setting/PhabricatorEmailSelfActionsSetting.php',
'PhabricatorEmailTagsSetting' => 'applications/settings/setting/PhabricatorEmailTagsSetting.php',
'PhabricatorEmailVarySubjectsSetting' => 'applications/settings/setting/PhabricatorEmailVarySubjectsSetting.php', 'PhabricatorEmailVarySubjectsSetting' => 'applications/settings/setting/PhabricatorEmailVarySubjectsSetting.php',
'PhabricatorEmailVerificationController' => 'applications/auth/controller/PhabricatorEmailVerificationController.php', 'PhabricatorEmailVerificationController' => 'applications/auth/controller/PhabricatorEmailVerificationController.php',
'PhabricatorEmbedFileRemarkupRule' => 'applications/files/markup/PhabricatorEmbedFileRemarkupRule.php', 'PhabricatorEmbedFileRemarkupRule' => 'applications/files/markup/PhabricatorEmbedFileRemarkupRule.php',
@ -6976,6 +6978,7 @@ phutil_register_library_map(array(
'PhabricatorElasticSearchSetupCheck' => 'PhabricatorSetupCheck', 'PhabricatorElasticSearchSetupCheck' => 'PhabricatorSetupCheck',
'PhabricatorEmailAddressesSettingsPanel' => 'PhabricatorSettingsPanel', 'PhabricatorEmailAddressesSettingsPanel' => 'PhabricatorSettingsPanel',
'PhabricatorEmailContentSource' => 'PhabricatorContentSource', 'PhabricatorEmailContentSource' => 'PhabricatorContentSource',
'PhabricatorEmailDeliverySettingsPanel' => 'PhabricatorEditEngineSettingsPanel',
'PhabricatorEmailFormatSetting' => 'PhabricatorSelectSetting', 'PhabricatorEmailFormatSetting' => 'PhabricatorSelectSetting',
'PhabricatorEmailFormatSettingsPanel' => 'PhabricatorEditEngineSettingsPanel', 'PhabricatorEmailFormatSettingsPanel' => 'PhabricatorEditEngineSettingsPanel',
'PhabricatorEmailLoginController' => 'PhabricatorAuthController', 'PhabricatorEmailLoginController' => 'PhabricatorAuthController',
@ -6983,6 +6986,7 @@ phutil_register_library_map(array(
'PhabricatorEmailPreferencesSettingsPanel' => 'PhabricatorSettingsPanel', 'PhabricatorEmailPreferencesSettingsPanel' => 'PhabricatorSettingsPanel',
'PhabricatorEmailRePrefixSetting' => 'PhabricatorSelectSetting', 'PhabricatorEmailRePrefixSetting' => 'PhabricatorSelectSetting',
'PhabricatorEmailSelfActionsSetting' => 'PhabricatorSelectSetting', 'PhabricatorEmailSelfActionsSetting' => 'PhabricatorSelectSetting',
'PhabricatorEmailTagsSetting' => 'PhabricatorInternalSetting',
'PhabricatorEmailVarySubjectsSetting' => 'PhabricatorSelectSetting', 'PhabricatorEmailVarySubjectsSetting' => 'PhabricatorSelectSetting',
'PhabricatorEmailVerificationController' => 'PhabricatorAuthController', 'PhabricatorEmailVerificationController' => 'PhabricatorAuthController',
'PhabricatorEmbedFileRemarkupRule' => 'PhabricatorObjectRemarkupRule', 'PhabricatorEmbedFileRemarkupRule' => 'PhabricatorObjectRemarkupRule',

View file

@ -214,8 +214,8 @@ final class PhabricatorFeedStoryPublisher extends Phobject {
$all_prefs = mpull($all_prefs, null, 'getUserPHID'); $all_prefs = mpull($all_prefs, null, 'getUserPHID');
} }
$pref_default = PhabricatorUserPreferences::MAILTAG_PREFERENCE_EMAIL; $pref_default = PhabricatorEmailTagsSetting::VALUE_EMAIL;
$pref_ignore = PhabricatorUserPreferences::MAILTAG_PREFERENCE_IGNORE; $pref_ignore = PhabricatorEmailTagsSetting::VALUE_IGNORE;
$keep = array(); $keep = array();
foreach ($phids as $phid) { foreach ($phids as $phid) {
@ -224,9 +224,8 @@ final class PhabricatorFeedStoryPublisher extends Phobject {
} }
if ($tags && isset($all_prefs[$phid])) { if ($tags && isset($all_prefs[$phid])) {
$mailtags = $all_prefs[$phid]->getPreference( $mailtags = $all_prefs[$phid]->getSettingValue(
PhabricatorUserPreferences::PREFERENCE_MAILTAGS, PhabricatorEmailTagsSetting::SETTINGKEY);
array());
$notify = false; $notify = false;
foreach ($tags as $tag) { foreach ($tags as $tag) {

View file

@ -435,32 +435,17 @@ final class PhabricatorMetaMTAMail
$add_cc = array(); $add_cc = array();
$add_to = array(); $add_to = array();
// Only try to use preferences if everything is multiplexed, so we // If multiplexing is enabled, some recipients will be in "Cc"
// get consistent behavior. // rather than "To". We'll move them to "To" later (or supply a
$use_prefs = self::shouldMultiplexAllMail(); // dummy "To") but need to look for the recipient in either the
// "To" or "Cc" fields here.
$prefs = null; $target_phid = head(idx($params, 'to', array()));
if ($use_prefs) { if (!$target_phid) {
$target_phid = head(idx($params, 'cc', array()));
// If multiplexing is enabled, some recipients will be in "Cc"
// rather than "To". We'll move them to "To" later (or supply a
// dummy "To") but need to look for the recipient in either the
// "To" or "Cc" fields here.
$target_phid = head(idx($params, 'to', array()));
if (!$target_phid) {
$target_phid = head(idx($params, 'cc', array()));
}
if ($target_phid) {
$user = id(new PhabricatorUser())->loadOneWhere(
'phid = %s',
$target_phid);
if ($user) {
$prefs = $user->loadPreferences();
}
}
} }
$preferences = $this->loadPreferences($target_phid);
foreach ($params as $key => $value) { foreach ($params as $key => $value) {
switch ($key) { switch ($key) {
case 'raw-from': case 'raw-from':
@ -526,15 +511,7 @@ final class PhabricatorMetaMTAMail
$subject = array(); $subject = array();
if ($is_threaded) { if ($is_threaded) {
$add_re = PhabricatorEnv::getEnvConfig('metamta.re-prefix'); if ($this->shouldAddRePrefix($preferences)) {
if ($prefs) {
$add_re = $prefs->getPreference(
PhabricatorUserPreferences::PREFERENCE_RE_PREFIX,
$add_re);
}
if ($add_re) {
$subject[] = 'Re:'; $subject[] = 'Re:';
} }
} }
@ -543,16 +520,7 @@ final class PhabricatorMetaMTAMail
$vary_prefix = idx($params, 'vary-subject-prefix'); $vary_prefix = idx($params, 'vary-subject-prefix');
if ($vary_prefix != '') { if ($vary_prefix != '') {
$use_subject = PhabricatorEnv::getEnvConfig( if ($this->shouldVarySubject($preferences)) {
'metamta.vary-subjects');
if ($prefs) {
$use_subject = $prefs->getPreference(
PhabricatorUserPreferences::PREFERENCE_VARY_SUBJECT,
$use_subject);
}
if ($use_subject) {
$subject[] = $vary_prefix; $subject[] = $vary_prefix;
} }
} }
@ -607,13 +575,7 @@ final class PhabricatorMetaMTAMail
} }
$mailer->setBody($body); $mailer->setBody($body);
$html_emails = true; $html_emails = $this->shouldSendHTML($preferences);
if ($use_prefs && $prefs) {
$html_emails = $prefs->getPreference(
PhabricatorUserPreferences::PREFERENCE_HTML_EMAILS,
$html_emails);
}
if ($html_emails && isset($params['html-body'])) { if ($html_emails && isset($params['html-body'])) {
$mailer->setHTMLBody($params['html-body']); $mailer->setHTMLBody($params['html-body']);
} }
@ -900,13 +862,12 @@ final class PhabricatorMetaMTAMail
$from_user = id(new PhabricatorPeopleQuery()) $from_user = id(new PhabricatorPeopleQuery())
->setViewer($viewer) ->setViewer($viewer)
->withPHIDs(array($from_phid)) ->withPHIDs(array($from_phid))
->needUserSettings(true)
->execute(); ->execute();
$from_user = head($from_user); $from_user = head($from_user);
if ($from_user) { if ($from_user) {
$pref_key = PhabricatorUserPreferences::PREFERENCE_NO_SELF_MAIL; $pref_key = PhabricatorEmailSelfActionsSetting::SETTINGKEY;
$exclude_self = $from_user $exclude_self = $from_user->getUserSetting($pref_key);
->loadPreferences()
->getPreference($pref_key);
if ($exclude_self) { if ($exclude_self) {
$from_actor->setUndeliverable(PhabricatorMetaMTAActor::REASON_SELF); $from_actor->setUndeliverable(PhabricatorMetaMTAActor::REASON_SELF);
} }
@ -919,7 +880,7 @@ final class PhabricatorMetaMTAMail
->execute(); ->execute();
$all_prefs = mpull($all_prefs, null, 'getUserPHID'); $all_prefs = mpull($all_prefs, null, 'getUserPHID');
$value_email = PhabricatorUserPreferences::MAILTAG_PREFERENCE_EMAIL; $value_email = PhabricatorEmailTagsSetting::VALUE_EMAIL;
// Exclude all recipients who have set preferences to not receive this type // Exclude all recipients who have set preferences to not receive this type
// of email (for example, a user who says they don't want emails about task // of email (for example, a user who says they don't want emails about task
@ -927,9 +888,8 @@ final class PhabricatorMetaMTAMail
$tags = $this->getParam('mailtags'); $tags = $this->getParam('mailtags');
if ($tags) { if ($tags) {
foreach ($all_prefs as $phid => $prefs) { foreach ($all_prefs as $phid => $prefs) {
$user_mailtags = $prefs->getPreference( $user_mailtags = $prefs->getSettingValue(
PhabricatorUserPreferences::PREFERENCE_MAILTAGS, PhabricatorEmailTagsSetting::SETTINGKEY);
array());
// The user must have elected to receive mail for at least one // The user must have elected to receive mail for at least one
// of the mailtags. // of the mailtags.
@ -982,9 +942,8 @@ final class PhabricatorMetaMTAMail
// Exclude recipients who don't want any mail. This rule is very strong // Exclude recipients who don't want any mail. This rule is very strong
// and runs last. // and runs last.
foreach ($all_prefs as $phid => $prefs) { foreach ($all_prefs as $phid => $prefs) {
$exclude = $prefs->getPreference( $exclude = $prefs->getSettingValue(
PhabricatorUserPreferences::PREFERENCE_NO_MAIL, PhabricatorEmailNotificationsSetting::SETTINGKEY);
false);
if ($exclude) { if ($exclude) {
$actors[$phid]->setUndeliverable( $actors[$phid]->setUndeliverable(
PhabricatorMetaMTAActor::REASON_MAIL_DISABLED); PhabricatorMetaMTAActor::REASON_MAIL_DISABLED);
@ -1142,6 +1101,67 @@ final class PhabricatorMetaMTAMail
return $this->routingMap; return $this->routingMap;
} }
/* -( Preferences )-------------------------------------------------------- */
private function loadPreferences($target_phid) {
if (!self::shouldMultiplexAllMail()) {
$target_phid = null;
}
if ($target_phid) {
$preferences = id(new PhabricatorUserPreferencesQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->withUserPHIDs(array($target_phid))
->executeOne();
} else {
$preferences = null;
}
// TODO: Here, we would load global preferences once they exist.
if (!$preferences) {
// If we haven't found suitable preferences yet, return an empty object
// which implicitly has all the default values.
$preferences = id(new PhabricatorUserPreferences())
->attachUser(new PhabricatorUser());
}
return $preferences;
}
private function shouldAddRePrefix(PhabricatorUserPreferences $preferences) {
$default_value = PhabricatorEnv::getEnvConfig('metamta.re-prefix');
$value = $preferences->getPreference(
PhabricatorEmailRePrefixSetting::SETTINGKEY);
if ($value === null) {
return $default_value;
}
return ($value == PhabricatorEmailRePrefixSetting::VALUE_RE_PREFIX);
}
private function shouldVarySubject(PhabricatorUserPreferences $preferences) {
$default_value = PhabricatorEnv::getEnvConfig('metamta.vary-subjects');
$value = $preferences->getPreference(
PhabricatorEmailVarySubjectsSetting::SETTINGKEY);
if ($value === null) {
return $default_value;
}
return ($value == PhabricatorEmailVarySubjectsSetting::VALUE_VARY_SUBJECTS);
}
private function shouldSendHTML(PhabricatorUserPreferences $preferences) {
$value = $preferences->getSettingValue(
PhabricatorEmailFormatSetting::SETTINGKEY);
return ($value == PhabricatorEmailFormatSetting::VALUE_HTML_EMAIL);
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */ /* -( PhabricatorPolicyInterface )----------------------------------------- */

View file

@ -60,8 +60,6 @@ final class PhabricatorMetaMTAMailTestCase extends PhabricatorTestCase {
$user = $this->generateNewTestUser(); $user = $this->generateNewTestUser();
$phid = $user->getPHID(); $phid = $user->getPHID();
$prefs = $user->loadPreferences();
$mailer = new PhabricatorMailImplementationTestAdapter(); $mailer = new PhabricatorMailImplementationTestAdapter();
$mail = new PhabricatorMetaMTAMail(); $mail = new PhabricatorMetaMTAMail();
@ -79,27 +77,28 @@ final class PhabricatorMetaMTAMailTestCase extends PhabricatorTestCase {
in_array($phid, $mail->buildRecipientList()), in_array($phid, $mail->buildRecipientList()),
pht('"From" does not exclude recipients by default.')); pht('"From" does not exclude recipients by default.'));
$prefs->setPreference( $user = $this->writeSetting(
PhabricatorUserPreferences::PREFERENCE_NO_SELF_MAIL, $user,
PhabricatorEmailSelfActionsSetting::SETTINGKEY,
true); true);
$prefs->save();
$this->assertFalse( $this->assertFalse(
in_array($phid, $mail->buildRecipientList()), in_array($phid, $mail->buildRecipientList()),
pht('"From" excludes recipients with no-self-mail set.')); pht('"From" excludes recipients with no-self-mail set.'));
$prefs->unsetPreference( $user = $this->writeSetting(
PhabricatorUserPreferences::PREFERENCE_NO_SELF_MAIL); $user,
$prefs->save(); PhabricatorEmailSelfActionsSetting::SETTINGKEY,
null);
$this->assertTrue( $this->assertTrue(
in_array($phid, $mail->buildRecipientList()), in_array($phid, $mail->buildRecipientList()),
pht('"From" does not exclude recipients by default.')); pht('"From" does not exclude recipients by default.'));
$prefs->setPreference( $user = $this->writeSetting(
PhabricatorUserPreferences::PREFERENCE_NO_MAIL, $user,
PhabricatorEmailNotificationsSetting::SETTINGKEY,
true); true);
$prefs->save();
$this->assertFalse( $this->assertFalse(
in_array($phid, $mail->buildRecipientList()), in_array($phid, $mail->buildRecipientList()),
@ -113,15 +112,15 @@ final class PhabricatorMetaMTAMailTestCase extends PhabricatorTestCase {
$mail->setForceDelivery(false); $mail->setForceDelivery(false);
$prefs->unsetPreference( $user = $this->writeSetting(
PhabricatorUserPreferences::PREFERENCE_NO_MAIL); $user,
$prefs->save(); PhabricatorEmailNotificationsSetting::SETTINGKEY,
null);
$this->assertTrue( $this->assertTrue(
in_array($phid, $mail->buildRecipientList()), in_array($phid, $mail->buildRecipientList()),
pht('"From" does not exclude recipients by default.')); pht('"From" does not exclude recipients by default.'));
// Test that explicit exclusion works correctly. // Test that explicit exclusion works correctly.
$mail->setExcludeMailRecipientPHIDs(array($phid)); $mail->setExcludeMailRecipientPHIDs(array($phid));
@ -133,12 +132,12 @@ final class PhabricatorMetaMTAMailTestCase extends PhabricatorTestCase {
// Test that mail tag preferences exclude recipients. // Test that mail tag preferences exclude recipients.
$prefs->setPreference( $user = $this->writeSetting(
PhabricatorUserPreferences::PREFERENCE_MAILTAGS, $user,
PhabricatorEmailTagsSetting::SETTINGKEY,
array( array(
'test-tag' => false, 'test-tag' => false,
)); ));
$prefs->save();
$mail->setMailTags(array('test-tag')); $mail->setMailTags(array('test-tag'));
@ -146,8 +145,10 @@ final class PhabricatorMetaMTAMailTestCase extends PhabricatorTestCase {
in_array($phid, $mail->buildRecipientList()), in_array($phid, $mail->buildRecipientList()),
pht('Tag preference excludes recipients.')); pht('Tag preference excludes recipients.'));
$prefs->unsetPreference(PhabricatorUserPreferences::PREFERENCE_MAILTAGS); $user = $this->writeSetting(
$prefs->save(); $user,
PhabricatorEmailTagsSetting::SETTINGKEY,
null);
$this->assertTrue( $this->assertTrue(
in_array($phid, $mail->buildRecipientList()), in_array($phid, $mail->buildRecipientList()),
@ -215,4 +216,23 @@ final class PhabricatorMetaMTAMailTestCase extends PhabricatorTestCase {
$case)); $case));
} }
private function writeSetting(PhabricatorUser $user, $key, $value) {
$preferences = PhabricatorUserPreferences::loadUserPreferences($user);
$editor = id(new PhabricatorUserPreferencesEditor())
->setActor($user)
->setContentSource($this->newContentSource())
->setContinueOnNoEffect(true)
->setContinueOnMissingFields(true);
$xactions = array();
$xactions[] = $preferences->newTransaction($key, $value);
$editor->applyTransactions($preferences, $xactions);
return id(new PhabricatorPeopleQuery())
->setViewer($user)
->withIDs(array($user->getID()))
->executeOne();
}
} }

View file

@ -0,0 +1,24 @@
<?php
final class PhabricatorEmailDeliverySettingsPanel
extends PhabricatorEditEngineSettingsPanel {
const PANELKEY = 'emaildelivery';
public function getPanelName() {
return pht('Email Delivery');
}
public function getPanelGroupKey() {
return PhabricatorSettingsEmailPanelGroup::PANELGROUPKEY;
}
public function isEditableByAdministrators() {
if ($this->getUser()->getIsMailingList()) {
return true;
}
return false;
}
}

View file

@ -27,23 +27,12 @@ final class PhabricatorEmailPreferencesSettingsPanel
$viewer = $this->getViewer(); $viewer = $this->getViewer();
$user = $this->getUser(); $user = $this->getUser();
$preferences = $user->loadPreferences(); $preferences = $this->loadTargetPreferences();
$pref_no_mail = PhabricatorUserPreferences::PREFERENCE_NO_MAIL; $value_email = PhabricatorEmailTagsSetting::VALUE_EMAIL;
$pref_no_self_mail = PhabricatorUserPreferences::PREFERENCE_NO_SELF_MAIL;
$value_email = PhabricatorUserPreferences::MAILTAG_PREFERENCE_EMAIL;
$errors = array(); $errors = array();
if ($request->isFormPost()) { if ($request->isFormPost()) {
$preferences->setPreference(
$pref_no_mail,
$request->getStr($pref_no_mail));
$preferences->setPreference(
$pref_no_self_mail,
$request->getStr($pref_no_self_mail));
$new_tags = $request->getArr('mailtags'); $new_tags = $request->getArr('mailtags');
$mailtags = $preferences->getPreference('mailtags', array()); $mailtags = $preferences->getPreference('mailtags', array());
$all_tags = $this->getAllTags($user); $all_tags = $this->getAllTags($user);
@ -51,59 +40,21 @@ final class PhabricatorEmailPreferencesSettingsPanel
foreach ($all_tags as $key => $label) { foreach ($all_tags as $key => $label) {
$mailtags[$key] = (int)idx($new_tags, $key, $value_email); $mailtags[$key] = (int)idx($new_tags, $key, $value_email);
} }
$preferences->setPreference('mailtags', $mailtags);
$preferences->save(); $this->writeSetting(
$preferences,
PhabricatorEmailTagsSetting::SETTINGKEY,
$mailtags);
return id(new AphrontRedirectResponse()) return id(new AphrontRedirectResponse())
->setURI($this->getPanelURI('?saved=true')); ->setURI($this->getPanelURI('?saved=true'));
} }
$form = new AphrontFormView(); $mailtags = $preferences->getSettingValue(
$form PhabricatorEmailTagsSetting::SETTINGKEY);
->setUser($viewer)
->appendRemarkupInstructions(
pht(
'These settings let you control how Phabricator notifies you about '.
'events. You can configure Phabricator to send you an email, '.
'just send a web notification, or not notify you at all.'))
->appendRemarkupInstructions(
pht(
'If you disable **Email Notifications**, Phabricator will never '.
'send email to notify you about events. This preference overrides '.
'all your other settings.'.
"\n\n".
"//You may still receive some administrative email, like password ".
"reset email.//"))
->appendChild(
id(new AphrontFormSelectControl())
->setLabel(pht('Email Notifications'))
->setName($pref_no_mail)
->setOptions(
array(
'0' => pht('Send me email notifications'),
'1' => pht('Never send email notifications'),
))
->setValue($preferences->getPreference($pref_no_mail, 0)))
->appendRemarkupInstructions(
pht(
'If you disable **Self Actions**, Phabricator will not notify '.
'you about actions you take.'))
->appendChild(
id(new AphrontFormSelectControl())
->setLabel(pht('Self Actions'))
->setName($pref_no_self_mail)
->setOptions(
array(
'0' => pht('Send me an email when I take an action'),
'1' => pht('Do not send me an email when I take an action'),
))
->setValue($preferences->getPreference($pref_no_self_mail, 0)));
$mailtags = $preferences->getPreference('mailtags', array()); $form = id(new AphrontFormView())
->setUser($viewer);
$form->appendChild(
id(new PHUIFormDividerControl()));
$form->appendRemarkupInstructions( $form->appendRemarkupInstructions(
pht( pht(
@ -183,11 +134,7 @@ final class PhabricatorEmailPreferencesSettingsPanel
->setFormErrors($errors) ->setFormErrors($errors)
->setForm($form); ->setForm($form);
return id(new AphrontNullView()) return $form_box;
->appendChild(
array(
$form_box,
));
} }
private function getAllEditorsWithTags(PhabricatorUser $user) { private function getAllEditorsWithTags(PhabricatorUser $user) {
@ -222,9 +169,9 @@ final class PhabricatorEmailPreferencesSettingsPanel
array $tags, array $tags,
array $prefs) { array $prefs) {
$value_email = PhabricatorUserPreferences::MAILTAG_PREFERENCE_EMAIL; $value_email = PhabricatorEmailTagsSetting::VALUE_EMAIL;
$value_notify = PhabricatorUserPreferences::MAILTAG_PREFERENCE_NOTIFY; $value_notify = PhabricatorEmailTagsSetting::VALUE_NOTIFY;
$value_ignore = PhabricatorUserPreferences::MAILTAG_PREFERENCE_IGNORE; $value_ignore = PhabricatorEmailTagsSetting::VALUE_IGNORE;
$content = array(); $content = array();
foreach ($tags as $key => $label) { foreach ($tags as $key => $label) {

View file

@ -5,8 +5,8 @@ final class PhabricatorEmailFormatSetting
const SETTINGKEY = 'html-emails'; const SETTINGKEY = 'html-emails';
const VALUE_HTML_EMAIL = 'true'; const VALUE_HTML_EMAIL = 'html';
const VALUE_TEXT_EMAIL = 'false'; const VALUE_TEXT_EMAIL = 'text';
public function getSettingName() { public function getSettingName() {
return pht('HTML Email'); return pht('HTML Email');

View file

@ -12,6 +12,14 @@ final class PhabricatorEmailNotificationsSetting
return pht('Email Notifications'); return pht('Email Notifications');
} }
public function getSettingPanelKey() {
return PhabricatorEmailDeliverySettingsPanel::PANELKEY;
}
protected function getSettingOrder() {
return 100;
}
protected function getControlInstructions() { protected function getControlInstructions() {
return pht( return pht(
'If you disable **Email Notifications**, Phabricator will never '. 'If you disable **Email Notifications**, Phabricator will never '.

View file

@ -5,8 +5,8 @@ final class PhabricatorEmailRePrefixSetting
const SETTINGKEY = 're-prefix'; const SETTINGKEY = 're-prefix';
const VALUE_RE_PREFIX = 'true'; const VALUE_RE_PREFIX = 're';
const VALUE_NO_PREFIX = 'false'; const VALUE_NO_PREFIX = 'none';
public function getSettingName() { public function getSettingName() {
return pht('Add "Re:" Prefix'); return pht('Add "Re:" Prefix');

View file

@ -12,6 +12,14 @@ final class PhabricatorEmailSelfActionsSetting
return pht('Self Actions'); return pht('Self Actions');
} }
public function getSettingPanelKey() {
return PhabricatorEmailDeliverySettingsPanel::PANELKEY;
}
protected function getSettingOrder() {
return 200;
}
protected function getControlInstructions() { protected function getControlInstructions() {
return pht( return pht(
'If you disable **Self Actions**, Phabricator will not notify '. 'If you disable **Self Actions**, Phabricator will not notify '.

View file

@ -0,0 +1,21 @@
<?php
final class PhabricatorEmailTagsSetting
extends PhabricatorInternalSetting {
const SETTINGKEY = 'mailtags';
// These are in an unusual order for historic reasons.
const VALUE_NOTIFY = 0;
const VALUE_EMAIL = 1;
const VALUE_IGNORE = 2;
public function getSettingName() {
return pht('Mail Tags');
}
public function getSettingDefaultValue() {
return array();
}
}

View file

@ -3,10 +3,10 @@
final class PhabricatorEmailVarySubjectsSetting final class PhabricatorEmailVarySubjectsSetting
extends PhabricatorSelectSetting { extends PhabricatorSelectSetting {
const SETTINGKEY = 'vary-subjects'; const SETTINGKEY = 'vary-subject';
const VALUE_VARY_SUBJECTS = 'true'; const VALUE_VARY_SUBJECTS = 'vary';
const VALUE_STATIC_SUBJECTS = 'false'; const VALUE_STATIC_SUBJECTS = 'static';
public function getSettingName() { public function getSettingName() {
return pht('Vary Subjects'); return pht('Vary Subjects');

View file

@ -7,18 +7,6 @@ final class PhabricatorUserPreferences
PhabricatorDestructibleInterface, PhabricatorDestructibleInterface,
PhabricatorApplicationTransactionInterface { PhabricatorApplicationTransactionInterface {
const PREFERENCE_RE_PREFIX = 're-prefix';
const PREFERENCE_NO_SELF_MAIL = 'self-mail';
const PREFERENCE_NO_MAIL = 'no-mail';
const PREFERENCE_MAILTAGS = 'mailtags';
const PREFERENCE_VARY_SUBJECT = 'vary-subject';
const PREFERENCE_HTML_EMAILS = 'html-emails';
// These are in an unusual order for historic reasons.
const MAILTAG_PREFERENCE_NOTIFY = 0;
const MAILTAG_PREFERENCE_EMAIL = 1;
const MAILTAG_PREFERENCE_IGNORE = 2;
protected $userPHID; protected $userPHID;
protected $preferences = array(); protected $preferences = array();