Differential D16038 Diff 38604 src/applications/settings/panel/PhabricatorEmailPreferencesSettingsPanel.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/settings/panel/PhabricatorEmailPreferencesSettingsPanel.php
| Show All 21 Lines | public function isEditableByAdministrators() { | ||||
| return false; | return false; | ||||
| } | } | ||||
| public function processRequest(AphrontRequest $request) { | public function processRequest(AphrontRequest $request) { | ||||
| $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); | ||||
| 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->appendChild( | $form = id(new AphrontFormView()) | ||||
| id(new PHUIFormDividerControl())); | ->setUser($viewer); | ||||
| $form->appendRemarkupInstructions( | $form->appendRemarkupInstructions( | ||||
| pht( | pht( | ||||
| 'You can adjust **Application Settings** here to customize when '. | 'You can adjust **Application Settings** here to customize when '. | ||||
| 'you are emailed and notified.'. | 'you are emailed and notified.'. | ||||
| "\n\n". | "\n\n". | ||||
| "| Setting | Effect\n". | "| Setting | Effect\n". | ||||
| "| ------- | -------\n". | "| ------- | -------\n". | ||||
| ▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | $form | ||||
| ->setValue(pht('Save Preferences'))); | ->setValue(pht('Save Preferences'))); | ||||
| $form_box = id(new PHUIObjectBoxView()) | $form_box = id(new PHUIObjectBoxView()) | ||||
| ->setHeaderText(pht('Email Preferences')) | ->setHeaderText(pht('Email Preferences')) | ||||
| ->setFormSaved($request->getStr('saved')) | ->setFormSaved($request->getStr('saved')) | ||||
| ->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) { | ||||
| $editors = id(new PhutilClassMapQuery()) | $editors = id(new PhutilClassMapQuery()) | ||||
| ->setAncestorClass('PhabricatorApplicationTransactionEditor') | ->setAncestorClass('PhabricatorApplicationTransactionEditor') | ||||
| ->setFilterMethod('getMailTagsMap') | ->setFilterMethod('getMailTagsMap') | ||||
| ->execute(); | ->execute(); | ||||
| Show All 18 Lines | private function getAllTags(PhabricatorUser $user) { | ||||
| return $tags; | return $tags; | ||||
| } | } | ||||
| private function buildMailTagControl( | private function buildMailTagControl( | ||||
| $control_label, | $control_label, | ||||
| 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) { | ||||
| $select = AphrontFormSelectControl::renderSelectTag( | $select = AphrontFormSelectControl::renderSelectTag( | ||||
| (int)idx($prefs, $key, $value_email), | (int)idx($prefs, $key, $value_email), | ||||
| array( | array( | ||||
| $value_email => pht("\xE2\x9A\xAB Email"), | $value_email => pht("\xE2\x9A\xAB Email"), | ||||
| $value_notify => pht("\xE2\x97\x90 Notify"), | $value_notify => pht("\xE2\x97\x90 Notify"), | ||||
| Show All 26 Lines | |||||