Skip to content

Conversation

@Hudell
Copy link
Contributor

@Hudell Hudell commented May 8, 2018

Ref #6535

This PR adds a migration to delete the subscriptions and empty rooms of users who have been removed.
It also changes the user deletion script to remove DM rooms and subscriptions to empty private rooms, using the same logic from the migration.

@Hudell Hudell requested a review from rodrigok May 8, 2018 13:38
@engelgabriel engelgabriel temporarily deployed to rocket-chat-pr-10700 May 8, 2018 13:38 Inactive
@sampaiodiego sampaiodiego self-requested a review May 22, 2018 12:37
@ggazzo
Copy link
Member

ggazzo commented Jun 12, 2018

@Hudell update the migration please

@@ -19,12 +19,13 @@ RocketChat.deleteUser = function(userId) {
RocketChat.models.Subscriptions.db.findByUserId(userId).forEach((subscription) => {
Copy link
Member

Choose a reason for hiding this comment

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

I think this code is wrong, we dont delete orphan subscriptions and we dont test if the user is the last owner/moderator and etc....

Copy link
Member

@ggazzo ggazzo Jun 13, 2018

Choose a reason for hiding this comment

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

		RocketChat.models.Subscriptions.db.findByUserId(userId).forEach(({rid}) => {
            const room = RocketChat.models.Rooms.findOneById(rid);
            RocketChat.models.Subscriptions.removeByRoomId(rid);
			if (room) {
                if (room.t === 'd') {
                    RocketChat.models.Messages.removeByRoomId(rid);
					return RocketChat.models.Rooms.removeById(rid);
                }
                if (room.usernames && room.usernames.length === 1) {//should test owners and choose another user
                  RocketChat.models.Messages.removeByRoomId(rid);
                  RocketChat.models.Rooms.removeById(rid); // Remove non-channel rooms with only 1 user (the one being deleted)
                }
			}
		});

Copy link
Member

@ggazzo ggazzo left a comment

Choose a reason for hiding this comment

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

check that situation (last owner)

@sampaiodiego sampaiodiego added this to the 0.69.0 milestone Aug 2, 2018
@rodrigok
Copy link
Member

@Hudell can you update and fix the conflicts?

@engelgabriel engelgabriel temporarily deployed to rocket-chat-pr-10700 August 14, 2018 17:38 Inactive
@engelgabriel engelgabriel temporarily deployed to rocket-chat-pr-10700 August 17, 2018 19:40 Inactive
@engelgabriel engelgabriel temporarily deployed to rocket-chat-pr-10700 August 17, 2018 19:42 Inactive
@engelgabriel engelgabriel temporarily deployed to rocket-chat-pr-10700 August 20, 2018 14:15 Inactive
@rodrigok rodrigok changed the title [FIX]Delete removed users' subscriptions [FIX] Delete removed user's subscriptions Aug 20, 2018
RocketChat.models.Subscriptions.removeByRoomId(subscription.rid);
RocketChat.models.Messages.removeByRoomId(subscription.rid);
RocketChat.models.Rooms.removeById(subscription.rid);
} else if (room.t !== 'c' && room.usernames.length === 1) {
Copy link
Member

Choose a reason for hiding this comment

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

  1. room.usernames isn't valid anymore.
  2. Don't we delete the messages?

@engelgabriel engelgabriel temporarily deployed to rocket-chat-pr-10700 August 20, 2018 17:40 Inactive
rodrigok
rodrigok previously approved these changes Aug 20, 2018
@sampaiodiego sampaiodiego merged commit 186f791 into develop Aug 21, 2018
@sampaiodiego sampaiodiego deleted the remove_subscriptions_upon_user_deletion branch August 21, 2018 01:30
@sampaiodiego sampaiodiego mentioned this pull request Aug 28, 2018
@maxdwit
Copy link

maxdwit commented Nov 5, 2018

This is still an Issue with 0.70.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants