diff --git a/changelog.d/9235.bugfix b/changelog.d/9235.bugfix new file mode 100644 index 000000000000..7809c8673bb7 --- /dev/null +++ b/changelog.d/9235.bugfix @@ -0,0 +1 @@ +Fix a bug in the `make_room_admin` admin API where it failed if the admin with the greatest power level was not in the room. Contributed by Pankaj Yadav. diff --git a/synapse/rest/admin/rooms.py b/synapse/rest/admin/rooms.py index da1499cab3b3..f14915d47ee7 100644 --- a/synapse/rest/admin/rooms.py +++ b/synapse/rest/admin/rooms.py @@ -431,7 +431,17 @@ async def on_POST(self, request, room_identifier): if not admin_users: raise SynapseError(400, "No local admin user in room") - admin_user_id = admin_users[-1] + admin_user_id = None + + for admin_user in reversed(admin_users): + if room_state.get((EventTypes.Member, admin_user)): + admin_user_id = admin_user + break + + if not admin_user_id: + raise SynapseError( + 400, "No local admin user in room", + ) pl_content = power_levels.content else: