Software /
code /
prosody
Comparison
plugins/mod_invites.lua @ 13742:47e537e340c4
Merge 13.0->trunk
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Mon, 17 Feb 2025 23:06:26 +0000 |
parent | 13741:e9edf9b50f32 |
child | 13851:ecafafec7806 |
comparison
equal
deleted
inserted
replaced
13739:347991cd1cc3 | 13742:47e537e340c4 |
---|---|
237 end | 237 end |
238 | 238 |
239 module:hook("invite-created", add_landing_url, -1); | 239 module:hook("invite-created", add_landing_url, -1); |
240 | 240 |
241 --- shell command | 241 --- shell command |
242 -- COMPAT: Dynamic groups are work in progress as of 13.0, so we'll use the | |
243 -- presence of mod_invites_groups (a community module) to determine whether to | |
244 -- expose our support for invites to groups. | |
245 local have_group_invites = module:get_option_inherited_set("modules_enabled"):contains("invites_groups"); | |
246 | |
242 module:add_item("shell-command", { | 247 module:add_item("shell-command", { |
243 section = "invite"; | 248 section = "invite"; |
244 section_desc = "Create and manage invitations"; | 249 section_desc = "Create and manage invitations"; |
245 name = "create_account"; | 250 name = "create_account"; |
246 desc = "Create an invitation to make an account on this server with the specified JID (supply only a hostname to allow any username)"; | 251 desc = "Create an invitation to make an account on this server with the specified JID (supply only a hostname to allow any username)"; |
247 args = { | 252 args = { |
248 { name = "user_jid", type = "string" }; | 253 { name = "user_jid", type = "string" }; |
249 }; | 254 }; |
250 host_selector = "user_jid"; | 255 host_selector = "user_jid"; |
251 flags = { | 256 flags = { |
252 array_params = { role = true, group = true }; | 257 array_params = { role = true, group = have_group_invites }; |
253 value_params = { expires_after = true }; | 258 value_params = { expires_after = true }; |
254 }; | 259 }; |
255 | 260 |
256 handler = function (self, user_jid, opts) --luacheck: ignore 212/self | 261 handler = function (self, user_jid, opts) --luacheck: ignore 212/self |
257 local username = jid_split(user_jid); | 262 local username = jid_split(user_jid); |
258 local roles = opts.role or {}; | 263 local roles = opts and opts.role or {}; |
259 local groups = opts.group or {}; | 264 local groups = opts and opts.group or {}; |
260 | 265 |
261 if opts.admin then | 266 if opts and opts.admin then |
262 -- Insert it first since we don't get order out of argparse | 267 -- Insert it first since we don't get order out of argparse |
263 table.insert(roles, 1, "prosody:admin"); | 268 table.insert(roles, 1, "prosody:admin"); |
264 end | 269 end |
265 | 270 |
266 local ttl; | 271 local ttl; |
267 if opts.expires_after then | 272 if opts and opts.expires_after then |
268 ttl = human_io.parse_duration(opts.expires_after); | 273 ttl = human_io.parse_duration(opts.expires_after); |
269 if not ttl then | 274 if not ttl then |
270 return false, "Unable to parse duration: "..opts.expires_after; | 275 return false, "Unable to parse duration: "..opts.expires_after; |
271 end | 276 end |
272 end | 277 end |
323 local username = jid_split(user_jid); | 328 local username = jid_split(user_jid); |
324 if not username then | 329 if not username then |
325 return nil, "Supply the JID of the account you want the recipient to become a contact of"; | 330 return nil, "Supply the JID of the account you want the recipient to become a contact of"; |
326 end | 331 end |
327 local ttl; | 332 local ttl; |
328 if opts.expires_after then | 333 if opts and opts.expires_after then |
329 ttl = require "prosody.util.human.io".parse_duration(opts.expires_after); | 334 ttl = require "prosody.util.human.io".parse_duration(opts.expires_after); |
330 if not ttl then | 335 if not ttl then |
331 return nil, "Unable to parse duration: "..opts.expires_after; | 336 return nil, "Unable to parse duration: "..opts.expires_after; |
332 end | 337 end |
333 end | 338 end |
334 local invite, err = create_contact(username, opts.allow_registration, nil, ttl); | 339 local invite, err = create_contact(username, opts and opts.allow_registration, nil, ttl); |
335 if not invite then return nil, err; end | 340 if not invite then return nil, err; end |
336 return true, invite.landing_page or invite.uri; | 341 return true, invite.landing_page or invite.uri; |
337 end; | 342 end; |
338 }); | 343 }); |
339 | 344 |