1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-03-31 22:48:16 +02:00
phorge-phorge/src/applications/people/storage/PhabricatorExternalAccountIdentifier.php
epriestley bcaf60015a Write ExternalAccountIdentifiers when interacting with external authentication providers
Summary:
Depends on D21015. When we sync an external account and get a list of account identifiers, write them to the database.

Nothing reads them yet and we still write "accountId", this just prepares us for reads.

Test Plan: Linked, refreshed, unlinked, and re-linked an external account. Peeked at the database and saw a sensible-looking row.

Differential Revision: https://secure.phabricator.com/D21016
2020-02-22 17:46:51 -08:00

81 lines
2.1 KiB
PHP

<?php
final class PhabricatorExternalAccountIdentifier
extends PhabricatorUserDAO
implements
PhabricatorPolicyInterface,
PhabricatorDestructibleInterface {
protected $externalAccountPHID;
protected $providerConfigPHID;
protected $identifierHash;
protected $identifierRaw;
public function getPHIDType() {
return PhabricatorPeopleExternalIdentifierPHIDType::TYPECONST;
}
protected function getConfiguration() {
return array(
self::CONFIG_AUX_PHID => true,
self::CONFIG_COLUMN_SCHEMA => array(
'identifierHash' => 'bytes12',
'identifierRaw' => 'text',
),
self::CONFIG_KEY_SCHEMA => array(
'key_identifier' => array(
'columns' => array('providerConfigPHID', 'identifierHash'),
'unique' => true,
),
'key_account' => array(
'columns' => array('externalAccountPHID'),
),
),
) + parent::getConfiguration();
}
public function save() {
$identifier_raw = $this->getIdentifierRaw();
$identifier_hash = PhabricatorHash::digestForIndex($identifier_raw);
$this->setIdentifierHash($identifier_hash);
return parent::save();
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */
// TODO: These permissions aren't very good. They should just be the same
// as the associated ExternalAccount. See T13381.
public function getCapabilities() {
return array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
);
}
public function getPolicy($capability) {
switch ($capability) {
case PhabricatorPolicyCapability::CAN_VIEW:
return PhabricatorPolicies::getMostOpenPolicy();
case PhabricatorPolicyCapability::CAN_EDIT:
return PhabricatorPolicies::POLICY_NOONE;
}
}
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
return false;
}
/* -( PhabricatorDestructibleInterface )----------------------------------- */
public function destroyObjectPermanently(
PhabricatorDestructionEngine $engine) {
$this->delete();
}
}