Differential D20907 Diff 49851 src/applications/repository/storage/PhabricatorRepositoryIdentity.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/repository/storage/PhabricatorRepositoryIdentity.php
<?php | <?php | ||||
final class PhabricatorRepositoryIdentity | final class PhabricatorRepositoryIdentity | ||||
extends PhabricatorRepositoryDAO | extends PhabricatorRepositoryDAO | ||||
implements | implements | ||||
PhabricatorPolicyInterface, | PhabricatorPolicyInterface, | ||||
PhabricatorApplicationTransactionInterface { | PhabricatorApplicationTransactionInterface { | ||||
protected $authorPHID; | protected $authorPHID; | ||||
protected $identityNameHash; | protected $identityNameHash; | ||||
protected $identityNameRaw; | protected $identityNameRaw; | ||||
protected $identityNameEncoding; | protected $identityNameEncoding; | ||||
protected $automaticGuessedUserPHID; | protected $automaticGuessedUserPHID; | ||||
protected $manuallySetUserPHID; | protected $manuallySetUserPHID; | ||||
protected $currentEffectiveUserPHID; | protected $currentEffectiveUserPHID; | ||||
protected $emailAddress; | |||||
protected function getConfiguration() { | protected function getConfiguration() { | ||||
return array( | return array( | ||||
self::CONFIG_AUX_PHID => true, | self::CONFIG_AUX_PHID => true, | ||||
self::CONFIG_BINARY => array( | self::CONFIG_BINARY => array( | ||||
'identityNameRaw' => true, | 'identityNameRaw' => true, | ||||
), | ), | ||||
self::CONFIG_COLUMN_SCHEMA => array( | self::CONFIG_COLUMN_SCHEMA => array( | ||||
'identityNameHash' => 'bytes12', | 'identityNameHash' => 'bytes12', | ||||
'identityNameEncoding' => 'text16?', | 'identityNameEncoding' => 'text16?', | ||||
'automaticGuessedUserPHID' => 'phid?', | 'automaticGuessedUserPHID' => 'phid?', | ||||
'manuallySetUserPHID' => 'phid?', | 'manuallySetUserPHID' => 'phid?', | ||||
'currentEffectiveUserPHID' => 'phid?', | 'currentEffectiveUserPHID' => 'phid?', | ||||
'emailAddress' => 'sort255?', | |||||
), | ), | ||||
self::CONFIG_KEY_SCHEMA => array( | self::CONFIG_KEY_SCHEMA => array( | ||||
'key_identity' => array( | 'key_identity' => array( | ||||
'columns' => array('identityNameHash'), | 'columns' => array('identityNameHash'), | ||||
'unique' => true, | 'unique' => true, | ||||
), | ), | ||||
'key_email' => array( | |||||
'columns' => array('emailAddress(64)'), | |||||
), | |||||
), | ), | ||||
) + parent::getConfiguration(); | ) + parent::getConfiguration(); | ||||
} | } | ||||
public function getPHIDType() { | public function getPHIDType() { | ||||
return PhabricatorRepositoryIdentityPHIDType::TYPECONST; | return PhabricatorRepositoryIdentityPHIDType::TYPECONST; | ||||
} | } | ||||
Show All 21 Lines | public function getIdentityDisplayName() { | ||||
return $address->getDisplayName(); | return $address->getDisplayName(); | ||||
} | } | ||||
public function getIdentityShortName() { | public function getIdentityShortName() { | ||||
// TODO | // TODO | ||||
return $this->getIdentityName(); | return $this->getIdentityName(); | ||||
} | } | ||||
public function getObjectName() { | |||||
return pht('Identity %d', $this->getID()); | |||||
} | |||||
public function getURI() { | public function getURI() { | ||||
return '/diffusion/identity/view/'.$this->getID().'/'; | return '/diffusion/identity/view/'.$this->getID().'/'; | ||||
} | } | ||||
public function hasEffectiveUser() { | public function hasEffectiveUser() { | ||||
return ($this->currentEffectiveUserPHID != null); | return ($this->currentEffectiveUserPHID != null); | ||||
} | } | ||||
public function getIdentityDisplayPHID() { | public function getIdentityDisplayPHID() { | ||||
if ($this->hasEffectiveUser()) { | if ($this->hasEffectiveUser()) { | ||||
return $this->getCurrentEffectiveUserPHID(); | return $this->getCurrentEffectiveUserPHID(); | ||||
} else { | } else { | ||||
return $this->getPHID(); | return $this->getPHID(); | ||||
} | } | ||||
} | } | ||||
public function save() { | public function save() { | ||||
if ($this->manuallySetUserPHID) { | if ($this->manuallySetUserPHID) { | ||||
$this->currentEffectiveUserPHID = $this->manuallySetUserPHID; | $this->currentEffectiveUserPHID = $this->manuallySetUserPHID; | ||||
} else { | } else { | ||||
$this->currentEffectiveUserPHID = $this->automaticGuessedUserPHID; | $this->currentEffectiveUserPHID = $this->automaticGuessedUserPHID; | ||||
} | } | ||||
$email_address = $this->getIdentityEmailAddress(); | |||||
// Raw identities are unrestricted binary data, and may consequently | |||||
// have arbitrarily long, binary email address information. We can't | |||||
// store this kind of information in the "emailAddress" column, which | |||||
// has column type "sort255". | |||||
// This kind of address almost certainly not legitimate and users can | |||||
// manually set the target of the identity, so just discard it rather | |||||
// than trying especially hard to make it work. | |||||
$byte_limit = $this->getColumnMaximumByteLength('emailAddress'); | |||||
$email_address = phutil_utf8ize($email_address); | |||||
if (strlen($email_address) > $byte_limit) { | |||||
$email_address = null; | |||||
} | |||||
$this->setEmailAddress($email_address); | |||||
return parent::save(); | return parent::save(); | ||||
} | } | ||||
/* -( PhabricatorPolicyInterface )----------------------------------------- */ | /* -( PhabricatorPolicyInterface )----------------------------------------- */ | ||||
public function getCapabilities() { | public function getCapabilities() { | ||||
return array( | return array( | ||||
PhabricatorPolicyCapability::CAN_VIEW, | PhabricatorPolicyCapability::CAN_VIEW, | ||||
PhabricatorPolicyCapability::CAN_EDIT, | PhabricatorPolicyCapability::CAN_EDIT, | ||||
); | ); | ||||
} | } | ||||
public function getPolicy($capability) { | public function getPolicy($capability) { | ||||
return PhabricatorPolicies::getMostOpenPolicy(); | return PhabricatorPolicies::getMostOpenPolicy(); | ||||
} | } | ||||
public function hasAutomaticCapability( | public function hasAutomaticCapability( | ||||
$capability, PhabricatorUser $viewer) { | $capability, | ||||
PhabricatorUser $viewer) { | |||||
return false; | return false; | ||||
} | } | ||||
/* -( PhabricatorApplicationTransactionInterface )------------------------- */ | /* -( PhabricatorApplicationTransactionInterface )------------------------- */ | ||||
public function getApplicationTransactionEditor() { | public function getApplicationTransactionEditor() { | ||||
return new DiffusionRepositoryIdentityEditor(); | return new DiffusionRepositoryIdentityEditor(); | ||||
} | } | ||||
public function getApplicationTransactionTemplate() { | public function getApplicationTransactionTemplate() { | ||||
return new PhabricatorRepositoryIdentityTransaction(); | return new PhabricatorRepositoryIdentityTransaction(); | ||||
} | } | ||||
} | } |