[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhabricatorExternalAccount extends PhabricatorUserDAO 4 implements PhabricatorPolicyInterface { 5 6 protected $userPHID; 7 protected $accountType; 8 protected $accountDomain; 9 protected $accountSecret; 10 protected $accountID; 11 protected $displayName; 12 protected $username; 13 protected $realName; 14 protected $email; 15 protected $emailVerified = 0; 16 protected $accountURI; 17 protected $profileImagePHID; 18 protected $properties = array(); 19 20 private $profileImageFile = self::ATTACHABLE; 21 22 public function getProfileImageFile() { 23 return $this->assertAttached($this->profileImageFile); 24 } 25 26 public function attachProfileImageFile(PhabricatorFile $file) { 27 $this->profileImageFile = $file; 28 return $this; 29 } 30 31 public function generatePHID() { 32 return PhabricatorPHID::generateNewPHID( 33 PhabricatorPeopleExternalPHIDType::TYPECONST); 34 } 35 36 public function getConfiguration() { 37 return array( 38 self::CONFIG_AUX_PHID => true, 39 self::CONFIG_SERIALIZATION => array( 40 'properties' => self::SERIALIZATION_JSON, 41 ), 42 self::CONFIG_COLUMN_SCHEMA => array( 43 'userPHID' => 'phid?', 44 'accountType' => 'text16', 45 'accountDomain' => 'text64', 46 'accountSecret' => 'text?', 47 'accountID' => 'text64', 48 'displayName' => 'text255?', 49 'username' => 'text255?', 50 'realName' => 'text255?', 51 'email' => 'text255?', 52 'emailVerified' => 'bool', 53 'profileImagePHID' => 'phid?', 54 'accountURI' => 'text255?', 55 ), 56 self::CONFIG_KEY_SCHEMA => array( 57 'key_phid' => null, 58 'phid' => array( 59 'columns' => array('phid'), 60 'unique' => true, 61 ), 62 'account_details' => array( 63 'columns' => array('accountType', 'accountDomain', 'accountID'), 64 'unique' => true, 65 ), 66 ), 67 ) + parent::getConfiguration(); 68 } 69 70 public function getPhabricatorUser() { 71 $tmp_usr = id(new PhabricatorUser()) 72 ->makeEphemeral() 73 ->setPHID($this->getPHID()); 74 return $tmp_usr; 75 } 76 77 public function getProviderKey() { 78 return $this->getAccountType().':'.$this->getAccountDomain(); 79 } 80 81 public function save() { 82 if (!$this->getAccountSecret()) { 83 $this->setAccountSecret(Filesystem::readRandomCharacters(32)); 84 } 85 return parent::save(); 86 } 87 88 public function setProperty($key, $value) { 89 $this->properties[$key] = $value; 90 return $this; 91 } 92 93 public function getProperty($key, $default = null) { 94 return idx($this->properties, $key, $default); 95 } 96 97 public function isUsableForLogin() { 98 $key = $this->getProviderKey(); 99 $provider = PhabricatorAuthProvider::getEnabledProviderByKey($key); 100 101 if (!$provider) { 102 return false; 103 } 104 105 if (!$provider->shouldAllowLogin()) { 106 return false; 107 } 108 109 return true; 110 } 111 112 public function getDisplayName() { 113 if (strlen($this->displayName)) { 114 return $this->displayName; 115 } 116 117 // TODO: Figure out how much identifying information we're going to show 118 // to users about external accounts. For now, just show a string which is 119 // clearly not an error, but don't disclose any identifying information. 120 121 $map = array( 122 'email' => pht('Email User'), 123 ); 124 125 $type = $this->getAccountType(); 126 127 return idx($map, $type, pht('"%s" User', $type)); 128 } 129 130 131 132 /* -( PhabricatorPolicyInterface )----------------------------------------- */ 133 134 135 public function getCapabilities() { 136 return array( 137 PhabricatorPolicyCapability::CAN_VIEW, 138 PhabricatorPolicyCapability::CAN_EDIT, 139 ); 140 } 141 142 public function getPolicy($capability) { 143 switch ($capability) { 144 case PhabricatorPolicyCapability::CAN_VIEW: 145 return PhabricatorPolicies::getMostOpenPolicy(); 146 case PhabricatorPolicyCapability::CAN_EDIT: 147 return PhabricatorPolicies::POLICY_NOONE; 148 } 149 } 150 151 public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { 152 return ($viewer->getPHID() == $this->getUserPHID()); 153 } 154 155 public function describeAutomaticCapability($capability) { 156 switch ($capability) { 157 case PhabricatorPolicyCapability::CAN_VIEW: 158 return null; 159 case PhabricatorPolicyCapability::CAN_EDIT: 160 return pht( 161 'External accounts can only be edited by the account owner.'); 162 } 163 } 164 165 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |