Skip to content
Snippets Groups Projects
Unverified Commit d996d0b4 authored by Pierre Lehnen's avatar Pierre Lehnen Committed by GitHub
Browse files

chore: move applyLicense function to the license package (#31808)

parent c4e58afd
No related branches found
No related tags found
No related merge requests found
import { applyLicense } from '@rocket.chat/license';
import { Settings } from '@rocket.chat/models';
import { applyLicense } from '../../../../ee/app/license/server/applyLicense';
import { settings } from '../../../settings/server';
import { syncCloudData } from './syncWorkspace/syncCloudData';
......
import { api } from '@rocket.chat/core-services';
import type { LicenseLimitKind } from '@rocket.chat/core-typings';
import { License } from '@rocket.chat/license';
import { applyLicense, applyLicenseOrRemove, License } from '@rocket.chat/license';
import { Subscriptions, Users, Settings, LivechatVisitors } from '@rocket.chat/models';
import { wrapExceptions } from '@rocket.chat/tools';
import moment from 'moment';
......@@ -8,7 +8,6 @@ import moment from 'moment';
import { syncWorkspace } from '../../../../app/cloud/server/functions/syncWorkspace';
import { settings } from '../../../../app/settings/server';
import { callbacks } from '../../../../lib/callbacks';
import { applyLicense, applyLicenseOrRemove } from './applyLicense';
import { getAppCount } from './lib/getAppCount';
export const startLicense = async () => {
......
import { License } from '@rocket.chat/license';
import { License } from './licenseImp';
export const applyLicense = async (license: string, isNewLicense: boolean): Promise<boolean> => {
const enterpriseLicense = (license ?? '').trim();
......
import type { LicenseLimitKind, LicenseInfo, LimitContext } from '@rocket.chat/core-typings';
import { getAppsConfig, getMaxActiveUsers, getUnmodifiedLicenseAndModules } from './deprecated';
import { onLicense } from './events/deprecated';
import {
onBehaviorToggled,
onBehaviorTriggered,
onInvalidFeature,
onInvalidateLicense,
onLimitReached,
onModule,
onChange,
onToggledFeature,
onValidFeature,
onValidateLicense,
onInstall,
onInvalidate,
onRemoveLicense,
} from './events/listeners';
import { overwriteClassOnLicense } from './events/overwriteClassOnLicense';
import { LicenseManager } from './license';
import { logger } from './logger';
import { getModules, hasModule } from './modules';
import { showLicense } from './showLicense';
import { getTags } from './tags';
import { getCurrentValueForLicenseLimit, setLicenseLimitCounter } from './validation/getCurrentValueForLicenseLimit';
import { validateFormat } from './validation/validateFormat';
export { DuplicatedLicenseError } from './errors/DuplicatedLicenseError';
export * from './licenseImp';
export * from './MockedLicenseBuilder';
// eslint-disable-next-line @typescript-eslint/naming-convention
interface License {
validateFormat: typeof validateFormat;
hasModule: typeof hasModule;
getModules: typeof getModules;
getTags: typeof getTags;
overwriteClassOnLicense: typeof overwriteClassOnLicense;
setLicenseLimitCounter: typeof setLicenseLimitCounter;
getCurrentValueForLicenseLimit: typeof getCurrentValueForLicenseLimit;
isLimitReached: <T extends LicenseLimitKind>(action: T, context?: Partial<LimitContext<T>>) => Promise<boolean>;
onValidFeature: typeof onValidFeature;
onInvalidFeature: typeof onInvalidFeature;
onToggledFeature: typeof onToggledFeature;
onModule: typeof onModule;
onValidateLicense: typeof onValidateLicense;
onInvalidateLicense: typeof onInvalidateLicense;
onLimitReached: typeof onLimitReached;
onBehaviorTriggered: typeof onBehaviorTriggered;
revalidateLicense: () => Promise<void>;
getInfo: (info: { limits: boolean; currentValues: boolean; license: boolean }) => Promise<LicenseInfo>;
// Deprecated:
onLicense: typeof onLicense;
// Deprecated:
getMaxActiveUsers: typeof getMaxActiveUsers;
// Deprecated:
getAppsConfig: typeof getAppsConfig;
// Deprecated:
getUnmodifiedLicenseAndModules: typeof getUnmodifiedLicenseAndModules;
}
export class LicenseImp extends LicenseManager implements License {
constructor() {
super();
this.onValidateLicense(() => showLicense.call(this, this.getLicense(), this.hasValidLicense()));
this.onValidateLicense(() => {
logger.startup({
msg: 'License installed',
version: this.getLicense()?.version,
hash: this._lockedLicense?.slice(-8),
});
});
this.onRemoveLicense(() => {
logger.startup({
msg: 'License removed',
});
});
this.onInvalidateLicense(() => {
logger.startup({
msg: 'License invalidated',
});
});
}
validateFormat = validateFormat;
hasModule = hasModule;
getModules = getModules;
getTags = getTags;
overwriteClassOnLicense = overwriteClassOnLicense;
public setLicenseLimitCounter = setLicenseLimitCounter;
getCurrentValueForLicenseLimit = getCurrentValueForLicenseLimit;
public async isLimitReached<T extends LicenseLimitKind>(action: T, context?: Partial<LimitContext<T>>): Promise<boolean> {
return this.shouldPreventAction(action, 0, context);
}
onChange = onChange;
onInstall = onInstall;
onRemoveLicense = onRemoveLicense;
onInvalidate = onInvalidate;
onValidFeature = onValidFeature;
onInvalidFeature = onInvalidFeature;
onToggledFeature = onToggledFeature;
onModule = onModule;
onValidateLicense = onValidateLicense;
onInvalidateLicense = onInvalidateLicense;
onLimitReached = onLimitReached;
onBehaviorTriggered = onBehaviorTriggered;
onBehaviorToggled = onBehaviorToggled;
// Deprecated:
onLicense = onLicense;
// Deprecated:
getMaxActiveUsers = getMaxActiveUsers;
// Deprecated:
getAppsConfig = getAppsConfig;
// Deprecated:
getUnmodifiedLicenseAndModules = getUnmodifiedLicenseAndModules;
}
const license = new LicenseImp();
export { license as License };
export * from './applyLicense';
import type { LicenseLimitKind, LicenseInfo, LimitContext } from '@rocket.chat/core-typings';
import { getAppsConfig, getMaxActiveUsers, getUnmodifiedLicenseAndModules } from './deprecated';
import { onLicense } from './events/deprecated';
import {
onBehaviorToggled,
onBehaviorTriggered,
onInvalidFeature,
onInvalidateLicense,
onLimitReached,
onModule,
onChange,
onToggledFeature,
onValidFeature,
onValidateLicense,
onInstall,
onInvalidate,
onRemoveLicense,
} from './events/listeners';
import { overwriteClassOnLicense } from './events/overwriteClassOnLicense';
import { LicenseManager } from './license';
import { logger } from './logger';
import { getModules, hasModule } from './modules';
import { showLicense } from './showLicense';
import { getTags } from './tags';
import { getCurrentValueForLicenseLimit, setLicenseLimitCounter } from './validation/getCurrentValueForLicenseLimit';
import { validateFormat } from './validation/validateFormat';
// eslint-disable-next-line @typescript-eslint/naming-convention
interface License {
validateFormat: typeof validateFormat;
hasModule: typeof hasModule;
getModules: typeof getModules;
getTags: typeof getTags;
overwriteClassOnLicense: typeof overwriteClassOnLicense;
setLicenseLimitCounter: typeof setLicenseLimitCounter;
getCurrentValueForLicenseLimit: typeof getCurrentValueForLicenseLimit;
isLimitReached: <T extends LicenseLimitKind>(action: T, context?: Partial<LimitContext<T>>) => Promise<boolean>;
onValidFeature: typeof onValidFeature;
onInvalidFeature: typeof onInvalidFeature;
onToggledFeature: typeof onToggledFeature;
onModule: typeof onModule;
onValidateLicense: typeof onValidateLicense;
onInvalidateLicense: typeof onInvalidateLicense;
onLimitReached: typeof onLimitReached;
onBehaviorTriggered: typeof onBehaviorTriggered;
revalidateLicense: () => Promise<void>;
getInfo: (info: { limits: boolean; currentValues: boolean; license: boolean }) => Promise<LicenseInfo>;
// Deprecated:
onLicense: typeof onLicense;
// Deprecated:
getMaxActiveUsers: typeof getMaxActiveUsers;
// Deprecated:
getAppsConfig: typeof getAppsConfig;
// Deprecated:
getUnmodifiedLicenseAndModules: typeof getUnmodifiedLicenseAndModules;
}
export class LicenseImp extends LicenseManager implements License {
constructor() {
super();
this.onValidateLicense(() => showLicense.call(this, this.getLicense(), this.hasValidLicense()));
this.onValidateLicense(() => {
logger.startup({
msg: 'License installed',
version: this.getLicense()?.version,
hash: this._lockedLicense?.slice(-8),
});
});
this.onRemoveLicense(() => {
logger.startup({
msg: 'License removed',
});
});
this.onInvalidateLicense(() => {
logger.startup({
msg: 'License invalidated',
});
});
}
validateFormat = validateFormat;
hasModule = hasModule;
getModules = getModules;
getTags = getTags;
overwriteClassOnLicense = overwriteClassOnLicense;
public setLicenseLimitCounter = setLicenseLimitCounter;
getCurrentValueForLicenseLimit = getCurrentValueForLicenseLimit;
public async isLimitReached<T extends LicenseLimitKind>(action: T, context?: Partial<LimitContext<T>>): Promise<boolean> {
return this.shouldPreventAction(action, 0, context);
}
onChange = onChange;
onInstall = onInstall;
onRemoveLicense = onRemoveLicense;
onInvalidate = onInvalidate;
onValidFeature = onValidFeature;
onInvalidFeature = onInvalidFeature;
onToggledFeature = onToggledFeature;
onModule = onModule;
onValidateLicense = onValidateLicense;
onInvalidateLicense = onInvalidateLicense;
onLimitReached = onLimitReached;
onBehaviorTriggered = onBehaviorTriggered;
onBehaviorToggled = onBehaviorToggled;
// Deprecated:
onLicense = onLicense;
// Deprecated:
getMaxActiveUsers = getMaxActiveUsers;
// Deprecated:
getAppsConfig = getAppsConfig;
// Deprecated:
getUnmodifiedLicenseAndModules = getUnmodifiedLicenseAndModules;
}
const license = new LicenseImp();
export { license as License };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment