1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-27 07:50:57 +01:00

MetaMTA - lay some ground work for having an application

Summary:
Ref T5791. This does a few bits there. Namely:

 - Adds PHID column to PhabricatorMetaMTAMail
   - Implements a PhabricatorMetaMTAMailPHIDType
   - Script to backpopulate them.
 - Makes PhabricatorMetaMTAMail implement PolicyInterface.
   - View policy is NOONE and the author and recipients have automatic view capabilities
   - No edit capability.
 - Adds a PhabricatorMetaMTAMailQuery for PhabricatorMetaMTAMail.

Test Plan: ran `./bin/storage upgrade` successfully. commented on a maniphest task and verifed the metamta mail object in the database was created successfully with a shiny new phid

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: epriestley, Korvin

Maniphest Tasks: T5791

Differential Revision: https://secure.phabricator.com/D13394
This commit is contained in:
Bob Trahan 2015-06-22 13:46:26 -07:00
parent c3efa261f9
commit ea5462fb60
7 changed files with 168 additions and 2 deletions

View file

@ -0,0 +1,2 @@
ALTER TABLE {$NAMESPACE}_metamta.metamta_mail
ADD phid VARBINARY(64) NOT NULL AFTER id;

View file

@ -0,0 +1,22 @@
<?php
$table = new PhabricatorMetaMTAMail();
$conn_w = $table->establishConnection('w');
echo pht('Assigning PHIDs to mails...')."\n";
foreach (new LiskMigrationIterator($table) as $mail) {
$id = $mail->getID();
echo pht('Updating mail %d...', $id)."\n";
if ($mail->getPHID()) {
continue;
}
queryfx(
$conn_w,
'UPDATE %T SET phid = %s WHERE id = %d',
$table->getTableName(),
$table->generatePHID(),
$id);
}
echo pht('Done.')."\n";

View file

@ -0,0 +1,2 @@
ALTER TABLE {$NAMESPACE}_metamta.metamta_mail
ADD UNIQUE KEY `key_phid` (phid);

View file

