Path: blob/master/src/applications/auth/storage/PhabricatorAuthProviderConfig.php
12256 views
<?php12final class PhabricatorAuthProviderConfig3extends PhabricatorAuthDAO4implements5PhabricatorApplicationTransactionInterface,6PhabricatorPolicyInterface,7PhabricatorDestructibleInterface {89protected $providerClass;10protected $providerType;11protected $providerDomain;1213protected $isEnabled;14protected $shouldAllowLogin = 0;15protected $shouldAllowRegistration = 0;16protected $shouldAllowLink = 0;17protected $shouldAllowUnlink = 0;18protected $shouldTrustEmails = 0;19protected $shouldAutoLogin = 0;2021protected $properties = array();2223private $provider;2425public function generatePHID() {26return PhabricatorPHID::generateNewPHID(27PhabricatorAuthAuthProviderPHIDType::TYPECONST);28}2930protected function getConfiguration() {31return array(32self::CONFIG_AUX_PHID => true,33self::CONFIG_SERIALIZATION => array(34'properties' => self::SERIALIZATION_JSON,35),36self::CONFIG_COLUMN_SCHEMA => array(37'isEnabled' => 'bool',38'providerClass' => 'text128',39'providerType' => 'text32',40'providerDomain' => 'text128',41'shouldAllowLogin' => 'bool',42'shouldAllowRegistration' => 'bool',43'shouldAllowLink' => 'bool',44'shouldAllowUnlink' => 'bool',45'shouldTrustEmails' => 'bool',46'shouldAutoLogin' => 'bool',47),48self::CONFIG_KEY_SCHEMA => array(49'key_provider' => array(50'columns' => array('providerType', 'providerDomain'),51'unique' => true,52),53'key_class' => array(54'columns' => array('providerClass'),55),56),57) + parent::getConfiguration();58}5960public function getProperty($key, $default = null) {61return idx($this->properties, $key, $default);62}6364public function setProperty($key, $value) {65$this->properties[$key] = $value;66return $this;67}6869public function getProvider() {70if (!$this->provider) {71$base = PhabricatorAuthProvider::getAllBaseProviders();72$found = null;73foreach ($base as $provider) {74if (get_class($provider) == $this->providerClass) {75$found = $provider;76break;77}78}79if ($found) {80$this->provider = id(clone $found)->attachProviderConfig($this);81}82}83return $this->provider;84}8586public function getURI() {87return '/auth/config/view/'.$this->getID().'/';88}8990public function getObjectName() {91return pht('Auth Provider %d', $this->getID());92}9394public function getDisplayName() {95return $this->getProvider()->getProviderName();96}9798public function getSortVector() {99return id(new PhutilSortVector())100->addString($this->getDisplayName());101}102103public function newIconView() {104return $this->getProvider()->newIconView();105}106107108/* -( PhabricatorApplicationTransactionInterface )------------------------- */109110111public function getApplicationTransactionEditor() {112return new PhabricatorAuthProviderConfigEditor();113}114115public function getApplicationTransactionTemplate() {116return new PhabricatorAuthProviderConfigTransaction();117}118119120/* -( PhabricatorPolicyInterface )----------------------------------------- */121122123public function getCapabilities() {124return array(125PhabricatorPolicyCapability::CAN_VIEW,126PhabricatorPolicyCapability::CAN_EDIT,127);128}129130public function getPolicy($capability) {131switch ($capability) {132case PhabricatorPolicyCapability::CAN_VIEW:133return PhabricatorPolicies::POLICY_USER;134case PhabricatorPolicyCapability::CAN_EDIT:135return PhabricatorPolicies::POLICY_ADMIN;136}137}138139public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {140return false;141}142143144/* -( PhabricatorDestructibleInterface )----------------------------------- */145146147public function destroyObjectPermanently(148PhabricatorDestructionEngine $engine) {149150$viewer = $engine->getViewer();151$config_phid = $this->getPHID();152153$accounts = id(new PhabricatorExternalAccountQuery())154->setViewer($viewer)155->withProviderConfigPHIDs(array($config_phid))156->newIterator();157foreach ($accounts as $account) {158$engine->destroyObject($account);159}160161$identifiers = id(new PhabricatorExternalAccountIdentifierQuery())162->setViewer($viewer)163->withProviderConfigPHIDs(array($config_phid))164->newIterator();165foreach ($identifiers as $identifier) {166$engine->destroyObject($identifier);167}168169$this->delete();170}171172}173174175