Mercurial > prosody-hg
comparison plugins/muc/members_only.lib.lua @ 8987:596c8c7d98b1
MUC: Clarify logic of invitations in members-only rooms
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Sat, 07 Jul 2018 16:54:44 +0100 |
| parents | 4101bcf9639a |
| children | 1c709e3d2e5e |
comparison
equal
deleted
inserted
replaced
| 8986:320ae6dbb2e8 | 8987:596c8c7d98b1 |
|---|---|
| 125 -- the service SHOULD return a <forbidden/> error to the occupant | 125 -- the service SHOULD return a <forbidden/> error to the occupant |
| 126 module:hook("muc-pre-invite", function(event) | 126 module:hook("muc-pre-invite", function(event) |
| 127 local room = event.room; | 127 local room = event.room; |
| 128 if get_members_only(room) then | 128 if get_members_only(room) then |
| 129 local stanza = event.stanza; | 129 local stanza = event.stanza; |
| 130 local affiliation = room:get_affiliation(stanza.attr.from); | 130 local inviter_affiliation = room:get_affiliation(stanza.attr.from) or "none"; |
| 131 if not room._data.allow_member_invites and valid_affiliations[affiliation or "none"] < valid_affiliations.admin then | 131 local required_affiliation = room._data.allow_member_invites and "member" or "admin"; |
| 132 if valid_affiliations[inviter_affiliation] < valid_affiliations[required_affiliation] then | |
| 132 event.origin.send(st.error_reply(stanza, "auth", "forbidden")); | 133 event.origin.send(st.error_reply(stanza, "auth", "forbidden")); |
| 133 return true; | 134 return true; |
| 134 end | 135 end |
| 135 end | 136 end |
| 136 end); | 137 end); |
| 140 local room = event.room; | 141 local room = event.room; |
| 141 if get_members_only(room) then | 142 if get_members_only(room) then |
| 142 local stanza = event.stanza; | 143 local stanza = event.stanza; |
| 143 local invitee = stanza.attr.to; | 144 local invitee = stanza.attr.to; |
| 144 local affiliation = room:get_affiliation(invitee); | 145 local affiliation = room:get_affiliation(invitee); |
| 145 if valid_affiliations[affiliation or "none"] <= valid_affiliations.none and room._data.allow_member_invites then | 146 local invited_unaffiliated = valid_affiliations[affiliation or "none"] <= valid_affiliations.none; |
| 147 if invited_unaffiliated then | |
| 146 local from = stanza:get_child("x", "http://jabber.org/protocol/muc#user") | 148 local from = stanza:get_child("x", "http://jabber.org/protocol/muc#user") |
| 147 :get_child("invite").attr.from; | 149 :get_child("invite").attr.from; |
| 148 module:log("debug", "%s invited %s into members only room %s, granting membership", | 150 module:log("debug", "%s invited %s into members only room %s, granting membership", |
| 149 from, invitee, room.jid); | 151 from, invitee, room.jid); |
| 150 -- This might fail; ignore for now | 152 -- This might fail; ignore for now |
