Path: blob/master/src/applications/herald/controller/HeraldDisableController.php
12256 views
<?php12final class HeraldDisableController extends HeraldController {34public function handleRequest(AphrontRequest $request) {5$viewer = $request->getViewer();6$id = $request->getURIData('id');7$action = $request->getURIData('action');89$rule = id(new HeraldRuleQuery())10->setViewer($viewer)11->withIDs(array($id))12->requireCapabilities(13array(14PhabricatorPolicyCapability::CAN_VIEW,15PhabricatorPolicyCapability::CAN_EDIT,16))17->executeOne();18if (!$rule) {19return new Aphront404Response();20}2122if ($rule->isGlobalRule()) {23$this->requireApplicationCapability(24HeraldManageGlobalRulesCapability::CAPABILITY);25}2627$view_uri = '/'.$rule->getMonogram();2829$is_disable = ($action === 'disable');3031if ($request->isFormPost()) {32$xaction = id(new HeraldRuleTransaction())33->setTransactionType(HeraldRuleDisableTransaction::TRANSACTIONTYPE)34->setNewValue($is_disable);3536id(new HeraldRuleEditor())37->setActor($viewer)38->setContinueOnNoEffect(true)39->setContentSourceFromRequest($request)40->applyTransactions($rule, array($xaction));4142return id(new AphrontRedirectResponse())->setURI($view_uri);43}4445if ($is_disable) {46$title = pht('Really disable this rule?');47$body = pht('This rule will no longer activate.');48$button = pht('Disable Rule');49} else {50$title = pht('Really enable this rule?');51$body = pht('This rule will become active again.');52$button = pht('Enable Rule');53}5455$dialog = id(new AphrontDialogView())56->setUser($viewer)57->setTitle($title)58->appendChild($body)59->addSubmitButton($button)60->addCancelButton($view_uri);6162return id(new AphrontDialogResponse())->setDialog($dialog);63}6465}666768