Software /
code /
prosody
Comparison
plugins/muc/members_only.lib.lua @ 6230:97d53caef325
plugins/muc/members_only.lib: Compare affiliations via rank; wrap some long lines
author | daurnimator <quae@daurnimator.com> |
---|---|
date | Mon, 21 Apr 2014 17:49:57 -0400 |
parent | 6221:f321536afeec |
child | 6329:6b3eb1611587 |
comparison
equal
deleted
inserted
replaced
6229:8aa59b73f801 | 6230:97d53caef325 |
---|---|
49 end | 49 end |
50 end); | 50 end); |
51 | 51 |
52 -- registration required for entering members-only room | 52 -- registration required for entering members-only room |
53 module:hook("muc-occupant-pre-join", function(event) | 53 module:hook("muc-occupant-pre-join", function(event) |
54 local room, stanza = event.room, event.stanza; | 54 local room = event.room; |
55 local affiliation = room:get_affiliation(stanza.attr.from); | 55 if get_members_only(room) then |
56 if affiliation == nil and get_members_only(event.room) then | 56 local stanza = event.stanza; |
57 local reply = st.error_reply(stanza, "auth", "registration-required"):up(); | 57 local affiliation = room:get_affiliation(stanza.attr.from); |
58 reply.tags[1].attr.code = "407"; | 58 if valid_affiliations[affiliation or "none"] <= valid_affiliations.none then |
59 event.origin.send(reply:tag("x", {xmlns = "http://jabber.org/protocol/muc"})); | 59 local reply = st.error_reply(stanza, "auth", "registration-required"):up(); |
60 return true; | 60 reply.tags[1].attr.code = "407"; |
61 event.origin.send(reply:tag("x", {xmlns = "http://jabber.org/protocol/muc"})); | |
62 return true; | |
63 end | |
61 end | 64 end |
62 end, -5); | 65 end, -5); |
63 | 66 |
64 -- Invitation privileges in members-only rooms SHOULD be restricted to room admins; | 67 -- Invitation privileges in members-only rooms SHOULD be restricted to room admins; |
65 -- if a member without privileges to edit the member list attempts to invite another user | 68 -- if a member without privileges to edit the member list attempts to invite another user |
66 -- the service SHOULD return a <forbidden/> error to the occupant | 69 -- the service SHOULD return a <forbidden/> error to the occupant |
67 module:hook("muc-pre-invite", function(event) | 70 module:hook("muc-pre-invite", function(event) |
68 local room, stanza = event.room, event.stanza; | 71 local room = event.room; |
69 if get_members_only(room) and room:get_affiliation(stanza.attr.from) or "none" < valid_affiliations.admin then | 72 if get_members_only(room) then |
70 event.origin.send(st.error_reply(stanza, "auth", "forbidden")); | 73 local stanza = event.stanza; |
71 return true; | 74 local affiliation = room:get_affiliation(stanza.attr.from); |
75 if valid_affiliations[affiliation or "none"] < valid_affiliations.admin then | |
76 event.origin.send(st.error_reply(stanza, "auth", "forbidden")); | |
77 return true; | |
78 end | |
72 end | 79 end |
73 end); | 80 end); |
74 | 81 |
75 -- When an invite is sent; add an affiliation for the invitee | 82 -- When an invite is sent; add an affiliation for the invitee |
76 module:hook("muc-invite", function(event) | 83 module:hook("muc-invite", function(event) |
77 local room, stanza = event.room, event.stanza; | 84 local room = event.room; |
78 local invitee = stanza.attr.to; | 85 if get_members_only(room) then |
79 if get_members_only(room) and not room:get_affiliation(invitee) then | 86 local stanza = event.stanza; |
80 local from = stanza:get_child("x", "http://jabber.org/protocol/muc#user"):get_child("invite").attr.from; | 87 local invitee = stanza.attr.to; |
81 module:log("debug", "%s invited %s into members only room %s, granting membership", from, invitee, room.jid); | 88 local affiliation = room:get_affiliation(invitee); |
82 room:set_affiliation(from, invitee, "member", "Invited by " .. from); -- This might fail; ignore for now | 89 if valid_affiliations[affiliation or "none"] <= valid_affiliations.none then |
90 local from = stanza:get_child("x", "http://jabber.org/protocol/muc#user") | |
91 :get_child("invite").attr.from; | |
92 module:log("debug", "%s invited %s into members only room %s, granting membership", | |
93 from, invitee, room.jid); | |
94 -- This might fail; ignore for now | |
95 room:set_affiliation(from, invitee, "member", "Invited by " .. from); | |
96 end | |
83 end | 97 end |
84 end); | 98 end); |
85 | 99 |
86 return { | 100 return { |
87 get = get_members_only; | 101 get = get_members_only; |