@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+168 -2
+2
resources/sql/autopatches/20150622.metamta.1.phid-col.sql
··· 1 + ALTER TABLE {$NAMESPACE}_metamta.metamta_mail 2 + ADD phid VARBINARY(64) NOT NULL AFTER id;
+22
resources/sql/autopatches/20150622.metamta.2.phid-mig.php
··· 1 + <?php 2 + 3 + $table = new PhabricatorMetaMTAMail(); 4 + $conn_w = $table->establishConnection('w'); 5 + 6 + echo pht('Assigning PHIDs to mails...')."\n"; 7 + foreach (new LiskMigrationIterator($table) as $mail) { 8 + $id = $mail->getID(); 9 + 10 + echo pht('Updating mail %d...', $id)."\n"; 11 + if ($mail->getPHID()) { 12 + continue; 13 + } 14 + 15 + queryfx( 16 + $conn_w, 17 + 'UPDATE %T SET phid = %s WHERE id = %d', 18 + $table->getTableName(), 19 + $table->generatePHID(), 20 + $id); 21 + } 22 + echo pht('Done.')."\n";
+2
resources/sql/autopatches/20150622.metamta.3.phid-key.sql
··· 1 + ALTER TABLE {$NAMESPACE}_metamta.metamta_mail 2 + ADD UNIQUE KEY `key_phid` (phid);
+8 -1
src/__phutil_library_map__.php
··· 2107 2107 'PhabricatorMetaMTAMail' => 'applications/metamta/storage/PhabricatorMetaMTAMail.php', 2108 2108 'PhabricatorMetaMTAMailBody' => 'applications/metamta/view/PhabricatorMetaMTAMailBody.php', 2109 2109 'PhabricatorMetaMTAMailBodyTestCase' => 'applications/metamta/view/__tests__/PhabricatorMetaMTAMailBodyTestCase.php', 2110 + 'PhabricatorMetaMTAMailPHIDType' => 'applications/metamta/phid/PhabricatorMetaMTAMailPHIDType.php', 2111 + 'PhabricatorMetaMTAMailQuery' => 'applications/metamta/query/PhabricatorMetaMTAMailQuery.php', 2110 2112 'PhabricatorMetaMTAMailSection' => 'applications/metamta/view/PhabricatorMetaMTAMailSection.php', 2111 2113 'PhabricatorMetaMTAMailTestCase' => 'applications/metamta/storage/__tests__/PhabricatorMetaMTAMailTestCase.php', 2112 2114 'PhabricatorMetaMTAMailableDatasource' => 'applications/metamta/typeahead/PhabricatorMetaMTAMailableDatasource.php', ··· 5744 5746 'PhabricatorMetaMTAEmailBodyParser' => 'Phobject', 5745 5747 'PhabricatorMetaMTAEmailBodyParserTestCase' => 'PhabricatorTestCase', 5746 5748 'PhabricatorMetaMTAErrorMailAction' => 'PhabricatorSystemAction', 5747 - 'PhabricatorMetaMTAMail' => 'PhabricatorMetaMTADAO', 5749 + 'PhabricatorMetaMTAMail' => array( 5750 + 'PhabricatorMetaMTADAO', 5751 + 'PhabricatorPolicyInterface', 5752 + ), 5748 5753 'PhabricatorMetaMTAMailBody' => 'Phobject', 5749 5754 'PhabricatorMetaMTAMailBodyTestCase' => 'PhabricatorTestCase', 5755 + 'PhabricatorMetaMTAMailPHIDType' => 'PhabricatorPHIDType', 5756 + 'PhabricatorMetaMTAMailQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 5750 5757 'PhabricatorMetaMTAMailSection' => 'Phobject', 5751 5758 'PhabricatorMetaMTAMailTestCase' => 'PhabricatorTestCase', 5752 5759 'PhabricatorMetaMTAMailableDatasource' => 'PhabricatorTypeaheadCompositeDatasource',
+43
src/applications/metamta/phid/PhabricatorMetaMTAMailPHIDType.php
··· 1 + <?php 2 + 3 + final class PhabricatorMetaMTAMailPHIDType extends PhabricatorPHIDType { 4 + 5 + const TYPECONST = 'MTAM'; 6 + 7 + public function getTypeName() { 8 + return pht('MetaMTA Mail'); 9 + } 10 + 11 + public function getPHIDTypeApplicationClass() { 12 + return 'PhabricatorMetaMTAApplication'; 13 + } 14 + 15 + public function newObject() { 16 + return new PhabricatorMetaMTAMail(); 17 + } 18 + 19 + protected function buildQueryForObjects( 20 + PhabricatorObjectQuery $query, 21 + array $phids) { 22 + 23 + return id(new PhabricatorMetaMTAMailQuery()) 24 + ->withPHIDs($phids); 25 + } 26 + 27 + public function loadHandles( 28 + PhabricatorHandleQuery $query, 29 + array $handles, 30 + array $objects) { 31 + 32 + foreach ($handles as $phid => $handle) { 33 + $mail = $objects[$phid]; 34 + 35 + $id = $mail->getID(); 36 + $name = pht('Mail %d', $id); 37 + 38 + $handle 39 + ->setName($name) 40 + ->setFullName($name); 41 + } 42 + } 43 + }
+57
src/applications/metamta/query/PhabricatorMetaMTAMailQuery.php
··· 1 + <?php 2 + 3 + final class PhabricatorMetaMTAMailQuery 4 + extends PhabricatorCursorPagedPolicyAwareQuery { 5 + 6 + private $ids; 7 + private $phids; 8 + 9 + public function withIDs(array $ids) { 10 + $this->ids = $ids; 11 + return $this; 12 + } 13 + 14 + public function withPHIDs(array $phids) { 15 + $this->phids = $phids; 16 + return $this; 17 + } 18 + 19 + protected function loadPage() { 20 + return $this->loadStandardPage($this->newResultObject()); 21 + } 22 + 23 + protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { 24 + $where = array(); 25 + 26 + if ($this->ids !== null) { 27 + $where[] = qsprintf( 28 + $conn_r, 29 + 'mail.id IN (%Ld)', 30 + $this->ids); 31 + } 32 + 33 + if ($this->phids !== null) { 34 + $where[] = qsprintf( 35 + $conn_r, 36 + 'mail.phid IN (%Ls)', 37 + $this->phids); 38 + } 39 + 40 + $where[] = $this->buildPagingClause($conn_r); 41 + 42 + return $this->formatWhereClause($where); 43 + } 44 + 45 + protected function getPrimaryTableAlias() { 46 + return 'mail'; 47 + } 48 + 49 + public function newResultObject() { 50 + return new PhabricatorMetaMTAMail(); 51 + } 52 + 53 + public function getQueryApplicationClass() { 54 + return 'PhabricatorMetaMTAApplication'; 55 + } 56 + 57 + }
+34 -1
src/applications/metamta/storage/PhabricatorMetaMTAMail.php
··· 3 3 /** 4 4 * @task recipients Managing Recipients 5 5 */ 6 - final class PhabricatorMetaMTAMail extends PhabricatorMetaMTADAO { 6 + final class PhabricatorMetaMTAMail 7 + extends PhabricatorMetaMTADAO 8 + implements PhabricatorPolicyInterface { 7 9 8 10 const STATUS_QUEUE = 'queued'; 9 11 const STATUS_SENT = 'sent'; ··· 29 31 30 32 protected function getConfiguration() { 31 33 return array( 34 + self::CONFIG_AUX_PHID => true, 32 35 self::CONFIG_SERIALIZATION => array( 33 36 'parameters' => self::SERIALIZATION_JSON, 34 37 ), ··· 52 55 ), 53 56 ), 54 57 ) + parent::getConfiguration(); 58 + } 59 + 60 + public function generatePHID() { 61 + return PhabricatorPHID::generateNewPHID( 62 + PhabricatorMetaMTAMailPHIDType::TYPECONST); 55 63 } 56 64 57 65 protected function setParam($param, $value) { ··· 990 998 } catch (PhabricatorSystemActionRateLimitException $ex) { 991 999 return true; 992 1000 } 1001 + } 1002 + 1003 + 1004 + /* -( PhabricatorPolicyInterface )----------------------------------------- */ 1005 + 1006 + 1007 + public function getCapabilities() { 1008 + return array( 1009 + PhabricatorPolicyCapability::CAN_VIEW, 1010 + ); 1011 + } 1012 + 1013 + public function getPolicy($capability) { 1014 + return PhabricatorPolicies::POLICY_NOONE; 1015 + } 1016 + 1017 + public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { 1018 + $actor_phids = $this->getAllActorPHIDs(); 1019 + $actor_phids = $this->expandRecipients($actor_phids); 1020 + return in_array($viewer->getPHID(), $actor_phids); 1021 + } 1022 + 1023 + public function describeAutomaticCapability($capability) { 1024 + return pht( 1025 + 'The mail sender and message recipients can always see the mail.'); 993 1026 } 994 1027 995 1028