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',
|
'LiskRawMigrationIterator' => 'infrastructure/storage/lisk/LiskRawMigrationIterator.php',
|
||||||
'ManiphestAction' => 'applications/maniphest/constants/ManiphestAction.php',
|
'ManiphestAction' => 'applications/maniphest/constants/ManiphestAction.php',
|
||||||
'ManiphestBatchEditController' => 'applications/maniphest/controller/ManiphestBatchEditController.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',
|
'ManiphestConfiguredCustomField' => 'applications/maniphest/field/ManiphestConfiguredCustomField.php',
|
||||||
'ManiphestConstants' => 'applications/maniphest/constants/ManiphestConstants.php',
|
'ManiphestConstants' => 'applications/maniphest/constants/ManiphestConstants.php',
|
||||||
'ManiphestController' => 'applications/maniphest/controller/ManiphestController.php',
|
'ManiphestController' => 'applications/maniphest/controller/ManiphestController.php',
|
||||||
|
@ -2821,6 +2823,8 @@ phutil_register_library_map(array(
|
||||||
'LiskRawMigrationIterator' => 'PhutilBufferedIterator',
|
'LiskRawMigrationIterator' => 'PhutilBufferedIterator',
|
||||||
'ManiphestAction' => 'ManiphestConstants',
|
'ManiphestAction' => 'ManiphestConstants',
|
||||||
'ManiphestBatchEditController' => 'ManiphestController',
|
'ManiphestBatchEditController' => 'ManiphestController',
|
||||||
|
'ManiphestCapabilityDefaultEdit' => 'PhabricatorPolicyCapability',
|
||||||
|
'ManiphestCapabilityDefaultView' => 'PhabricatorPolicyCapability',
|
||||||
'ManiphestConfiguredCustomField' =>
|
'ManiphestConfiguredCustomField' =>
|
||||||
array(
|
array(
|
||||||
0 => 'ManiphestCustomField',
|
0 => 'ManiphestCustomField',
|
||||||
|
|
|
@ -90,5 +90,18 @@ final class PhabricatorApplicationManiphest extends PhabricatorApplication {
|
||||||
return $status;
|
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) {
|
protected function execute(ConduitAPIRequest $request) {
|
||||||
$task = new ManiphestTask();
|
$task = ManiphestTask::initializeNewTask($request->getUser());
|
||||||
$task->setPriority(ManiphestTaskPriority::getDefaultPriority());
|
|
||||||
$task->setAuthorPHID($request->getUser()->getPHID());
|
|
||||||
|
|
||||||
$this->applyRequest($task, $request, $is_new = true);
|
$this->applyRequest($task, $request, $is_new = true);
|
||||||
|
|
||||||
|
|
|
@ -34,9 +34,7 @@ final class ManiphestTaskEditController extends ManiphestController {
|
||||||
return new Aphront404Response();
|
return new Aphront404Response();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$task = new ManiphestTask();
|
$task = ManiphestTask::initializeNewTask($user);
|
||||||
$task->setPriority(ManiphestTaskPriority::getDefaultPriority());
|
|
||||||
$task->setAuthorPHID($user->getPHID());
|
|
||||||
|
|
||||||
// These allow task creation with defaults.
|
// These allow task creation with defaults.
|
||||||
if (!$request->isFormPost()) {
|
if (!$request->isFormPost()) {
|
||||||
|
|
|
@ -7,9 +7,8 @@ final class PhabricatorManiphestTaskTestDataGenerator
|
||||||
$authorPHID = $this->loadPhabrictorUserPHID();
|
$authorPHID = $this->loadPhabrictorUserPHID();
|
||||||
$author = id(new PhabricatorUser())
|
$author = id(new PhabricatorUser())
|
||||||
->loadOneWhere('phid = %s', $authorPHID);
|
->loadOneWhere('phid = %s', $authorPHID);
|
||||||
$task = id(new ManiphestTask())
|
$task = ManiphestTask::initializeNewTask($author)
|
||||||
->setSubPriority($this->generateTaskSubPriority())
|
->setSubPriority($this->generateTaskSubPriority())
|
||||||
->setAuthorPHID($authorPHID)
|
|
||||||
->setTitle($this->generateTitle())
|
->setTitle($this->generateTitle())
|
||||||
->setStatus(ManiphestTaskStatus::STATUS_OPEN);
|
->setStatus(ManiphestTaskStatus::STATUS_OPEN);
|
||||||
|
|
||||||
|
|
|
@ -60,11 +60,8 @@ final class ManiphestCreateMailReceiver extends PhabricatorMailReceiver {
|
||||||
PhabricatorMetaMTAReceivedMail $mail,
|
PhabricatorMetaMTAReceivedMail $mail,
|
||||||
PhabricatorUser $sender) {
|
PhabricatorUser $sender) {
|
||||||
|
|
||||||
$task = new ManiphestTask();
|
$task = ManiphestTask::initializeNewTask($sender);
|
||||||
|
|
||||||
$task->setAuthorPHID($sender->getPHID());
|
|
||||||
$task->setOriginalEmailSource($mail->getHeader('From'));
|
$task->setOriginalEmailSource($mail->getHeader('From'));
|
||||||
$task->setPriority(ManiphestTaskPriority::getDefaultPriority());
|
|
||||||
|
|
||||||
$editor = new ManiphestTransactionEditor();
|
$editor = new ManiphestTransactionEditor();
|
||||||
$editor->setActor($sender);
|
$editor->setActor($sender);
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
|
||||||
* @group maniphest
|
|
||||||
*/
|
|
||||||
final class ManiphestTask extends ManiphestDAO
|
final class ManiphestTask extends ManiphestDAO
|
||||||
implements
|
implements
|
||||||
PhabricatorMarkupInterface,
|
PhabricatorMarkupInterface,
|
||||||
|
@ -40,6 +37,22 @@ final class ManiphestTask extends ManiphestDAO
|
||||||
private $groupByProjectPHID = self::ATTACHABLE;
|
private $groupByProjectPHID = self::ATTACHABLE;
|
||||||
private $customFields = 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() {
|
public function getConfiguration() {
|
||||||
return array(
|
return array(
|
||||||
self::CONFIG_AUX_PHID => true,
|
self::CONFIG_AUX_PHID => true,
|
||||||
|
|
|
@ -54,6 +54,12 @@ final class PhabricatorMailManagementShowInboundWorkflow
|
||||||
$info[] = pht('Author PHID: %s', $message->getAuthorPHID());
|
$info[] = pht('Author PHID: %s', $message->getAuthorPHID());
|
||||||
$info[] = pht('Message ID Hash: %s', $message->getMessageIDHash());
|
$info[] = pht('Message ID Hash: %s', $message->getMessageIDHash());
|
||||||
|
|
||||||
|
if ($message->getMessage()) {
|
||||||
|
$info[] = null;
|
||||||
|
$info[] = pht('MESSAGE');
|
||||||
|
$info[] = $message->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
$info[] = null;
|
$info[] = null;
|
||||||
$info[] = pht('HEADERS');
|
$info[] = pht('HEADERS');
|
||||||
foreach ($message->getHeaders() as $key => $value) {
|
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
|
* @return string Human-readable name describing what failing a check for this
|
||||||
* capability prevents the user from doing.
|
* capability prevents the user from doing.
|
||||||
*/
|
*/
|
||||||
abstract public function describeCapabilityRejection();
|
public function describeCapabilityRejection() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
final public static function getCapabilityByKey($key) {
|
final public static function getCapabilityByKey($key) {
|
||||||
|
|
|
@ -243,15 +243,21 @@ final class PhabricatorPolicyFilter {
|
||||||
}
|
}
|
||||||
|
|
||||||
$capobj = PhabricatorPolicyCapability::getCapabilityByKey($capability);
|
$capobj = PhabricatorPolicyCapability::getCapabilityByKey($capability);
|
||||||
|
$rejection = null;
|
||||||
if ($capobj) {
|
if ($capobj) {
|
||||||
$rejection = $capobj->describeCapabilityRejection();
|
$rejection = $capobj->describeCapabilityRejection();
|
||||||
$capability_name = $capobj->getCapabilityName();
|
$capability_name = $capobj->getCapabilityName();
|
||||||
} else {
|
} else {
|
||||||
|
$capability_name = $capability;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$rejection) {
|
||||||
|
// We couldn't find the capability object, or it doesn't provide a
|
||||||
|
// tailored rejection string.
|
||||||
$rejection = pht(
|
$rejection = pht(
|
||||||
'You do not have the required capability ("%s") to do whatever you '.
|
'You do not have the required capability ("%s") to do whatever you '.
|
||||||
'are trying to do.',
|
'are trying to do.',
|
||||||
$capability);
|
$capability);
|
||||||
$capability_name = $capability;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$more = PhabricatorPolicy::getPolicyExplanation($this->viewer, $policy);
|
$more = PhabricatorPolicy::getPolicyExplanation($this->viewer, $policy);
|
||||||
|
@ -264,7 +270,8 @@ final class PhabricatorPolicyFilter {
|
||||||
// a better error message if we can.
|
// a better error message if we can.
|
||||||
|
|
||||||
$phid = '?';
|
$phid = '?';
|
||||||
if ($object instanceof PhabricatorLiskDAO) {
|
if (($object instanceof PhabricatorLiskDAO) ||
|
||||||
|
(method_exists($object, 'getPHID'))) {
|
||||||
try {
|
try {
|
||||||
$phid = $object->getPHID();
|
$phid = $object->getPHID();
|
||||||
} catch (Exception $ignored) {
|
} catch (Exception $ignored) {
|
||||||
|
@ -276,6 +283,7 @@ final class PhabricatorPolicyFilter {
|
||||||
->setViewer($this->viewer)
|
->setViewer($this->viewer)
|
||||||
->withPHIDs(array($phid))
|
->withPHIDs(array($phid))
|
||||||
->executeOne();
|
->executeOne();
|
||||||
|
|
||||||
$object_name = pht(
|
$object_name = pht(
|
||||||
'%s %s',
|
'%s %s',
|
||||||
$handle->getTypeName(),
|
$handle->getTypeName(),
|
||||||
|
|
Loading…
Reference in a new issue