Changeset

4369:29b7f445aec5

mod_http_admin_api: add support for updating groups
author Jonas Schäfer <jonas@wielicki.name>
date Thu, 21 Jan 2021 17:30:34 +0100
parents 4368:e0c8d866d58c
children 4370:dee6b5098278
files mod_http_admin_api/mod_http_admin_api.lua
diffstat 1 files changed, 26 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mod_http_admin_api/mod_http_admin_api.lua	Thu Jan 21 16:02:31 2021 +0000
+++ b/mod_http_admin_api/mod_http_admin_api.lua	Thu Jan 21 17:30:34 2021 +0100
@@ -437,7 +437,32 @@
 		elseif not group_memberships:set(group_id, member_name, true) then
 			return 500;
 		end
-		return 200;
+		return 204;
+	end
+
+	local group_id = group:match("^([^/]+)$")
+	if group_id then
+		local request = event.request;
+		if request.headers.content_type ~= json_content_type
+		or (not request.body or #request.body == 0) then
+			return 400;
+		end
+
+		local update = json.decode(event.request.body);
+		if not update then
+			return 400;
+		end
+
+		local group_info = group_info_store:get(group_id);
+		if not group_info then
+			return 404;
+		end
+
+		if update.name then
+			group_info["name"] = update.name
+		end
+		group_info_store:set(group_id, group_info);
+		return 204;
 	end
 	return 400;
 end