Skip to content

Commit

Permalink
Move to core instead of livechat
Browse files Browse the repository at this point in the history
  • Loading branch information
KevLehman committed Dec 27, 2022
1 parent 7e418b4 commit 1592ae0
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 31 deletions.
28 changes: 0 additions & 28 deletions apps/meteor/app/livechat/server/settingsRegenerator.ts

This file was deleted.

3 changes: 0 additions & 3 deletions apps/meteor/app/livechat/server/startup.js
Expand Up @@ -12,7 +12,6 @@ import { createDefaultBusinessHourIfNotExists } from './business-hour/Helper';
import { hasPermission } from '../../authorization/server';
import { Livechat } from './lib/Livechat';
import { RoutingManager } from './lib/RoutingManager';
import { settingsRegenerator } from './settingsRegenerator';

import './roomAccessValidator.internalService';

Expand Down Expand Up @@ -84,6 +83,4 @@ Meteor.startup(async () => {
!user?.roles?.includes('bot') &&
Livechat.setUserStatusLivechatIf(user._id, 'not-available', {}, { livechatStatusSystemModified: true }),
);

await settingsRegenerator();
});
40 changes: 40 additions & 0 deletions apps/meteor/server/lib/settingsRegenerator.ts
@@ -0,0 +1,40 @@
// Validates settings on DB are correct on structure
// And deletes invalid ones
import { Meteor } from 'meteor/meteor';
import { Settings } from '@rocket.chat/models';

import { Logger } from './logger/Logger';

// Validates settings on DB are correct on structure by matching the ones missing all the required fields
const logger = new Logger('SettingsRegenerator');
export async function settingsRegenerator() {
const invalidSettings = await Settings.find(
{
// Putting the $and explicit to ensure it's "intentional"
$and: [
{ value: { $exists: false } },
{ type: { $exists: false } },
{ public: { $exists: false } },
{ packageValue: { $exists: false } },
{ blocked: { $exists: false } },
{ sorter: { $exists: false } },
{ i18nLabel: { $exists: false } },
],
},
{ projection: { _id: 1 } },
).toArray();

if (invalidSettings.length > 0) {
logger.warn({
msg: 'Invalid settings found on DB. Deleting them.',
settings: invalidSettings.map(({ _id }) => _id),
});
await Settings.deleteMany({ _id: { $in: invalidSettings.map(({ _id }) => _id) } });
} else {
logger.info('No invalid settings found on DB.');
}
}

Meteor.startup(async () => {
await settingsRegenerator();
});
1 change: 1 addition & 0 deletions apps/meteor/server/startup/index.ts
Expand Up @@ -9,6 +9,7 @@ import './coreApps';
import './presenceTroubleshoot';
import '../hooks';
import '../lib/rooms/roomTypes';
import '../lib/settingsRegenerator';
import { isRunningMs } from '../lib/isRunningMs';

// only starts network broker if running in micro services mode
Expand Down

0 comments on commit 1592ae0

Please sign in to comment.