1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-18 11:30:55 +01:00

Remove dedicated storage for NuanceRequestor

Summary:
Ref T10537. Currently, Nuance has a `NuanceRequestor` object, intended to represent the external user who created content (e.g., a GitHub account or a Twitter account or whatever).

This object is currently almost unused, and its design predates Doorkeeper. In D15541, I chose to use doorkeeper objects instead of NuanceRequestor objects to represent requestors.

I don't currently anticipate a need for such an object, given that we have Doorkeeper. If we do need it in the future for some reason, it would be fairly easy to restore it, create a requestor type which wraps a Doorkeeper object, and then migrate. Not super thrilling to do that, but not a huge mess.

`NuanceItem` still has a `requestorPHID`, but this is now a less formal object PHID instead of a more formal Requestor-object PHID, and holds a doorkeeper exeternal object PHID for GitHub events.

Test Plan:
  - Grepped for `nuancerequestor`.
  - Ran `bin/storage upgrade -f`.
  - Grepped for `requestor`, remaining uses of this term seem reasonable/correct.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10537

Differential Revision: https://secure.phabricator.com/D15546
This commit is contained in:
epriestley 2016-03-29 07:12:05 -07:00
parent 6dc30ecc8e
commit f50693de61
19 changed files with 4 additions and 481 deletions

View file

@ -0,0 +1 @@
DROP TABLE IF EXISTS {$NAMESPACE}_nuance.nuance_requestor;

View file

@ -0,0 +1 @@
DROP TABLE IF EXISTS {$NAMESPACE}_nuance.nuance_requestorsource;

View file

@ -0,0 +1 @@
DROP TABLE IF EXISTS {$NAMESPACE}_nuance.nuance_requestortransaction;

View file

@ -0,0 +1 @@
DROP TABLE IF EXISTS {$NAMESPACE}_nuance.nuance_requestortransaction_comment;

View file

