Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove direct chat channels when banishing user #5784

Merged
merged 3 commits into from
Feb 4, 2020

Conversation

citizen428
Copy link
Contributor

Closes #3601

What type of PR is this? (check all applicable)

  • Bug Fix

Description

Users who got banished left some dangling associations, most notably direct chat channels. This PR adds code for cleaning them up.

Related Tickets & Documents

#3601

Mobile & Desktop Screenshots/Recordings (if there are UI changes)

n/a

Added to documentation?

  • docs.dev.to
  • readme
  • no documentation needed

@pr-triage pr-triage bot added the PR: unreviewed bot applied label for PR's with no review label Jan 28, 2020
@citizen428 citizen428 force-pushed the citizen428/remove-banished-user-data branch 3 times, most recently from 4e707d7 to 37716ef Compare January 28, 2020 05:08
@citizen428 citizen428 force-pushed the citizen428/remove-banished-user-data branch from 37716ef to bc57690 Compare January 28, 2020 05:13
@@ -19,6 +19,7 @@ def banish
delete_user_activity
delete_comments
delete_articles
cleanup_chat_channels
Copy link
Contributor Author

@citizen428 citizen428 Jan 28, 2020

Choose a reason for hiding this comment

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

Not sure if we really need this level of indirection, I was just following the established pattern here. Will we also be calling delete_chat_channels in other contexts than banishing users?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think there aren't other contexts where we'd deleted chat channels; maybe an opportunity to refactor in a different PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since I just added this method, I'd rather update this PR and move it right away.

ccm.destroy!
end

# We only destroy direct message channels, not open and invite-only ones
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Zhao-Andy Your snippet in #3601 did not include a check list this, but I guess it's better to err on the side of caution here. Running the specs with the next line commented out would remove all open channels the banished user was in, which is probably not what we want.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah yes, we should only destroy direct chat channels. I think we might also want to only remove_from_index! for direct chat channels as well. Most banished users won't be a part of any open channels, but better to be safe here.

Copy link
Contributor Author

@citizen428 citizen428 Jan 29, 2020

Choose a reason for hiding this comment

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

That's what I thought.

Also, this snippet:

        chat_channel.chat_channel_memberships.each do |ccm|
          ccm.remove_from_index!
          ccm.destroy!
        end

This would remove channel memberships for all other users if a banished account was part of an open channel, I just confirmed this via a spec.

I'd rather play this safe, so I rewrote the whole method to do this in a two step process:

  1. Get all direct channels and clean them up.
  2. Iterate over the user's remaining memberships and clean them up, leaving the channels alone.

Copy link
Contributor

@Zhao-Andy Zhao-Andy left a comment

Choose a reason for hiding this comment

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

Just one change about only completing the action for direct chat channels.

Thanks for the PR! Looks great overall.

@@ -19,6 +19,7 @@ def banish
delete_user_activity
delete_comments
delete_articles
cleanup_chat_channels
Copy link
Contributor

Choose a reason for hiding this comment

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

I think there aren't other contexts where we'd deleted chat channels; maybe an opportunity to refactor in a different PR?

app/services/users/delete_articles.rb Show resolved Hide resolved
ccm.destroy!
end

# We only destroy direct message channels, not open and invite-only ones
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah yes, we should only destroy direct chat channels. I think we might also want to only remove_from_index! for direct chat channels as well. Most banished users won't be a part of any open channels, but better to be safe here.

@pr-triage pr-triage bot added PR: reviewed-changes-requested bot applied label for PR's where reviewer requests changes and removed PR: unreviewed bot applied label for PR's with no review labels Jan 28, 2020
@pr-triage pr-triage bot added PR: unreviewed bot applied label for PR's with no review and removed PR: reviewed-changes-requested bot applied label for PR's where reviewer requests changes labels Jan 29, 2020
@citizen428
Copy link
Contributor Author

@Zhao-Andy Thanks for the feedback. I actually found another problem, so I rewrote the whole process little bit, see comment above. Please review again.

Copy link
Contributor

@Zhao-Andy Zhao-Andy left a comment

Choose a reason for hiding this comment

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

Looks great! Thanks for the fix + refactor!

@pr-triage pr-triage bot added PR: reviewed-approved bot applied label for PR's where reviewer approves changes and removed PR: unreviewed bot applied label for PR's with no review labels Jan 29, 2020
Copy link
Contributor

@maestromac maestromac left a comment

Choose a reason for hiding this comment

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

This is great! LGTM

@maestromac maestromac merged commit a26ea73 into master Feb 4, 2020
@pr-triage pr-triage bot added PR: merged bot applied label for PR's that are merged and removed PR: reviewed-approved bot applied label for PR's where reviewer approves changes labels Feb 4, 2020
@maestromac maestromac deleted the citizen428/remove-banished-user-data branch February 4, 2020 22:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: merged bot applied label for PR's that are merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Banishing accounts should remove all related data
3 participants