Path: blob/master/src/applications/oauthserver/editor/PhabricatorOAuthServerEditor.php
12241 views
<?php12final class PhabricatorOAuthServerEditor3extends PhabricatorApplicationTransactionEditor {45public function getEditorApplicationClass() {6return 'PhabricatorOAuthServerApplication';7}89public function getEditorObjectsDescription() {10return pht('OAuth Applications');11}1213public function getTransactionTypes() {14$types = parent::getTransactionTypes();1516$types[] = PhabricatorOAuthServerTransaction::TYPE_NAME;17$types[] = PhabricatorOAuthServerTransaction::TYPE_REDIRECT_URI;18$types[] = PhabricatorOAuthServerTransaction::TYPE_DISABLED;1920$types[] = PhabricatorTransactions::TYPE_VIEW_POLICY;21$types[] = PhabricatorTransactions::TYPE_EDIT_POLICY;2223return $types;24}2526protected function getCustomTransactionOldValue(27PhabricatorLiskDAO $object,28PhabricatorApplicationTransaction $xaction) {2930switch ($xaction->getTransactionType()) {31case PhabricatorOAuthServerTransaction::TYPE_NAME:32return $object->getName();33case PhabricatorOAuthServerTransaction::TYPE_REDIRECT_URI:34return $object->getRedirectURI();35case PhabricatorOAuthServerTransaction::TYPE_DISABLED:36return $object->getIsDisabled();37}38}3940protected function getCustomTransactionNewValue(41PhabricatorLiskDAO $object,42PhabricatorApplicationTransaction $xaction) {4344switch ($xaction->getTransactionType()) {45case PhabricatorOAuthServerTransaction::TYPE_NAME:46case PhabricatorOAuthServerTransaction::TYPE_REDIRECT_URI:47return $xaction->getNewValue();48case PhabricatorOAuthServerTransaction::TYPE_DISABLED:49return (int)$xaction->getNewValue();50}51}5253protected function applyCustomInternalTransaction(54PhabricatorLiskDAO $object,55PhabricatorApplicationTransaction $xaction) {5657switch ($xaction->getTransactionType()) {58case PhabricatorOAuthServerTransaction::TYPE_NAME:59$object->setName($xaction->getNewValue());60return;61case PhabricatorOAuthServerTransaction::TYPE_REDIRECT_URI:62$object->setRedirectURI($xaction->getNewValue());63return;64case PhabricatorOAuthServerTransaction::TYPE_DISABLED:65$object->setIsDisabled($xaction->getNewValue());66return;67}6869return parent::applyCustomInternalTransaction($object, $xaction);70}7172protected function applyCustomExternalTransaction(73PhabricatorLiskDAO $object,74PhabricatorApplicationTransaction $xaction) {7576switch ($xaction->getTransactionType()) {77case PhabricatorOAuthServerTransaction::TYPE_NAME:78case PhabricatorOAuthServerTransaction::TYPE_REDIRECT_URI:79case PhabricatorOAuthServerTransaction::TYPE_DISABLED:80return;81}8283return parent::applyCustomExternalTransaction($object, $xaction);84}8586protected function validateTransaction(87PhabricatorLiskDAO $object,88$type,89array $xactions) {9091$errors = parent::validateTransaction($object, $type, $xactions);9293switch ($type) {94case PhabricatorOAuthServerTransaction::TYPE_NAME:95$missing = $this->validateIsEmptyTextField(96$object->getName(),97$xactions);9899if ($missing) {100$error = new PhabricatorApplicationTransactionValidationError(101$type,102pht('Required'),103pht('OAuth applications must have a name.'),104nonempty(last($xactions), null));105106$error->setIsMissingFieldError(true);107$errors[] = $error;108}109break;110case PhabricatorOAuthServerTransaction::TYPE_REDIRECT_URI:111$missing = $this->validateIsEmptyTextField(112$object->getRedirectURI(),113$xactions);114if ($missing) {115$error = new PhabricatorApplicationTransactionValidationError(116$type,117pht('Required'),118pht('OAuth applications must have a valid redirect URI.'),119nonempty(last($xactions), null));120121$error->setIsMissingFieldError(true);122$errors[] = $error;123} else {124foreach ($xactions as $xaction) {125$redirect_uri = $xaction->getNewValue();126127try {128$server = new PhabricatorOAuthServer();129$server->assertValidRedirectURI($redirect_uri);130} catch (Exception $ex) {131$errors[] = new PhabricatorApplicationTransactionValidationError(132$type,133pht('Invalid'),134$ex->getMessage(),135$xaction);136}137}138}139break;140}141142return $errors;143}144145}146147148