@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
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at recaptime-dev/main 111 lines 3.1 kB view raw
1<?php 2 3final class PhabricatorConduitTokenEditController 4 extends PhabricatorConduitController { 5 6 public function handleRequest(AphrontRequest $request) { 7 $viewer = $request->getViewer(); 8 $id = $request->getURIData('id'); 9 10 if ($id) { 11 $token = id(new PhabricatorConduitTokenQuery()) 12 ->setViewer($viewer) 13 ->withIDs(array($id)) 14 ->withExpired(false) 15 ->requireCapabilities( 16 array( 17 PhabricatorPolicyCapability::CAN_VIEW, 18 PhabricatorPolicyCapability::CAN_EDIT, 19 )) 20 ->executeOne(); 21 if (!$token) { 22 return new Aphront404Response(); 23 } 24 25 $object = $token->getObject(); 26 27 $is_new = false; 28 $title = pht('View API Token'); 29 } else { 30 $object = id(new PhabricatorObjectQuery()) 31 ->setViewer($viewer) 32 ->withPHIDs(array($request->getStr('objectPHID'))) 33 ->requireCapabilities( 34 array( 35 PhabricatorPolicyCapability::CAN_VIEW, 36 PhabricatorPolicyCapability::CAN_EDIT, 37 )) 38 ->executeOne(); 39 if (!$object) { 40 return new Aphront404Response(); 41 } 42 43 $token = PhabricatorConduitToken::initializeNewToken( 44 $object->getPHID(), 45 PhabricatorConduitToken::TYPE_STANDARD); 46 47 $is_new = true; 48 $title = pht('Generate API Token'); 49 $submit_button = pht('Generate Token'); 50 } 51 52 $panel_uri = id(new PhabricatorConduitTokensSettingsPanel()) 53 ->setViewer($viewer) 54 ->setUser($object) 55 ->getPanelURI(); 56 57 id(new PhabricatorAuthSessionEngine())->requireHighSecuritySession( 58 $viewer, 59 $request, 60 $panel_uri); 61 62 if ($request->isFormPost()) { 63 $token->save(); 64 65 if ($is_new) { 66 $token_uri = '/conduit/token/edit/'.$token->getID().'/'; 67 } else { 68 $token_uri = $panel_uri; 69 } 70 71 return id(new AphrontRedirectResponse())->setURI($token_uri); 72 } 73 74 $dialog = $this->newDialog() 75 ->setTitle($title) 76 ->addHiddenInput('objectPHID', $object->getPHID()); 77 78 if ($is_new) { 79 $dialog 80 ->appendParagraph(pht('Generate a new API token?')) 81 ->addSubmitButton($submit_button) 82 ->addCancelButton($panel_uri); 83 } else { 84 if ($token->getTokenType() === PhabricatorConduitToken::TYPE_CLUSTER) { 85 $dialog->appendChild( 86 pht( 87 'This token is automatically generated, and used to make '. 88 'requests between nodes in a cluster. You can not use this '. 89 'token in external applications.')); 90 } else { 91 Javelin::initBehavior('select-on-click'); 92 $form = id(new AphrontFormView()) 93 ->setUser($viewer) 94 ->appendChild( 95 id(new AphrontFormTextControl()) 96 ->setLabel(pht('Token')) 97 ->setReadOnly(true) 98 ->setSigil('select-on-click') 99 ->setHasCopyButton(true) 100 ->setValue($token->getToken())); 101 102 $dialog->appendForm($form); 103 } 104 105 $dialog->addCancelButton($panel_uri, pht('Done')); 106 } 107 108 return $dialog; 109 } 110 111}