1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-18 21:02:41 +01:00

When all actions in a submenu are disabled, disable the submenu header

Summary: Fixes T11240. Also simplify things a little and share a bit more code.

Test Plan:
  - Viewed revisions and tasks, opened submenu.
  - Viewed as a user without edit permission, saw the menus greyed out.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T11240

Differential Revision: https://secure.phabricator.com/D16201
This commit is contained in:
epriestley 2016-06-30 10:20:56 -07:00
parent 2a7545a452
commit 7574f8dcf5
5 changed files with 57 additions and 43 deletions

View file

@ -527,22 +527,16 @@ final class DifferentialRevisionViewController extends DifferentialController {
$viewer, $viewer,
$revision); $revision);
$parent_key = DifferentialRevisionHasParentRelationship::RELATIONSHIPKEY; $revision_actions = array(
$child_key = DifferentialRevisionHasChildRelationship::RELATIONSHIPKEY; DifferentialRevisionHasParentRelationship::RELATIONSHIPKEY,
DifferentialRevisionHasChildRelationship::RELATIONSHIPKEY,
);
$revision_submenu = array(); $revision_submenu = $relationship_list->newActionSubmenu($revision_actions)
->setName(pht('Edit Related Revisions...'))
->setIcon('fa-cog');
$revision_submenu[] = $relationship_list->getRelationship($parent_key) $curtain->addAction($revision_submenu);
->newAction($revision);
$revision_submenu[] = $relationship_list->getRelationship($child_key)
->newAction($revision);
$curtain->addAction(
id(new PhabricatorActionView())
->setName(pht('Edit Related Revisions...'))
->setIcon('fa-cog')
->setSubmenu($revision_submenu));
$relationship_submenu = $relationship_list->newActionMenu(); $relationship_submenu = $relationship_list->newActionMenu();
if ($relationship_submenu) { if ($relationship_submenu) {

View file

@ -199,28 +199,18 @@ final class ManiphestTaskDetailController extends ManiphestController {
$viewer, $viewer,
$task); $task);
$parent_key = ManiphestTaskHasParentRelationship::RELATIONSHIPKEY; $submenu_actions = array(
$subtask_key = ManiphestTaskHasSubtaskRelationship::RELATIONSHIPKEY; ManiphestTaskHasParentRelationship::RELATIONSHIPKEY,
$merge_key = ManiphestTaskMergeInRelationship::RELATIONSHIPKEY; ManiphestTaskHasSubtaskRelationship::RELATIONSHIPKEY,
$close_key = ManiphestTaskCloseAsDuplicateRelationship::RELATIONSHIPKEY; ManiphestTaskMergeInRelationship::RELATIONSHIPKEY,
ManiphestTaskCloseAsDuplicateRelationship::RELATIONSHIPKEY,
);
$task_submenu[] = $relationship_list->getRelationship($parent_key) $task_submenu = $relationship_list->newActionSubmenu($submenu_actions)
->newAction($task); ->setName(pht('Edit Related Tasks...'))
->setIcon('fa-anchor');
$task_submenu[] = $relationship_list->getRelationship($subtask_key) $curtain->addAction($task_submenu);
->newAction($task);
$task_submenu[] = $relationship_list->getRelationship($merge_key)
->newAction($task);
$task_submenu[] = $relationship_list->getRelationship($close_key)
->newAction($task);
$curtain->addAction(
id(new PhabricatorActionView())
->setName(pht('Edit Related Tasks...'))
->setIcon('fa-anchor')
->setSubmenu($task_submenu));
$relationship_submenu = $relationship_list->newActionMenu(); $relationship_submenu = $relationship_list->newActionMenu();
if ($relationship_submenu) { if ($relationship_submenu) {

View file

@ -2,13 +2,6 @@
abstract class PhabricatorSearchBaseController extends PhabricatorController { abstract class PhabricatorSearchBaseController extends PhabricatorController {
const ACTION_ATTACH = 'attach';
const ACTION_MERGE = 'merge';
const ACTION_DEPENDENCIES = 'dependencies';
const ACTION_BLOCKS = 'blocks';
const ACTION_EDGE = 'edge';
protected function loadRelationshipObject() { protected function loadRelationshipObject() {
$request = $this->getRequest(); $request = $this->getRequest();
$viewer = $this->getViewer(); $viewer = $this->getViewer();

View file

@ -46,6 +46,26 @@ final class PhabricatorObjectRelationshipList extends Phobject {
return $this->relationships; return $this->relationships;
} }
public function newActionSubmenu(array $keys) {
$object = $this->getObject();
$actions = array();
foreach ($keys as $key) {
$relationship = $this->getRelationship($key);
if (!$relationship) {
throw new Exception(
pht(
'No object relationship of type "%s" exists.',
$key));
}
$actions[$key] = $relationship->newAction($object);
}
return $this->newMenuWithActions($actions);
}
public function newActionMenu() { public function newActionMenu() {
$relationships = $this->getRelationships(); $relationships = $this->getRelationships();
$object = $this->getObject(); $object = $this->getObject();
@ -65,9 +85,22 @@ final class PhabricatorObjectRelationshipList extends Phobject {
$actions = msort($actions, 'getName'); $actions = msort($actions, 'getName');
return id(new PhabricatorActionView()) return $this->newMenuWithActions($actions)
->setName(pht('Edit Related Objects...')) ->setName(pht('Edit Related Objects...'))
->setIcon('fa-link') ->setIcon('fa-link');
}
private function newMenuWithActions(array $actions) {
$any_enabled = false;
foreach ($actions as $action) {
if (!$action->getDisabled()) {
$any_enabled = true;
break;
}
}
return id(new PhabricatorActionView())
->setDisabled(!$any_enabled)
->setSubmenu($actions); ->setSubmenu($actions);
} }

View file

@ -84,6 +84,10 @@ final class PhabricatorActionView extends AphrontView {
return $this; return $this;
} }
public function getDisabled() {
return $this->disabled;
}
public function setWorkflow($workflow) { public function setWorkflow($workflow) {
$this->workflow = $workflow; $this->workflow = $workflow;
return $this; return $this;