MUC: Prevent admins from being given affiliatons other than owner
[prosody.git] / plugins / muc / mod_muc.lua
index 7861092c40598dfa7aabbbb2780d5c580732db08..acc2da0d7c040beb1c66ec3b7aa2c11ba3aa4c3e 100644 (file)
@@ -51,7 +51,7 @@ function muclib.room_mt:get_affiliation(jid)
        return _get_affiliation(self, jid);
 end
 function muclib.room_mt:set_affiliation(actor, jid, affiliation, callback, reason)
-       if is_admin(jid) then return nil, "modify", "not-acceptable"; end
+       if affiliation ~= "owner" and is_admin(jid) then return nil, "modify", "not-acceptable"; end
        return _set_affiliation(self, actor, jid, affiliation, callback, reason);
 end
 
@@ -83,6 +83,7 @@ function create_room(jid)
        room.route_stanza = room_route_stanza;
        room.save = room_save;
        rooms[jid] = room;
+       module:fire_event("muc-room-created", { room = room });
        return room;
 end
 
@@ -154,7 +155,7 @@ function stanza_handler(event)
                        return true;
                end
                if not(restrict_room_creation) or
-                 (restrict_room_creation == "admin" and is_admin(stanza.attr.from)) or
+                 is_admin(stanza.attr.from) or
                  (restrict_room_creation == "local" and select(2, jid_split(stanza.attr.from)) == module.host:gsub("^[^%.]+%.", "")) then
                        room = create_room(bare);
                end
@@ -162,6 +163,7 @@ function stanza_handler(event)
        if room then
                room:handle_stanza(origin, stanza);
                if not next(room._occupants) and not persistent_rooms[room.jid] then -- empty, non-persistent room
+                       module:fire_event("muc-room-destroyed", { room = room });
                        rooms[bare] = nil; -- discard room
                end
        else