Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / repository / storage / PhabricatorRepositoryIdentity.php
blob74fbd06544ba5ec7bf6bb4e5955b220454cbe659
1 <?php
3 final class PhabricatorRepositoryIdentity
4 extends PhabricatorRepositoryDAO
5 implements
6 PhabricatorPolicyInterface,
7 PhabricatorApplicationTransactionInterface {
9 protected $authorPHID;
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() {
19 return array(
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'),
35 'unique' => true,
37 'key_email' => array(
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));
53 return $this;
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() {
73 // TODO
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();
92 } else {
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;
102 } else {
103 $effective_phid = $this->manuallySetUserPHID;
105 } else {
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() {
138 return array(
139 PhabricatorPolicyCapability::CAN_VIEW,
140 PhabricatorPolicyCapability::CAN_EDIT,
144 public function getPolicy($capability) {
145 return PhabricatorPolicies::getMostOpenPolicy();
148 public function hasAutomaticCapability(
149 $capability,
150 PhabricatorUser $viewer) {
151 return false;
155 /* -( PhabricatorApplicationTransactionInterface )------------------------- */
158 public function getApplicationTransactionEditor() {
159 return new DiffusionRepositoryIdentityEditor();
162 public function getApplicationTransactionTemplate() {
163 return new PhabricatorRepositoryIdentityTransaction();