@ -2107,6 +2107,8 @@ phutil_register_library_map(array(
'PhabricatorMetaMTAMail' => 'applications/metamta/storage/PhabricatorMetaMTAMail.php',
'PhabricatorMetaMTAMailBody' => 'applications/metamta/view/PhabricatorMetaMTAMailBody.php',
'PhabricatorMetaMTAMailBodyTestCase' => 'applications/metamta/view/__tests__/PhabricatorMetaMTAMailBodyTestCase.php',
'PhabricatorMetaMTAMailPHIDType' => 'applications/metamta/phid/PhabricatorMetaMTAMailPHIDType.php',
'PhabricatorMetaMTAMailQuery' => 'applications/metamta/query/PhabricatorMetaMTAMailQuery.php',
'PhabricatorMetaMTAMailSection' => 'applications/metamta/view/PhabricatorMetaMTAMailSection.php',
'PhabricatorMetaMTAMailTestCase' => 'applications/metamta/storage/__tests__/PhabricatorMetaMTAMailTestCase.php',
'PhabricatorMetaMTAMailableDatasource' => 'applications/metamta/typeahead/PhabricatorMetaMTAMailableDatasource.php',
@ -5744,9 +5746,14 @@ phutil_register_library_map(array(
'PhabricatorMetaMTAEmailBodyParser' => 'Phobject',
'PhabricatorMetaMTAEmailBodyParserTestCase' => 'PhabricatorTestCase',
'PhabricatorMetaMTAErrorMailAction' => 'PhabricatorSystemAction',
'PhabricatorMetaMTAMail' => 'PhabricatorMetaMTADAO',
'PhabricatorMetaMTAMail' => array(
'PhabricatorMetaMTADAO',
'PhabricatorPolicyInterface',
),
'PhabricatorMetaMTAMailBody' => 'Phobject',
'PhabricatorMetaMTAMailBodyTestCase' => 'PhabricatorTestCase',
'PhabricatorMetaMTAMailPHIDType' => 'PhabricatorPHIDType',
'PhabricatorMetaMTAMailQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhabricatorMetaMTAMailSection' => 'Phobject',
'PhabricatorMetaMTAMailTestCase' => 'PhabricatorTestCase',
'PhabricatorMetaMTAMailableDatasource' => 'PhabricatorTypeaheadCompositeDatasource',

View file

@ -0,0 +1,43 @@
<?php
final class PhabricatorMetaMTAMailPHIDType extends PhabricatorPHIDType {
const TYPECONST = 'MTAM';
public function getTypeName() {
return pht('MetaMTA Mail');
}
public function getPHIDTypeApplicationClass() {
return 'PhabricatorMetaMTAApplication';
}
public function newObject() {
return new PhabricatorMetaMTAMail();
}
protected function buildQueryForObjects(
PhabricatorObjectQuery $query,
array $phids) {
return id(new PhabricatorMetaMTAMailQuery())
->withPHIDs($phids);
}
public function loadHandles(
PhabricatorHandleQuery $query,
array $handles,
array $objects) {
foreach ($handles as $phid => $handle) {
$mail = $objects[$phid];
$id = $mail->getID();
$name = pht('Mail %d', $id);
$handle
->setName($name)
->setFullName($name);
}
}
}

View file

@ -0,0 +1,57 @@
<?php
final class PhabricatorMetaMTAMailQuery
extends PhabricatorCursorPagedPolicyAwareQuery {
private $ids;
private $phids;
public function withIDs(array $ids) {
$this->ids = $ids;
return $this;
}
public function withPHIDs(array $phids) {
$this->phids = $phids;
return $this;
}
protected function loadPage() {
return $this->loadStandardPage($this->newResultObject());
}
protected function buildWhereClause(AphrontDatabaseConnection $conn_r) {
$where = array();
if ($this->ids !== null) {
$where[] = qsprintf(
$conn_r,
'mail.id IN (%Ld)',
$this->ids);
}
if ($this->phids !== null) {
$where[] = qsprintf(
$conn_r,
'mail.phid IN (%Ls)',
$this->phids);
}
$where[] = $this->buildPagingClause($conn_r);
return $this->formatWhereClause($where);
}
protected function getPrimaryTableAlias() {
return 'mail';
}
public function newResultObject() {
return new PhabricatorMetaMTAMail();
}
public function getQueryApplicationClass() {
return 'PhabricatorMetaMTAApplication';
}
}

View file

@ -3,7 +3,9 @@
/**
* @task recipients Managing Recipients
*/
final class PhabricatorMetaMTAMail extends PhabricatorMetaMTADAO {
final class PhabricatorMetaMTAMail
extends PhabricatorMetaMTADAO
implements PhabricatorPolicyInterface {
const STATUS_QUEUE = 'queued';
const STATUS_SENT = 'sent';
@ -29,6 +31,7 @@ final class PhabricatorMetaMTAMail extends PhabricatorMetaMTADAO {
protected function getConfiguration() {
return array(
self::CONFIG_AUX_PHID => true,
self::CONFIG_SERIALIZATION => array(
'parameters' => self::SERIALIZATION_JSON,
),
@ -54,6 +57,11 @@ final class PhabricatorMetaMTAMail extends PhabricatorMetaMTADAO {
) + parent::getConfiguration();
}
public function generatePHID() {
return PhabricatorPHID::generateNewPHID(
PhabricatorMetaMTAMailPHIDType::TYPECONST);
}
protected function setParam($param, $value) {
$this->parameters[$param] = $value;
return $this;
@ -993,4 +1001,29 @@ final class PhabricatorMetaMTAMail extends PhabricatorMetaMTADAO {
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */
public function getCapabilities() {
return array(
PhabricatorPolicyCapability::CAN_VIEW,
);
}
public function getPolicy($capability) {
return PhabricatorPolicies::POLICY_NOONE;
}
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
$actor_phids = $this->getAllActorPHIDs();
$actor_phids = $this->expandRecipients($actor_phids);
return in_array($viewer->getPHID(), $actor_phids);
}
public function describeAutomaticCapability($capability) {
return pht(
'The mail sender and message recipients can always see the mail.');
}
}