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

fix!: LDAP sync triggers multiple cron jobs in case an invalid sync interval is provided #32285

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/sixty-vans-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": major
---

Fixed issue with LDAP sync triggering multiple cron jobs in case an invalid sync interval is provided
6 changes: 5 additions & 1 deletion apps/meteor/ee/server/configuration/ldap.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { IImportUser, ILDAPEntry, IUser } from '@rocket.chat/core-typings';
import { cronJobs } from '@rocket.chat/cron';
import { License } from '@rocket.chat/license';
import { Settings } from '@rocket.chat/models';
import { isValidCron } from 'cron-validator';
import { Meteor } from 'meteor/meteor';

import { settings } from '../../../app/settings/server';
Expand Down Expand Up @@ -28,7 +30,9 @@ Meteor.startup(async () => {
}

const settingValue = settings.get<string>(intervalSetting);
const schedule = ldapIntervalValuesToCronMap[settingValue] ?? settingValue;
const schedule =
ldapIntervalValuesToCronMap[settingValue] ??
(isValidCron(settingValue) ? settingValue : ((await Settings.findOneById(intervalSetting))?.packageValue as string));
if (schedule) {
if (schedule !== lastSchedule && (await cronJobs.has(jobName))) {
await cronJobs.remove(jobName);
Expand Down
1 change: 1 addition & 0 deletions apps/meteor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@
"cookie-parser": "^1.4.6",
"cors": "^2.8.5",
"cron": "~1.8.2",
"cron-validator": "^1.3.1",
"css-vars-ponyfill": "^2.4.9",
"csv-parse": "^5.2.0",
"date-fns": "^2.28.0",
Expand Down
1 change: 1 addition & 0 deletions apps/meteor/server/startup/migrations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ import './v304';
import './v305';
import './v306';
import './v307';
import './v308';

export * from './xrun';
31 changes: 31 additions & 0 deletions apps/meteor/server/startup/migrations/v308.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { ISetting } from '@rocket.chat/core-typings';
import { Settings } from '@rocket.chat/models';
import { isValidCron } from 'cron-validator';

import { addMigration } from '../../lib/migrations';

addMigration({
version: 308,
name: 'Update packageValue from LDAP interval settings',
async up() {
const newAvatarSyncPackageValue = '0 0 * * *';
const newAutoLogoutPackageValue = '*/5 * * * *';
const ldapAvatarSyncInterval = await Settings.findOneById<Pick<ISetting, 'value'>>('LDAP_Background_Sync_Avatars_Interval', {
projection: { value: 1 },
});
const ldapAutoLogoutInterval = await Settings.findOneById<Pick<ISetting, 'value'>>('LDAP_Sync_AutoLogout_Interval', {
projection: { value: 1 },
});
const isValidAvatarSyncInterval = ldapAvatarSyncInterval && isValidCron(ldapAvatarSyncInterval.value as string);
const isValidAutoLogoutInterval = ldapAutoLogoutInterval && isValidCron(ldapAutoLogoutInterval.value as string);

await Settings.updateOne(
{ _id: 'LDAP_Background_Sync_Avatars_Interval' },
{ $set: { packageValue: newAvatarSyncPackageValue, ...(!isValidAvatarSyncInterval && { value: newAvatarSyncPackageValue }) } },
);
await Settings.updateOne(
{ _id: 'LDAP_Sync_AutoLogout_Interval' },
{ $set: { packageValue: newAutoLogoutPackageValue, ...(!isValidAutoLogoutInterval && { value: newAutoLogoutPackageValue }) } },
);
},
});
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9734,6 +9734,7 @@ __metadata:
cookie-parser: ^1.4.6
cors: ^2.8.5
cron: ~1.8.2
cron-validator: ^1.3.1
cross-env: ^7.0.3
css-vars-ponyfill: ^2.4.9
csv-parse: ^5.2.0
Expand Down Expand Up @@ -20492,6 +20493,13 @@ __metadata:
languageName: node
linkType: hard

"cron-validator@npm:^1.3.1":
version: 1.3.1
resolution: "cron-validator@npm:1.3.1"
checksum: 82895b417bc35a96c8ad8501d2f236492403ba6e35c1112762e9573939eb15cd80bd0693d5ae95e3a15e15fc6442b1a6e6cc3dd0f740f0a3320b202082aeabec
languageName: node
linkType: hard

"cron@npm:~1.8.2":
version: 1.8.2
resolution: "cron@npm:1.8.2"
Expand Down
Loading