@ -1479,16 +1479,6 @@ phutil_register_library_map(array(
'NuanceQueueTransactionComment' => 'applications/nuance/storage/NuanceQueueTransactionComment.php',
'NuanceQueueTransactionQuery' => 'applications/nuance/query/NuanceQueueTransactionQuery.php',
'NuanceQueueViewController' => 'applications/nuance/controller/NuanceQueueViewController.php',
'NuanceRequestor' => 'applications/nuance/storage/NuanceRequestor.php',
'NuanceRequestorEditController' => 'applications/nuance/controller/NuanceRequestorEditController.php',
'NuanceRequestorEditor' => 'applications/nuance/editor/NuanceRequestorEditor.php',
'NuanceRequestorPHIDType' => 'applications/nuance/phid/NuanceRequestorPHIDType.php',
'NuanceRequestorQuery' => 'applications/nuance/query/NuanceRequestorQuery.php',
'NuanceRequestorSource' => 'applications/nuance/storage/NuanceRequestorSource.php',
'NuanceRequestorTransaction' => 'applications/nuance/storage/NuanceRequestorTransaction.php',
'NuanceRequestorTransactionComment' => 'applications/nuance/storage/NuanceRequestorTransactionComment.php',
'NuanceRequestorTransactionQuery' => 'applications/nuance/query/NuanceRequestorTransactionQuery.php',
'NuanceRequestorViewController' => 'applications/nuance/controller/NuanceRequestorViewController.php',
'NuanceSchemaSpec' => 'applications/nuance/storage/NuanceSchemaSpec.php',
'NuanceSource' => 'applications/nuance/storage/NuanceSource.php',
'NuanceSourceActionController' => 'applications/nuance/controller/NuanceSourceActionController.php',
@ -5797,20 +5787,6 @@ phutil_register_library_map(array(
'NuanceQueueTransactionComment' => 'PhabricatorApplicationTransactionComment',
'NuanceQueueTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
'NuanceQueueViewController' => 'NuanceQueueController',
'NuanceRequestor' => array(
'NuanceDAO',
'PhabricatorPolicyInterface',
'PhabricatorApplicationTransactionInterface',
),
'NuanceRequestorEditController' => 'NuanceController',
'NuanceRequestorEditor' => 'PhabricatorApplicationTransactionEditor',
'NuanceRequestorPHIDType' => 'PhabricatorPHIDType',
'NuanceRequestorQuery' => 'NuanceQuery',
'NuanceRequestorSource' => 'NuanceDAO',
'NuanceRequestorTransaction' => 'NuanceTransaction',
'NuanceRequestorTransactionComment' => 'PhabricatorApplicationTransactionComment',
'NuanceRequestorTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
'NuanceRequestorViewController' => 'NuanceController',
'NuanceSchemaSpec' => 'PhabricatorConfigSchemaSpec',
'NuanceSource' => array(
'NuanceDAO',

View file

@ -56,11 +56,6 @@ final class PhabricatorNuanceApplication extends PhabricatorApplication {
$this->getEditRoutePattern('edit/') => 'NuanceQueueEditController',
'view/(?P<id>[1-9]\d*)/' => 'NuanceQueueViewController',
),
'requestor/' => array(
'view/(?P<id>[1-9]\d*)/' => 'NuanceRequestorViewController',
'edit/(?P<id>[1-9]\d*)/' => 'NuanceRequestorEditController',
'new/' => 'NuanceRequestorEditController',
),
),
'/action/' => array(
'(?P<id>[1-9]\d*)/(?P<path>.*)' => 'NuanceSourceActionController',

View file

@ -1,33 +0,0 @@
<?php
final class NuanceRequestorEditController extends NuanceController {
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$id = $request->getURIData('id');
if (!$id) {
$requestor = new NuanceRequestor();
} else {
$requestor = id(new NuanceRequestorQuery())
->setViewer($viewer)
->withIDs(array($id))
->executeOne();
}
if (!$requestor) {
return new Aphront404Response();
}
$crumbs = $this->buildApplicationCrumbs();
$title = pht('TODO');
return $this->buildApplicationPage(
$crumbs,
array(
'title' => $title,
));
}
}

View file

@ -1,27 +0,0 @@
<?php
final class NuanceRequestorViewController extends NuanceController {
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$id = $request->getURIData('id');
$requestor = id(new NuanceRequestorQuery())
->setViewer($viewer)
->withIDs(array($id))
->executeOne();
if (!$requestor) {
return new Aphront404Response();
}
$crumbs = $this->buildApplicationCrumbs();
$title = 'TODO';
return $this->buildApplicationPage(
$crumbs,
array(
'title' => $title,
));
}
}

View file

@ -1,75 +0,0 @@
<?php
final class NuanceRequestorEditor
extends PhabricatorApplicationTransactionEditor {
public function getEditorApplicationClass() {
return 'PhabricatorNuanceApplication';
}
public function getEditorObjectsDescription() {
return pht('Nuance Requestors');
}
public function getTransactionTypes() {
$types = parent::getTransactionTypes();
$types[] = NuanceRequestorTransaction::TYPE_PROPERTY;
$types[] = PhabricatorTransactions::TYPE_VIEW_POLICY;
$types[] = PhabricatorTransactions::TYPE_EDIT_POLICY;
return $types;
}
protected function getCustomTransactionOldValue(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
case NuanceRequestorTransaction::TYPE_PROPERTY:
$key = $xaction->getMetadataValue(
NuanceRequestorTransaction::PROPERTY_KEY);
return $object->getNuanceProperty($key);
}
return parent::getCustomTransactionOldValue($object, $xaction);
}
protected function getCustomTransactionNewValue(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
case NuanceRequestorTransaction::TYPE_PROPERTY:
return $xaction->getNewValue();
}
return parent::getCustomTransactionNewValue($object, $xaction);
}
protected function applyCustomInternalTransaction(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
case NuanceRequestorTransaction::TYPE_PROPERTY:
$key = $xaction->getMetadataValue(
NuanceRequestorTransaction::PROPERTY_KEY);
$object->setNuanceProperty($key, $xaction->getNewValue());
break;
}
}
protected function applyCustomExternalTransaction(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
case NuanceRequestorTransaction::TYPE_PROPERTY:
return;
}
return parent::applyCustomExternalTransaction($object, $xaction);
}
}

View file

@ -1,43 +0,0 @@
<?php
final class NuanceRequestorPHIDType extends PhabricatorPHIDType {
const TYPECONST = 'NUAR';
public function getTypeName() {
return pht('Requestor');
}
public function newObject() {
return new NuanceRequestor();
}
public function getPHIDTypeApplicationClass() {
return 'PhabricatorNuanceApplication';
}
protected function buildQueryForObjects(
PhabricatorObjectQuery $query,
array $phids) {
return id(new NuanceRequestorQuery())
->withPHIDs($phids);
}
public function loadHandles(
PhabricatorHandleQuery $query,
array $handles,
array $objects) {
$viewer = $query->getViewer();
foreach ($handles as $phid => $handle) {
$requestor = $objects[$phid];
// TODO: This is currently useless and should be far more informative.
$handle->setName(pht('Requestor %d', $requestor->getID()));
$handle->setURI($requestor->getURI());
}
}
}

View file

@ -1,47 +0,0 @@
<?php
final class NuanceRequestorQuery
extends NuanceQuery {
private $ids;
private $phids;
public function withIDs(array $ids) {
$this->ids = $ids;
return $this;
}
public function withPHIDs(array $phids) {
$this->phids = $phids;
return $this;
}
public function newObject() {
return new NuanceRequestor();
}
protected function loadPage() {
return $this->loadStandardPage($this->newObject());
}
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
$where = parent::buildWhereClauseParts($conn);
if ($this->ids !== null) {
$where[] = qsprintf(
$conn,
'id IN (%Ld)',
$this->ids);
}
if ($this->phids !== null) {
$where[] = qsprintf(
$conn,
'phid IN (%Ls)',
$this->phids);
}
return $where;
}
}

View file

@ -1,10 +0,0 @@
<?php
final class NuanceRequestorTransactionQuery
extends PhabricatorApplicationTransactionQuery {
public function getTemplateApplicationTransaction() {
return new NuanceRequestorTransaction();
}
}

View file

@ -38,12 +38,7 @@ final class NuancePhabricatorFormSourceDefinition
$content_source = PhabricatorContentSource::newFromRequest($request);
$requestor = NuanceRequestor::newFromPhabricatorUser(
$viewer,
$content_source);
$item = $this->newItemFromProperties(
$requestor,
$properties,
$content_source);

View file

