Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Prevent showing non-fed rooms in fed /publicRooms #4736

Merged
merged 15 commits into from
Feb 26, 2019

Conversation

erikjohnston
Copy link
Member

Replaces #4714

@erikjohnston erikjohnston requested a review from a team February 25, 2019 15:12
@codecov-io
Copy link

codecov-io commented Feb 25, 2019

Codecov Report

Merging #4736 into develop will decrease coverage by 0.05%.
The diff coverage is 50%.

@@             Coverage Diff             @@
##           develop    #4736      +/-   ##
===========================================
- Coverage    75.14%   75.09%   -0.06%     
===========================================
  Files          340      340              
  Lines        34826    34861      +35     
  Branches      5704     5711       +7     
===========================================
+ Hits         26170    26178       +8     
- Misses        7046     7071      +25     
- Partials      1610     1612       +2

Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generally looks pretty sane, though I am led to the question of why you would ever want to set this option to True?


def get_local_public_room_list(self, limit=None, since_token=None,
search_filter=None,
network_tuple=EMPTY_THIRD_PARTY_ID,):
network_tuple=EMPTY_THIRD_PARTY_ID,
from_federation=False):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docstring pls


Args:
room_id (str): The room's ID.
disabled should be shown.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

if result["m.federate"] == False:
# This is a non-federating room and the config has chosen not
# to show these rooms to other servers
chunk.append(None)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we not just pass ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original code was returning None and then appending it to the chunk, so I kept doing so. Not sure if it's necessary or we can just leave it out.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the code, I don't think Nones in there are particularly useful, so just not inserting anything (by returning instead) seems like the right way to go.


if result and _matches_room_entry(result, search_filter):
if from_federation and not self.config.allow_non_federated_in_public_rooms:
if result["m.federate"] == False:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

result may be None. Suggest adding

if not result:
    return

)

@defer.inlineCallbacks
def _get_public_room_list(self, limit=None, since_token=None,
search_filter=None,
network_tuple=EMPTY_THIRD_PARTY_ID,
timeout=None,):
from_federation=False, timeout=None,):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
from_federation=False, timeout=None,):
from_federation=False,
timeout=None,
):

(or whatever the right alignment for the closing paren is with this style)

@@ -288,23 +292,41 @@ def get_order_for_room(room_id):

@defer.inlineCallbacks
def _append_room_entry_to_chunk(self, room_id, num_joined_users, chunk, limit,
search_filter):
search_filter, from_federation=False):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docstring for from_federation wouldn't hurt.

"""Generate a public room list.

Args:
limit (int): Maximum amount of rooms to return.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int|None


Args:
limit (int): Maximum amount of rooms to return.
since_token (str)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

str|None

Args:
limit (int): Maximum amount of rooms to return.
since_token (str)
search_filter (dict): Dictionary to filter rooms by.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dict|None

Setting to None returns all public rooms across all lists.
from_federation (bool): Whether this request originated from a
federating server or a client. Used for room filtering.
timeout (int): Amount of seconds to wait for a response before
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int|None

@@ -295,19 +311,28 @@ def _append_room_entry_to_chunk(self, room_id, num_joined_users, chunk, limit,
search_filter, from_federation=False):
"""Generate the entry for a room in the public room list and append it
to the `chunk` if it matches the search filter

Args:
room_id (str): The ID of the room.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, if you're going to add these, please get the types right

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

room_id (str)

Are they supposed to be RoomIDs?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, you meant adding |None. Have done so for the other types yes.


if from_federation and not self.config.allow_non_federated_in_public_rooms:
if result["m.federate"] == False:
if not result or result["m.federate"] is False:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not result["m.federate"] is clearer

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem was that if "m.federate" wasn't in result, it would imply a federating room.

I've realized this logic doesn't cover that and could lead to a crash, and thus have replaced with:

        if from_federation:
            if "m.federate" in result and not result["m.federate"]:
            # This is a room that other servers cannot join. Do not show them
            # this room.
            return

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, m.federate will always be present in this case afaict.

However, for the record, what you want to handle the case you mention is if not result.get("m.federate", True).

Also, consider merging it with the other if: if from_federation and result...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, split it up as two ands was getting unclean. This is cleaner though, thank you.

"""
if limit and len(chunk) > limit + 1:
# We've already got enough, so lets just drop it.
return

result = yield self.generate_room_entry(room_id,
num_joined_users)
result = yield self.generate_room_entry(room_id, num_joined_users)

if from_federation and not self.config.allow_non_federated_in_public_rooms:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unless I'm completely misreading this, it will never do anything if from_federation is true.

I still suggest adding:

if not result:
    return

before looking at from_federation or whatever.

Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm \o/

@anoadragon453
Copy link
Member

\ooooooooooooo/

@anoadragon453 anoadragon453 merged commit a1a6473 into develop Feb 26, 2019
@anoadragon453 anoadragon453 deleted the anoa/public_rooms_federate branch February 26, 2019 13:07
@anoadragon453 anoadragon453 changed the title Config option to prevent showing non-fed rooms in fed /publicRooms Prevent showing non-fed rooms in fed /publicRooms Feb 26, 2019
@anoadragon453 anoadragon453 restored the anoa/public_rooms_federate branch February 26, 2019 13:25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants