Software /
code /
prosody-modules
Comparison
mod_http_admin_api/mod_http_admin_api.lua @ 5710:4c84cfb586c1
mod_http_admin_api: Support for adding/removing group MUCs
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 02 Nov 2023 17:00:53 +0000 |
parent | 5284:5178c13deb78 |
child | 5798:4c3216d9b118 |
comparison
equal
deleted
inserted
replaced
5709:d5ff386dc97f | 5710:4c84cfb586c1 |
---|---|
463 for group_id in mod_groups.groups() do | 463 for group_id in mod_groups.groups() do |
464 local group_info = mod_groups.get_info(group_id); | 464 local group_info = mod_groups.get_info(group_id); |
465 table.insert(group_list, { | 465 table.insert(group_list, { |
466 id = group_id; | 466 id = group_id; |
467 name = group_info.name; | 467 name = group_info.name; |
468 muc_jid = group_info.muc_jid; | |
469 members = mod_groups.get_members(group_id); | 468 members = mod_groups.get_members(group_id); |
469 chats = mod_groups.get_group_chats(group_id); | |
470 }); | 470 }); |
471 end | 471 end |
472 | 472 |
473 event.response.headers["Content-Type"] = json_content_type; | 473 event.response.headers["Content-Type"] = json_content_type; |
474 return json.encode_array(group_list); | 474 return json.encode_array(group_list); |
483 event.response.headers["Content-Type"] = json_content_type; | 483 event.response.headers["Content-Type"] = json_content_type; |
484 | 484 |
485 return json.encode({ | 485 return json.encode({ |
486 id = group_id; | 486 id = group_id; |
487 name = group.name; | 487 name = group.name; |
488 muc_jid = group.muc_jid; | |
489 members = mod_groups.get_members(group_id); | 488 members = mod_groups.get_members(group_id); |
489 chats = mod_groups.get_group_chats(group_id); | |
490 }); | 490 }); |
491 end | 491 end |
492 | 492 |
493 function create_group(event) | 493 function create_group(event) |
494 local request = event.request; | 494 local request = event.request; |
522 | 522 |
523 local info = mod_groups.get_info(group_id); | 523 local info = mod_groups.get_info(group_id); |
524 return json.encode({ | 524 return json.encode({ |
525 id = group_id; | 525 id = group_id; |
526 name = info.name; | 526 name = info.name; |
527 muc_jid = info.muc_jid or nil; | |
528 members = {}; | 527 members = {}; |
528 chats = {}; | |
529 }); | 529 }); |
530 end | 530 end |
531 | 531 |
532 function update_group(event, group) --luacheck: ignore 212/event | 532 function update_group(event, group) --luacheck: ignore 212/event |
533 -- Add member | 533 -- Add member |
566 end | 566 end |
567 end | 567 end |
568 return 404; | 568 return 404; |
569 end | 569 end |
570 | 570 |
571 function extend_group(event, subpath) | |
572 -- Add group chat | |
573 local group_id = subpath:match("^([^/]+)/chats$"); | |
574 if group_id then | |
575 local muc_params = json.decode(event.request.body); | |
576 if not muc_params then | |
577 return 400; | |
578 end | |
579 local muc = mod_groups.add_group_chat(group_id, muc_params.name); | |
580 if not muc then | |
581 return 500; | |
582 end | |
583 return json.encode(muc); | |
584 end | |
585 | |
586 return 404; | |
587 end | |
588 | |
571 function delete_group(event, subpath) --luacheck: ignore 212/event | 589 function delete_group(event, subpath) --luacheck: ignore 212/event |
572 -- Check if this is a membership deletion and handle it | 590 -- Check if this is a membership deletion and handle it |
573 local group_id, member_name = subpath:match("^([^/]+)/members/([^/]+)$"); | 591 local group_id, sub_resource_type, sub_resource_id = subpath:match("^([^/]+)/([^/]+)/([^/]+)$"); |
574 if group_id and member_name then | 592 if group_id then |
575 if mod_groups.remove_member(group_id, member_name) then | 593 -- Operation is on a sub-resource |
576 return 204; | 594 if sub_resource_type == "members" then |
595 if mod_groups.remove_member(group_id, sub_resource_id) then | |
596 return 204; | |
597 else | |
598 return 500; | |
599 end | |
600 elseif sub_resource_type == "chats" then | |
601 if mod_groups.remove_group_chat(group_id, sub_resource_id) then | |
602 return 204; | |
603 else | |
604 return 500; | |
605 end | |
577 else | 606 else |
578 return 500; | 607 return 404; |
579 end | 608 end |
580 else | 609 else |
581 -- Action refers to the group | 610 -- Action refers to the group |
582 group_id = subpath; | 611 group_id = subpath; |
583 end | 612 end |
698 ["DELETE /users/*"] = delete_user; | 727 ["DELETE /users/*"] = delete_user; |
699 | 728 |
700 ["GET /groups"] = list_groups; | 729 ["GET /groups"] = list_groups; |
701 ["GET /groups/*"] = get_group_by_id; | 730 ["GET /groups/*"] = get_group_by_id; |
702 ["POST /groups"] = create_group; | 731 ["POST /groups"] = create_group; |
732 ["POST /groups/*"] = extend_group; | |
703 ["PUT /groups/*"] = update_group; | 733 ["PUT /groups/*"] = update_group; |
704 ["DELETE /groups/*"] = delete_group; | 734 ["DELETE /groups/*"] = delete_group; |
705 | 735 |
706 ["GET /server/info"] = get_server_info; | 736 ["GET /server/info"] = get_server_info; |
707 | 737 |