1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-15 19:32:40 +01:00
phorge-phorge/src/applications/search/controller/PhabricatorSearchRelationshipSourceController.php
epriestley 2a7545a452 Convert Maniphest merge operations to modern Relationship code
Summary:
Ref T4788. Fixes T7820. This updates the "Merge Duplicates In" interaction, and adds a "Close as Duplicate" action.

These are the last interactions that were using the old code, so it removes that code.

Merges are now recorded as real edges, so we can show them in the UI later on (originally from T9390, etc).

Also provides more general support for relationships which need EDIT permission, not-undoable relationships like merges, preventing relating an object to itself, and relationship side effects like merges.

Finally, fixes a couple of behaviors around typing an exact object name (like `T123`) to find the related object.

Test Plan:
  - Merged tasks into the current task.
  - Closed the current task as a duplicate of another task.
  - Edited other relationships.
  - Searched for tasks, commits, etc., by object monogram.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T4788, T7820

Differential Revision: https://secure.phabricator.com/D16196
2016-06-30 08:35:45 -07:00

95 lines
2.7 KiB
PHP

<?php
final class PhabricatorSearchRelationshipSourceController
extends PhabricatorSearchBaseController {
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$object = $this->loadRelationshipObject();
if (!$object) {
return new Aphront404Response();
}
$relationship = $this->loadRelationship($object);
if (!$relationship) {
return new Aphront404Response();
}
$source = $relationship->newSource();
$query = new PhabricatorSavedQuery();
$action = $request->getURIData('action');
$query_str = $request->getStr('query');
$filter = $request->getStr('filter');
$query->setEngineClassName('PhabricatorSearchApplicationSearchEngine');
$query->setParameter('query', $query_str);
$types = $source->getResultPHIDTypes();
$query->setParameter('types', $types);
$status_open = PhabricatorSearchRelationship::RELATIONSHIP_OPEN;
switch ($filter) {
case 'assigned':
$query->setParameter('ownerPHIDs', array($viewer->getPHID()));
$query->setParameter('statuses', array($status_open));
break;
case 'created';
$query->setParameter('authorPHIDs', array($viewer->getPHID()));
$query->setParameter('statuses', array($status_open));
break;
case 'open':
$query->setParameter('statuses', array($status_open));
break;
}
$query->setParameter('excludePHIDs', array($request->getStr('exclude')));
$capabilities = $relationship->getRequiredRelationshipCapabilities();
$results = id(new PhabricatorSearchDocumentQuery())
->setViewer($viewer)
->requireObjectCapabilities($capabilities)
->withSavedQuery($query)
->setOffset(0)
->setLimit(100)
->execute();
$phids = array_fill_keys(mpull($results, 'getPHID'), true);
$phids = $this->queryObjectNames($query, $capabilities) + $phids;
$phids = array_keys($phids);
$handles = $viewer->loadHandles($phids);
$data = array();
foreach ($handles as $handle) {
$view = new PhabricatorHandleObjectSelectorDataView($handle);
$data[] = $view->renderData();
}
return id(new AphrontAjaxResponse())->setContent($data);
}
private function queryObjectNames(
PhabricatorSavedQuery $query,
array $capabilities) {
$request = $this->getRequest();
$viewer = $request->getUser();
$types = $query->getParameter('types');
$match = $query->getParameter('query');
$objects = id(new PhabricatorObjectQuery())
->setViewer($viewer)
->requireCapabilities($capabilities)
->withTypes($query->getParameter('types'))
->withNames(array($match))
->execute();
return mpull($objects, 'getPHID');
}
}