Changeset View
Changeset View
Standalone View
Standalone View
src/applications/chronicle/action/ChronicleSendEmailAction.php
- This file was added.
<?php | |||||
final class ChronicleSendEmailAction | |||||
extends ChronicleAction { | |||||
public function getName() { | |||||
return pht('Send Email'); | |||||
} | |||||
public function getDescription() { | |||||
return pht('Sends an email to one or more users'); | |||||
} | |||||
public function execute(ChronicleTrigger $trigger) { | |||||
$recipients = phutil_json_decode($this->getSetting('recipients')); | |||||
if (count($recipients) === 0) { | |||||
return; | |||||
} | |||||
$body = $this->getSetting('message'); | |||||
$body .= <<<EOF | |||||
Message triggered by: | |||||
EOF; | |||||
$body .= PhabricatorEnv::getURI( | |||||
'/chronicle/trigger/'.$trigger->getID().'/'); | |||||
$mail = id(new PhabricatorMetaMTAMail()) | |||||
->addTos($recipients) | |||||
->setSubject('[Chronicle] [Automatic Email] '.$this->getSetting('title')) | |||||
->setBody($body) | |||||
->saveAndSend(); | |||||
} | |||||
public function getFieldSpecifications() { | |||||
return array( | |||||
'recipients' => array( | |||||
'name' => pht('Recipients'), | |||||
'type' => 'users', | |||||
'required' => true, | |||||
), | |||||
'title' => array( | |||||
'name' => pht('Title'), | |||||
'type' => 'text' | |||||
), | |||||
'message' => array( | |||||
'name' => pht('Message'), | |||||
'type' => 'text' | |||||
), | |||||
); | |||||
} | |||||
public function canCreateOrEdit(PhabricatorUser $viewer) { | |||||
if (PhabricatorPolicyFilter::hasCapability( | |||||
$viewer, | |||||
new PhabricatorApplicationHerald(), | |||||
HeraldCapabilityManageGlobalRules::CAPABILITY)) { | |||||
return true; | |||||
} | |||||
// Anyone in the recipients list can also edit the trigger. | |||||
$recipients = phutil_json_decode($this->getSetting('recipients')); | |||||
return in_array($viewer->getPHID(), $recipients); | |||||
} | |||||
} |