Skip to content

Commit

Permalink
expose exceptions to non logged users
Browse files Browse the repository at this point in the history
  • Loading branch information
ggazzo committed Sep 18, 2023
1 parent bd2b193 commit 66dc626
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 55 deletions.
5 changes: 1 addition & 4 deletions apps/meteor/app/api/server/default/info.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { API } from '../api';
import { getLoggedInUser } from '../helpers/getLoggedInUser';
import { getServerInfo } from '../lib/getServerInfo';

API.default.addRoute(
'info',
{ authRequired: false },
{
async get() {
const user = await getLoggedInUser(this.request);

return API.v1.success(await getServerInfo(user?._id));
return API.v1.success(await getServerInfo(this.userId));
},
},
);
Expand Down
40 changes: 19 additions & 21 deletions apps/meteor/app/api/server/lib/getServerInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,33 @@ import {
} from '../../../cloud/server/functions/supportedVersionsToken/supportedVersionsToken';
import { Info, minimumClientVersions } from '../../../utils/rocketchat.info';

type ServerInfo =
| {
info: typeof Info;
supportedVersions?: string;
minimumClientVersions: typeof minimumClientVersions;
}
| {
version: string | undefined;
};
type ServerInfo = {
info?: typeof Info;
supportedVersions?: string;
minimumClientVersions: typeof minimumClientVersions;
version: string | undefined;
};

const removePatchInfo = (version: string): string => version.replace(/(\d+\.\d+).*/, '$1');

export async function getServerInfo(userId?: string): Promise<ServerInfo> {
if (userId && (await hasPermissionAsync(userId, 'get-server-info'))) {
const supportedVersionsToken = await wrapPromise(getCachedSupportedVersionsToken());
const hasPermissionToViewStatistics = userId && (await hasPermissionAsync(userId, 'view-statistics'));
const supportedVersionsToken = await wrapPromise(getCachedSupportedVersionsToken());

return {
return {
version: removePatchInfo(Info.version),

...(hasPermissionToViewStatistics && {
info: {
...Info,
},
minimumClientVersions,
...(supportedVersionsToken.success &&
supportedVersionsToken.result && {
supportedVersions: supportedVersionsToken.result,
}),
};
}
version: Info.version,
}),

return {
version: removePatchInfo(Info.version),
minimumClientVersions,
...(supportedVersionsToken.success &&
supportedVersionsToken.result && {
supportedVersions: supportedVersionsToken.result,
}),
};
}
62 changes: 32 additions & 30 deletions packages/rest-typings/src/default/index.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
// eslint-disable-next-line @typescript-eslint/naming-convention
export interface DefaultEndpoints {
'/info': {
GET: () =>
| {
info: {
build: {
arch: string;
cpus: number;
date: string;
freeMemory: number;
nodeVersion: string;
osRelease: string;
platform: string;
totalMemory: number;
};
commit: {
author?: string;
branch?: string;
date?: string;
hash?: string;
subject?: string;
tag?: string;
};
marketplaceApiVersion: string;
version: string;
tag?: string;
branch?: string;
};
}
| {
version: string | undefined;
};
GET: () => {
info: {
build: {
arch: string;
cpus: number;
date: string;
freeMemory: number;
nodeVersion: string;
osRelease: string;
platform: string;
totalMemory: number;
};
commit: {
author?: string;
branch?: string;
date?: string;
hash?: string;
subject?: string;
tag?: string;
};
marketplaceApiVersion: string;
version: string;
tag?: string;
branch?: string;
};
supportedVersions?: string;
minimumClientVersions: {
desktop: string;
mobile: string;
};
version: string | undefined;
};
};
'/ecdh_proxy/initEncryptedSession': {
POST: () => void;
Expand Down

0 comments on commit 66dc626

Please sign in to comment.