-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX] Missing user data on files uploaded through the API (#10473)
* Added missing userId * Fixed roomFiles method to return files without users too * Added migration to add userId on orphan files * Changed migration code to make sure the message exist before trying to use it's data
- Loading branch information
Showing
3 changed files
with
35 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
RocketChat.Migrations.add({ | ||
version: 113, | ||
up() { | ||
if (RocketChat && RocketChat.models && RocketChat.models.Uploads && RocketChat.models.Messages) { | ||
const fileQuery = { | ||
userId: null | ||
}; | ||
|
||
const filesToUpdate = RocketChat.models.Uploads.find(fileQuery); | ||
filesToUpdate.forEach((file) => { | ||
const messageQuery = { | ||
'file._id' : file._id | ||
}; | ||
const message = RocketChat.models.Messages.findOne(messageQuery); | ||
if (message) { | ||
const filter = { | ||
_id: file._id | ||
}; | ||
|
||
const update = { | ||
$set: { | ||
userId: message.u._id | ||
} | ||
}; | ||
|
||
RocketChat.models.Uploads.model.direct.update(filter, update); | ||
} | ||
}); | ||
} | ||
} | ||
}); |