mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-27 01:02:42 +01:00
Add defualt view and default edit policies for tasks
Summary: Ref T603. Allow global default policies to be configured for tasks. Test Plan: - Created task via web UI. - Created task via Conduit. - Created task via email. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T603 Differential Revision: https://secure.phabricator.com/D7267
This commit is contained in:
parent
3147a6ca57
commit
1ee455c441
12 changed files with 88 additions and 18 deletions
|
@ -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',
|
||||
|
|
|
@ -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.'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
final class ManiphestCapabilityDefaultEdit
|
||||
extends PhabricatorPolicyCapability {
|
||||
|
||||
const CAPABILITY = 'maniphest.default.edit';
|
||||
|
||||
public function getCapabilityKey() {
|
||||
return self::CAPABILITY;
|
||||
}
|
||||
|
||||
public function getCapabilityName() {
|
||||
return pht('Default Edit Policy');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
final class ManiphestCapabilityDefaultView
|
||||
extends PhabricatorPolicyCapability {
|
||||
|
||||
const CAPABILITY = 'maniphest.default.view';
|
||||
|
||||
public function getCapabilityKey() {
|
||||
return self::CAPABILITY;
|
||||
}
|
||||
|
||||
public function getCapabilityName() {
|
||||
return pht('Default View Policy');
|
||||
}
|
||||
|
||||
}
|
|
@ -25,9 +25,7 @@ final class ConduitAPI_maniphest_createtask_Method
|
|||
}
|
||||
|
||||
protected function execute(ConduitAPIRequest $request) {
|
||||
$task = new ManiphestTask();
|
||||
$task->setPriority(ManiphestTaskPriority::getDefaultPriority());
|
||||
$task->setAuthorPHID($request->getUser()->getPHID());
|
||||
$task = ManiphestTask::initializeNewTask($request->getUser());
|
||||
|
||||
$this->applyRequest($task, $request, $is_new = true);
|
||||
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @group maniphest
|
||||
*/
|
||||
final class ManiphestTask extends ManiphestDAO
|
||||
implements
|
||||
PhabricatorMarkupInterface,
|
||||
|
@ -40,6 +37,22 @@ final class ManiphestTask extends ManiphestDAO
|
|||
private $groupByProjectPHID = self::ATTACHABLE;
|
||||
private $customFields = self::ATTACHABLE;
|
||||
|
||||
public static function initializeNewTask(PhabricatorUser $actor) {
|
||||
$app = id(new PhabricatorApplicationQuery())
|
||||
->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,
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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(),
|
||||
|
|
Loading…
Reference in a new issue