Software /
code /
prosody
Comparison
plugins/muc/mod_muc.lua @ 10698:e4034f6668a5
MUC: Add ad-hoc command setting affiliation in a room (fixes #1174)
This gives service admins a way to set an arbitrary affiliation in any
room. Enables various administrative use cases such as room ownership
reassignment or recovery.
Reduces the need for the admins-as-owners feature, as this can be used
by admins to make themselves owner in any room when needed, instead of
being owners all the time.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 21 Mar 2020 00:00:50 +0100 |
parent | 10693:76bb806cdd4b |
child | 11057:13eee48071c8 |
comparison
equal
deleted
inserted
replaced
10697:08ec83f90ce0 | 10698:e4034f6668a5 |
---|---|
497 do -- Ad-hoc commands | 497 do -- Ad-hoc commands |
498 module:depends "adhoc"; | 498 module:depends "adhoc"; |
499 local t_concat = table.concat; | 499 local t_concat = table.concat; |
500 local adhoc_new = module:require "adhoc".new; | 500 local adhoc_new = module:require "adhoc".new; |
501 local adhoc_initial = require "util.adhoc".new_initial_data_form; | 501 local adhoc_initial = require "util.adhoc".new_initial_data_form; |
502 local adhoc_simple = require "util.adhoc".new_simple_form; | |
502 local array = require "util.array"; | 503 local array = require "util.array"; |
503 local dataforms_new = require "util.dataforms".new; | 504 local dataforms_new = require "util.dataforms".new; |
504 | 505 |
505 local destroy_rooms_layout = dataforms_new { | 506 local destroy_rooms_layout = dataforms_new { |
506 title = "Destroy rooms"; | 507 title = "Destroy rooms"; |
527 end); | 528 end); |
528 local destroy_rooms_desc = adhoc_new("Destroy Rooms", | 529 local destroy_rooms_desc = adhoc_new("Destroy Rooms", |
529 "http://prosody.im/protocol/muc#destroy", destroy_rooms_handler, "admin"); | 530 "http://prosody.im/protocol/muc#destroy", destroy_rooms_handler, "admin"); |
530 | 531 |
531 module:provides("adhoc", destroy_rooms_desc); | 532 module:provides("adhoc", destroy_rooms_desc); |
532 end | 533 |
534 | |
535 local set_affiliation_layout = dataforms_new { | |
536 -- FIXME wordsmith title, instructions, labels etc | |
537 title = "Set affiliation"; | |
538 | |
539 { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/muc#set-affiliation" }; | |
540 { name = "room", type = "jid-single", required = true, label = "Room"}; | |
541 { name = "jid", type = "jid-single", required = true, label = "JID"}; | |
542 { name = "affiliation", type = "list-single", required = true, label = "Affiliation", | |
543 options = { "owner"; "admin"; "member"; "none"; "outcast"; }, | |
544 }; | |
545 { name = "reason", type = "text-single", "Reason", } | |
546 }; | |
547 | |
548 local set_affiliation_handler = adhoc_simple(set_affiliation_layout, function (fields, errors) | |
549 if errors then | |
550 local errmsg = {}; | |
551 for field, err in pairs(errors) do | |
552 errmsg[#errmsg + 1] = field .. ": " .. err; | |
553 end | |
554 return { status = "completed", error = { message = t_concat(errmsg, "\n") } }; | |
555 end | |
556 | |
557 local room = get_room_from_jid(fields.room); | |
558 if not room then | |
559 return { status = "canceled", error = { message = "No such room"; }; }; | |
560 end | |
561 local ok, err, condition = room:set_affiliation(true, fields.jid, fields.affiliation, fields.reason); | |
562 | |
563 if not ok then | |
564 return { status = "canceled", error = { message = "Affiliation change failed: "..err..":"..condition; }; }; | |
565 end | |
566 | |
567 return { status = "completed", info = "Affiliation updated", | |
568 }; | |
569 end); | |
570 | |
571 local set_affiliation_desc = adhoc_new("Set affiliation in room", | |
572 "http://prosody.im/protocol/muc#set-affiliation", set_affiliation_handler, "admin"); | |
573 | |
574 module:provides("adhoc", set_affiliation_desc); | |
575 end |