Allow task policies to be edited from the UI; show policy information on the detail page
Summary: Ref T603. Adds policy controls to the task edit UI. @chad, status + policy renders a little weird -- did I mess something up? See screenshot. Test Plan: Edited policies, viewed a task. Reviewers: btrahan, chad Reviewed By: chad CC: aran Maniphest Tasks: T603 Differential Revision: https://secure.phabricator.com/D7123
This commit is contained in:
@@ -372,7 +372,9 @@ final class ManiphestTaskDetailController extends ManiphestController {
|
|||||||
|
|
||||||
private function buildHeaderView(ManiphestTask $task) {
|
private function buildHeaderView(ManiphestTask $task) {
|
||||||
$view = id(new PHUIHeaderView())
|
$view = id(new PHUIHeaderView())
|
||||||
->setHeader($task->getTitle());
|
->setHeader($task->getTitle())
|
||||||
|
->setUser($this->getRequest()->getUser())
|
||||||
|
->setPolicyObject($task);
|
||||||
|
|
||||||
$status = $task->getStatus();
|
$status = $task->getStatus();
|
||||||
$status_name = ManiphestTaskStatus::renderFullDescription($status);
|
$status_name = ManiphestTaskStatus::renderFullDescription($status);
|
||||||
|
|||||||
@@ -181,6 +181,11 @@ final class ManiphestTaskEditController extends ManiphestController {
|
|||||||
$changes[ManiphestTransaction::TYPE_PROJECTS] =
|
$changes[ManiphestTransaction::TYPE_PROJECTS] =
|
||||||
$request->getArr('projects');
|
$request->getArr('projects');
|
||||||
|
|
||||||
|
$changes[PhabricatorTransactions::TYPE_VIEW_POLICY] =
|
||||||
|
$request->getStr('viewPolicy');
|
||||||
|
$changes[PhabricatorTransactions::TYPE_EDIT_POLICY] =
|
||||||
|
$request->getStr('editPolicy');
|
||||||
|
|
||||||
if ($files) {
|
if ($files) {
|
||||||
$file_map = mpull($files, 'getPHID');
|
$file_map = mpull($files, 'getPHID');
|
||||||
$file_map = array_fill_keys($file_map, array());
|
$file_map = array_fill_keys($file_map, array());
|
||||||
@@ -431,6 +436,11 @@ final class ManiphestTaskEditController extends ManiphestController {
|
|||||||
->setOptions(ManiphestTaskStatus::getTaskStatusMap()));
|
->setOptions(ManiphestTaskStatus::getTaskStatusMap()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$policies = id(new PhabricatorPolicyQuery())
|
||||||
|
->setViewer($user)
|
||||||
|
->setObject($task)
|
||||||
|
->execute();
|
||||||
|
|
||||||
$form
|
$form
|
||||||
->appendChild(
|
->appendChild(
|
||||||
id(new AphrontFormTokenizerControl())
|
id(new AphrontFormTokenizerControl())
|
||||||
@@ -453,6 +463,24 @@ final class ManiphestTaskEditController extends ManiphestController {
|
|||||||
->setName('priority')
|
->setName('priority')
|
||||||
->setOptions($priority_map)
|
->setOptions($priority_map)
|
||||||
->setValue($task->getPriority()))
|
->setValue($task->getPriority()))
|
||||||
|
->appendChild(
|
||||||
|
id(new AphrontFormPolicyControl())
|
||||||
|
->setUser($user)
|
||||||
|
->setCapability(PhabricatorPolicyCapability::CAN_VIEW)
|
||||||
|
->setPolicyObject($task)
|
||||||
|
->setPolicies($policies)
|
||||||
|
->setName('viewPolicy'))
|
||||||
|
->appendChild(
|
||||||
|
id(new AphrontFormPolicyControl())
|
||||||
|
->setUser($user)
|
||||||
|
->setCapability(PhabricatorPolicyCapability::CAN_EDIT)
|
||||||
|
->setPolicyObject($task)
|
||||||
|
->setPolicies($policies)
|
||||||
|
->setCaption(
|
||||||
|
pht(
|
||||||
|
'NOTE: These policy controls still have some rough edges and '.
|
||||||
|
'are not yet fully functional.'))
|
||||||
|
->setName('editPolicy'))
|
||||||
->appendChild(
|
->appendChild(
|
||||||
id(new AphrontFormTokenizerControl())
|
id(new AphrontFormTokenizerControl())
|
||||||
->setLabel(pht('Projects'))
|
->setLabel(pht('Projects'))
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ final class ManiphestTransactionEditorPro
|
|||||||
$types[] = ManiphestTransaction::TYPE_PROJECTS;
|
$types[] = ManiphestTransaction::TYPE_PROJECTS;
|
||||||
$types[] = ManiphestTransaction::TYPE_ATTACH;
|
$types[] = ManiphestTransaction::TYPE_ATTACH;
|
||||||
$types[] = ManiphestTransaction::TYPE_EDGE;
|
$types[] = ManiphestTransaction::TYPE_EDGE;
|
||||||
|
$types[] = PhabricatorTransactions::TYPE_VIEW_POLICY;
|
||||||
|
$types[] = PhabricatorTransactions::TYPE_EDIT_POLICY;
|
||||||
|
|
||||||
return $types;
|
return $types;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -199,10 +199,25 @@ final class ManiphestTask extends ManiphestDAO
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function getPolicy($capability) {
|
public function getPolicy($capability) {
|
||||||
return PhabricatorPolicies::POLICY_USER;
|
switch ($capability) {
|
||||||
|
case PhabricatorPolicyCapability::CAN_VIEW:
|
||||||
|
return $this->getViewPolicy();
|
||||||
|
case PhabricatorPolicyCapability::CAN_EDIT:
|
||||||
|
return $this->getEditPolicy();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hasAutomaticCapability($capability, PhabricatorUser $user) {
|
public function hasAutomaticCapability($capability, PhabricatorUser $user) {
|
||||||
|
|
||||||
|
// The owner of a task can always view and edit it.
|
||||||
|
$owner_phid = $this->getOwnerPHID();
|
||||||
|
if ($owner_phid) {
|
||||||
|
$user_phid = $user->getPHID();
|
||||||
|
if ($user_phid == $owner_phid) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user