Differential D21699 Diff 51675 src/applications/harbormaster/xaction/build/HarbormasterBuildMessageTransaction.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/harbormaster/xaction/build/HarbormasterBuildMessageTransaction.php
Show First 20 Lines • Show All 80 Lines • ▼ Show 20 Lines | abstract class HarbormasterBuildMessageTransaction | ||||
final public function canApplyMessage( | final public function canApplyMessage( | ||||
PhabricatorUser $viewer, | PhabricatorUser $viewer, | ||||
HarbormasterBuild $build) { | HarbormasterBuild $build) { | ||||
try { | try { | ||||
$this->assertCanApplyMessage($viewer, $build); | $this->assertCanApplyMessage($viewer, $build); | ||||
return true; | return true; | ||||
} catch (HarbormasterRestartException $ex) { | } catch (HarbormasterMessageException $ex) { | ||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
final public function canSendMessage( | final public function canSendMessage( | ||||
PhabricatorUser $viewer, | PhabricatorUser $viewer, | ||||
HarbormasterBuild $build) { | HarbormasterBuild $build) { | ||||
try { | try { | ||||
$this->assertCanSendMessage($viewer, $build); | $this->assertCanSendMessage($viewer, $build); | ||||
return true; | return true; | ||||
} catch (HarbormasterRestartException $ex) { | } catch (HarbormasterMessageException $ex) { | ||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
final public function assertCanApplyMessage( | final public function assertCanApplyMessage( | ||||
PhabricatorUser $viewer, | PhabricatorUser $viewer, | ||||
HarbormasterBuild $build) { | HarbormasterBuild $build) { | ||||
$this->newCanApplyMessageAssertion($viewer, $build); | $this->newCanApplyMessageAssertion($viewer, $build); | ||||
} | } | ||||
final public function assertCanSendMessage( | final public function assertCanSendMessage( | ||||
PhabricatorUser $viewer, | PhabricatorUser $viewer, | ||||
HarbormasterBuild $build) { | HarbormasterBuild $build) { | ||||
$plan = $build->getBuildPlan(); | $plan = $build->getBuildPlan(); | ||||
// See T13526. Users without permission to access the build plan can | // See T13526. Users without permission to access the build plan can | ||||
// currently end up here with no "BuildPlan" object. | // currently end up here with no "BuildPlan" object. | ||||
if (!$plan) { | if (!$plan) { | ||||
throw new HarbormasterRestartException( | throw new HarbormasterMessageException( | ||||
pht('No Build Plan Permission'), | pht('No Build Plan Permission'), | ||||
pht( | pht( | ||||
'You can not issue this command because you do not have '. | 'You can not issue this command because you do not have '. | ||||
'permission to access the build plan for this build.')); | 'permission to access the build plan for this build.')); | ||||
} | } | ||||
// Issuing these commands requires that you be able to edit the build, to | // Issuing these commands requires that you be able to edit the build, to | ||||
// prevent enemy engineers from sabotaging your builds. See T9614. | // prevent enemy engineers from sabotaging your builds. See T9614. | ||||
if (!$plan->canRunWithoutEditCapability()) { | if (!$plan->canRunWithoutEditCapability()) { | ||||
try { | try { | ||||
PhabricatorPolicyFilter::requireCapability( | PhabricatorPolicyFilter::requireCapability( | ||||
$viewer, | $viewer, | ||||
$plan, | $plan, | ||||
PhabricatorPolicyCapability::CAN_EDIT); | PhabricatorPolicyCapability::CAN_EDIT); | ||||
} catch (PhabricatorPolicyException $ex) { | } catch (PhabricatorPolicyException $ex) { | ||||
throw new HarbormasterRestartException( | throw new HarbormasterMessageException( | ||||
pht('Insufficent Build Plan Permission'), | pht('Insufficent Build Plan Permission'), | ||||
pht( | pht( | ||||
'The build plan for this build is configured to prevent '. | 'The build plan for this build is configured to prevent '. | ||||
'users who can not edit it from issuing commands to the '. | 'users who can not edit it from issuing commands to the '. | ||||
'build, and you do not have permission to edit the build '. | 'build, and you do not have permission to edit the build '. | ||||
'plan.')); | 'plan.')); | ||||
} | } | ||||
} | } | ||||
Show All 14 Lines |