Path: blob/master/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldCredential.php
12242 views
<?php12final class PhabricatorStandardCustomFieldCredential3extends PhabricatorStandardCustomField {45public function getFieldType() {6return 'credential';7}89public function buildFieldIndexes() {10$indexes = array();1112$value = $this->getFieldValue();13if (strlen($value)) {14$indexes[] = $this->newStringIndex($value);15}1617return $indexes;18}1920public function renderEditControl(array $handles) {21$provides_type = $this->getFieldConfigValue('credential.provides');22$credential_type = $this->getFieldConfigValue('credential.type');2324$all_types = PassphraseCredentialType::getAllProvidesTypes();25if (!in_array($provides_type, $all_types)) {26$provides_type = PassphrasePasswordCredentialType::PROVIDES_TYPE;27}2829$credentials = id(new PassphraseCredentialQuery())30->setViewer($this->getViewer())31->withIsDestroyed(false)32->withProvidesTypes(array($provides_type))33->execute();3435return id(new PassphraseCredentialControl())36->setViewer($this->getViewer())37->setLabel($this->getFieldName())38->setName($this->getFieldKey())39->setCaption($this->getCaption())40->setAllowNull(!$this->getRequired())41->setCredentialType($credential_type)42->setValue($this->getFieldValue())43->setError($this->getFieldError())44->setOptions($credentials);45}4647public function getRequiredHandlePHIDsForPropertyView() {48$value = $this->getFieldValue();49if ($value) {50return array($value);51}52return array();53}5455public function renderPropertyViewValue(array $handles) {56$value = $this->getFieldValue();57if ($value) {58return $handles[$value]->renderLink();59}60return null;61}6263public function validateApplicationTransactions(64PhabricatorApplicationTransactionEditor $editor,65$type,66array $xactions) {6768$errors = parent::validateApplicationTransactions(69$editor,70$type,71$xactions);7273$ok = PassphraseCredentialControl::validateTransactions(74$this->getViewer(),75$xactions);7677if (!$ok) {78foreach ($xactions as $xaction) {79$errors[] = new PhabricatorApplicationTransactionValidationError(80$type,81pht('Invalid'),82pht(83'The selected credential does not exist, or you do not have '.84'permission to use it.'),85$xaction);86$this->setFieldError(pht('Invalid'));87}88}8990return $errors;91}9293public function getApplicationTransactionRequiredHandlePHIDs(94PhabricatorApplicationTransaction $xaction) {95$phids = array();96$old = $xaction->getOldValue();97$new = $xaction->getNewValue();98if ($old) {99$phids[] = $old;100}101if ($new) {102$phids[] = $new;103}104return $phids;105}106107108public function getApplicationTransactionTitle(109PhabricatorApplicationTransaction $xaction) {110$author_phid = $xaction->getAuthorPHID();111112$old = $xaction->getOldValue();113$new = $xaction->getNewValue();114115if ($old && !$new) {116return pht(117'%s removed %s as %s.',118$xaction->renderHandleLink($author_phid),119$xaction->renderHandleLink($old),120$this->getFieldName());121} else if ($new && !$old) {122return pht(123'%s set %s to %s.',124$xaction->renderHandleLink($author_phid),125$this->getFieldName(),126$xaction->renderHandleLink($new));127} else {128return pht(129'%s changed %s from %s to %s.',130$xaction->renderHandleLink($author_phid),131$this->getFieldName(),132$xaction->renderHandleLink($old),133$xaction->renderHandleLink($new));134}135}136137138protected function getHTTPParameterType() {139return new AphrontPHIDHTTPParameterType();140}141142protected function newConduitSearchParameterType() {143return new ConduitPHIDParameterType();144}145146protected function newConduitEditParameterType() {147return new ConduitPHIDParameterType();148}149150}151152153