Skip to content

Commit

Permalink
chore!: remove deprecated endpoints licenses.isEnterprise and license…
Browse files Browse the repository at this point in the history
…s.get (#33470)
  • Loading branch information
abhinavkrin authored and ggazzo committed Oct 17, 2024
1 parent b167db0 commit 3f9c3f1
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 125 deletions.
6 changes: 6 additions & 0 deletions .changeset/ten-houses-repair.md
Original file line number Diff line number Diff line change
@@ -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.`
3 changes: 1 addition & 2 deletions apps/meteor/client/hooks/useIsEnterprise.ts
Original file line number Diff line number Diff line change
@@ -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) }) });
};
28 changes: 0 additions & 28 deletions apps/meteor/ee/server/api/licenses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down Expand Up @@ -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 });
},
},
);
78 changes: 0 additions & 78 deletions apps/meteor/tests/end-to-end/api/licenses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
});
});
});
10 changes: 0 additions & 10 deletions packages/mock-providers/src/MockedServerContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ export const MockedServerContext = ({
handleRequest,
handleMethod,
children,

isEnterprise,
}: {
handleRequest?: <TMethod extends Method, TPathPattern extends PathPattern>(args: {
method: TMethod;
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 1 addition & 7 deletions packages/rest-typings/src/v1/licenses.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand Down Expand Up @@ -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;
Expand All @@ -57,7 +54,4 @@ export type LicensesEndpoints = {
'/v1/licenses.requestSeatsLink': {
GET: () => { url: string };
};
'/v1/licenses.isEnterprise': {
GET: () => { isEnterprise: boolean };
};
};

0 comments on commit 3f9c3f1

Please sign in to comment.