Skip to content

Remove duplicate implementations of "who can invite" logic #19374

@MadLittleMods

Description

@MadLittleMods

Spawning from #19321 (comment),

We have two functions which try to find the users who can invite:

  1. get_user_which_could_invite()
  2. get_users_which_can_issue_invite(...)

Disparate implementations cause problems

Before #19321, for v12 rooms:

  • get_users_which_can_issue_invite(...) would indicate a local user was available.
  • But get_user_which_could_invite(...) would find no eligible user due to flawed logic.

This mismatch caused #19120, resulting in a user-facing error. If we instead were working from the same source of truth, a flawed implementation would only result in falling back to the slower but successful remote join instead of the most correct local join.

allowed_servers = get_servers_from_users(
get_users_which_can_issue_invite(current_state)
)
# If the local server is not one of allowed servers, then a remote
# join must be done. Return the list of prospective servers based on
# which can issue invites.
if self.hs.hostname not in allowed_servers:
return True, list(allowed_servers)
# Ensure the member should be allowed access via membership in a room.
await self.event_auth_handler.check_restricted_join_rules(
state_before_join, room_version, user_id, previous_membership
)
# If this is going to be a local join, additional information must
# be included in the event content in order to efficiently validate
# the event.
content[
EventContentFields.AUTHORISING_USER
] = await self.event_auth_handler.get_user_which_could_invite(
room_id,
state_before_join,
)

Refactor

We should refactor get_user_which_could_invite(...) to use get_users_which_can_issue_invite(...) under the hood.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-InviteT-Taskgood first issueThis is a fix that might be an easy place for someone to start for their first contribution

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions