Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(prosody): extend jigasi kick endpoint to work for any participant #15387

Merged
merged 3 commits into from
Dec 12, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions resources/prosody-plugins/mod_muc_kick_jigasi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ local formdecode = require "util.http".formdecode;
local urlencode = require "util.http".urlencode;
local jid = require "util.jid";
local json = require 'cjson.safe';
local split_jid = require "util.jid".split;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We jimport jid above, would it make sense to just call jid.split(...) ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


local muc_domain_prefix = module:get_option_string("muc_mapper_domain_prefix", "conference");

Expand Down Expand Up @@ -115,9 +116,10 @@ function handle_kick_participant (event)
end

local number = params["number"];
local participantId = params["participantId"];

if not number then
module:log("warn", "Missing number param");
if (not number and not participantId) or (number and participantId) then
module:log("warn", "Invalid parameters: exactly one of 'number' or 'participantId' must be provided.");
return { status_code = 400; };
end

Expand All @@ -134,10 +136,8 @@ function handle_kick_participant (event)

for _, occupant in room:each_occupant() do
local pr = occupant:get_presence();
local displayName = pr:get_child_text(
'nick', 'http://jabber.org/protocol/nick');

if is_sip_jigasi(pr) and displayName and starts_with(displayName, number) then
if is_participant_match(pr, number, participantId) then
room:set_role(true, occupant.nick, nil);
module:log('info', 'Occupant kicked %s from %s', occupant.nick, room.jid);
return { status_code = 200; }
Expand All @@ -148,6 +148,20 @@ function handle_kick_participant (event)
return { status_code = 404; };
end

function is_participant_match(pr, number, participantId)
if number then
local displayName = pr:get_child_text('nick', 'http://jabber.org/protocol/nick');
return is_sip_jigasi(pr) and displayName and starts_with(displayName, number);
elseif participantId then
local from = pr.attr.from;
local _, _, from_resource = split_jid(from);
if from_resource then
return from_resource == participantId;
end
end
return false;
end

module:log("info","Adding http handler for /kick-participant on %s", module.host);
module:depends("http");
module:provides("http", {
Expand Down
Loading