@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
at upstream/main 67 lines 2.2 kB view raw
1<?php 2 3final class PhabricatorOAuthClientDisableController 4 extends PhabricatorOAuthClientController { 5 6 public function handleRequest(AphrontRequest $request) { 7 $viewer = $this->getViewer(); 8 9 $client = id(new PhabricatorOAuthServerClientQuery()) 10 ->setViewer($viewer) 11 ->withIDs(array($request->getURIData('id'))) 12 ->requireCapabilities( 13 array( 14 PhabricatorPolicyCapability::CAN_VIEW, 15 PhabricatorPolicyCapability::CAN_EDIT, 16 )) 17 ->executeOne(); 18 if (!$client) { 19 return new Aphront404Response(); 20 } 21 22 $done_uri = $client->getViewURI(); 23 $is_disable = !$client->getIsDisabled(); 24 25 if ($request->isFormPost()) { 26 $xactions = array(); 27 28 $xactions[] = id(new PhabricatorOAuthServerTransaction()) 29 ->setTransactionType(PhabricatorOAuthServerTransaction::TYPE_DISABLED) 30 ->setNewValue((int)$is_disable); 31 32 $editor = id(new PhabricatorOAuthServerEditor()) 33 ->setActor($viewer) 34 ->setContentSourceFromRequest($request) 35 ->setContinueOnNoEffect(true) 36 ->setContinueOnMissingFields(true) 37 ->applyTransactions($client, $xactions); 38 39 return id(new AphrontRedirectResponse())->setURI($done_uri); 40 } 41 42 if ($is_disable) { 43 $title = pht('Disable OAuth Application'); 44 $body = pht( 45 'Really disable the %s OAuth application? Users will no longer be '. 46 'able to authenticate against it, nor access this server using '. 47 'tokens generated by this application.', 48 phutil_tag('strong', array(), $client->getName())); 49 $button = pht('Disable Application'); 50 } else { 51 $title = pht('Enable OAuth Application'); 52 $body = pht( 53 'Really enable the %s OAuth application? Users will be able to '. 54 'authenticate against it, and existing tokens will become usable '. 55 'again.', 56 phutil_tag('strong', array(), $client->getName())); 57 $button = pht('Enable Application'); 58 } 59 60 return $this->newDialog() 61 ->setTitle($title) 62 ->appendParagraph($body) 63 ->addCancelButton($done_uri) 64 ->addSubmitButton($button); 65 } 66 67}