Page MenuHomePhabricator

D7365.id16581.diff
No OneTemporary

D7365.id16581.diff

Index: src/__phutil_library_map__.php
===================================================================
--- src/__phutil_library_map__.php
+++ src/__phutil_library_map__.php
@@ -297,7 +297,7 @@
'DefaultDatabaseConfigurationProvider' => 'infrastructure/storage/configuration/DefaultDatabaseConfigurationProvider.php',
'DifferentialAction' => 'applications/differential/constants/DifferentialAction.php',
'DifferentialActionHasNoEffectException' => 'applications/differential/exception/DifferentialActionHasNoEffectException.php',
- 'DifferentialActionMenuEventListener' => 'applications/differential/events/DifferentialActionMenuEventListener.php',
+ 'DifferentialActionMenuEventListener' => 'applications/differential/event/DifferentialActionMenuEventListener.php',
'DifferentialAddCommentView' => 'applications/differential/view/DifferentialAddCommentView.php',
'DifferentialAffectedPath' => 'applications/differential/storage/DifferentialAffectedPath.php',
'DifferentialApplyPatchFieldSpecification' => 'applications/differential/field/specification/DifferentialApplyPatchFieldSpecification.php',
@@ -368,7 +368,7 @@
'DifferentialFreeformFieldTestCase' => 'applications/differential/field/specification/__tests__/DifferentialFreeformFieldTestCase.php',
'DifferentialGitSVNIDFieldSpecification' => 'applications/differential/field/specification/DifferentialGitSVNIDFieldSpecification.php',
'DifferentialHostFieldSpecification' => 'applications/differential/field/specification/DifferentialHostFieldSpecification.php',
- 'DifferentialHovercardEventListener' => 'applications/differential/events/DifferentialHovercardEventListener.php',
+ 'DifferentialHovercardEventListener' => 'applications/differential/event/DifferentialHovercardEventListener.php',
'DifferentialHunk' => 'applications/differential/storage/DifferentialHunk.php',
'DifferentialHunkParser' => 'applications/differential/parser/DifferentialHunkParser.php',
'DifferentialHunkParserTestCase' => 'applications/differential/parser/__tests__/DifferentialHunkParserTestCase.php',
@@ -1873,6 +1873,7 @@
'PhluxVariableEditor' => 'applications/phlux/editor/PhluxVariableEditor.php',
'PhluxVariableQuery' => 'applications/phlux/query/PhluxVariableQuery.php',
'PhluxViewController' => 'applications/phlux/controller/PhluxViewController.php',
+ 'PholioActionMenuEventListener' => 'applications/pholio/event/PholioActionMenuEventListener.php',
'PholioConstants' => 'applications/pholio/constants/PholioConstants.php',
'PholioController' => 'applications/pholio/controller/PholioController.php',
'PholioDAO' => 'applications/pholio/storage/PholioDAO.php',
@@ -4116,6 +4117,7 @@
'PhluxVariableEditor' => 'PhabricatorApplicationTransactionEditor',
'PhluxVariableQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhluxViewController' => 'PhluxController',
+ 'PholioActionMenuEventListener' => 'PhabricatorEventListener',
'PholioController' => 'PhabricatorController',
'PholioDAO' => 'PhabricatorLiskDAO',
'PholioImage' =>
Index: src/applications/audit/events/AuditActionMenuEventListener.php
===================================================================
--- src/applications/audit/events/AuditActionMenuEventListener.php
+++ src/applications/audit/events/AuditActionMenuEventListener.php
@@ -14,24 +14,32 @@
}
}
- private function handleActionsEvent($event) {
- $person = $event->getValue('object');
- if (!($person instanceof PhabricatorUser)) {
- return;
+ private function handleActionsEvent(PhutilEvent $event) {
+ $object = $event->getValue('object');
+
+ $actions = null;
+ if ($object instanceof PhabricatorUser) {
+ $actions = $this->renderUserItems($event);
+ }
+
+ $this->addActionMenuItems($event, $actions);
+ }
+
+ private function renderUserItems(PhutilEvent $event) {
+ if (!$this->canUseApplication($event->getUser())) {
+ return null;
}
- $actions = $event->getValue('actions');
+ $user = $event->getValue('object');
- $username = phutil_escape_uri($person->getUsername());
- $href = '/audit/view/author/'.$username.'/';
+ $username = phutil_escape_uri($user->getUsername());
+ $view_uri = '/audit/view/author/'.$username.'/';
- $actions[] = id(new PhabricatorActionView())
+ return id(new PhabricatorActionView())
->setIcon('audit-dark')
->setIconSheet(PHUIIconView::SPRITE_APPS)
->setName(pht('View Commits'))
- ->setHref($href);
-
- $event->setValue('actions', $actions);
+ ->setHref($view_uri);
}
}
Index: src/applications/conpherence/events/ConpherenceActionMenuEventListener.php
===================================================================
--- src/applications/conpherence/events/ConpherenceActionMenuEventListener.php
+++ src/applications/conpherence/events/ConpherenceActionMenuEventListener.php
@@ -15,23 +15,30 @@
}
}
- private function handleActionsEvent($event) {
- $person = $event->getValue('object');
- if (!($person instanceof PhabricatorUser)) {
- return;
+ private function handleActionsEvent(PhutilEvent $event) {
+ $object = $event->getValue('object');
+
+ $actions = null;
+ if ($object instanceof PhabricatorUser) {
+ $actions = $this->renderUserItems($event);
}
- $href = '/conpherence/new/?participant='.$person->getPHID();
+ $this->addActionMenuItems($event, $actions);
+ }
- $actions = $event->getValue('actions');
+ private function renderUserItems(PhutilEvent $event) {
+ if (!$this->canUseApplication($event->getUser())) {
+ return null;
+ }
- $actions[] = id(new PhabricatorActionView())
+ $user = $event->getValue('object');
+ $href = '/conpherence/new/?participant='.$user->getPHID();
+
+ return id(new PhabricatorActionView())
->setIcon('message')
->setName(pht('Send Message'))
->setWorkflow(true)
->setHref($href);
-
- $event->setValue('actions', $actions);
}
}
Index: src/applications/differential/event/DifferentialActionMenuEventListener.php
===================================================================
--- /dev/null
+++ src/applications/differential/event/DifferentialActionMenuEventListener.php
@@ -0,0 +1,70 @@
+<?php
+
+final class DifferentialActionMenuEventListener
+ extends PhabricatorEventListener {
+
+ public function register() {
+ $this->listen(PhabricatorEventType::TYPE_UI_DIDRENDERACTIONS);
+ }
+
+ public function handleEvent(PhutilEvent $event) {
+ switch ($event->getType()) {
+ case PhabricatorEventType::TYPE_UI_DIDRENDERACTIONS:
+ $this->handleActionsEvent($event);
+ break;
+ }
+ }
+
+ private function handleActionsEvent(PhutilEvent $event) {
+ $object = $event->getValue('object');
+
+ $actions = null;
+ if ($object instanceof PhabricatorUser) {
+ $actions = $this->renderUserItems($event);
+ } else if ($object instanceof ManiphestTask) {
+ $actions = $this->renderTaskItems($event);
+ }
+
+ $this->addActionMenuItems($event, $actions);
+ }
+
+ private function renderUserItems(PhutilEvent $event) {
+ if (!$this->canUseApplication($event->getUser())) {
+ return null;
+ }
+
+ $person = $event->getValue('object');
+ $href = '/differential/?authorPHIDs[]='.$person->getPHID();
+
+ return id(new PhabricatorActionView())
+ ->setRenderAsForm(true)
+ ->setIcon('differential-dark')
+ ->setIconSheet(PHUIIconView::SPRITE_APPS)
+ ->setName(pht('View Revisions'))
+ ->setHref($href);
+ }
+
+ private function renderTaskItems(PhutilEvent $event) {
+ if (!$this->canUseApplication($event->getUser())) {
+ return null;
+ }
+
+ $task = $event->getValue('object');
+ $phid = $task->getPHID();
+
+ $can_edit = PhabricatorPolicyFilter::hasCapability(
+ $event->getUser(),
+ $task,
+ PhabricatorPolicyCapability::CAN_EDIT);
+
+ return id(new PhabricatorActionView())
+ ->setName(pht('Edit Differential Revisions'))
+ ->setHref("/search/attach/{$phid}/DREV/")
+ ->setWorkflow(true)
+ ->setIcon('attach')
+ ->setDisabled(!$can_edit)
+ ->setWorkflow(true);
+ }
+
+}
+
Index: src/applications/differential/events/DifferentialActionMenuEventListener.php
===================================================================
--- src/applications/differential/events/DifferentialActionMenuEventListener.php
+++ /dev/null
@@ -1,39 +0,0 @@
-<?php
-
-final class DifferentialActionMenuEventListener
- extends PhabricatorEventListener {
-
- public function register() {
- $this->listen(PhabricatorEventType::TYPE_UI_DIDRENDERACTIONS);
- }
-
- public function handleEvent(PhutilEvent $event) {
- switch ($event->getType()) {
- case PhabricatorEventType::TYPE_UI_DIDRENDERACTIONS:
- $this->handleActionsEvent($event);
- break;
- }
- }
-
- private function handleActionsEvent($event) {
- $person = $event->getValue('object');
- if (!($person instanceof PhabricatorUser)) {
- return;
- }
-
- $href = '/differential/?authorPHIDs[]='.$person->getPHID();
-
- $actions = $event->getValue('actions');
-
- $actions[] = id(new PhabricatorActionView())
- ->setRenderAsForm(true)
- ->setIcon('differential-dark')
- ->setIconSheet(PHUIIconView::SPRITE_APPS)
- ->setName(pht('View Revisions'))
- ->setHref($href);
-
- $event->setValue('actions', $actions);
- }
-
-}
-
Index: src/applications/differential/events/DifferentialHovercardEventListener.php
===================================================================
--- /dev/null
+++ src/applications/differential/events/DifferentialHovercardEventListener.php
@@ -1,81 +0,0 @@
-<?php
-
-final class DifferentialHovercardEventListener
- extends PhabricatorEventListener {
-
- public function register() {
- $this->listen(PhabricatorEventType::TYPE_UI_DIDRENDERHOVERCARD);
- }
-
- public function handleEvent(PhutilEvent $event) {
- switch ($event->getType()) {
- case PhabricatorEventType::TYPE_UI_DIDRENDERHOVERCARD:
- $this->handleHovercardEvent($event);
- break;
- }
- }
-
- private function handleHovercardEvent($event) {
- $viewer = $event->getUser();
- $hovercard = $event->getValue('hovercard');
- $object_handle = $event->getValue('handle');
- $phid = $object_handle->getPHID();
- $rev = $event->getValue('object');
-
- if (!($rev instanceof DifferentialRevision)) {
- return;
- }
-
- $rev->loadRelationships();
- $reviewer_phids = $rev->getReviewers();
- $e_task = PhabricatorEdgeConfig::TYPE_DREV_HAS_RELATED_TASK;
- $edge_query = id(new PhabricatorEdgeQuery())
- ->withSourcePHIDs(array($phid))
- ->withEdgeTypes(
- array(
- $e_task,
- ));
- $edge_query->execute();
- $tasks = $edge_query->getDestinationPHIDs();
-
- $phids = array_merge(
- array(
- $rev->getAuthorPHID(),
- ),
- $reviewer_phids,
- $tasks);
-
- $handles = id(new PhabricatorHandleQuery())
- ->setViewer($viewer)
- ->withPHIDs($phids)
- ->execute();
-
- $hovercard->setTitle('D'.$rev->getID());
- $hovercard->setDetail($rev->getTitle());
-
- $hovercard->addField(pht('Author'),
- $handles[$rev->getAuthorPHID()]->renderLink());
-
- $hovercard->addField(pht('Date'),
- phabricator_datetime($rev->getDateModified(), $viewer));
-
- $hovercard->addField(pht('Reviewers'),
- implode_selected_handle_links(', ', $handles, $reviewer_phids));
-
- if ($tasks) {
- $hovercard->addField(pht('Task(s)', count($tasks)),
- implode_selected_handle_links(', ', $handles, $tasks));
- }
-
- if ($rev->getSummary()) {
- $hovercard->addField(pht('Summary'),
- phutil_utf8_shorten($rev->getSummary(), 120));
- }
-
- $hovercard->addTag(
- DifferentialRevisionDetailView::renderTagForRevision($rev));
-
- $event->setValue('hovercard', $hovercard);
- }
-
-}
Index: src/applications/flag/events/PhabricatorFlagsUIEventListener.php
===================================================================
--- src/applications/flag/events/PhabricatorFlagsUIEventListener.php
+++ src/applications/flag/events/PhabricatorFlagsUIEventListener.php
@@ -31,6 +31,10 @@
return;
}
+ if (!$this->canUseApplication($event->getUser())) {
+ return null;
+ }
+
$flag = PhabricatorFlagQuery::loadUserFlag($user, $object->getPHID());
if ($flag) {
Index: src/applications/maniphest/controller/ManiphestTaskDetailController.php
===================================================================
--- src/applications/maniphest/controller/ManiphestTaskDetailController.php
+++ src/applications/maniphest/controller/ManiphestTaskDetailController.php
@@ -479,28 +479,6 @@
->setDisabled(!$can_edit)
->setWorkflow(true));
- $view->addAction(
- id(new PhabricatorActionView())
- ->setName(pht('Edit Differential Revisions'))
- ->setHref("/search/attach/{$phid}/DREV/")
- ->setWorkflow(true)
- ->setIcon('attach')
- ->setDisabled(!$can_edit)
- ->setWorkflow(true));
-
- $pholio_app =
- PhabricatorApplication::getByClass('PhabricatorApplicationPholio');
- if ($pholio_app->isInstalled()) {
- $view->addAction(
- id(new PhabricatorActionView())
- ->setName(pht('Edit Pholio Mocks'))
- ->setHref("/search/attach/{$phid}/MOCK/edge/")
- ->setWorkflow(true)
- ->setIcon('attach')
- ->setDisabled(!$can_edit)
- ->setWorkflow(true));
- }
-
return $view;
}
Index: src/applications/maniphest/event/ManiphestActionMenuEventListener.php
===================================================================
--- src/applications/maniphest/event/ManiphestActionMenuEventListener.php
+++ src/applications/maniphest/event/ManiphestActionMenuEventListener.php
@@ -14,29 +14,58 @@
}
}
- private function handleActionsEvent($event) {
- $actions = $event->getValue('actions');
+ private function handleActionsEvent(PhutilEvent $event) {
+ $object = $event->getValue('object');
+
+ $actions = null;
+ if ($object instanceof PhabricatorUser) {
+ $actions = $this->renderUserItems($event);
+ } else if ($object instanceof PhabricatorProject) {
+ $actions = $this->renderProjectItems($event);
+ }
+
+ $this->addActionMenuItems($event, $actions);
+ }
+
+ private function renderUserItems(PhutilEvent $event) {
+ if (!$this->canUseApplication($event->getUser())) {
+ return null;
+ }
+
+ $user = $event->getValue('object');
+ $phid = $user->getPHID();
+ $view_uri = '/maniphest/?statuses[]=0&assigned='.$phid.'#R';
- $action = id(new PhabricatorActionView())
+ return id(new PhabricatorActionView())
->setIcon('maniphest-dark')
->setIconSheet(PHUIIconView::SPRITE_APPS)
- ->setName(pht('View Tasks'));
+ ->setName(pht('View Tasks'))
+ ->setHref($view_uri);
+ }
- $object = $event->getValue('object');
- if ($object instanceof PhabricatorUser) {
- $href = '/maniphest/?statuses[]=0&assigned='.$object->getPHID().'#R';
- $actions[] = $action->setHref($href);
- } else if ($object instanceof PhabricatorProject) {
- $href = '/maniphest/?statuses[]=0&allProjects[]='.$object->getPHID().'#R';
- $actions[] = $action->setHref($href);
+ private function renderProjectItems(PhutilEvent $event) {
+ if (!$this->canUseApplication($event->getUser())) {
+ return null;
+ }
- $actions[] = id(new PhabricatorActionView())
+ $project = $event->getValue('object');
+
+ $phid = $project->getPHID();
+ $view_uri = '/maniphest/?statuses[]=0&allProjects[]='.$phid.'#R';
+ $create_uri = '/maniphest/task/create/?projects='.$phid;
+
+ return array(
+ id(new PhabricatorActionView())
+ ->setIcon('maniphest-dark')
+ ->setIconSheet(PHUIIconView::SPRITE_APPS)
+ ->setName(pht('View Tasks'))
+ ->setHref($view_uri),
+ id(new PhabricatorActionView())
->setName(pht("Add Task"))
->setIcon('create')
- ->setHref('/maniphest/task/create/?projects=' . $object->getPHID());
- }
-
- $event->setValue('actions', $actions);
+ ->setHref($create_uri),
+ );
}
+
}
Index: src/applications/pholio/application/PhabricatorApplicationPholio.php
===================================================================
--- src/applications/pholio/application/PhabricatorApplicationPholio.php
+++ src/applications/pholio/application/PhabricatorApplicationPholio.php
@@ -34,6 +34,12 @@
return true;
}
+ public function getEventListeners() {
+ return array(
+ new PholioActionMenuEventListener(),
+ );
+ }
+
public function getRemarkupRules() {
return array(
new PholioRemarkupRule(),
Index: src/applications/pholio/event/PholioActionMenuEventListener.php
===================================================================
--- /dev/null
+++ src/applications/pholio/event/PholioActionMenuEventListener.php
@@ -0,0 +1,52 @@
+<?php
+
+final class PholioActionMenuEventListener
+ extends PhabricatorEventListener {
+
+ public function register() {
+ $this->listen(PhabricatorEventType::TYPE_UI_DIDRENDERACTIONS);
+ }
+
+ public function handleEvent(PhutilEvent $event) {
+ switch ($event->getType()) {
+ case PhabricatorEventType::TYPE_UI_DIDRENDERACTIONS:
+ $this->handleActionsEvent($event);
+ break;
+ }
+ }
+
+ private function handleActionsEvent(PhutilEvent $event) {
+ $object = $event->getValue('object');
+
+ $actions = null;
+ if ($object instanceof ManiphestTask) {
+ $actions = $this->renderTaskItems($event);
+ }
+
+ $this->addActionMenuItems($event, $actions);
+ }
+
+ private function renderTaskItems(PhutilEvent $event) {
+ if (!$this->canUseApplication($event->getUser())) {
+ return;
+ }
+
+ $task = $event->getValue('object');
+ $phid = $task->getPHID();
+
+ $can_edit = PhabricatorPolicyFilter::hasCapability(
+ $event->getUser(),
+ $task,
+ PhabricatorPolicyCapability::CAN_EDIT);
+
+ return id(new PhabricatorActionView())
+ ->setName(pht('Edit Pholio Mocks'))
+ ->setHref("/search/attach/{$phid}/MOCK/edge/")
+ ->setWorkflow(true)
+ ->setIcon('attach')
+ ->setDisabled(!$can_edit)
+ ->setWorkflow(true);
+ }
+
+}
+
Index: src/applications/phrequent/event/PhrequentUIEventListener.php
===================================================================
--- src/applications/phrequent/event/PhrequentUIEventListener.php
+++ src/applications/phrequent/event/PhrequentUIEventListener.php
@@ -33,6 +33,10 @@
return;
}
+ if (!$this->canUseApplication($event->getUser())) {
+ return;
+ }
+
$tracking = PhrequentUserTimeQuery::isUserTrackingObject(
$user,
$object->getPHID());
@@ -56,9 +60,7 @@
$track_action->setDisabled(true);
}
- $actions = $event->getValue('actions');
- $actions[] = $track_action;
- $event->setValue('actions', $actions);
+ $this->addActionMenuItems($event, $track_action);
}
private function handlePropertyEvent($ui_event) {
@@ -75,6 +77,10 @@
return;
}
+ if (!$this->canUseApplication($ui_event->getUser())) {
+ return;
+ }
+
$events = id(new PhrequentUserTimeQuery())
->setViewer($user)
->withObjectPHIDs(array($object->getPHID()))
Index: src/applications/phriction/event/PhrictionActionMenuEventListener.php
===================================================================
--- src/applications/phriction/event/PhrictionActionMenuEventListener.php
+++ src/applications/phriction/event/PhrictionActionMenuEventListener.php
@@ -14,22 +14,31 @@
}
}
- private function handleActionsEvent($event) {
- $actions = $event->getValue('actions');
-
- $action = id(new PhabricatorActionView())
- ->setIcon('phriction-dark')
- ->setIconSheet(PHUIIconView::SPRITE_APPS)
- ->setName(pht('View Wiki'));
-
+ private function handleActionsEvent(PhutilEvent $event) {
$object = $event->getValue('object');
+
+ $actions = null;
if ($object instanceof PhabricatorProject) {
- $slug = PhabricatorSlug::normalize($object->getPhrictionSlug());
- $href = '/w/projects/'.$slug;
- $actions[] = $action->setHref($href);
+ $actions = $this->buildProjectActions($event);
+ }
+
+ $this->addActionMenuItems($event, $actions);
+ }
+
+ private function buildProjectActions(PhutilEvent $event) {
+ if (!$this->canUseApplication($event->getUser())) {
+ return null;
}
- $event->setValue('actions', $actions);
+ $project = $event->getValue('object');
+ $slug = PhabricatorSlug::normalize($project->getPhrictionSlug());
+ $href = '/w/projects/'.$slug;
+
+ return id(new PhabricatorActionView())
+ ->setIcon('phriction-dark')
+ ->setIconSheet(PHUIIconView::SPRITE_APPS)
+ ->setName(pht('View Wiki'))
+ ->setHref($href);
}
}
Index: src/applications/tokens/event/PhabricatorTokenUIEventListener.php
===================================================================
--- src/applications/tokens/event/PhabricatorTokenUIEventListener.php
+++ src/applications/tokens/event/PhabricatorTokenUIEventListener.php
@@ -33,6 +33,10 @@
return;
}
+ if (!$this->canUseApplication($event->getUser())) {
+ return null;
+ }
+
$current = id(new PhabricatorTokenGivenQuery())
->setViewer($user)
->withAuthorPHIDs(array($user->getPHID()))
@@ -75,6 +79,10 @@
return;
}
+ if (!$this->canUseApplication($event->getUser())) {
+ return null;
+ }
+
$limit = 1;
$tokens_given = id(new PhabricatorTokenGivenQuery())
Index: src/infrastructure/events/PhabricatorEventListener.php
===================================================================
--- src/infrastructure/events/PhabricatorEventListener.php
+++ src/infrastructure/events/PhabricatorEventListener.php
@@ -28,6 +28,26 @@
PhabricatorPolicyCapability::CAN_VIEW);
}
+ protected function addActionMenuItems(PhutilEvent $event, $items) {
+ if ($event->getType() !== PhabricatorEventType::TYPE_UI_DIDRENDERACTIONS) {
+ throw new Exception("Not an action menu event!");
+ }
+
+ if (!$items) {
+ return;
+ }
+
+ if (!is_array($items)) {
+ $items = array($items);
+ }
+
+ $event_actions = $event->getValue('actions');
+ foreach ($items as $item) {
+ $event_actions[] = $item;
+ }
+ $event->setValue('actions', $event_actions);
+ }
+
}
Index: src/view/layout/PhabricatorActionListView.php
===================================================================
--- src/view/layout/PhabricatorActionListView.php
+++ src/view/layout/PhabricatorActionListView.php
@@ -42,7 +42,6 @@
PhutilEventEngine::dispatchEvent($event);
$actions = $event->getValue('actions');
-
if (!$actions) {
return null;
}

File Metadata

Mime Type
text/plain
Expires
Fri, Sep 20, 4:23 AM (1 h, 28 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6622464
Default Alt Text
D7365.id16581.diff (22 KB)

Event Timeline