Mercurial > prosody-hg
comparison util/pubsub.lua @ 4100:69e3f1e7111e
util.pubsub: Pass true instead of nil as the actor in a bunch of places, and fix a bunch of methods to not traceback on this (those with *_other capability checking).
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Sat, 08 Jan 2011 23:17:17 +0000 |
| parents | 5c0b7947f0ef |
| children | af40cf682eba |
comparison
equal
deleted
inserted
replaced
| 4099:5c0b7947f0ef | 4100:69e3f1e7111e |
|---|---|
| 67 local node_obj = self.nodes[node]; | 67 local node_obj = self.nodes[node]; |
| 68 if not node_obj then | 68 if not node_obj then |
| 69 return false, "item-not-found"; | 69 return false, "item-not-found"; |
| 70 end | 70 end |
| 71 node_obj.affiliations[jid] = affiliation; | 71 node_obj.affiliations[jid] = affiliation; |
| 72 local _, jid_sub = self:get_subscription(node, nil, jid); | 72 local _, jid_sub = self:get_subscription(node, true, jid); |
| 73 if not jid_sub and not self:may(node, jid, "be_unsubscribed") then | 73 if not jid_sub and not self:may(node, jid, "be_unsubscribed") then |
| 74 local ok, err = self:add_subscription(node, nil, jid); | 74 local ok, err = self:add_subscription(node, true, jid); |
| 75 if not ok then | 75 if not ok then |
| 76 return ok, err; | 76 return ok, err; |
| 77 end | 77 end |
| 78 elseif jid_sub and not self:may(node, jid, "be_subscribed") then | 78 elseif jid_sub and not self:may(node, jid, "be_subscribed") then |
| 79 local ok, err = self:add_subscription(node, nil, jid); | 79 local ok, err = self:add_subscription(node, true, jid); |
| 80 if not ok then | 80 if not ok then |
| 81 return ok, err; | 81 return ok, err; |
| 82 end | 82 end |
| 83 end | 83 end |
| 84 return true; | 84 return true; |
| 85 end | 85 end |
| 86 | 86 |
| 87 function service:add_subscription(node, actor, jid, options) | 87 function service:add_subscription(node, actor, jid, options) |
| 88 -- Access checking | 88 -- Access checking |
| 89 local cap; | 89 local cap; |
| 90 if jid == actor or self:jids_equal(actor, jid) then | 90 if actor == true or jid == actor or self:jids_equal(actor, jid) then |
| 91 cap = "subscribe"; | 91 cap = "subscribe"; |
| 92 else | 92 else |
| 93 cap = "subscribe_other"; | 93 cap = "subscribe_other"; |
| 94 end | 94 end |
| 95 if not self:may(node, actor, cap) then | 95 if not self:may(node, actor, cap) then |
| 127 end | 127 end |
| 128 | 128 |
| 129 function service:remove_subscription(node, actor, jid) | 129 function service:remove_subscription(node, actor, jid) |
| 130 -- Access checking | 130 -- Access checking |
| 131 local cap; | 131 local cap; |
| 132 if jid == actor or self:jids_equal(actor, jid) then | 132 if actor == true or jid == actor or self:jids_equal(actor, jid) then |
| 133 cap = "unsubscribe"; | 133 cap = "unsubscribe"; |
| 134 else | 134 else |
| 135 cap = "unsubscribe_other"; | 135 cap = "unsubscribe_other"; |
| 136 end | 136 end |
| 137 if not self:may(node, actor, cap) then | 137 if not self:may(node, actor, cap) then |
| 167 end | 167 end |
| 168 | 168 |
| 169 function service:get_subscription(node, actor, jid) | 169 function service:get_subscription(node, actor, jid) |
| 170 -- Access checking | 170 -- Access checking |
| 171 local cap; | 171 local cap; |
| 172 if jid == actor or self:jids_equal(actor, jid) then | 172 if actor == true or jid == actor or self:jids_equal(actor, jid) then |
| 173 cap = "get_subscription"; | 173 cap = "get_subscription"; |
| 174 else | 174 else |
| 175 cap = "get_subscription_other"; | 175 cap = "get_subscription_other"; |
| 176 end | 176 end |
| 177 if not self:may(node, actor, cap) then | 177 if not self:may(node, actor, cap) then |
| 275 end | 275 end |
| 276 | 276 |
| 277 function service:get_subscriptions(node, actor, jid) | 277 function service:get_subscriptions(node, actor, jid) |
| 278 -- Access checking | 278 -- Access checking |
| 279 local cap; | 279 local cap; |
| 280 if jid == actor or self:jids_equal(actor, jid) then | 280 if actor == true or jid == actor or self:jids_equal(actor, jid) then |
| 281 cap = "get_subscriptions"; | 281 cap = "get_subscriptions"; |
| 282 else | 282 else |
| 283 cap = "get_subscriptions_other"; | 283 cap = "get_subscriptions_other"; |
| 284 end | 284 end |
| 285 if not self:may(node, actor, cap) then | 285 if not self:may(node, actor, cap) then |
