-
Notifications
You must be signed in to change notification settings - Fork 13.1k
[FIX] Delete removed user's subscriptions #10700
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
[FIX] Delete removed user's subscriptions #10700
Conversation
…te past subscriptions
|
@Hudell update the migration please |
| @@ -19,12 +19,13 @@ RocketChat.deleteUser = function(userId) { | |||
| RocketChat.models.Subscriptions.db.findByUserId(userId).forEach((subscription) => { | |||
There was a problem hiding this comment.
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....
There was a problem hiding this comment.
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)
}
}
});
ggazzo
left a comment
There was a problem hiding this 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)
|
@Hudell can you update and fix the conflicts? |
server/startup/migrations/v131.js
Outdated
| 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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
room.usernamesisn't valid anymore.- Don't we delete the messages?
|
This is still an Issue with 0.70.4 |
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.