annotate mod_http_admin_api/mod_http_admin_api.lua @ 4362:116c88c28532

mod_http_admin_api: restructure group-related info in API - Return the members of the group right in the get_group_by_id call. This is an O(1) of extra work. - Remove the groups attribute from get_user_by_name as that is O(n) of work and rarely immediately needed. The replacement for the group membership information in the user is for now to use the group API and iterate; future work may fix that.
author Jonas Schäfer <jonas@wielicki.name>
date Wed, 20 Jan 2021 15:30:29 +0100
parents 7f1f3b79d991
children 636d56bbad97
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4345
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
1 local usermanager = require "core.usermanager";
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
2
4343
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 local json = require "util.json";
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 module:depends("http");
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7 local invites = module:depends("invites");
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8 local tokens = module:depends("tokenauth");
4345
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
9 local mod_pep = module:depends("pep");
4343
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10
4353
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
11 local group_store = module:open_store("groups");
4352
f6da234b21b8 mod_http_admin_api: Add groups property to users
Matthew Wild <mwild1@gmail.com>
parents: 4351
diff changeset
12 local group_memberships = module:open_store("groups", "map");
f6da234b21b8 mod_http_admin_api: Add groups property to users
Matthew Wild <mwild1@gmail.com>
parents: 4351
diff changeset
13
4343
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 local json_content_type = "application/json";
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 local www_authenticate_header = ("Bearer realm=%q"):format(module.host.."/"..module.name);
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 local function check_credentials(request)
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 local auth_type, auth_data = string.match(request.headers.authorization or "", "^(%S+)%s(.+)$");
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 if not (auth_type and auth_data) then
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 return false;
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 end
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 if auth_type == "Bearer" then
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 local token_info = tokens.get_token_info(auth_data);
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26 if not token_info or not token_info.session then
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 return false;
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28 end
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29 return token_info.session;
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 end
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 return nil;
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32 end
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34 function check_auth(routes)
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35 local function check_request_auth(event)
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
36 local session = check_credentials(event.request);
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
37 if not session then
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38 event.response.headers.authorization = www_authenticate_header;
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39 return false, 401;
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40 elseif session.auth_scope ~= "prosody:scope:admin" then
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41 return false, 403;
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
42 end
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
43 event.session = session;
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
44 return true;
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
45 end
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
46
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
47 for route, handler in pairs(routes) do
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
48 routes[route] = function (event, ...)
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
49 local permit, code = check_request_auth(event);
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
50 if not permit then
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
51 return code;
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
52 end
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
53 return handler(event, ...);
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
54 end;
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
55 end
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
56 return routes;
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
57 end
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
58
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
59 local function token_info_to_invite_info(token_info)
4349
5ca36c36ab05 mod_http_admin_api: Expose new invite properties: groups, source and reusable
Matthew Wild <mwild1@gmail.com>
parents: 4345
diff changeset
60 local additional_data = token_info.additional_data;
5ca36c36ab05 mod_http_admin_api: Expose new invite properties: groups, source and reusable
Matthew Wild <mwild1@gmail.com>
parents: 4345
diff changeset
61 local groups = additional_data and additional_data.groups or nil;
5ca36c36ab05 mod_http_admin_api: Expose new invite properties: groups, source and reusable
Matthew Wild <mwild1@gmail.com>
parents: 4345
diff changeset
62 local source = additional_data and additional_data.source or nil;
4343
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
63 return {
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
64 id = token_info.token;
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
65 type = token_info.type;
4358
d3e0fe470877 mod_http_admin_api: Ensure 'reusable' flag is always present on an invite
Matthew Wild <mwild1@gmail.com>
parents: 4357
diff changeset
66 reusable = not not token_info.reusable;
4343
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
67 inviter = token_info.inviter;
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
68 jid = token_info.jid;
4354
d61d7d30f38d mod_http_admin_api: Add XMPP URI into invite objects
Matthew Wild <mwild1@gmail.com>
parents: 4353
diff changeset
69 uri = token_info.uri;
4343
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
70 landing_page = token_info.landing_page;
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
71 created_at = token_info.created_at;
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
72 expires = token_info.expires;
4349
5ca36c36ab05 mod_http_admin_api: Expose new invite properties: groups, source and reusable
Matthew Wild <mwild1@gmail.com>
parents: 4345
diff changeset
73 groups = groups;
5ca36c36ab05 mod_http_admin_api: Expose new invite properties: groups, source and reusable
Matthew Wild <mwild1@gmail.com>
parents: 4345
diff changeset
74 source = source;
4343
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
75 };
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
76 end
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
77
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
78 function list_invites(event)
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
79 local invites_list = {};
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
80 for token, invite in invites.pending_account_invites() do --luacheck: ignore 213/token
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
81 table.insert(invites_list, token_info_to_invite_info(invite));
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
82 end
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
83 table.sort(invites_list, function (a, b)
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
84 return a.created_at < b.created_at;
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
85 end);
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
86
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
87 event.response.headers["Content-Type"] = json_content_type;
4350
270025e76bf8 mod_http_admin_api: Use json.encode_array() when returning an array
Matthew Wild <mwild1@gmail.com>
parents: 4349
diff changeset
88 return json.encode_array(invites_list);
4343
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
89 end
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
90
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
91 function get_invite_by_id(event, invite_id)
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
92 local invite = invites.get_account_invite_info(invite_id);
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
93 if not invite then
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
94 return 404;
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
95 end
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
96
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
97 event.response.headers["Content-Type"] = json_content_type;
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
98 return json.encode(token_info_to_invite_info(invite));
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
99 end
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
100
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
101 function create_invite(event)
4351
c0b1b2a61e3c mod_http_admin_api: Add support for creating reusable/group/custom-ttl invites
Matthew Wild <mwild1@gmail.com>
parents: 4350
diff changeset
102 local invite_options;
c0b1b2a61e3c mod_http_admin_api: Add support for creating reusable/group/custom-ttl invites
Matthew Wild <mwild1@gmail.com>
parents: 4350
diff changeset
103
c0b1b2a61e3c mod_http_admin_api: Add support for creating reusable/group/custom-ttl invites
Matthew Wild <mwild1@gmail.com>
parents: 4350
diff changeset
104 local request = event.request;
c0b1b2a61e3c mod_http_admin_api: Add support for creating reusable/group/custom-ttl invites
Matthew Wild <mwild1@gmail.com>
parents: 4350
diff changeset
105 if request.body and #request.body > 0 then
c0b1b2a61e3c mod_http_admin_api: Add support for creating reusable/group/custom-ttl invites
Matthew Wild <mwild1@gmail.com>
parents: 4350
diff changeset
106 if request.headers.content_type ~= json_content_type then
c0b1b2a61e3c mod_http_admin_api: Add support for creating reusable/group/custom-ttl invites
Matthew Wild <mwild1@gmail.com>
parents: 4350
diff changeset
107 module:log("warn", "Invalid content type");
c0b1b2a61e3c mod_http_admin_api: Add support for creating reusable/group/custom-ttl invites
Matthew Wild <mwild1@gmail.com>
parents: 4350
diff changeset
108 return 400;
c0b1b2a61e3c mod_http_admin_api: Add support for creating reusable/group/custom-ttl invites
Matthew Wild <mwild1@gmail.com>
parents: 4350
diff changeset
109 end
c0b1b2a61e3c mod_http_admin_api: Add support for creating reusable/group/custom-ttl invites
Matthew Wild <mwild1@gmail.com>
parents: 4350
diff changeset
110 invite_options = json.decode(event.request.body);
c0b1b2a61e3c mod_http_admin_api: Add support for creating reusable/group/custom-ttl invites
Matthew Wild <mwild1@gmail.com>
parents: 4350
diff changeset
111 if not invite_options then
c0b1b2a61e3c mod_http_admin_api: Add support for creating reusable/group/custom-ttl invites
Matthew Wild <mwild1@gmail.com>
parents: 4350
diff changeset
112 module:log("warn", "Invalid JSON");
c0b1b2a61e3c mod_http_admin_api: Add support for creating reusable/group/custom-ttl invites
Matthew Wild <mwild1@gmail.com>
parents: 4350
diff changeset
113 return 400;
c0b1b2a61e3c mod_http_admin_api: Add support for creating reusable/group/custom-ttl invites
Matthew Wild <mwild1@gmail.com>
parents: 4350
diff changeset
114 end
4359
5dbce7f35aa0 mod_http_admin_api: Fix logic bug
Matthew Wild <mwild1@gmail.com>
parents: 4358
diff changeset
115 else
5dbce7f35aa0 mod_http_admin_api: Fix logic bug
Matthew Wild <mwild1@gmail.com>
parents: 4358
diff changeset
116 invite_options = {};
4351
c0b1b2a61e3c mod_http_admin_api: Add support for creating reusable/group/custom-ttl invites
Matthew Wild <mwild1@gmail.com>
parents: 4350
diff changeset
117 end
c0b1b2a61e3c mod_http_admin_api: Add support for creating reusable/group/custom-ttl invites
Matthew Wild <mwild1@gmail.com>
parents: 4350
diff changeset
118
c0b1b2a61e3c mod_http_admin_api: Add support for creating reusable/group/custom-ttl invites
Matthew Wild <mwild1@gmail.com>
parents: 4350
diff changeset
119 local invite;
4359
5dbce7f35aa0 mod_http_admin_api: Fix logic bug
Matthew Wild <mwild1@gmail.com>
parents: 4358
diff changeset
120 if invite_options.reusable then
4357
a49ca492e621 mod_invites, mod_http_admin_api: Allow specifying multiple groups when creating an invite
Matthew Wild <mwild1@gmail.com>
parents: 4354
diff changeset
121 invite = invites.create_group(invite_options.groups, invite_options.ttl, {
4351
c0b1b2a61e3c mod_http_admin_api: Add support for creating reusable/group/custom-ttl invites
Matthew Wild <mwild1@gmail.com>
parents: 4350
diff changeset
122 source = "admin_api/"..event.session.username;
c0b1b2a61e3c mod_http_admin_api: Add support for creating reusable/group/custom-ttl invites
Matthew Wild <mwild1@gmail.com>
parents: 4350
diff changeset
123 });
c0b1b2a61e3c mod_http_admin_api: Add support for creating reusable/group/custom-ttl invites
Matthew Wild <mwild1@gmail.com>
parents: 4350
diff changeset
124 else
c0b1b2a61e3c mod_http_admin_api: Add support for creating reusable/group/custom-ttl invites
Matthew Wild <mwild1@gmail.com>
parents: 4350
diff changeset
125 invite = invites.create_account(nil, {
c0b1b2a61e3c mod_http_admin_api: Add support for creating reusable/group/custom-ttl invites
Matthew Wild <mwild1@gmail.com>
parents: 4350
diff changeset
126 source = "admin_api/"..event.session.username;
4357
a49ca492e621 mod_invites, mod_http_admin_api: Allow specifying multiple groups when creating an invite
Matthew Wild <mwild1@gmail.com>
parents: 4354
diff changeset
127 groups = invite_options.groups;
4351
c0b1b2a61e3c mod_http_admin_api: Add support for creating reusable/group/custom-ttl invites
Matthew Wild <mwild1@gmail.com>
parents: 4350
diff changeset
128 });
c0b1b2a61e3c mod_http_admin_api: Add support for creating reusable/group/custom-ttl invites
Matthew Wild <mwild1@gmail.com>
parents: 4350
diff changeset
129 end
4343
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
130 if not invite then
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
131 return 500;
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
132 end
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
133
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
134 event.response.headers["Content-Type"] = json_content_type;
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
135 return json.encode(token_info_to_invite_info(invite));
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
136 end
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
137
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
138 function delete_invite(event, invite_id) --luacheck: ignore 212/event
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
139 if not invites.delete_account_invite(invite_id) then
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
140 return 404;
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
141 end
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
142 return 200;
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
143 end
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
144
4345
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
145 local function get_user_info(username)
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
146 if not usermanager.user_exists(username, module.host) then
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
147 return nil;
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
148 end
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
149 local display_name;
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
150 do
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
151 local pep_service = mod_pep.get_pep_service(username);
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
152 local ok, _, nick_item = pep_service:get_last_item("http://jabber.org/protocol/nick", true);
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
153 if ok and nick_item then
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
154 display_name = nick_item:get_child_text("nick", "http://jabber.org/protocol/nick");
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
155 end
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
156 end
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
157
4362
116c88c28532 mod_http_admin_api: restructure group-related info in API
Jonas Schäfer <jonas@wielicki.name>
parents: 4361
diff changeset
158 return {
116c88c28532 mod_http_admin_api: restructure group-related info in API
Jonas Schäfer <jonas@wielicki.name>
parents: 4361
diff changeset
159 username = username;
116c88c28532 mod_http_admin_api: restructure group-related info in API
Jonas Schäfer <jonas@wielicki.name>
parents: 4361
diff changeset
160 display_name = display_name;
116c88c28532 mod_http_admin_api: restructure group-related info in API
Jonas Schäfer <jonas@wielicki.name>
parents: 4361
diff changeset
161 };
116c88c28532 mod_http_admin_api: restructure group-related info in API
Jonas Schäfer <jonas@wielicki.name>
parents: 4361
diff changeset
162 end
116c88c28532 mod_http_admin_api: restructure group-related info in API
Jonas Schäfer <jonas@wielicki.name>
parents: 4361
diff changeset
163
116c88c28532 mod_http_admin_api: restructure group-related info in API
Jonas Schäfer <jonas@wielicki.name>
parents: 4361
diff changeset
164 local function get_user_groups(username)
4352
f6da234b21b8 mod_http_admin_api: Add groups property to users
Matthew Wild <mwild1@gmail.com>
parents: 4351
diff changeset
165 local groups;
f6da234b21b8 mod_http_admin_api: Add groups property to users
Matthew Wild <mwild1@gmail.com>
parents: 4351
diff changeset
166 do
f6da234b21b8 mod_http_admin_api: Add groups property to users
Matthew Wild <mwild1@gmail.com>
parents: 4351
diff changeset
167 local group_set = group_memberships:get_all(username);
f6da234b21b8 mod_http_admin_api: Add groups property to users
Matthew Wild <mwild1@gmail.com>
parents: 4351
diff changeset
168 if group_set and next(group_set) then
f6da234b21b8 mod_http_admin_api: Add groups property to users
Matthew Wild <mwild1@gmail.com>
parents: 4351
diff changeset
169 groups = {};
f6da234b21b8 mod_http_admin_api: Add groups property to users
Matthew Wild <mwild1@gmail.com>
parents: 4351
diff changeset
170 for group_id in pairs(group_set) do
f6da234b21b8 mod_http_admin_api: Add groups property to users
Matthew Wild <mwild1@gmail.com>
parents: 4351
diff changeset
171 table.insert(groups, group_id);
f6da234b21b8 mod_http_admin_api: Add groups property to users
Matthew Wild <mwild1@gmail.com>
parents: 4351
diff changeset
172 end
f6da234b21b8 mod_http_admin_api: Add groups property to users
Matthew Wild <mwild1@gmail.com>
parents: 4351
diff changeset
173 end
f6da234b21b8 mod_http_admin_api: Add groups property to users
Matthew Wild <mwild1@gmail.com>
parents: 4351
diff changeset
174 end
4362
116c88c28532 mod_http_admin_api: restructure group-related info in API
Jonas Schäfer <jonas@wielicki.name>
parents: 4361
diff changeset
175 return groups;
4345
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
176 end
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
177
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
178 function list_users(event)
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
179 local user_list = {};
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
180 for username in usermanager.users(module.host) do
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
181 table.insert(user_list, get_user_info(username));
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
182 end
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
183
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
184 event.response.headers["Content-Type"] = json_content_type;
4350
270025e76bf8 mod_http_admin_api: Use json.encode_array() when returning an array
Matthew Wild <mwild1@gmail.com>
parents: 4349
diff changeset
185 return json.encode_array(user_list);
4345
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
186 end
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
187
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
188 function get_user_by_name(event, username)
4362
116c88c28532 mod_http_admin_api: restructure group-related info in API
Jonas Schäfer <jonas@wielicki.name>
parents: 4361
diff changeset
189 local property
116c88c28532 mod_http_admin_api: restructure group-related info in API
Jonas Schäfer <jonas@wielicki.name>
parents: 4361
diff changeset
190 do
116c88c28532 mod_http_admin_api: restructure group-related info in API
Jonas Schäfer <jonas@wielicki.name>
parents: 4361
diff changeset
191 local name, sub_path = username:match("^([^/]+)/(%w+)$");
116c88c28532 mod_http_admin_api: restructure group-related info in API
Jonas Schäfer <jonas@wielicki.name>
parents: 4361
diff changeset
192 if name then
116c88c28532 mod_http_admin_api: restructure group-related info in API
Jonas Schäfer <jonas@wielicki.name>
parents: 4361
diff changeset
193 username = name;
116c88c28532 mod_http_admin_api: restructure group-related info in API
Jonas Schäfer <jonas@wielicki.name>
parents: 4361
diff changeset
194 property = sub_path;
116c88c28532 mod_http_admin_api: restructure group-related info in API
Jonas Schäfer <jonas@wielicki.name>
parents: 4361
diff changeset
195 end
116c88c28532 mod_http_admin_api: restructure group-related info in API
Jonas Schäfer <jonas@wielicki.name>
parents: 4361
diff changeset
196 end
116c88c28532 mod_http_admin_api: restructure group-related info in API
Jonas Schäfer <jonas@wielicki.name>
parents: 4361
diff changeset
197
116c88c28532 mod_http_admin_api: restructure group-related info in API
Jonas Schäfer <jonas@wielicki.name>
parents: 4361
diff changeset
198 if property == "groups" then
116c88c28532 mod_http_admin_api: restructure group-related info in API
Jonas Schäfer <jonas@wielicki.name>
parents: 4361
diff changeset
199 return json.encode(get_user_groups(username));
116c88c28532 mod_http_admin_api: restructure group-related info in API
Jonas Schäfer <jonas@wielicki.name>
parents: 4361
diff changeset
200 end
116c88c28532 mod_http_admin_api: restructure group-related info in API
Jonas Schäfer <jonas@wielicki.name>
parents: 4361
diff changeset
201
4345
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
202 local user_info = get_user_info(username);
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
203 if not user_info then
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
204 return 404;
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
205 end
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
206
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
207 event.response.headers["Content-Type"] = json_content_type;
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
208 return json.encode(user_info);
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
209 end
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
210
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
211 function delete_user(event, username) --luacheck: ignore 212/event
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
212 if not usermanager.delete_user(username, module.host) then
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
213 return 404;
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
214 end
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
215 return 200;
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
216 end
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
217
4353
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
218 function list_groups(event)
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
219 local group_list = {};
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
220 for group_id in group_store:users() do
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
221 table.insert(group_list, {
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
222 id = group_id;
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
223 name = group_id;
4362
116c88c28532 mod_http_admin_api: restructure group-related info in API
Jonas Schäfer <jonas@wielicki.name>
parents: 4361
diff changeset
224 members = group_store:get(group_id);
4353
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
225 });
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
226 end
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
227
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
228 event.response.headers["Content-Type"] = json_content_type;
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
229 return json.encode_array(group_list);
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
230 end
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
231
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
232 function get_group_by_id(event, group_id)
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
233 local group = group_store:get(group_id);
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
234 if not group then
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
235 return 404;
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
236 end
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
237
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
238 event.response.headers["Content-Type"] = json_content_type;
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
239
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
240 return json.encode({
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
241 id = group_id;
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
242 name = group_id;
4362
116c88c28532 mod_http_admin_api: restructure group-related info in API
Jonas Schäfer <jonas@wielicki.name>
parents: 4361
diff changeset
243 members = group;
4353
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
244 });
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
245 end
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
246
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
247 function create_group(event)
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
248 local request = event.request;
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
249 if request.headers.content_type ~= json_content_type
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
250 or (not request.body or #request.body == 0) then
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
251 return 400;
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
252 end
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
253 local group = json.decode(event.request.body);
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
254 if not group then
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
255 return 400;
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
256 end
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
257
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
258 local ok = group_store:set(group.id, {});
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
259 if not ok then
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
260 return 500;
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
261 end
4361
7f1f3b79d991 mod_http_admin_api: Return new group object on successful creation
Matthew Wild <mwild1@gmail.com>
parents: 4360
diff changeset
262
7f1f3b79d991 mod_http_admin_api: Return new group object on successful creation
Matthew Wild <mwild1@gmail.com>
parents: 4360
diff changeset
263 event.response.headers["Content-Type"] = json_content_type;
7f1f3b79d991 mod_http_admin_api: Return new group object on successful creation
Matthew Wild <mwild1@gmail.com>
parents: 4360
diff changeset
264 return json.encode({
7f1f3b79d991 mod_http_admin_api: Return new group object on successful creation
Matthew Wild <mwild1@gmail.com>
parents: 4360
diff changeset
265 id = group.id or group.name;
7f1f3b79d991 mod_http_admin_api: Return new group object on successful creation
Matthew Wild <mwild1@gmail.com>
parents: 4360
diff changeset
266 name = group.name;
7f1f3b79d991 mod_http_admin_api: Return new group object on successful creation
Matthew Wild <mwild1@gmail.com>
parents: 4360
diff changeset
267 });
4353
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
268 end
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
269
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
270 function delete_group(event, group_id) --luacheck: ignore 212/event
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
271 if not group_id then
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
272 return 400;
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
273 end
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
274 if not group_store:set(group_id, nil) then
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
275 return 500;
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
276 end
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
277 return 200;
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
278 end
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
279
4343
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
280 module:provides("http", {
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
281 route = check_auth {
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
282 ["GET /invites"] = list_invites;
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
283 ["GET /invites/*"] = get_invite_by_id;
4360
76bec3f66b24 mod_http_admin_api: Switch PUT to POST where appropriate
Matthew Wild <mwild1@gmail.com>
parents: 4359
diff changeset
284 ["POST /invites"] = create_invite;
4343
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
285 ["DELETE /invites/*"] = delete_invite;
4345
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
286
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
287 ["GET /users"] = list_users;
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
288 ["GET /users/*"] = get_user_by_name;
1bb08e9ffa82 mod_http_admin_api: Add methods for managing users
Matthew Wild <mwild1@gmail.com>
parents: 4343
diff changeset
289 ["DELETE /users/*"] = delete_user;
4353
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
290
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
291 ["GET /groups"] = list_groups;
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
292 ["GET /groups/*"] = get_group_by_id;
4360
76bec3f66b24 mod_http_admin_api: Switch PUT to POST where appropriate
Matthew Wild <mwild1@gmail.com>
parents: 4359
diff changeset
293 ["POST /groups"] = create_group;
4353
535d80be110d mod_http_admin_api: Add groups management endpoints
Matthew Wild <mwild1@gmail.com>
parents: 4352
diff changeset
294 ["DELETE /groups/*"] = delete_group;
4343
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
295 };
ee313922b8d1 mod_http_admin_api: HTTP API for managing users and invites
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
296 });