Changeset

4352:f6da234b21b8

mod_http_admin_api: Add groups property to users
author Matthew Wild <mwild1@gmail.com>
date Sun, 17 Jan 2021 17:51:23 +0000
parents 4351:c0b1b2a61e3c
children 4353:535d80be110d
files mod_http_admin_api/mod_http_admin_api.lua
diffstat 1 files changed, 14 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mod_http_admin_api/mod_http_admin_api.lua	Sun Jan 17 17:50:42 2021 +0000
+++ b/mod_http_admin_api/mod_http_admin_api.lua	Sun Jan 17 17:51:23 2021 +0000
@@ -8,6 +8,8 @@
 local tokens = module:depends("tokenauth");
 local mod_pep = module:depends("pep");
 
+local group_memberships = module:open_store("groups", "map");
+
 local json_content_type = "application/json";
 
 local www_authenticate_header = ("Bearer realm=%q"):format(module.host.."/"..module.name);
@@ -149,9 +151,21 @@
 		end
 	end
 
+	local groups;
+	do
+		local group_set = group_memberships:get_all(username);
+		if group_set and next(group_set) then
+			groups = {};
+			for group_id in pairs(group_set) do
+				table.insert(groups, group_id);
+			end
+		end
+	end
+
 	return {
 		username = username;
 		display_name = display_name;
+		groups = groups;
 	};
 end