@ -149,7 +149,6 @@ abstract class NuanceSourceDefinition extends Phobject {
}
protected function newItemFromProperties(
NuanceRequestor $requestor,
array $properties,
PhabricatorContentSource $content_source) {
@ -166,10 +165,6 @@ abstract class NuanceSourceDefinition extends Phobject {
->setTransactionType(NuanceItemTransaction::TYPE_SOURCE)
->setNewValue($source->getPHID());
$xactions[] = id(new NuanceItemTransaction())
->setTransactionType(NuanceItemTransaction::TYPE_REQUESTOR)
->setNewValue($requestor->getPHID());
// TODO: Eventually, apply real routing rules. For now, just put everything
// in the default queue for the source.
$xactions[] = id(new NuanceItemTransaction())
@ -185,7 +180,6 @@ abstract class NuanceSourceDefinition extends Phobject {
$editor = id(new NuanceItemEditor())
->setActor($actor)
->setActingAsPHID($requestor->getActingAsPHID())
->setContentSource($content_source);
$editor->applyTransactions($item, $xactions);

View file

@ -87,14 +87,6 @@ final class NuanceItem
return '/nuance/item/view/'.$this->getID().'/';
}
public function getRequestor() {
return $this->assertAttached($this->requestor);
}
public function attachRequestor(NuanceRequestor $requestor) {
return $this->requestor = $requestor;
}
public function getSource() {
return $this->assertAttached($this->source);
}

View file

@ -1,137 +0,0 @@
<?php
final class NuanceRequestor
extends NuanceDAO
implements
PhabricatorPolicyInterface,
PhabricatorApplicationTransactionInterface {
protected $data = array();
protected function getConfiguration() {
return array(
self::CONFIG_AUX_PHID => true,
self::CONFIG_SERIALIZATION => array(
'data' => self::SERIALIZATION_JSON,
),
) + parent::getConfiguration();
}
public function generatePHID() {
return PhabricatorPHID::generateNewPHID(
NuanceRequestorPHIDType::TYPECONST);
}
public static function initializeNewRequestor() {
return new NuanceRequestor();
}
public function getURI() {
return '/nuance/requestor/view/'.$this->getID().'/';
}
public function getPhabricatorUserPHID() {
return idx($this->getData(), 'phabricatorUserPHID');
}
public function getActingAsPHID() {
$user_phid = $this->getPhabricatorUserPHID();
if ($user_phid) {
return $user_phid;
}
return id(new PhabricatorNuanceApplication())->getPHID();
}
public static function newFromPhabricatorUser(
PhabricatorUser $viewer,
PhabricatorContentSource $content_source) {
// TODO: This is real sketchy and creates a new requestor every time. It
// shouldn't do that.
$requestor = self::initializeNewRequestor();
$xactions = array();
$properties = array(
'phabricatorUserPHID' => $viewer->getPHID(),
);
foreach ($properties as $key => $value) {
$xactions[] = id(new NuanceRequestorTransaction())
->setTransactionType(NuanceRequestorTransaction::TYPE_PROPERTY)
->setMetadataValue(NuanceRequestorTransaction::PROPERTY_KEY, $key)
->setNewValue($value);
}
$editor = id(new NuanceRequestorEditor())
->setActor($viewer)
->setContentSource($content_source);
$editor->applyTransactions($requestor, $xactions);
return $requestor;
}
public function getNuanceProperty($key, $default = null) {
return idx($this->data, $key, $default);
}
public function setNuanceProperty($key, $value) {
$this->data[$key] = $value;
return $this;
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */
public function getCapabilities() {
return array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
);
}
public function getPolicy($capability) {
switch ($capability) {
case PhabricatorPolicyCapability::CAN_VIEW:
return PhabricatorPolicies::POLICY_USER;
case PhabricatorPolicyCapability::CAN_EDIT:
return PhabricatorPolicies::POLICY_USER;
}
}
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
return false;
}
public function describeAutomaticCapability($capability) {
return null;
}
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
public function getApplicationTransactionEditor() {
return new NuanceRequestorEditor();
}
public function getApplicationTransactionObject() {
return $this;
}
public function getApplicationTransactionTemplate() {
return new NuanceRequestorTransaction();
}
public function willRenderTimeline(
PhabricatorApplicationTransactionView $timeline,
AphrontRequest $request) {
return $timeline;
}
}

View file

@ -1,34 +0,0 @@
<?php
final class NuanceRequestorSource
extends NuanceDAO {
protected $requestorPHID;
protected $sourcePHID;
protected $sourceKey;
protected $data;
protected function getConfiguration() {
return array(
self::CONFIG_SERIALIZATION => array(
'data' => self::SERIALIZATION_JSON,
),
self::CONFIG_COLUMN_SCHEMA => array(
'sourceKey' => 'text128',
),
self::CONFIG_KEY_SCHEMA => array(
'key_source_key' => array(
'columns' => array('sourcePHID', 'sourceKey'),
'unique' => true,
),
'key_requestor' => array(
'columns' => array('requestorPHID', 'id'),
),
'key_source' => array(
'columns' => array('sourcePHID', 'id'),
),
),
) + parent::getConfiguration();
}
}

View file

@ -1,17 +0,0 @@
<?php
final class NuanceRequestorTransaction
extends NuanceTransaction {
const PROPERTY_KEY = 'property.key';
const TYPE_PROPERTY = 'nuance.requestor.property';
public function getApplicationTransactionType() {
return NuanceRequestorPHIDType::TYPECONST;
}
public function getApplicationTransactionCommentObject() {
return new NuanceRequestorTransactionComment();
}
}

View file

@ -1,10 +0,0 @@
<?php
final class NuanceRequestorTransactionComment
extends PhabricatorApplicationTransactionComment {
public function getApplicationTransactionObject() {
return new NuanceRequestorTransaction();
}
}