diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index ec8f1a4432..28aaa63c27 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -706,6 +706,8 @@ phutil_register_library_map(array( 'LiskRawMigrationIterator' => 'infrastructure/storage/lisk/LiskRawMigrationIterator.php', 'ManiphestAction' => 'applications/maniphest/constants/ManiphestAction.php', 'ManiphestBatchEditController' => 'applications/maniphest/controller/ManiphestBatchEditController.php', + 'ManiphestCapabilityDefaultEdit' => 'applications/maniphest/capability/ManiphestCapabilityDefaultEdit.php', + 'ManiphestCapabilityDefaultView' => 'applications/maniphest/capability/ManiphestCapabilityDefaultView.php', 'ManiphestConfiguredCustomField' => 'applications/maniphest/field/ManiphestConfiguredCustomField.php', 'ManiphestConstants' => 'applications/maniphest/constants/ManiphestConstants.php', 'ManiphestController' => 'applications/maniphest/controller/ManiphestController.php', @@ -2821,6 +2823,8 @@ phutil_register_library_map(array( 'LiskRawMigrationIterator' => 'PhutilBufferedIterator', 'ManiphestAction' => 'ManiphestConstants', 'ManiphestBatchEditController' => 'ManiphestController', + 'ManiphestCapabilityDefaultEdit' => 'PhabricatorPolicyCapability', + 'ManiphestCapabilityDefaultView' => 'PhabricatorPolicyCapability', 'ManiphestConfiguredCustomField' => array( 0 => 'ManiphestCustomField', diff --git a/src/applications/maniphest/application/PhabricatorApplicationManiphest.php b/src/applications/maniphest/application/PhabricatorApplicationManiphest.php index 044a40ab10..0bcf54bfc2 100644 --- a/src/applications/maniphest/application/PhabricatorApplicationManiphest.php +++ b/src/applications/maniphest/application/PhabricatorApplicationManiphest.php @@ -90,5 +90,18 @@ final class PhabricatorApplicationManiphest extends PhabricatorApplication { return $status; } + protected function getCustomCapabilities() { + return array( + ManiphestCapabilityDefaultView::CAPABILITY => array( + 'caption' => pht( + 'Default view policy for newly created tasks.'), + ), + ManiphestCapabilityDefaultEdit::CAPABILITY => array( + 'caption' => pht( + 'Default edit policy for newly created tasks.'), + ), + ); + } + } diff --git a/src/applications/maniphest/capability/ManiphestCapabilityDefaultEdit.php b/src/applications/maniphest/capability/ManiphestCapabilityDefaultEdit.php new file mode 100644 index 0000000000..b7a79fa95a --- /dev/null +++ b/src/applications/maniphest/capability/ManiphestCapabilityDefaultEdit.php @@ -0,0 +1,16 @@ +setPriority(ManiphestTaskPriority::getDefaultPriority()); - $task->setAuthorPHID($request->getUser()->getPHID()); + $task = ManiphestTask::initializeNewTask($request->getUser()); $this->applyRequest($task, $request, $is_new = true); diff --git a/src/applications/maniphest/controller/ManiphestTaskEditController.php b/src/applications/maniphest/controller/ManiphestTaskEditController.php index 73a2445d6b..9bd375a00a 100644 --- a/src/applications/maniphest/controller/ManiphestTaskEditController.php +++ b/src/applications/maniphest/controller/ManiphestTaskEditController.php @@ -34,9 +34,7 @@ final class ManiphestTaskEditController extends ManiphestController { return new Aphront404Response(); } } else { - $task = new ManiphestTask(); - $task->setPriority(ManiphestTaskPriority::getDefaultPriority()); - $task->setAuthorPHID($user->getPHID()); + $task = ManiphestTask::initializeNewTask($user); // These allow task creation with defaults. if (!$request->isFormPost()) { diff --git a/src/applications/maniphest/lipsum/PhabricatorManiphestTaskTestDataGenerator.php b/src/applications/maniphest/lipsum/PhabricatorManiphestTaskTestDataGenerator.php index bf3573cbed..801ec899c4 100644 --- a/src/applications/maniphest/lipsum/PhabricatorManiphestTaskTestDataGenerator.php +++ b/src/applications/maniphest/lipsum/PhabricatorManiphestTaskTestDataGenerator.php @@ -7,9 +7,8 @@ final class PhabricatorManiphestTaskTestDataGenerator $authorPHID = $this->loadPhabrictorUserPHID(); $author = id(new PhabricatorUser()) ->loadOneWhere('phid = %s', $authorPHID); - $task = id(new ManiphestTask()) + $task = ManiphestTask::initializeNewTask($author) ->setSubPriority($this->generateTaskSubPriority()) - ->setAuthorPHID($authorPHID) ->setTitle($this->generateTitle()) ->setStatus(ManiphestTaskStatus::STATUS_OPEN); diff --git a/src/applications/maniphest/mail/ManiphestCreateMailReceiver.php b/src/applications/maniphest/mail/ManiphestCreateMailReceiver.php index c295ef7760..090fda420c 100644 --- a/src/applications/maniphest/mail/ManiphestCreateMailReceiver.php +++ b/src/applications/maniphest/mail/ManiphestCreateMailReceiver.php @@ -60,11 +60,8 @@ final class ManiphestCreateMailReceiver extends PhabricatorMailReceiver { PhabricatorMetaMTAReceivedMail $mail, PhabricatorUser $sender) { - $task = new ManiphestTask(); - - $task->setAuthorPHID($sender->getPHID()); + $task = ManiphestTask::initializeNewTask($sender); $task->setOriginalEmailSource($mail->getHeader('From')); - $task->setPriority(ManiphestTaskPriority::getDefaultPriority()); $editor = new ManiphestTransactionEditor(); $editor->setActor($sender); diff --git a/src/applications/maniphest/storage/ManiphestTask.php b/src/applications/maniphest/storage/ManiphestTask.php index b9750b06dd..b15544429d 100644 --- a/src/applications/maniphest/storage/ManiphestTask.php +++ b/src/applications/maniphest/storage/ManiphestTask.php @@ -1,8 +1,5 @@ setViewer($actor) + ->withClasses(array('PhabricatorApplicationManiphest')) + ->executeOne(); + + $view_policy = $app->getPolicy(ManiphestCapabilityDefaultView::CAPABILITY); + $edit_policy = $app->getPolicy(ManiphestCapabilityDefaultEdit::CAPABILITY); + + return id(new ManiphestTask()) + ->setPriority(ManiphestTaskPriority::getDefaultPriority()) + ->setAuthorPHID($actor->getPHID()) + ->setViewPolicy($view_policy) + ->setEditPolicy($edit_policy); + } + public function getConfiguration() { return array( self::CONFIG_AUX_PHID => true, diff --git a/src/applications/metamta/management/PhabricatorMailManagementShowInboundWorkflow.php b/src/applications/metamta/management/PhabricatorMailManagementShowInboundWorkflow.php index 6e307735ba..5226bd2dc2 100644 --- a/src/applications/metamta/management/PhabricatorMailManagementShowInboundWorkflow.php +++ b/src/applications/metamta/management/PhabricatorMailManagementShowInboundWorkflow.php @@ -54,6 +54,12 @@ final class PhabricatorMailManagementShowInboundWorkflow $info[] = pht('Author PHID: %s', $message->getAuthorPHID()); $info[] = pht('Message ID Hash: %s', $message->getMessageIDHash()); + if ($message->getMessage()) { + $info[] = null; + $info[] = pht('MESSAGE'); + $info[] = $message->getMessage(); + } + $info[] = null; $info[] = pht('HEADERS'); foreach ($message->getHeaders() as $key => $value) { diff --git a/src/applications/policy/capability/PhabricatorPolicyCapability.php b/src/applications/policy/capability/PhabricatorPolicyCapability.php index 7526c5c5b3..ea925f2541 100644 --- a/src/applications/policy/capability/PhabricatorPolicyCapability.php +++ b/src/applications/policy/capability/PhabricatorPolicyCapability.php @@ -36,7 +36,9 @@ abstract class PhabricatorPolicyCapability extends Phobject { * @return string Human-readable name describing what failing a check for this * capability prevents the user from doing. */ - abstract public function describeCapabilityRejection(); + public function describeCapabilityRejection() { + return null; + } final public static function getCapabilityByKey($key) { diff --git a/src/applications/policy/filter/PhabricatorPolicyFilter.php b/src/applications/policy/filter/PhabricatorPolicyFilter.php index 2838982249..8bc32e22a7 100644 --- a/src/applications/policy/filter/PhabricatorPolicyFilter.php +++ b/src/applications/policy/filter/PhabricatorPolicyFilter.php @@ -243,15 +243,21 @@ final class PhabricatorPolicyFilter { } $capobj = PhabricatorPolicyCapability::getCapabilityByKey($capability); + $rejection = null; if ($capobj) { $rejection = $capobj->describeCapabilityRejection(); $capability_name = $capobj->getCapabilityName(); } else { + $capability_name = $capability; + } + + if (!$rejection) { + // We couldn't find the capability object, or it doesn't provide a + // tailored rejection string. $rejection = pht( 'You do not have the required capability ("%s") to do whatever you '. 'are trying to do.', $capability); - $capability_name = $capability; } $more = PhabricatorPolicy::getPolicyExplanation($this->viewer, $policy); @@ -264,7 +270,8 @@ final class PhabricatorPolicyFilter { // a better error message if we can. $phid = '?'; - if ($object instanceof PhabricatorLiskDAO) { + if (($object instanceof PhabricatorLiskDAO) || + (method_exists($object, 'getPHID'))) { try { $phid = $object->getPHID(); } catch (Exception $ignored) { @@ -276,6 +283,7 @@ final class PhabricatorPolicyFilter { ->setViewer($this->viewer) ->withPHIDs(array($phid)) ->executeOne(); + $object_name = pht( '%s %s', $handle->getTypeName(),