Mercurial > prosody-hg
comparison plugins/mod_pubsub/mod_pubsub.lua @ 13524:cfc42ed3892c
mod_pubsub: Check new role framework for node creation privileges
This enables granting regular users permission to create nodes via the
new roles framework. Previously this required either making everyone an
admin or writing a custom mod_pubsub variant with different permission
details.
Previous default behavior of only allowing creation by admin is kept as
to not give out unexpected permissions on upgrade, but could be
reevaluated at a later time.
Fixes #1324
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sun, 13 Oct 2024 13:03:08 +0200 |
| parents | 3347ed1014b8 |
| children | eae0272b87e3 |
comparison
equal
deleted
inserted
replaced
| 13523:365212120b82 | 13524:cfc42ed3892c |
|---|---|
| 188 reply:tag("item", { jid = module.host, node = node, name = node_obj.config.title }):up(); | 188 reply:tag("item", { jid = module.host, node = node, name = node_obj.config.title }):up(); |
| 189 end | 189 end |
| 190 end); | 190 end); |
| 191 | 191 |
| 192 local admin_aff = module:get_option_enum("default_admin_affiliation", "owner", "publisher", "member", "outcast", "none"); | 192 local admin_aff = module:get_option_enum("default_admin_affiliation", "owner", "publisher", "member", "outcast", "none"); |
| 193 | |
| 193 module:default_permission("prosody:admin", ":service-admin"); | 194 module:default_permission("prosody:admin", ":service-admin"); |
| 194 local function get_affiliation(jid) | 195 module:default_permission("prosody:admin", ":create-node"); |
| 196 | |
| 197 local function get_affiliation(jid, _, action) | |
| 195 local bare_jid = jid_bare(jid); | 198 local bare_jid = jid_bare(jid); |
| 196 if bare_jid == module.host or module:may(":service-admin", bare_jid) then | 199 if bare_jid == module.host then |
| 200 -- The host itself (i.e. local modules) is treated as an admin. | |
| 201 -- Check this first as to avoid sendig a host JID to :may() | |
| 202 return admin_aff; | |
| 203 end | |
| 204 if action == "create" and module:may(":create-node", bare_jid) then | |
| 205 -- Only one affiliation is allowed to create nodes by default | |
| 206 return "owner"; | |
| 207 end | |
| 208 if module:may(":service-admin", bare_jid) then | |
| 197 return admin_aff; | 209 return admin_aff; |
| 198 end | 210 end |
| 199 end | 211 end |
| 200 | 212 |
| 201 function get_service() | 213 function get_service() |
