Skip to content

Commit

Permalink
fix CI
Browse files Browse the repository at this point in the history
  • Loading branch information
ggazzo committed Jun 9, 2022
1 parent 13bba40 commit 1edfa28
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 72 deletions.
28 changes: 18 additions & 10 deletions apps/meteor/app/api/server/v1/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
isMethodCallAnonProps,
isMeteorCall,
} from '@rocket.chat/rest-typings';
import { IUser } from '@rocket.chat/core-typings';

import { hasPermission } from '../../../authorization/server';
import { Users } from '../../../models/server';
Expand Down Expand Up @@ -166,17 +167,24 @@ API.v1.addRoute(
'me',
{ authRequired: true },
{
get() {
async get() {
const fields = getDefaultUserFields();
const user = Users.findOneById(this.userId, { fields });

// The password hash shouldn't be leaked but the client may need to know if it exists.
if (user?.services?.password?.bcrypt) {
user.services.password.exists = true;
delete user.services.password.bcrypt;
}

return API.v1.success(this.getUserInfo(user));
const { services, ...user } = Users.findOneById(this.userId, { fields }) as IUser;

return API.v1.success(
this.getUserInfo({
...user,
...(services && {
services: {
...services,
password: {
// The password hash shouldn't be leaked but the client may need to know if it exists.
exists: Boolean(services?.password?.bcrypt),
} as any,
},
}),
}),
);
},
},
);
Expand Down
8 changes: 3 additions & 5 deletions apps/meteor/client/lib/meteorCallWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,13 @@ function wrapMeteorDDPCalls(): void {
});
Meteor.connection.onMessage(_message);
};
const method = encodeURIComponent(message.method.replace(/\//g, ':'));

APIClient.post(
`/v1/${endpoint}/${encodeURIComponent(message.method.replace(/\//g, ':'))}` as Parameters<typeof APIClient.post>[0],
restParams as any,
)
APIClient.post(`/v1/${endpoint}/${method}`, restParams)
.then(({ message: _message }) => {
processResult(_message);
if (message.method === 'login') {
const parsedMessage = DDPCommon.parseDDP(_message) as { result?: { token?: string } };
const parsedMessage = DDPCommon.parseDDP(_message as any) as { result?: { token?: string } };
if (parsedMessage.result?.token) {
Meteor.loginWithToken(parsedMessage.result.token);
}
Expand Down
27 changes: 26 additions & 1 deletion apps/meteor/client/lib/userData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,35 @@ export const synchronizeUserData = async (uid: Meteor.User['_id']): Promise<RawU
}
});

const userData = await APIClient.get('/v1/me');
const { ldap, lastLogin, services, ...userData } = await APIClient.get('/v1/me');

// email?: {
// verificationTokens?: IUserEmailVerificationToken[];
// };
// export interface IUserEmailVerificationToken {
// token: string;
// address: string;
// when: Date;
// }

if (userData) {
updateUser({
...userData,
...(services && {
...services,
...(services.email?.verificationTokens && {
email: {
verificationTokens: services.email.verificationTokens.map((token) => ({
...token,
when: new Date(token.when),
})),
},
}),
}),
...(lastLogin && {
lastLogin: new Date(lastLogin),
}),
ldap: Boolean(ldap),
createdAt: new Date(userData.createdAt),
_updatedAt: new Date(userData._updatedAt),
});
Expand Down
8 changes: 4 additions & 4 deletions apps/meteor/client/providers/ServerProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ const callEndpoint = <TMethod extends Method, TPath extends PathFor<TMethod>>(
): Promise<Serialized<OperationResult<TMethod, MatchPathPattern<TPath>>>> => {
switch (method) {
case 'GET':
return APIClient.get(path as Parameters<typeof APIClient.get>[0], params) as any;
return APIClient.get(path as Parameters<typeof APIClient.get>[0], params as any | undefined) as any;

case 'POST':
return APIClient.post(path as Parameters<typeof APIClient.post>[0], params) as ReturnType<typeof APIClient.post>;
return APIClient.post(path as Parameters<typeof APIClient.post>[0], params as never) as ReturnType<typeof APIClient.post>;

case 'DELETE':
return APIClient.delete(path as Parameters<typeof APIClient.delete>[0], params) as ReturnType<typeof APIClient.delete>;
return APIClient.delete(path as Parameters<typeof APIClient.delete>[0], params as never) as ReturnType<typeof APIClient.delete>;

default:
throw new Error('Invalid HTTP method');
}
};

const uploadToEndpoint = (endpoint: PathFor<'POST'>, formData: any): Promise<UploadResult> => APIClient.post(endpoint, formData);
const uploadToEndpoint = (endpoint: PathFor<'POST'>, formData: any): Promise<UploadResult> => APIClient.post(endpoint, formData as never);

const getStream = (streamName: string, options: {} = {}): (<T>(eventName: string, callback: (data: T) => void) => () => void) => {
const streamer = Meteor.StreamerCentral.instances[streamName]
Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/client/views/admin/apps/AppDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useMutableCallback } from '@rocket.chat/fuselage-hooks';
import { useTranslation, useCurrentRoute, useRoute, useRouteParameter } from '@rocket.chat/ui-contexts';
import React, { useState, useCallback, useRef, FC } from 'react';

import { ISettings, ISettingsPayload } from '../../../../app/apps/client/@types/IOrchestrator';
import { ISettings } from '../../../../app/apps/client/@types/IOrchestrator';
import { Apps } from '../../../../app/apps/client/orchestrator';
import Page from '../../../components/Page';
import APIsDisplay from './APIsDisplay';
Expand Down Expand Up @@ -49,7 +49,7 @@ const AppDetailsPage: FC<{ id: string }> = function AppDetailsPage({ id }) {
(Object.values(settings || {}) as ISetting[]).map((value) => ({
...value,
value: current?.[value.id],
})) as unknown as ISettingsPayload,
})),
);
} catch (e) {
handleAPIError(e);
Expand Down
3 changes: 1 addition & 2 deletions apps/meteor/client/views/admin/apps/hooks/useCategories.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useTranslation } from '@rocket.chat/ui-contexts';
import { useCallback, useEffect, useMemo, useState } from 'react';

