3 final class DiffusionRepositoryURICredentialController
4 extends DiffusionController
{
6 public function handleRequest(AphrontRequest
$request) {
7 $response = $this->loadDiffusionContextForEdit();
12 $viewer = $this->getViewer();
13 $drequest = $this->getDiffusionRequest();
14 $repository = $drequest->getRepository();
16 $id = $request->getURIData('id');
17 $uri = id(new PhabricatorRepositoryURIQuery())
20 ->withRepositories(array($repository))
21 ->requireCapabilities(
23 PhabricatorPolicyCapability
::CAN_VIEW
,
24 PhabricatorPolicyCapability
::CAN_EDIT
,
28 return new Aphront404Response();
31 $is_builtin = $uri->isBuiltin();
32 $has_credential = (bool)$uri->getCredentialPHID();
33 $view_uri = $uri->getViewURI();
34 $is_remove = ($request->getURIData('action') == 'remove');
37 return $this->newDialog()
38 ->setTitle(pht('Builtin URIs Do Not Use Credentials'))
41 'You can not set a credential for builtin URIs which this '.
42 'server hosts. These URIs are not fetched from or pushed to, '.
43 'and credentials are not required to authenticate any '.
44 'activity against them.'))
45 ->addCancelButton($view_uri);
48 if ($request->isFormPost()) {
54 $new_phid = $request->getStr('credentialPHID');
57 $type_credential = PhabricatorRepositoryURITransaction
::TYPE_CREDENTIAL
;
59 $xactions[] = id(new PhabricatorRepositoryURITransaction())
60 ->setTransactionType($type_credential)
61 ->setNewValue($new_phid);
63 $editor = id(new DiffusionURIEditor())
65 ->setContinueOnNoEffect(true)
66 ->setContinueOnMissingFields(true)
67 ->setContentSourceFromRequest($request)
68 ->applyTransactions($uri, $xactions);
70 return id(new AphrontRedirectResponse())->setURI($view_uri);
73 $command_engine = $uri->newCommandEngine();
74 $is_supported = $command_engine->isCredentialSupported();
78 $width = AphrontDialogView
::WIDTH_DEFAULT
;
80 if ($has_credential) {
81 $title = pht('Remove Credential');
83 'This credential will no longer be used to authenticate activity '.
85 $button = pht('Remove Credential');
87 $title = pht('No Credential');
89 'This URI does not have an associated credential.');
92 } else if (!$is_supported) {
93 $title = pht('Unauthenticated Protocol');
95 'The protocol for this URI ("%s") does not use authentication, so '.
96 'you can not provide a credential.',
97 $command_engine->getDisplayProtocol());
100 $effective_uri = $uri->getEffectiveURI();
102 $label = $command_engine->getPassphraseCredentialLabel();
103 $credential_type = $command_engine->getPassphraseDefaultCredentialType();
105 $provides_type = $command_engine->getPassphraseProvidesCredentialType();
106 $options = id(new PassphraseCredentialQuery())
108 ->withIsDestroyed(false)
109 ->withProvidesTypes(array($provides_type))
112 $control = id(new PassphraseCredentialControl())
113 ->setName('credentialPHID')
115 ->setValue($uri->getCredentialPHID())
116 ->setCredentialType($credential_type)
117 ->setOptions($options);
119 $default_user = $effective_uri->getUser();
120 if (strlen($default_user)) {
121 $control->setDefaultUsername($default_user);
124 $form = id(new AphrontFormView())
126 ->appendControl($control);
128 if ($has_credential) {
129 $title = pht('Update Credential');
130 $button = pht('Update Credential');
132 $title = pht('Set Credential');
133 $button = pht('Set Credential');
136 $width = AphrontDialogView
::WIDTH_FORM
;
139 $dialog = $this->newDialog()
142 ->addCancelButton($view_uri);
145 $dialog->appendParagraph($body);
149 $dialog->appendForm($form);
153 $dialog->addSubmitButton($button);