From 855695a8620a3a5ffada836fd28e04bb912bbd3a Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 28 Oct 2023 18:43:47 +0300 Subject: add stuff necessary to run integration tests using phpunit --- update.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'update.php') diff --git a/update.php b/update.php index 4fd517701..4c10e3072 100755 --- a/update.php +++ b/update.php @@ -104,6 +104,7 @@ "user-check-password:" => ["USER:PASSWORD", "returns 0 if user has specified PASSWORD"], "user-set-password:" => ["USER:PASSWORD", "sets PASSWORD of specified USER"], "user-set-access-level:" => ["USER:LEVEL", "sets access LEVEL of specified USER"], + "user-enable-api:" => ["USER:BOOL", "enables or disables API access of specified USER"], "user-exists:" => ["USER", "returns 0 if specified USER exists in the database"], "force-yes" => "assume 'yes' to all queries", "help" => "", @@ -500,6 +501,35 @@ } } + if (isset($options["user-enable-api"])) { + list ($login, $enable) = explode(":", $options["user-enable-api"], 2); + + $uid = UserHelper::find_user_by_login($login); + $enable = Handler::_param_to_bool($enable); + + if (!$uid) { + Debug::log("Error: User not found: $login"); + exit(1); + } + + $rc = -1; + + if ($enable) { + Debug::log("Enabling API access for user $login..."); + $rc = Prefs::set(Prefs::ENABLE_API_ACCESS, true, $uid, null); + } else { + Debug::log("Disabling API access for user $login..."); + $rc = Prefs::set(Prefs::ENABLE_API_ACCESS, false, $uid, null); + } + + if ($rc) { + Debug::log("Success."); + } else { + Debug::log("Operation failed, check the logs for more information."); + exit(1); + } + } + if (isset($options["user-remove"])) { $login = $options["user-remove"]; -- cgit v1.2.3