import { ICategory } from '../../../../../app/apps/client/@types/IOrchestrator';
import { Apps } from '../../../../../app/apps/client/orchestrator';
import { CategoryDropdownItem, CategoryDropDownListProps } from '../definitions/CategoryDropdownDefinitions';
import { handleAPIError } from '../helpers';
Expand All @@ -21,7 +20,7 @@ export const useCategories = (): [
try {
const fetchedCategories = await Apps.getCategories();

const mappedCategories = fetchedCategories.map((currentCategory: ICategory) => ({
const mappedCategories = fetchedCategories.map((currentCategory) => ({
id: currentCategory.id,
label: currentCategory.title,
checked: false,
Expand Down
1 change: 1 addition & 0 deletions packages/core-typings/src/IUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export interface IUser extends IRocketChatRecord {
status?: UserStatus;
statusConnection?: string;
lastLogin?: Date;
bio?: string;
avatarOrigin?: string;
avatarETag?: string;
utcOffset?: number;
Expand Down
71 changes: 42 additions & 29 deletions packages/rest-typings/src/v1/me.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,48 @@
import type { IUser, Serialized } from '@rocket.chat/core-typings';
import type { IUser } from '@rocket.chat/core-typings';

type RawUserData = Serialized<
Pick<
IUser,
| '_id'
| 'type'
| 'name'
| 'username'
| 'emails'
| 'status'
| 'statusDefault'
| 'statusText'
| 'statusConnection'
| 'avatarOrigin'
| 'utcOffset'
| 'language'
| 'settings'
| 'roles'
| 'active'
| 'defaultRoom'
| 'customFields'
| 'statusLivechat'
| 'oauth'
| 'createdAt'
| '_updatedAt'
| 'avatarETag'
>
>;
type Keys =
| 'name'
| 'username'
| 'nickname'
| 'emails'
| 'status'
| 'statusDefault'
| 'statusText'
| 'statusConnection'
| 'bio'
| 'avatarOrigin'
| 'utcOffset'
| 'language'
| 'settings'
| 'idleTimeLimit'
| 'roles'
| 'active'
| 'defaultRoom'
| 'customFields'
| 'requirePasswordChange'
| 'requirePasswordChangeReason'
| 'services.github'
| 'services.gitlab'
| 'services.tokenpass'
| 'services.password.bcrypt'
| 'services.totp.enabled'
| 'services.email2fa.enabled'
| 'statusLivechat'
| 'banners'
| 'oauth.authorizedClients'
| '_updatedAt'
| 'avatarETag'
| 'extension';

export type MeEndpoints = {
'/v1/me': {
GET: () => RawUserData;
GET: (params: { fields: Record<Keys, 0> | Record<Keys, 1>; user: IUser }) => IUser & {
email?: string;
settings: {
profile: {};
preferences: unknown;
};
avatarUrl: string;
};
};
};
28 changes: 9 additions & 19 deletions packages/rest-typings/src/v1/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,45 +180,35 @@ export type MiscEndpoints = {
}[];
};
};
'me': {
GET: (params: { fields: { [k: string]: number }; user: IUser }) => IUser & {
email?: string;
settings: {
profile: {};
preferences: unknown;
};
avatarUrl: string;
};
};

'shield.svg': {
'/v1/shield.svg': {
GET: (params: ShieldSvg) => {
svg: string;
};
};

'spotlight': {
'/v1/spotlight': {
GET: (params: Spotlight) => {
users: Pick<IUser, 'username' | 'name' | 'status' | 'statusText' | 'avatarETag'>[];
rooms: IRoom[];
};
};

'directory': {
'/v1/directory': {
GET: (params: Directory) => PaginatedResult<{
result: (IUser | IRoom | ITeam)[];
}>;
};

'method.call': {
POST: (params: MethodCall) => {
result: unknown;
'/v1/method.call/:method': {
POST: (params: { message: string }) => {
message: unknown;
};
};

'method.callAnon': {
POST: (params: MethodCallAnon) => {
result: unknown;
'/v1/method.callAnon/:method': {
POST: (params: { message: string }) => {
message: unknown;
};
};
};

0 comments on commit 1edfa28

Please sign in to comment.