Skip to content
Snippets Groups Projects
Commit 3f9c3f1f authored by Abhinav Kumar's avatar Abhinav Kumar Committed by Guilherme Gazzo
Browse files

chore!: remove deprecated endpoints licenses.isEnterprise and licenses.get (#33470)

parent b167db0b
No related branches found
No related tags found
No related merge requests found
---
'@rocket.chat/rest-typings': major
'@rocket.chat/meteor': major
---
Removes deprecated endpoints `licenses.isEnterprise` and `licenses.get`. Moving forward use the endpoint `licenses.info.`
import type { OperationResult } from '@rocket.chat/rest-typings';
import type { UseQueryResult } from '@tanstack/react-query';
import { useLicenseBase } from './useLicense';
export const useIsEnterprise = (): UseQueryResult<OperationResult<'GET', '/v1/licenses.isEnterprise'>> => {
export const useIsEnterprise = (): UseQueryResult<{ isEnterprise: boolean }> => {
return useLicenseBase({ select: (data) => ({ isEnterprise: Boolean(data?.license.license) }) });
};
......@@ -7,23 +7,6 @@ import { API } from '../../../app/api/server/api';
import { hasPermissionAsync } from '../../../app/authorization/server/functions/hasPermission';
import { notifyOnSettingChangedById } from '../../../app/lib/server/lib/notifyListener';
API.v1.addRoute(
'licenses.get',
{ authRequired: true, deprecation: { version: '7.0.0', alternatives: ['licenses.info'] } },
{
async get() {
if (!(await hasPermissionAsync(this.userId, 'view-privileged-setting'))) {
return API.v1.unauthorized();
}
const license = License.getUnmodifiedLicenseAndModules();
const licenses = license ? [license] : [];
return API.v1.success({ licenses });
},
},
);
API.v1.addRoute(
'licenses.info',
{ authRequired: true, validateParams: isLicensesInfoProps },
......@@ -73,14 +56,3 @@ API.v1.addRoute(
},
},
);
API.v1.addRoute(
'licenses.isEnterprise',
{ authOrAnonRequired: true, deprecation: { version: '7.0.0', alternatives: ['licenses.info'] } },
{
get() {
const isEnterpriseEdition = License.hasValidLicense();
return API.v1.success({ isEnterprise: isEnterpriseEdition });
},
},
);
......@@ -70,46 +70,6 @@ describe('licenses', () => {
});
});
describe('[/licenses.get]', () => {
it('should fail if not logged in', (done) => {
void request
.get(api('licenses.get'))
.expect('Content-Type', 'application/json')
.expect(401)
.expect((res) => {
expect(res.body).to.have.property('status', 'error');
expect(res.body).to.have.property('message');
})
.end(done);
});
it('should fail if user is unauthorized', (done) => {
void request
.get(api('licenses.get'))
.set(unauthorizedUserCredentials)
.expect('Content-Type', 'application/json')
.expect(403)
.expect((res) => {
expect(res.body).to.have.property('success', false);
expect(res.body).to.have.property('error', 'unauthorized');
})
.end(done);
});
it('should return licenses if user is logged in and is authorized', (done) => {
void request
.get(api('licenses.get'))
.set(credentials)
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('licenses').and.to.be.an('array');
})
.end(done);
});
});
describe('[/licenses.info]', () => {
it('should fail if not logged in', (done) => {
void request
......@@ -155,42 +115,4 @@ describe('licenses', () => {
.end(done);
});
});
describe('[/licenses.isEnterprise]', () => {
it('should fail if not logged in', (done) => {
void request
.get(api('licenses.isEnterprise'))
.expect('Content-Type', 'application/json')
.expect(401)
.expect((res) => {
expect(res.body).to.have.property('status', 'error');
expect(res.body).to.have.property('message');
})
.end(done);
});
it('should pass if user has user role', (done) => {
void request
.get(api('licenses.isEnterprise'))
.set(unauthorizedUserCredentials)
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('isEnterprise', Boolean(process.env.IS_EE));
})
.end(done);
});
it('should pass if user has admin role', (done) => {
void request
.get(api('licenses.isEnterprise'))
.set(credentials)
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('isEnterprise', Boolean(process.env.IS_EE));
})
.end(done);
});
});
});
......@@ -9,8 +9,6 @@ export const MockedServerContext = ({
handleRequest,
handleMethod,
children,
isEnterprise,
}: {
handleRequest?: <TMethod extends Method, TPathPattern extends PathPattern>(args: {
method: TMethod;
......@@ -41,14 +39,6 @@ export const MockedServerContext = ({
keys: UrlParams<TPathPattern>;
params: OperationParams<TMethod, TPathPattern>;
}) => {
if (isEnterprise !== undefined) {
if (args.method === 'GET' && args.pathPattern === '/v1/licenses.isEnterprise') {
return {
isEnterprise,
} as any;
}
}
return handleRequest?.(args);
},
getStream: () => () => undefined,
......
import type { ILicenseV2, ILicenseV3, LicenseInfo } from '@rocket.chat/core-typings';
import type { LicenseInfo } from '@rocket.chat/core-typings';
import Ajv from 'ajv';
const ajv = new Ajv({
......@@ -40,9 +40,6 @@ const licensesInfoPropsSchema = {
export const isLicensesInfoProps = ajv.compile<licensesInfoProps>(licensesInfoPropsSchema);
export type LicensesEndpoints = {
'/v1/licenses.get': {
GET: () => { licenses: Array<ILicenseV2 | (ILicenseV3 & { modules: string[] })> };
};
'/v1/licenses.info': {
GET: (params: licensesInfoProps) => {
license: LicenseInfo;
......@@ -57,7 +54,4 @@ export type LicensesEndpoints = {
'/v1/licenses.requestSeatsLink': {
GET: () => { url: string };
};
'/v1/licenses.isEnterprise': {
GET: () => { isEnterprise: boolean };
};
};
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