diff --git a/batch/apispec.php b/batch/apispec.php index c0e6f0727a..f39eed8b72 100644 --- a/batch/apispec.php +++ b/batch/apispec.php @@ -101,8 +101,7 @@ static private function parse_parameters($j) { return $known; } - /** @param string $fn - * @return mixed */ + /** @param string $fn */ private function expand_paths($fn) { foreach (["GET", "POST"] as $method) { if (!($j = $this->conf->api($fn, null, $method))) { @@ -124,19 +123,16 @@ private function expand_paths($fn) { /** @param string $path * @param 'GET'|'POST' $method * @param array $known - * @param object $j - * @param array &$x - * @return object */ + * @param object $j */ private function expand_path_method($path, $method, $known, $j) { $this->paths[$path] = $this->paths[$path] ?? []; $this->paths[$path][strtolower($method)] = $x = (object) []; $this->expand_request($x, $known, $j); $this->expand_response($x, $j); - return $x; } /** @param string $name - * @return array */ + * @return object */ private function resolve_common_schema($name) { if (!isset($this->schemas[$name])) { if ($name === "pid") { @@ -168,11 +164,11 @@ private function resolve_common_schema($name) { assert(false); } } - return ["\$ref" => "#/components/schemas/{$name}"]; + return (object) ["\$ref" => "#/components/schemas/{$name}"]; } /** @param string $name - * @return array */ + * @return object */ private function resolve_common_param($name) { if (!isset($this->parameters[$name])) { if ($name === "p") { @@ -193,13 +189,12 @@ private function resolve_common_param($name) { assert(false); } } - return ["\$ref" => "#/components/parameters/{$name}"]; + return (object) ["\$ref" => "#/components/parameters/{$name}"]; } /** @param object $x * @param array $known - * @param object $j - * @return object */ + * @param object $j */ private function expand_request($x, $known, $j) { $params = $body_properties = $body_required = []; $has_file = false; @@ -211,14 +206,14 @@ private function expand_request($x, $known, $j) { } else if ($name === "redirect" && $f === 0) { $params[] = $this->resolve_common_param("redirect"); } else if (($f & (self::F_BODY | self::F_FILE)) === 0) { - $params[] = [ + $params[] = (object) [ "name" => $name, "in" => "query", "required" => ($f & self::F_REQUIRED) !== 0, "schema" => (object) [] ]; } else { - $body_properties[$name] = [ + $body_properties[$name] = (object) [ "schema" => (object) [] ]; if (($f & self::F_REQUIRED) !== 0) { @@ -253,8 +248,7 @@ private function expand_request($x, $known, $j) { } /** @param object $x - * @param object $j - * @return object */ + * @param object $j */ private function expand_response($x, $j) { $body_properties = $body_required = []; $response = $j->response ?? []; diff --git a/etc/apifunctions.json b/etc/apifunctions.json index fbf9ff20ae..72e53a0d34 100644 --- a/etc/apifunctions.json +++ b/etc/apifunctions.json @@ -8,12 +8,14 @@ { "name": "account", "get": true, "function": "User_API::account", - "parameters": "email" + "parameters": "email", + "response": "email disabled placeholder" }, { "name": "account", "post": true, "function": "User_API::account", - "parameters": "email ?disable ?enable ?sendinfo" + "parameters": "email ?disable ?enable ?sendinfo", + "response": "email disabled placeholder" }, { "name": "alltags", "get": true, @@ -28,7 +30,8 @@ { "name": "claimreview", "paper": true, "post": true, "redirect": true, "function": "RequestReview_API::claimreview", - "parameters": "r email" + "parameters": "r email", + "response": "action review_site_relative" }, { "name": "clickthrough", "post": true, @@ -39,20 +42,21 @@ "name": "comment", "paper": true, "get": true, "function": "Comment_API::run", "parameters": "c", - "response": "comment", + "response": "?comment", "response_deprecated": "cmt" }, { "name": "comment", "paper": true, "post": true, "function": "Comment_API::run", "parameters": "c ?override ?=text ?=response ?=ready ?=topic ?=draft ?=blind ?=tags ?=visibility ?=:attachment ?=by_author ?=review_token ?delete", - "response": "comment", + "response": "?comment ?conflict", "response_deprecated": "cmt" }, { "name": "declinereview", "post": true, "redirect": true, "function": "RequestReview_API::declinereview", - "parameters": "p r ?=reason" + "parameters": "p r ?=reason", + "response": "action ?reason review_site_relative" }, { "name": "decision", "paper": true, "get": true, @@ -108,7 +112,7 @@ { "name": "jserror", "get": true, "function": "Error_API::jserror", - "parameters": "=error" + "parameters": "=error ?=url ?=lineno ?=colno ?=stack" }, { "name": "lead", "paper": true, "get": true, @@ -276,7 +280,7 @@ { "name": "tags", "post": true, "function": "Tags_API::run", - "parameters": "?p ?forceShow ?=tags ?=addtags ?=deltags ?=tagassignment ?=search", + "parameters": "?p ?=tags ?=addtags ?=deltags ?=tagassignment ?=search", "response": "?pid ?tags ?tags_edit_text ?tags_view_html ?tag_decoration_html ?color_classes ?p" }, { diff --git a/scripts/script.js b/scripts/script.js index 2ecac73d76..51ad230734 100644 --- a/scripts/script.js +++ b/scripts/script.js @@ -12991,8 +12991,9 @@ handle_ui.on("js-delete-user", function () { handle_ui.on("js-disable-user", function () { var disabled = hasClass(this, "btn-success"), self = this; self.disabled = true; - $.post(hoturl("=api/account", {u: this.getAttribute("data-user") || this.form.getAttribute("data-user")}), - disabled ? {enable: 1} : {disable: 1}, + const param = {email: this.getAttribute("data-user") || this.form.getAttribute("data-user")}; + param[disabled ? "enable" : "disable"] = 1; + $.post(hoturl("=api/account", param), {}, function (data) { self.disabled = false; if (data.ok) { @@ -13023,8 +13024,7 @@ handle_ui.on("js-disable-user", function () { handle_ui.on("js-send-user-accountinfo", function () { var self = this; self.disabled = true; - $.post(hoturl("=api/account", {u: this.getAttribute("data-user") || this.form.getAttribute("data-user")}), - {sendinfo: 1}, + $.post(hoturl("=api/account", {email: this.getAttribute("data-user") || this.form.getAttribute("data-user"), sendinfo: 1}), {}, function (data) { minifeedback(self, data); }); diff --git a/src/api/api_user.php b/src/api/api_user.php index 957f862a0a..d8a4743ef5 100644 --- a/src/api/api_user.php +++ b/src/api/api_user.php @@ -128,20 +128,13 @@ static function account_disable(Contact $user, Contact $viewer, $disabled) { return JsonResult::make_permission_error(); } else if ($viewer->contactId === $user->contactId) { return JsonResult::make_error(400, "<0>You cannot disable your own account"); - } else { - $ustatus = new UserStatus($viewer); - $ustatus->set_user($user); - if ($ustatus->save_user((object) ["disabled" => $disabled], $user)) { - return new JsonResult([ - "ok" => true, - "u" => $user->email, - "disabled" => $user->is_disabled(), - "placeholder" => $user->is_placeholder() - ]); - } else { - return new JsonResult(["ok" => false, "u" => $user->email]); - } } + $ustatus = new UserStatus($viewer); + $ustatus->set_user($user); + if (!$ustatus->save_user((object) ["disabled" => $disabled], $user)) { + return new JsonResult(["ok" => false]); + } + return new JsonResult(["ok" => true]); } /** @return JsonResult */ @@ -151,22 +144,19 @@ static function account_sendinfo(Contact $user, Contact $viewer) { } $user->activate_placeholder(false); $prep = $user->prepare_mail("@accountinfo"); - if ($prep->send()) { - $jr = new JsonResult(200); - } else { - $jr = new JsonResult(400); - $jr->content["message_list"] = $prep->message_list(); + if (!$prep->send()) { + return new JsonResult(["ok" => false, "message_list" => $prep->message_list()]); } - $jr->content["u"] = $user->email; - return $jr; + return new JsonResult(["ok" => true]); } /** @return JsonResult */ static function account(Contact $viewer, Qrequest $qreq) { - if (!isset($qreq->u) || $qreq->u === "me" || strcasecmp($qreq->u, $viewer->email) === 0) { + $u = $qreq->email ?? $qreq->u; + if ($u === null || $u === "me" || strcasecmp($u, $viewer->email) === 0) { $user = $viewer; } else if ($viewer->isPC) { - $user = $viewer->conf->user_by_email($qreq->u); + $user = $viewer->conf->user_by_email($u); } else { return JsonResult::make_permission_error(); } @@ -174,11 +164,17 @@ static function account(Contact $viewer, Qrequest $qreq) { return JsonResult::make_error(404, "<0>User not found"); } if ($qreq->valid_post() && ($qreq->disable || $qreq->enable)) { - return self::account_disable($user, $viewer, !!$qreq->disable); + $jr = self::account_disable($user, $viewer, !!$qreq->disable); } else if ($qreq->valid_post() && $qreq->sendinfo) { - return self::account_sendinfo($user, $viewer); + $jr = self::account_sendinfo($user, $viewer); } else { - return new JsonResult(["ok" => true]); + $jr = new JsonResult(["ok" => true]); } + if ($jr->content["ok"]) { + $jr->content["email"] = $user->email; + $jr->content["disabled"] = $user->is_disabled(); + $jr->content["placeholder"] = $user->is_placeholder(); + } + return $jr; } } diff --git a/src/assignmentset.php b/src/assignmentset.php index a40daeecc4..1ed703e52a 100644 --- a/src/assignmentset.php +++ b/src/assignmentset.php @@ -1262,7 +1262,7 @@ function json_result() { } private static function req_user_text($req) { - return Text::name($req["firstName"], $req["lastName"], $req["email"], NAME_E); + return Text::name($req["firstName"] ?? "", $req["lastName"] ?? "", $req["email"] ?? "", NAME_E); } private static function apply_user_parts($req, $a) { @@ -1368,12 +1368,12 @@ private function lookup_users($req, AssignmentParser $aparser) { if ($cset) { $text = ""; if ($first && $last) { - $text = "$last, $first"; + $text = "{$last}, {$first}"; } else if ($first || $last) { - $text = "$last$first"; + $text = $first . $last; } if ($email) { - $text .= " <$email>"; + $text = $text ? "{$text} <{$email}>" : "<{$email}>"; } $ret = ContactSearch::make_cset($text, $this->astate->user, $cset); if (count($ret->user_ids()) === 1) { diff --git a/src/papertable.php b/src/papertable.php index ff321b4afa..31d20fa281 100644 --- a/src/papertable.php +++ b/src/papertable.php @@ -1653,9 +1653,6 @@ function papstripOutcomeSelector() { echo $this->papt("decision", Ht::label("Decision", $id), ["type" => "ps", "fold" => "decision"]), '
'; - if (isset($this->qreq->forceShow)) { - echo Ht::hidden("forceShow", $this->qreq->forceShow ? 1 : 0); - } $opts = []; foreach ($this->conf->decision_set() as $dec) { $opts[$dec->id] = $dec->name_as(5);