Page MenuHomePhabricator
Paste P1236

SecurityPolicyEnforcerAction.php
ActivePublic

Authored by epriestley on Aug 14 2014, 9:28 PM.
Tags
None
Referenced Files
F190655: SecurityPolicyEnforcerAction.php
Aug 14 2014, 9:28 PM
Subscribers
None
<?php
class SecurityPolicyEnforcerAction extends HeraldCustomAction {
public function appliesToAdapter(HeraldAdapter $adapter) {
return $adapter instanceof HeraldManiphestTaskAdapter;
}
public function appliesToRuleType($rule_type) {
switch ($rule_type) {
case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL:
return true;
case HeraldRuleTypeConfig::RULE_TYPE_PERSONAL:
case HeraldRuleTypeConfig::RULE_TYPE_OBJECT:
default:
return false;
}
}
public function getActionKey() {
return "SecurityPolicy";
}
public function getActionName() {
return "Ensure Security Task Policy Are Enforced";
}
public function getActionType() {
return HeraldAdapter::VALUE_NONE;
}
public function applyEffect(
HeraldAdapter $adapter,
$object,
HeraldEffect $effect) {
$task = $object;
$viewer = PhabricatorUser::getOmnipotentUser();
$field_list = PhabricatorCustomField::getObjectFields(
$task,
PhabricatorCustomField::ROLE_EDIT);
$field_list
->setViewer($viewer)
->readFieldsFromStorage($task);
$field_value = null;
foreach ($field_list->getFields() as $field) {
$field_key = $field->getFieldKey();
// NOTE: Replace 'std:maniphest:ext_id' with your actual field key.
if ($field_key == 'std:maniphest:ext_id') {
$field_value = $field->getValueForStorage();
break;
}
}
$transactions = array();
$transactions[] = id(new ManiphestTransaction())
->setTransactionType(ManiphestTransaction::TYPE_TITLE)
->setNewValue($field_value);
foreach ($transactions as $transaction) {
$adapter->queueTransaction($transaction);
}
return new HeraldApplyTranscript(
$effect,
true,
pht('Set security policy'));
}
}

Event Timeline

epriestley changed the title of this paste from untitled to SecurityPolicyEnforcerAction.php.
epriestley updated the paste's language from autodetect to autodetect.