From 3f9c3f1f5293576b9356b927db6a9d00100e9fac Mon Sep 17 00:00:00 2001
From: Abhinav Kumar <abhinav@avitechlab.com>
Date: Thu, 10 Oct 2024 01:22:52 +0530
Subject: [PATCH] chore!: remove deprecated endpoints licenses.isEnterprise and
 licenses.get (#33470)

---
 .changeset/ten-houses-repair.md               |  6 ++
 apps/meteor/client/hooks/useIsEnterprise.ts   |  3 +-
 apps/meteor/ee/server/api/licenses.ts         | 28 -------
 apps/meteor/tests/end-to-end/api/licenses.ts  | 78 -------------------
 .../src/MockedServerContext.tsx               | 10 ---
 packages/rest-typings/src/v1/licenses.ts      |  8 +-
 6 files changed, 8 insertions(+), 125 deletions(-)
 create mode 100644 .changeset/ten-houses-repair.md

diff --git a/.changeset/ten-houses-repair.md b/.changeset/ten-houses-repair.md
new file mode 100644
index 00000000000..7d3cd67ce15
--- /dev/null
+++ b/.changeset/ten-houses-repair.md
@@ -0,0 +1,6 @@
+---
+'@rocket.chat/rest-typings': major
+'@rocket.chat/meteor': major
+---
+
+Removes deprecated endpoints `licenses.isEnterprise` and `licenses.get`. Moving forward use the endpoint `licenses.info.`
diff --git a/apps/meteor/client/hooks/useIsEnterprise.ts b/apps/meteor/client/hooks/useIsEnterprise.ts
index e2622d8b695..dffaf8b3687 100644
--- a/apps/meteor/client/hooks/useIsEnterprise.ts
+++ b/apps/meteor/client/hooks/useIsEnterprise.ts
@@ -1,8 +1,7 @@
-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) }) });
 };
diff --git a/apps/meteor/ee/server/api/licenses.ts b/apps/meteor/ee/server/api/licenses.ts
index 22ddbda9e31..9d8d60c0be5 100644
--- a/apps/meteor/ee/server/api/licenses.ts
+++ b/apps/meteor/ee/server/api/licenses.ts
@@ -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 });
-		},
-	},
-);
diff --git a/apps/meteor/tests/end-to-end/api/licenses.ts b/apps/meteor/tests/end-to-end/api/licenses.ts
index 10dce4177ae..931f9958846 100644
--- a/apps/meteor/tests/end-to-end/api/licenses.ts
+++ b/apps/meteor/tests/end-to-end/api/licenses.ts
@@ -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);
-		});
-	});
 });
diff --git a/packages/mock-providers/src/MockedServerContext.tsx b/packages/mock-providers/src/MockedServerContext.tsx
index 1f30cd6f1c2..84bca6c1d69 100644
--- a/packages/mock-providers/src/MockedServerContext.tsx
+++ b/packages/mock-providers/src/MockedServerContext.tsx
@@ -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,
diff --git a/packages/rest-typings/src/v1/licenses.ts b/packages/rest-typings/src/v1/licenses.ts
index 4a18bc113a6..99ba936e349 100644
--- a/packages/rest-typings/src/v1/licenses.ts
+++ b/packages/rest-typings/src/v1/licenses.ts
@@ -1,4 +1,4 @@
-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 };
-	};
 };
-- 
GitLab