Something went wrong. Try again.
@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
Something went wrong. Try again.
4.7 kB · 159 lines
PHP
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160<?php
final class DiffusionRepositoryURICredentialController extends DiffusionController {
public function handleRequest(AphrontRequest $request) { $response = $this->loadDiffusionContextForEdit(); if ($response) { return $response; }
$viewer = $this->getViewer(); $drequest = $this->getDiffusionRequest(); $repository = $drequest->getRepository();
$id = $request->getURIData('id'); $uri = id(new PhabricatorRepositoryURIQuery()) ->setViewer($viewer) ->withIDs(array($id)) ->withRepositories(array($repository)) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, )) ->executeOne(); if (!$uri) { return new Aphront404Response(); }
$is_builtin = $uri->isBuiltin(); $has_credential = (bool)$uri->getCredentialPHID(); $view_uri = $uri->getViewURI(); $is_remove = ($request->getURIData('action') == 'remove');
if ($is_builtin) { return $this->newDialog() ->setTitle(pht('Builtin URIs Do Not Use Credentials')) ->appendParagraph( pht( 'You can not set a credential for builtin URIs which this '. 'server hosts. These URIs are not fetched from or pushed to, '. 'and credentials are not required to authenticate any '. 'activity against them.')) ->addCancelButton($view_uri); }
if ($request->isFormPost()) { $xactions = array();
if ($is_remove) { $new_phid = null; } else { $new_phid = $request->getStr('credentialPHID'); }
$type_credential = PhabricatorRepositoryURITransaction::TYPE_CREDENTIAL;
$xactions[] = id(new PhabricatorRepositoryURITransaction()) ->setTransactionType($type_credential) ->setNewValue($new_phid);
$editor = id(new DiffusionURIEditor()) ->setActor($viewer) ->setContinueOnNoEffect(true) ->setContinueOnMissingFields(true) ->setContentSourceFromRequest($request) ->applyTransactions($uri, $xactions);
return id(new AphrontRedirectResponse())->setURI($view_uri); }
$command_engine = $uri->newCommandEngine(); $is_supported = $command_engine->isCredentialSupported();
$body = null; $form = null; $width = AphrontDialogView::WIDTH_DEFAULT; if ($is_remove) { if ($has_credential) { $title = pht('Remove Credential'); $body = pht( 'This credential will no longer be used to authenticate activity '. 'against this URI.'); $button = pht('Remove Credential'); } else { $title = pht('No Credential'); $body = pht( 'This URI does not have an associated credential.'); $button = null; } } else if (!$is_supported) { $title = pht('Unauthenticated Protocol'); $body = pht( 'The protocol for this URI ("%s") does not use authentication, so '. 'you can not provide a credential.', $command_engine->getDisplayProtocol()); $button = null; } else { $effective_uri = $uri->getEffectiveURI();
$label = $command_engine->getPassphraseCredentialLabel(); $credential_type = $command_engine->getPassphraseDefaultCredentialType();
$provides_type = $command_engine->getPassphraseProvidesCredentialType(); $options = id(new PassphraseCredentialQuery()) ->setViewer($viewer) ->withIsDestroyed(false) ->withProvidesTypes(array($provides_type)) ->execute();
$control = id(new PassphraseCredentialControl()) ->setName('credentialPHID') ->setLabel($label) ->setValue($uri->getCredentialPHID()) ->setCredentialType($credential_type) ->setOptions($options);
$default_user = $effective_uri->getUser(); if (strlen($default_user)) { $control->setDefaultUsername($default_user); }
$form = id(new AphrontFormView()) ->setViewer($viewer) ->appendControl($control);
if ($has_credential) { $title = pht('Update Credential'); $button = pht('Update Credential'); } else { $title = pht('Set Credential'); $button = pht('Set Credential'); }
$width = AphrontDialogView::WIDTH_FORM; }
$dialog = $this->newDialog() ->setWidth($width) ->setTitle($title) ->addCancelButton($view_uri);
if ($body) { $dialog->appendParagraph($body); }
if ($form) { $dialog->appendForm($form); }
if ($button) { $dialog->addSubmitButton($button); }
return $dialog; }
}