From 27d426e3fe922badc21cffeb247897ad230bfd16 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 21 Apr 2014 15:32:48 -0700 Subject: [PATCH] Allow Conduit console to be browsed by logged-out users Summary: Ref T4830. A few methods, like `conduit.ping`, are callable without authentication, so this even has some use cases. Also: - Make some Differential stuff a little more consistent. - Use slightly more modern rendering. - Deprecate the status-oriented `user` calls; these will be replaced by Calendar methods. Test Plan: Browsed console as logged out / logged in users. Reviewers: chad, btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T4830 Differential Revision: https://secure.phabricator.com/D8826 --- src/__phutil_library_map__.php | 26 +++--- .../PhabricatorConduitConsoleController.php | 92 ++++++++++--------- .../PhabricatorConduitListController.php | 7 +- ...tAPI_differential_createcomment_Method.php | 5 +- ...duitAPI_differential_creatediff_Method.php | 3 +- ...itAPI_differential_createinline_Method.php | 3 - ...tAPI_differential_createrawdiff_Method.php | 3 - .../ConduitAPI_differential_find_Method.php | 6 +- ...erential_finishpostponedlinters_Method.php | 5 +- ...uitAPI_differential_getalldiffs_Method.php | 5 +- ...I_differential_getcommitmessage_Method.php | 2 +- ...API_differential_getcommitpaths_Method.php | 5 +- ...ConduitAPI_differential_getdiff_Method.php | 5 +- ...duitAPI_differential_getrawdiff_Method.php | 2 +- ...differential_parsecommitmessage_Method.php | 2 +- ...duitAPI_differential_querydiffs_Method.php | 5 +- ...PI_differential_setdiffproperty_Method.php | 5 +- ..._differential_updateunitresults_Method.php | 5 +- .../people/conduit/ConduitAPI_user_Method.php | 3 - .../ConduitAPI_user_addstatus_Method.php | 16 ++-- .../ConduitAPI_user_removestatus_Method.php | 13 ++- 21 files changed, 100 insertions(+), 118 deletions(-) diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index ba266c91ed..d1761cbce3 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -2718,26 +2718,26 @@ phutil_register_library_map(array( 'ConduitAPI_conpherence_updatethread_Method' => 'ConduitAPI_conpherence_Method', 'ConduitAPI_differential_Method' => 'ConduitAPIMethod', 'ConduitAPI_differential_close_Method' => 'ConduitAPI_differential_Method', - 'ConduitAPI_differential_createcomment_Method' => 'ConduitAPIMethod', - 'ConduitAPI_differential_creatediff_Method' => 'ConduitAPIMethod', + 'ConduitAPI_differential_createcomment_Method' => 'ConduitAPI_differential_Method', + 'ConduitAPI_differential_creatediff_Method' => 'ConduitAPI_differential_Method', 'ConduitAPI_differential_createinline_Method' => 'ConduitAPI_differential_Method', 'ConduitAPI_differential_createrawdiff_Method' => 'ConduitAPI_differential_Method', 'ConduitAPI_differential_createrevision_Method' => 'ConduitAPI_differential_Method', - 'ConduitAPI_differential_find_Method' => 'ConduitAPIMethod', - 'ConduitAPI_differential_finishpostponedlinters_Method' => 'ConduitAPIMethod', - 'ConduitAPI_differential_getalldiffs_Method' => 'ConduitAPIMethod', - 'ConduitAPI_differential_getcommitmessage_Method' => 'ConduitAPIMethod', - 'ConduitAPI_differential_getcommitpaths_Method' => 'ConduitAPIMethod', - 'ConduitAPI_differential_getdiff_Method' => 'ConduitAPIMethod', - 'ConduitAPI_differential_getrawdiff_Method' => 'ConduitAPIMethod', + 'ConduitAPI_differential_find_Method' => 'ConduitAPI_differential_Method', + 'ConduitAPI_differential_finishpostponedlinters_Method' => 'ConduitAPI_differential_Method', + 'ConduitAPI_differential_getalldiffs_Method' => 'ConduitAPI_differential_Method', + 'ConduitAPI_differential_getcommitmessage_Method' => 'ConduitAPI_differential_Method', + 'ConduitAPI_differential_getcommitpaths_Method' => 'ConduitAPI_differential_Method', + 'ConduitAPI_differential_getdiff_Method' => 'ConduitAPI_differential_Method', + 'ConduitAPI_differential_getrawdiff_Method' => 'ConduitAPI_differential_Method', 'ConduitAPI_differential_getrevision_Method' => 'ConduitAPI_differential_Method', 'ConduitAPI_differential_getrevisioncomments_Method' => 'ConduitAPI_differential_Method', - 'ConduitAPI_differential_parsecommitmessage_Method' => 'ConduitAPIMethod', + 'ConduitAPI_differential_parsecommitmessage_Method' => 'ConduitAPI_differential_Method', 'ConduitAPI_differential_query_Method' => 'ConduitAPI_differential_Method', - 'ConduitAPI_differential_querydiffs_Method' => 'ConduitAPIMethod', - 'ConduitAPI_differential_setdiffproperty_Method' => 'ConduitAPIMethod', + 'ConduitAPI_differential_querydiffs_Method' => 'ConduitAPI_differential_Method', + 'ConduitAPI_differential_setdiffproperty_Method' => 'ConduitAPI_differential_Method', 'ConduitAPI_differential_updaterevision_Method' => 'ConduitAPI_differential_Method', - 'ConduitAPI_differential_updateunitresults_Method' => 'ConduitAPIMethod', + 'ConduitAPI_differential_updateunitresults_Method' => 'ConduitAPI_differential_Method', 'ConduitAPI_diffusion_Method' => 'ConduitAPIMethod', 'ConduitAPI_diffusion_abstractquery_Method' => 'ConduitAPI_diffusion_Method', 'ConduitAPI_diffusion_branchquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method', diff --git a/src/applications/conduit/controller/PhabricatorConduitConsoleController.php b/src/applications/conduit/controller/PhabricatorConduitConsoleController.php index e6d8d975c3..cc4f752223 100644 --- a/src/applications/conduit/controller/PhabricatorConduitConsoleController.php +++ b/src/applications/conduit/controller/PhabricatorConduitConsoleController.php @@ -1,13 +1,14 @@ method = $data['method']; } @@ -26,28 +27,25 @@ final class PhabricatorConduitConsoleController return new Aphront404Response(); } + $can_call_method = false; + $status = $method->getMethodStatus(); $reason = $method->getMethodStatusDescription(); + $errors = array(); - $status_view = null; - if ($status != ConduitAPIMethod::METHOD_STATUS_STABLE) { - $status_view = new AphrontErrorView(); - switch ($status) { - case ConduitAPIMethod::METHOD_STATUS_DEPRECATED: - $status_view->setTitle('Deprecated Method'); - $status_view->appendChild( - nonempty($reason, "This method is deprecated.")); - break; - case ConduitAPIMethod::METHOD_STATUS_UNSTABLE: - $status_view->setSeverity(AphrontErrorView::SEVERITY_WARNING); - $status_view->setTitle('Unstable Method'); - $status_view->appendChild( - nonempty( - $reason, - "This method is new and unstable. Its interface is subject ". - "to change.")); - break; - } + switch ($status) { + case ConduitAPIMethod::METHOD_STATUS_DEPRECATED: + $reason = nonempty($reason, pht('This method is deprecated.')); + $errors[] = pht('Deprecated Method: %s', $reason); + break; + case ConduitAPIMethod::METHOD_STATUS_UNSTABLE: + $reason = nonempty( + $reason, + pht( + 'This method is new and unstable. Its interface is subject '. + 'to change.')); + $errors[] = pht('Unstable Method: %s', $reason); + break; } $error_types = $method->defineErrorTypes(); @@ -61,7 +59,8 @@ final class PhabricatorConduitConsoleController } $error_description = phutil_tag('ul', array(), $error_description); } else { - $error_description = "This method does not raise any specific errors."; + $error_description = pht( + 'This method does not raise any specific errors.'); } $form = new AphrontFormView(); @@ -95,29 +94,38 @@ final class PhabricatorConduitConsoleController ->setCaption($desc)); } - $form - ->appendChild( - id(new AphrontFormSelectControl()) - ->setLabel('Output Format') - ->setName('output') - ->setOptions( - array( - 'human' => 'Human Readable', - 'json' => 'JSON', - ))) - ->appendChild( - id(new AphrontFormSubmitControl()) - ->addCancelButton($this->getApplicationURI()) - ->setValue('Call Method')); + $must_login = !$viewer->isLoggedIn() && + $method->shouldRequireAuthentication(); + if ($must_login) { + $errors[] = pht( + 'Login Required: This method requires authentication. You must '. + 'log in before you can make calls to it.'); + } else { + $form + ->appendChild( + id(new AphrontFormSelectControl()) + ->setLabel('Output Format') + ->setName('output') + ->setOptions( + array( + 'human' => 'Human Readable', + 'json' => 'JSON', + ))) + ->appendChild( + id(new AphrontFormSubmitControl()) + ->addCancelButton($this->getApplicationURI()) + ->setValue(pht('Call Method'))); + } + + $header = id(new PHUIHeaderView()) + ->setUser($viewer) + ->setHeader($method->getAPIMethodName()); $form_box = id(new PHUIObjectBoxView()) - ->setHeaderText($method->getAPIMethodName()) + ->setHeader($header) + ->setFormErrors($errors) ->setForm($form); - if ($status_view) { - $form_box->setErrorView($status_view); - } - $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb($method->getAPIMethodName()); diff --git a/src/applications/conduit/controller/PhabricatorConduitListController.php b/src/applications/conduit/controller/PhabricatorConduitListController.php index fdf46a0fd0..2d8fd2dab2 100644 --- a/src/applications/conduit/controller/PhabricatorConduitListController.php +++ b/src/applications/conduit/controller/PhabricatorConduitListController.php @@ -1,14 +1,15 @@ queryKey = idx($data, 'queryKey'); } diff --git a/src/applications/differential/conduit/ConduitAPI_differential_createcomment_Method.php b/src/applications/differential/conduit/ConduitAPI_differential_createcomment_Method.php index df39032142..726d5171fd 100644 --- a/src/applications/differential/conduit/ConduitAPI_differential_createcomment_Method.php +++ b/src/applications/differential/conduit/ConduitAPI_differential_createcomment_Method.php @@ -1,10 +1,7 @@