Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/herald/controller/HeraldDisableController.php
12256 views
1
<?php
2
3
final class HeraldDisableController extends HeraldController {
4
5
public function handleRequest(AphrontRequest $request) {
6
$viewer = $request->getViewer();
7
$id = $request->getURIData('id');
8
$action = $request->getURIData('action');
9
10
$rule = id(new HeraldRuleQuery())
11
->setViewer($viewer)
12
->withIDs(array($id))
13
->requireCapabilities(
14
array(
15
PhabricatorPolicyCapability::CAN_VIEW,
16
PhabricatorPolicyCapability::CAN_EDIT,
17
))
18
->executeOne();
19
if (!$rule) {
20
return new Aphront404Response();
21
}
22
23
if ($rule->isGlobalRule()) {
24
$this->requireApplicationCapability(
25
HeraldManageGlobalRulesCapability::CAPABILITY);
26
}
27
28
$view_uri = '/'.$rule->getMonogram();
29
30
$is_disable = ($action === 'disable');
31
32
if ($request->isFormPost()) {
33
$xaction = id(new HeraldRuleTransaction())
34
->setTransactionType(HeraldRuleDisableTransaction::TRANSACTIONTYPE)
35
->setNewValue($is_disable);
36
37
id(new HeraldRuleEditor())
38
->setActor($viewer)
39
->setContinueOnNoEffect(true)
40
->setContentSourceFromRequest($request)
41
->applyTransactions($rule, array($xaction));
42
43
return id(new AphrontRedirectResponse())->setURI($view_uri);
44
}
45
46
if ($is_disable) {
47
$title = pht('Really disable this rule?');
48
$body = pht('This rule will no longer activate.');
49
$button = pht('Disable Rule');
50
} else {
51
$title = pht('Really enable this rule?');
52
$body = pht('This rule will become active again.');
53
$button = pht('Enable Rule');
54
}
55
56
$dialog = id(new AphrontDialogView())
57
->setUser($viewer)
58
->setTitle($title)
59
->appendChild($body)
60
->addSubmitButton($button)
61
->addCancelButton($view_uri);
62
63
return id(new AphrontDialogResponse())->setDialog($dialog);
64
}
65
66
}
67
68