Implement PolicyInterface, ExtendedPolicyInterface, and DestructibleInterface on PhrictionContent
Summary: Depends on D19093. Ref T13077. Although content objects normally don't have any edges today, they may in the future. Also implement Policy stuff properly. Test Plan: Used `bin/remove destroy` to destroy a document, verified it also loaded and destroyed the correspoding Content correctly by looking at `--trace` and the database rows. Maniphest Tasks: T13077 Differential Revision: https://secure.phabricator.com/D19094
This commit is contained in:
parent
b2c829f274
commit
9404e2b3d4
|
@ -10755,7 +10755,11 @@ phutil_register_library_map(array(
|
||||||
'PhrictionChangeType' => 'PhrictionConstants',
|
'PhrictionChangeType' => 'PhrictionConstants',
|
||||||
'PhrictionConduitAPIMethod' => 'ConduitAPIMethod',
|
'PhrictionConduitAPIMethod' => 'ConduitAPIMethod',
|
||||||
'PhrictionConstants' => 'Phobject',
|
'PhrictionConstants' => 'Phobject',
|
||||||
'PhrictionContent' => 'PhrictionDAO',
|
'PhrictionContent' => array(
|
||||||
|
'PhrictionDAO',
|
||||||
|
'PhabricatorPolicyInterface',
|
||||||
|
'PhabricatorDestructibleInterface',
|
||||||
|
),
|
||||||
'PhrictionContentPHIDType' => 'PhabricatorPHIDType',
|
'PhrictionContentPHIDType' => 'PhabricatorPHIDType',
|
||||||
'PhrictionContentQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
'PhrictionContentQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||||
'PhrictionController' => 'PhabricatorController',
|
'PhrictionController' => 'PhabricatorController',
|
||||||
|
|
|
@ -5,6 +5,7 @@ final class PhrictionContentQuery
|
||||||
|
|
||||||
private $ids;
|
private $ids;
|
||||||
private $phids;
|
private $phids;
|
||||||
|
private $documentPHIDs;
|
||||||
|
|
||||||
public function withIDs(array $ids) {
|
public function withIDs(array $ids) {
|
||||||
$this->ids = $ids;
|
$this->ids = $ids;
|
||||||
|
@ -16,6 +17,11 @@ final class PhrictionContentQuery
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function withDocumentPHIDs(array $phids) {
|
||||||
|
$this->documentPHIDs = $phids;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function newResultObject() {
|
public function newResultObject() {
|
||||||
return new PhrictionContent();
|
return new PhrictionContent();
|
||||||
}
|
}
|
||||||
|
@ -30,20 +36,78 @@ final class PhrictionContentQuery
|
||||||
if ($this->ids !== null) {
|
if ($this->ids !== null) {
|
||||||
$where[] = qsprintf(
|
$where[] = qsprintf(
|
||||||
$conn,
|
$conn,
|
||||||
'id IN (%Ld)',
|
'c.id IN (%Ld)',
|
||||||
$this->ids);
|
$this->ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->phids !== null) {
|
if ($this->phids !== null) {
|
||||||
$where[] = qsprintf(
|
$where[] = qsprintf(
|
||||||
$conn,
|
$conn,
|
||||||
'phid IN (%Ls)',
|
'c.phid IN (%Ls)',
|
||||||
$this->phids);
|
$this->phids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->documentPHIDs !== null) {
|
||||||
|
$where[] = qsprintf(
|
||||||
|
$conn,
|
||||||
|
'd.phid IN (%Ls)',
|
||||||
|
$this->documentPHIDs);
|
||||||
|
}
|
||||||
|
|
||||||
return $where;
|
return $where;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) {
|
||||||
|
$joins = parent::buildJoinClauseParts($conn);
|
||||||
|
|
||||||
|
if ($this->shouldJoinDocumentTable()) {
|
||||||
|
$joins[] = qsprintf(
|
||||||
|
$conn,
|
||||||
|
'JOIN %T d ON d.id = c.documentID',
|
||||||
|
id(new PhrictionDocument())->getTableName());
|
||||||
|
}
|
||||||
|
|
||||||
|
return $joins;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function willFilterPage(array $contents) {
|
||||||
|
$document_ids = mpull($contents, 'getDocumentID');
|
||||||
|
|
||||||
|
$documents = id(new PhrictionDocumentQuery())
|
||||||
|
->setViewer($this->getViewer())
|
||||||
|
->setParentQuery($this)
|
||||||
|
->withIDs($document_ids)
|
||||||
|
->execute();
|
||||||
|
$documents = mpull($documents, null, 'getID');
|
||||||
|
|
||||||
|
foreach ($contents as $key => $content) {
|
||||||
|
$document_id = $content->getDocumentID();
|
||||||
|
|
||||||
|
$document = idx($documents, $document_id);
|
||||||
|
if (!$document) {
|
||||||
|
unset($contents[$key]);
|
||||||
|
$this->didRejectResult($content);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$content->attachDocument($document);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $contents;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function shouldJoinDocumentTable() {
|
||||||
|
if ($this->documentPHIDs !== null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getPrimaryTableAlias() {
|
||||||
|
return 'c';
|
||||||
|
}
|
||||||
|
|
||||||
public function getQueryApplicationClass() {
|
public function getQueryApplicationClass() {
|
||||||
return 'PhabricatorPhrictionApplication';
|
return 'PhabricatorPhrictionApplication';
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
final class PhrictionContent
|
final class PhrictionContent
|
||||||
extends PhrictionDAO {
|
extends PhrictionDAO
|
||||||
|
implements
|
||||||
|
PhabricatorPolicyInterface,
|
||||||
|
PhabricatorDestructibleInterface {
|
||||||
|
|
||||||
protected $id;
|
|
||||||
protected $documentID;
|
protected $documentID;
|
||||||
protected $version;
|
protected $version;
|
||||||
protected $authorPHID;
|
protected $authorPHID;
|
||||||
|
@ -16,6 +18,8 @@ final class PhrictionContent
|
||||||
protected $changeType;
|
protected $changeType;
|
||||||
protected $changeRef;
|
protected $changeRef;
|
||||||
|
|
||||||
|
private $document = self::ATTACHABLE;
|
||||||
|
|
||||||
protected function getConfiguration() {
|
protected function getConfiguration() {
|
||||||
return array(
|
return array(
|
||||||
self::CONFIG_AUX_PHID => true,
|
self::CONFIG_AUX_PHID => true,
|
||||||
|
@ -56,4 +60,50 @@ final class PhrictionContent
|
||||||
->setGenerateTableOfContents(true);
|
->setGenerateTableOfContents(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function attachDocument(PhrictionDocument $document) {
|
||||||
|
$this->document = $document;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDocument() {
|
||||||
|
return $this->assertAttached($this->document);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
|
public function getCapabilities() {
|
||||||
|
return array(
|
||||||
|
PhabricatorPolicyCapability::CAN_VIEW,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPolicy($capability) {
|
||||||
|
return PhabricatorPolicies::getMostOpenPolicy();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* -( PhabricatorExtendedPolicyInterface )--------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
|
public function getExtendedPolicy($capability, PhabricatorUser $viewer) {
|
||||||
|
return array(
|
||||||
|
array($this->getDocument(), PhabricatorPolicyCapability::CAN_VIEW),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* -( PhabricatorDestructibleInterface )----------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
|
public function destroyObjectPermanently(
|
||||||
|
PhabricatorDestructionEngine $engine) {
|
||||||
|
$this->delete();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -236,15 +236,16 @@ final class PhrictionDocument extends PhrictionDAO
|
||||||
|
|
||||||
$this->openTransaction();
|
$this->openTransaction();
|
||||||
|
|
||||||
$this->delete();
|
$contents = id(new PhrictionContentQuery())
|
||||||
|
->setViewer($engine->getViewer())
|
||||||
$contents = id(new PhrictionContent())->loadAllWhere(
|
->withDocumentPHIDs(array($this->getPHID()))
|
||||||
'documentID = %d',
|
->execute();
|
||||||
$this->getID());
|
|
||||||
foreach ($contents as $content) {
|
foreach ($contents as $content) {
|
||||||
$content->delete();
|
$engine->destroyObject($content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->delete();
|
||||||
|
|
||||||
$this->saveTransaction();
|
$this->saveTransaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue