1309 local bare = node and node.."@"..host or host; |
1309 local bare = node and node.."@"..host or host; |
1310 local result = self._affiliations[bare]; -- Affiliations are granted, revoked, and maintained based on the user's bare JID. |
1310 local result = self._affiliations[bare]; -- Affiliations are granted, revoked, and maintained based on the user's bare JID. |
1311 if not result and self._affiliations[host] == "outcast" then result = "outcast"; end -- host banned |
1311 if not result and self._affiliations[host] == "outcast" then result = "outcast"; end -- host banned |
1312 return result; |
1312 return result; |
1313 end |
1313 end |
|
1314 |
|
1315 local valid_affiliations = { |
|
1316 outcast = true; |
|
1317 none = true; |
|
1318 member = true; |
|
1319 admin = true; |
|
1320 owner = true; |
|
1321 }; |
1314 function room_mt:set_affiliation(actor, jid, affiliation, reason) |
1322 function room_mt:set_affiliation(actor, jid, affiliation, reason) |
|
1323 if not actor then return nil, "modify", "not-acceptable"; end; |
|
1324 |
1315 jid = jid_bare(jid); |
1325 jid = jid_bare(jid); |
1316 if affiliation == "none" then affiliation = nil; end |
1326 |
1317 if affiliation and affiliation ~= "outcast" and affiliation ~= "owner" and affiliation ~= "admin" and affiliation ~= "member" then |
1327 if valid_affiliations[affiliation or "none"] == nil then |
1318 return nil, "modify", "not-acceptable"; |
1328 return nil, "modify", "not-acceptable"; |
1319 end |
1329 end |
|
1330 affiliation = affiliation ~= "none" and affiliation or nil; -- coerces `affiliation == false` to `nil` |
|
1331 |
1320 if actor ~= true then |
1332 if actor ~= true then |
1321 local actor_affiliation = self:get_affiliation(actor); |
1333 local actor_affiliation = self:get_affiliation(actor); |
1322 local target_affiliation = self:get_affiliation(jid); |
1334 local target_affiliation = self:get_affiliation(jid); |
1323 if target_affiliation == affiliation then -- no change, shortcut |
1335 if target_affiliation == affiliation then -- no change, shortcut |
1324 return true; |
1336 return true; |