refactor: Make onLicense support async callbacks (#28791)

pull/28861/head^2
Kevin Aleman 3 years ago committed by GitHub
parent 9c154297af
commit 5bc5b191c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      apps/meteor/ee/app/api-enterprise/server/index.ts
  2. 13
      apps/meteor/ee/app/canned-responses/server/index.js
  3. 13
      apps/meteor/ee/app/canned-responses/server/index.ts
  4. 6
      apps/meteor/ee/app/license/server/license.ts
  5. 2
      apps/meteor/ee/app/livechat-enterprise/server/index.ts
  6. 2
      apps/meteor/ee/app/message-read-receipt/server/index.ts
  7. 6
      apps/meteor/ee/app/teams-mention/server/index.ts
  8. 2
      apps/meteor/ee/app/voip-enterprise/server/services/voipService.ts
  9. 2
      apps/meteor/ee/server/configuration/oauth.ts
  10. 4
      apps/meteor/ee/server/configuration/saml.ts
  11. 2
      apps/meteor/ee/server/models/startup.ts
  12. 2
      apps/meteor/ee/server/startup/audit.ts
  13. 2
      apps/meteor/ee/server/startup/services.ts

@ -1,5 +1,5 @@
import { onLicense } from '../../license/server';
onLicense('canned-responses', async () => {
await onLicense('canned-responses', async () => {
await import('./canned-responses');
});

@ -1,13 +0,0 @@
import { onLicense } from '../../license/server';
onLicense('canned-responses', () => {
const { createSettings } = require('./settings');
require('./permissions');
require('./hooks/onRemoveAgentDepartment');
require('./hooks/onSaveAgentDepartment');
require('./hooks/onMessageSentParsePlaceholder');
require('./methods/saveCannedResponse');
require('./methods/removeCannedResponse');
createSettings();
});

@ -0,0 +1,13 @@
import { onLicense } from '../../license/server';
await onLicense('canned-responses', async () => {
const { createSettings } = await import('./settings');
await import('./permissions');
await import('./hooks/onRemoveAgentDepartment');
await import('./hooks/onSaveAgentDepartment');
await import('./hooks/onMessageSentParsePlaceholder');
await import('./methods/saveCannedResponse');
await import('./methods/removeCannedResponse');
createSettings();
});

@ -344,7 +344,7 @@ export async function canEnableApp(app: IAppStorageItem): Promise<boolean> {
return License.canEnableApp(app.installationSource);
}
export function onLicense(feature: BundleFeature, cb: (...args: any[]) => void): void {
export function onLicense(feature: BundleFeature, cb: (...args: any[]) => void): void | Promise<void> {
if (hasLicense(feature)) {
return cb();
}
@ -435,8 +435,8 @@ interface IOverrideClassProperties {
type Class = { new (...args: any[]): any };
export function overwriteClassOnLicense(license: BundleFeature, original: Class, overwrite: IOverrideClassProperties): void {
onLicense(license, () => {
export async function overwriteClassOnLicense(license: BundleFeature, original: Class, overwrite: IOverrideClassProperties): Promise<void> {
await onLicense(license, () => {
Object.entries(overwrite).forEach(([key, value]) => {
const originalFn = original.prototype[key];
original.prototype[key] = function (...args: any[]): any {

@ -30,7 +30,7 @@ import { onLicense } from '../../license/server';
import './business-hour';
import { createDefaultPriorities } from './priorities';
onLicense('livechat-enterprise', async () => {
await onLicense('livechat-enterprise', async () => {
require('./api');
require('./hooks');
await import('./startup');

@ -1,5 +1,5 @@
import { onLicense } from '../../license/server';
onLicense('message-read-receipt', async () => {
await onLicense('message-read-receipt', async () => {
await import('./hooks');
});

@ -15,10 +15,10 @@ interface IExtraDataForNotification {
message: IMessage;
}
onLicense('teams-mention', () => {
await onLicense('teams-mention', async () => {
// Override spotlight with EE version
overwriteClassOnLicense('teams-mention', Spotlight, SpotlightEnterprise);
overwriteClassOnLicense('teams-mention', MentionQueries, MentionQueriesEnterprise);
await overwriteClassOnLicense('teams-mention', Spotlight, SpotlightEnterprise);
await overwriteClassOnLicense('teams-mention', MentionQueries, MentionQueriesEnterprise);
callbacks.add('beforeGetMentions', async (mentionIds: string[], extra?: IExtraDataForNotification) => {
const { otherMentions } = extra ?? {};

@ -5,7 +5,7 @@ import { OmnichannelVoipService } from '../../../../../server/services/omnichann
import { overwriteClassOnLicense } from '../../../license/server';
import { calculateOnHoldTimeForRoom } from '../lib/calculateOnHoldTimeForRoom';
overwriteClassOnLicense('voip-enterprise', OmnichannelVoipService, {
await overwriteClassOnLicense('voip-enterprise', OmnichannelVoipService, {
async getRoomClosingData(
_originalFn: (
closer: ILivechatVisitor | ILivechatAgent,

@ -54,7 +54,7 @@ function getChannelsMap(channelsMap: string): Record<string, any> | undefined {
}
}
onLicense('oauth-enterprise', () => {
await onLicense('oauth-enterprise', () => {
callbacks.add('afterProcessOAuthUser', async (auth: IOAuthUserService) => {
auth.serviceName = capitalize(auth.serviceName);
const settings = getOAuthSettings(auth.serviceName);

@ -7,7 +7,7 @@ import { settings } from '../../../app/settings/server';
import { addSettings } from '../settings/saml';
import { ensureArray } from '../../../lib/utils/arrayUtils';
onLicense('saml-enterprise', () => {
await onLicense('saml-enterprise', () => {
SAMLUtils.events.on('mapUser', async ({ profile, userObject }: { profile: Record<string, any>; userObject: ISAMLUser }) => {
const roleAttributeName = settings.get('SAML_Custom_Default_role_attribute_name') as string;
const roleAttributeSync = settings.get('SAML_Custom_Default_role_attribute_sync');
@ -67,4 +67,4 @@ onLicense('saml-enterprise', () => {
});
// For setting creation we add the listener first because the event is emmited during startup
SAMLUtils.events.on('addSettings', (name: string): void => onLicense('saml-enterprise', () => addSettings(name)));
SAMLUtils.events.on('addSettings', (name: string): void | Promise<void> => onLicense('saml-enterprise', () => addSettings(name)));

@ -7,7 +7,7 @@ import('./LivechatPriority');
import('./OmnichannelServiceLevelAgreements');
import('./AuditLog');
onLicense('livechat-enterprise', () => {
await onLicense('livechat-enterprise', () => {
import('./CannedResponse');
import('./LivechatTag');
import('./LivechatUnit');

@ -1,7 +1,7 @@
import { onLicense } from '../../app/license/server';
import { createPermissions } from '../lib/audit/startup';
onLicense('auditing', async () => {
await onLicense('auditing', async () => {
await import('../lib/audit/methods');
await createPermissions();

@ -30,7 +30,7 @@ void (async () => {
}
})();
onLicense('federation', async () => {
await onLicense('federation', async () => {
const federationServiceEE = new FederationServiceEE();
if (federationService) {
api.destroyService(federationService);

Loading…
Cancel
Save