@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.

Implement "PolicyInterface" on "UserEmail" so "EmailQuery" can load them properly

Summary:
See PHI1558. Ref T11860. Ref T13444. I partly implemented PHIDs for "UserEmail" objects, but they can't load on their own so you can't directly `bin/remove destroy` them yet.

Allow them to actually load by implementing "PolicyInterface".

Addresses are viewable and editable by the associated user, unless they are a bot/list address, in which case they are viewable and editable by administrators (in preparation for T11860). This has no real impact on anything today.

Test Plan:
- Used `bin/remove destroy <phid>` to destroy an individual email address.
- Before: error while loading the object by PHID in the query policy layer.
- After: clean load and destroy.

Maniphest Tasks: T13444, T11860

Differential Revision: https://secure.phabricator.com/D20927

+71 -1
+1
src/__phutil_library_map__.php
··· 11690 11690 'PhabricatorUserEmail' => array( 11691 11691 'PhabricatorUserDAO', 11692 11692 'PhabricatorDestructibleInterface', 11693 + 'PhabricatorPolicyInterface', 11693 11694 ), 11694 11695 'PhabricatorUserEmailTestCase' => 'PhabricatorTestCase', 11695 11696 'PhabricatorUserEmpowerTransaction' => 'PhabricatorUserTransactionType',
+6
src/applications/people/phid/PhabricatorPeopleUserEmailPHIDType.php
··· 29 29 PhabricatorHandleQuery $query, 30 30 array $handles, 31 31 array $objects) { 32 + 33 + foreach ($handles as $phid => $handle) { 34 + $email = $objects[$phid]; 35 + $handle->setName($email->getAddress()); 36 + } 37 + 32 38 return null; 33 39 } 34 40
+26
src/applications/people/query/PhabricatorPeopleUserEmailQuery.php
··· 48 48 return $where; 49 49 } 50 50 51 + protected function willLoadPage(array $page) { 52 + 53 + $user_phids = mpull($page, 'getUserPHID'); 54 + 55 + $users = id(new PhabricatorPeopleQuery()) 56 + ->setViewer($this->getViewer()) 57 + ->setParentQuery($this) 58 + ->withPHIDs($user_phids) 59 + ->execute(); 60 + $users = mpull($users, null, 'getPHID'); 61 + 62 + foreach ($page as $key => $address) { 63 + $user = idx($users, $address->getUserPHID()); 64 + 65 + if (!$user) { 66 + unset($page[$key]); 67 + $this->didRejectResult($address); 68 + continue; 69 + } 70 + 71 + $address->attachUser($user); 72 + } 73 + 74 + return $page; 75 + } 76 + 51 77 public function getQueryApplicationClass() { 52 78 return 'PhabricatorPeopleApplication'; 53 79 }
+38 -1
src/applications/people/storage/PhabricatorUserEmail.php
··· 6 6 */ 7 7 final class PhabricatorUserEmail 8 8 extends PhabricatorUserDAO 9 - implements PhabricatorDestructibleInterface { 9 + implements 10 + PhabricatorDestructibleInterface, 11 + PhabricatorPolicyInterface { 10 12 11 13 protected $userPHID; 12 14 protected $address; 13 15 protected $isVerified; 14 16 protected $isPrimary; 15 17 protected $verificationCode; 18 + 19 + private $user = self::ATTACHABLE; 16 20 17 21 const MAX_ADDRESS_LENGTH = 128; 18 22 ··· 50 54 $this->setVerificationCode(Filesystem::readRandomCharacters(24)); 51 55 } 52 56 return parent::save(); 57 + } 58 + 59 + public function attachUser(PhabricatorUser $user) { 60 + $this->user = $user; 61 + return $this; 62 + } 63 + 64 + public function getUser() { 65 + return $this->assertAttached($this->user); 53 66 } 54 67 55 68 ··· 285 298 public function destroyObjectPermanently( 286 299 PhabricatorDestructionEngine $engine) { 287 300 $this->delete(); 301 + } 302 + 303 + 304 + /* -( PhabricatorPolicyInterface )----------------------------------------- */ 305 + 306 + public function getCapabilities() { 307 + return array( 308 + PhabricatorPolicyCapability::CAN_VIEW, 309 + PhabricatorPolicyCapability::CAN_EDIT, 310 + ); 311 + } 312 + 313 + public function getPolicy($capability) { 314 + $user = $this->getUser(); 315 + 316 + if ($this->getIsSystemAgent() || $this->getIsMailingList()) { 317 + return PhabricatorPolicies::POLICY_ADMIN; 318 + } 319 + 320 + return $user->getPHID(); 321 + } 322 + 323 + public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { 324 + return false; 288 325 } 289 326 290 327 }