3 final class PhabricatorRepositoryIdentity
4 extends PhabricatorRepositoryDAO
6 PhabricatorPolicyInterface
,
7 PhabricatorApplicationTransactionInterface
{
10 protected $identityNameHash;
11 protected $identityNameRaw;
12 protected $identityNameEncoding;
13 protected $automaticGuessedUserPHID;
14 protected $manuallySetUserPHID;
15 protected $currentEffectiveUserPHID;
16 protected $emailAddress;
18 protected function getConfiguration() {
20 self
::CONFIG_AUX_PHID
=> true,
21 self
::CONFIG_BINARY
=> array(
22 'identityNameRaw' => true,
24 self
::CONFIG_COLUMN_SCHEMA
=> array(
25 'identityNameHash' => 'bytes12',
26 'identityNameEncoding' => 'text16?',
27 'automaticGuessedUserPHID' => 'phid?',
28 'manuallySetUserPHID' => 'phid?',
29 'currentEffectiveUserPHID' => 'phid?',
30 'emailAddress' => 'sort255?',
32 self
::CONFIG_KEY_SCHEMA
=> array(
33 'key_identity' => array(
34 'columns' => array('identityNameHash'),
38 'columns' => array('emailAddress(64)'),
41 ) + parent
::getConfiguration();
44 public function getPHIDType() {
45 return PhabricatorRepositoryIdentityPHIDType
::TYPECONST
;
48 public function setIdentityName($name_raw) {
49 $this->setIdentityNameRaw($name_raw);
50 $this->setIdentityNameHash(PhabricatorHash
::digestForIndex($name_raw));
51 $this->setIdentityNameEncoding($this->detectEncodingForStorage($name_raw));
56 public function getIdentityName() {
57 return $this->getUTF8StringFromStorage(
58 $this->getIdentityNameRaw(),
59 $this->getIdentityNameEncoding());
62 public function getIdentityEmailAddress() {
63 $address = new PhutilEmailAddress($this->getIdentityName());
64 return $address->getAddress();
67 public function getIdentityDisplayName() {
68 $address = new PhutilEmailAddress($this->getIdentityName());
69 return $address->getDisplayName();
72 public function getIdentityShortName() {
74 return $this->getIdentityName();
77 public function getObjectName() {
78 return pht('Identity %d', $this->getID());
81 public function getURI() {
82 return '/diffusion/identity/view/'.$this->getID().'/';
85 public function hasEffectiveUser() {
86 return ($this->currentEffectiveUserPHID
!= null);
89 public function getIdentityDisplayPHID() {
90 if ($this->hasEffectiveUser()) {
91 return $this->getCurrentEffectiveUserPHID();
93 return $this->getPHID();
97 public function save() {
98 if ($this->manuallySetUserPHID
) {
99 $unassigned = DiffusionIdentityUnassignedDatasource
::FUNCTION_TOKEN
;
100 if ($this->manuallySetUserPHID
=== $unassigned) {
101 $effective_phid = null;
103 $effective_phid = $this->manuallySetUserPHID
;
106 $effective_phid = $this->automaticGuessedUserPHID
;
109 $this->setCurrentEffectiveUserPHID($effective_phid);
111 $email_address = $this->getIdentityEmailAddress();
113 // Raw identities are unrestricted binary data, and may consequently
114 // have arbitrarily long, binary email address information. We can't
115 // store this kind of information in the "emailAddress" column, which
116 // has column type "sort255".
118 // This kind of address almost certainly not legitimate and users can
119 // manually set the target of the identity, so just discard it rather
120 // than trying especially hard to make it work.
122 $byte_limit = $this->getColumnMaximumByteLength('emailAddress');
123 $email_address = phutil_utf8ize($email_address);
124 if (strlen($email_address) > $byte_limit) {
125 $email_address = null;
128 $this->setEmailAddress($email_address);
130 return parent
::save();
134 /* -( PhabricatorPolicyInterface )----------------------------------------- */
137 public function getCapabilities() {
139 PhabricatorPolicyCapability
::CAN_VIEW
,
140 PhabricatorPolicyCapability
::CAN_EDIT
,
144 public function getPolicy($capability) {
145 return PhabricatorPolicies
::getMostOpenPolicy();
148 public function hasAutomaticCapability(
150 PhabricatorUser
$viewer) {
155 /* -( PhabricatorApplicationTransactionInterface )------------------------- */
158 public function getApplicationTransactionEditor() {
159 return new DiffusionRepositoryIdentityEditor();
162 public function getApplicationTransactionTemplate() {
163 return new PhabricatorRepositoryIdentityTransaction();