diff --git a/resources/sql/autopatches/20150622.metamta.1.phid-col.sql b/resources/sql/autopatches/20150622.metamta.1.phid-col.sql new file mode 100644 index 0000000000..9bdd1a005e --- /dev/null +++ b/resources/sql/autopatches/20150622.metamta.1.phid-col.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_metamta.metamta_mail + ADD phid VARBINARY(64) NOT NULL AFTER id; diff --git a/resources/sql/autopatches/20150622.metamta.2.phid-mig.php b/resources/sql/autopatches/20150622.metamta.2.phid-mig.php new file mode 100644 index 0000000000..35932a701b --- /dev/null +++ b/resources/sql/autopatches/20150622.metamta.2.phid-mig.php @@ -0,0 +1,22 @@ +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"; diff --git a/resources/sql/autopatches/20150622.metamta.3.phid-key.sql b/resources/sql/autopatches/20150622.metamta.3.phid-key.sql new file mode 100644 index 0000000000..dae8d7e604 --- /dev/null +++ b/resources/sql/autopatches/20150622.metamta.3.phid-key.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_metamta.metamta_mail + ADD UNIQUE KEY `key_phid` (phid); diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index a8162414f3..9c4acc6ec3 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -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', diff --git a/src/applications/metamta/phid/PhabricatorMetaMTAMailPHIDType.php b/src/applications/metamta/phid/PhabricatorMetaMTAMailPHIDType.php new file mode 100644 index 0000000000..8159045dbd --- /dev/null +++ b/src/applications/metamta/phid/PhabricatorMetaMTAMailPHIDType.php @@ -0,0 +1,43 @@ +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); + } + } +} diff --git a/src/applications/metamta/query/PhabricatorMetaMTAMailQuery.php b/src/applications/metamta/query/PhabricatorMetaMTAMailQuery.php new file mode 100644 index 0000000000..d5fd3342ef --- /dev/null +++ b/src/applications/metamta/query/PhabricatorMetaMTAMailQuery.php @@ -0,0 +1,57 @@ +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'; + } + +} diff --git a/src/applications/metamta/storage/PhabricatorMetaMTAMail.php b/src/applications/metamta/storage/PhabricatorMetaMTAMail.php index af7007cd87..61f376381a 100644 --- a/src/applications/metamta/storage/PhabricatorMetaMTAMail.php +++ b/src/applications/metamta/storage/PhabricatorMetaMTAMail.php @@ -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.'); + } + + }