Software /
code /
prosody-modules
Comparison
mod_http_admin_api/mod_http_admin_api.lua @ 5807:5c589fab6f53
mod_http_admin_api: Support PATCH for user enabled status
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 07 Dec 2023 15:41:55 +0000 |
parent | 5806:6c8cf3ecb885 |
child | 5808:671a6ad1f026 |
comparison
equal
deleted
inserted
replaced
5806:6c8cf3ecb885 | 5807:5c589fab6f53 |
---|---|
1 local usermanager = require "core.usermanager"; | 1 local usermanager = require "core.usermanager"; |
2 | 2 |
3 local array = require "util.array"; | |
4 local it = require "util.iterators"; | |
3 local jid = require "util.jid"; | 5 local jid = require "util.jid"; |
4 local it = require "util.iterators"; | |
5 local json = require "util.json"; | 6 local json = require "util.json"; |
7 local set = require "util.set"; | |
6 local st = require "util.stanza"; | 8 local st = require "util.stanza"; |
7 local array = require "util.array"; | |
8 local statsmanager = require "core.statsmanager"; | 9 local statsmanager = require "core.statsmanager"; |
9 | 10 |
10 module:depends("http"); | 11 module:depends("http"); |
11 | 12 |
12 local announce = module:depends("announce"); | 13 local announce = module:depends("announce"); |
442 return true; | 443 return true; |
443 end; | 444 end; |
444 }; | 445 }; |
445 local writable_user_attributes = set.new(array.collect(it.keys(user_attribute_writers))); | 446 local writable_user_attributes = set.new(array.collect(it.keys(user_attribute_writers))); |
446 | 447 |
448 function patch_user(event, username) | |
449 if not username then return; end | |
450 | |
451 local current_user = get_user_info(username); | |
452 if not current_user then return 404; end | |
453 | |
454 local request = event.request; | |
455 if request.headers.content_type ~= json_content_type | |
456 or (not request.body or #request.body == 0) then | |
457 return 400; | |
458 end | |
459 local new_user = json.decode(event.request.body); | |
460 if not new_user then | |
461 return 400; | |
462 end | |
463 | |
464 local updated_attributes = set.new(array.collect(it.keys(new_user))); | |
465 if not (updated_attributes - writable_user_attributes):empty() then | |
466 module:log("warn", "Unable to service PATCH user request, unsupported attributes: %s", (updated_attributes - writable_user_attributes)); | |
467 return 400; | |
468 end | |
469 | |
470 if new_user.enabled ~= nil and new_user.enabled ~= current_user.enabled then | |
471 if not user_attribute_writers.enabled(username, new_user.enabled) then | |
472 return 500; | |
473 end | |
474 end | |
475 | |
476 return 200; | |
477 end | |
478 | |
447 function update_user(event, username) | 479 function update_user(event, username) |
448 local current_user = get_user_info(username); | 480 local current_user = get_user_info(username); |
449 | 481 |
450 local request = event.request; | 482 local request = event.request; |
451 if request.headers.content_type ~= json_content_type | 483 if request.headers.content_type ~= json_content_type |
782 ["DELETE /invites/*"] = delete_invite; | 814 ["DELETE /invites/*"] = delete_invite; |
783 | 815 |
784 ["GET /users"] = list_users; | 816 ["GET /users"] = list_users; |
785 ["GET /users/*"] = get_user_by_name; | 817 ["GET /users/*"] = get_user_by_name; |
786 ["PUT /users/*"] = update_user; | 818 ["PUT /users/*"] = update_user; |
819 ["PATCH /users/*"] = patch_user; | |
787 ["DELETE /users/*"] = delete_user; | 820 ["DELETE /users/*"] = delete_user; |
788 | 821 |
789 ["GET /groups"] = list_groups; | 822 ["GET /groups"] = list_groups; |
790 ["GET /groups/*"] = get_group_by_id; | 823 ["GET /groups/*"] = get_group_by_id; |
791 ["POST /groups"] = create_group; | 824 ["POST /groups"] = create_group; |