Skip to content

Commit

Permalink
fix: offboarding: remove ppl only from groups they were part of
Browse files Browse the repository at this point in the history
fix #16
  • Loading branch information
missytake committed Aug 20, 2024
1 parent db8ff5c commit b131be5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/team_bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,4 +270,6 @@ def get_relay_group(self, outside_id: int) -> deltachat.Chat:

def offboard(self, ex_admin):
for mapping in self.kvstore.get("relays"):
self.account.get_chat_by_id(mapping[1]).remove_contact(ex_admin)
relay_group = self.account.get_chat_by_id(mapping[1])
if ex_admin in relay_group.get_contacts():
relay_group.remove_contact(ex_admin)
40 changes: 35 additions & 5 deletions tests/test_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
TIMEOUT = 40


def get_user_crew(crewuser: deltachat.Account) -> deltachat.Chat:
def get_user_crew(crewuser: deltachat.Account, id=11) -> deltachat.Chat:
"""Get the Team chat from the team member's point of view.
:param crewuser: the account object of the team member
:return: the chat object of the team chat
"""
for chat in crewuser.get_chats():
print(chat.id, chat.get_name())
user_crew = crewuser.get_chat_by_id(11)
user_crew = crewuser.get_chat_by_id(id)
assert user_crew.get_name().startswith("Team")
return user_crew

Expand Down Expand Up @@ -156,12 +156,42 @@ def test_relay_group_forwarding(relaycrew, outsider):
for msg in chat.get_messages():
assert "This is the relay group for" not in msg.text


@pytest.mark.timeout(TIMEOUT)
def test_offboarding(team_bot, relaycrew, outsider, team_user):
# outsider sends message, creates relay group
outsider_botcontact = outsider.create_contact(team_bot.get_config("addr"))
outsider_outside_chat = outsider.create_chat(outsider_botcontact)
outsider_outside_chat.send_text("test 1:1 message to bot")

# get relay group
user_relay_group = team_user._evtracker.wait_next_incoming_message().chat
bot_relay_group = team_bot.get_chats()[-1]

# outsider gets added to crew
qr = relaycrew.get_join_qr()
outsider.qr_join_chat(qr)
outsider._evtracker.wait_securejoin_joiner_progress(1000)

# user kicks outsider from crew
user_crew = get_user_crew(team_user)
user_crew.remove_contact(team_user.create_contact(outsider))
team_bot._evtracker.wait_next_incoming_message()

# user leaves crew
get_user_crew(user).remove_contact(user)
user_crew.remove_contact(team_user)
# make sure they are also offboarded from relay group
user._evtracker.wait_next_incoming_message()
team_bot._evtracker.wait_next_incoming_message()
team_user._evtracker.wait_next_incoming_message()
team_user._evtracker.wait_next_incoming_message()
team_user._evtracker.wait_next_incoming_message()
for contact in bot_relay_group.get_contacts():
assert user.get_config("addr") != contact.addr
assert team_user.get_config("addr") != contact.addr

# make sure there is no message in relay group that outsider was kicked
for msg in user_relay_group.get_messages():
print(msg.text)
assert outsider.get_config("addr") + " removed by " not in msg.text


@pytest.mark.timeout(TIMEOUT)
Expand Down

0 comments on commit b131be5

Please sign in to comment.