The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/server/startup/migrations/v152.js

37 lines
1.0 KiB

import { Meteor } from 'meteor/meteor';
import { Migrations } from '../../../app/migrations/server';
import { Users } from '../../../app/models/server';
import { MAX_RESUME_LOGIN_TOKENS } from '../../../app/authentication/server';
Migrations.add({
version: 152,
async up() {
await Users.model.rawCollection().aggregate([
{
$project: {
tokens: {
$filter: {
input: '$services.resume.loginTokens',
as: 'token',
cond: {
$ne: ['$$token.type', 'personalAccessToken'],
},
},
},
},
},
{ $unwind: '$tokens' },
{ $group: { _id: '$_id', tokens: { $push: '$tokens' } } },
{
$project: {
sizeOfTokens: { $size: '$tokens' }, tokens: '$tokens' },
},
{ $match: { sizeOfTokens: { $gt: MAX_RESUME_LOGIN_TOKENS } } },
{ $sort: { 'tokens.when': 1 } },
]).forEach(Meteor.bindEnvironment((user) => {
const oldestDate = user.tokens.reverse()[MAX_RESUME_LOGIN_TOKENS - 1];
Users.removeOlderResumeTokensByUserId(user._id, oldestDate.when);
}));
},
});