Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into chore/assets-endpo…
Browse files Browse the repository at this point in the history
…ints-to-ts
  • Loading branch information
ggazzo committed Jun 17, 2022
2 parents 6b4769b + 6b6f9dc commit 1fb1259
Show file tree
Hide file tree
Showing 318 changed files with 8,078 additions and 10,104 deletions.
1 change: 1 addition & 0 deletions .github/auto-label-action-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
11 changes: 11 additions & 0 deletions .github/workflows/auto-label.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: 'Auto label QA'
on:
pull_request:
types: [opened, synchronize, labeled, unlabeled]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: ggazzo/gh-action-auto-label@beta-5
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7 changes: 5 additions & 2 deletions .kodiak.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# .kodiak.toml
version = 1


[merge]
method = "squash"
automerge_label = ["stat: ready to merge", "QA tested", "automerge"]
automerge_label = ["stat: ready to merge", "automerge"]
block_on_neutral_required_check_runs = true
blocking_labels = ["stat: needs QA", "Invalid PR Title"]
prioritize_ready_to_merge = true


[merge.message]
title = "pull_request_title" # default: "github_default"
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/.docker/Dockerfile.rhel
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM registry.access.redhat.com/ubi8/nodejs-12

ENV RC_VERSION 5.0.0
ENV RC_VERSION 5.0.0-develop

MAINTAINER buildmaster@rocket.chat

Expand Down
7 changes: 6 additions & 1 deletion apps/meteor/.mocharc.api.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,10 @@ module.exports = {
timeout: 10000,
bail: true,
file: 'tests/end-to-end/teardown.js',
spec: ['tests/unit/app/api/server/v1/*.spec.ts', 'tests/end-to-end/api/*.js', 'tests/end-to-end/api/*.ts', 'tests/end-to-end/apps/*.js'],
spec: [
'tests/unit/app/api/server/v1/**/*.spec.ts',
'tests/end-to-end/api/*.js',
'tests/end-to-end/api/*.ts',
'tests/end-to-end/apps/*.js',
],
};
20 changes: 18 additions & 2 deletions apps/meteor/.storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,24 @@ const { resolve, relative, join } = require('path');
const webpack = require('webpack');

module.exports = {
stories: ['../app/**/*.stories.{js,tsx}', '../client/**/*.stories.{js,tsx}', '../ee/**/*.stories.{js,tsx}'],
addons: ['@storybook/addon-essentials', '@storybook/addon-interactions', '@storybook/addon-postcss'],
stories: [
'../client/**/*.stories.{js,tsx}',
'../app/**/*.stories.{js,tsx}',
'../ee/app/**/*.stories.{js,tsx}',
'../ee/client/**/*.stories.{js,tsx}',
],
addons: [
'@storybook/addon-essentials',
'@storybook/addon-interactions',
{
name: '@storybook/addon-postcss',
options: {
postcssLoaderOptions: {
implementation: require('postcss'),
},
},
},
],
webpackFinal: async (config) => {
const cssRule = config.module.rules.find(({ test }) => test.test('index.css'));

Expand Down
17 changes: 10 additions & 7 deletions apps/meteor/app/api/server/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
} from '@rocket.chat/rest-typings';
import type { IUser, IMethodConnection, IRoom } from '@rocket.chat/core-typings';
import type { ValidateFunction } from 'ajv';
import type { Request, Response } from 'express';

import { ITwoFactorOptions } from '../../2fa/server/code';

Expand Down Expand Up @@ -70,20 +71,15 @@ type Options = (
validateParams?: ValidateFunction;
};

type Request = {
method: 'GET' | 'POST' | 'PUT' | 'DELETE';
url: string;
headers: Record<string, string>;
body: any;
};

type PartialThis = {
readonly request: Request & { query: Record<string, string> };
readonly response: Response;
};

type ActionThis<TMethod extends Method, TPathPattern extends PathPattern, TOptions> = {
readonly requestIp: string;
urlParams: UrlParams<TPathPattern>;
readonly response: Response;
// TODO make it unsafe
readonly queryParams: TMethod extends 'GET'
? TOptions extends { validateParams: ValidateFunction<infer T> }
Expand All @@ -97,6 +93,9 @@ type ActionThis<TMethod extends Method, TPathPattern extends PathPattern, TOptio
? T
: Partial<OperationParams<TMethod, TPathPattern>>;
readonly request: Request;

readonly queryOperations: TOptions extends { queryOperations: infer T } ? T : never;

/* @deprecated */
requestParams(): OperationParams<TMethod, TPathPattern>;
getLoggedInUser(): TOptions extends { authRequired: true } ? IUser : IUser | undefined;
Expand All @@ -112,6 +111,8 @@ type ActionThis<TMethod extends Method, TPathPattern extends PathPattern, TOptio
/* @deprecated */
getUserFromParams(): IUser;
/* @deprecated */
isUserFromParams(): boolean;
/* @deprecated */
getUserInfo(me: IUser): TOptions extends { authRequired: true }
? IUser & {
email?: string;
Expand Down Expand Up @@ -159,6 +160,8 @@ type Operations<TPathPattern extends PathPattern, TOptions extends Options = {}>
declare class APIClass<TBasePath extends string = '/'> {
fieldSeparator: string;

updateRateLimiterDictionaryForRoute(route: string, rateLimiterDictionary: number): void;

limitedUserFieldsToExclude(fields: { [x: string]: unknown }, limitedUserFieldsToExclude: unknown): { [x: string]: unknown };

limitedUserFieldsToExcludeIfIsPrivilegedUser(
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/api/server/helpers/parseJsonQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ API.helperMethods.set(
if (typeof fields === 'object') {
let nonSelectableFields = Object.keys(API.v1.defaultFieldsToExclude);
if (this.request.route.includes('/v1/users.')) {
const getFields = () =>
const getFields = (): string[] =>
Object.keys(
hasPermission(this.userId, 'view-full-other-user-info')
? API.v1.limitedUserFieldsToExcludeIfIsPrivilegedUser
Expand Down
20 changes: 0 additions & 20 deletions apps/meteor/app/api/server/lib/emoji-custom.js

This file was deleted.

34 changes: 34 additions & 0 deletions apps/meteor/app/api/server/lib/emoji-custom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { IEmojiCustom, ILivechatDepartmentRecord } from '@rocket.chat/core-typings';
import { FilterQuery, SortOptionObject } from 'mongodb';

import { EmojiCustom } from '../../../models/server/raw';

export async function findEmojisCustom({
query = {},
pagination: { offset, count, sort },
}: {
query: FilterQuery<ILivechatDepartmentRecord>;
pagination: { offset: number; count: number; sort: SortOptionObject<IEmojiCustom> };
}): Promise<{
emojis: IEmojiCustom[];
count: number;
offset: any;
total: number;
}> {
const cursor = EmojiCustom.find(query, {
sort: sort || { name: 1 },
skip: offset,
limit: count,
});

const total = await cursor.count();

const emojis = await cursor.toArray();

return {
emojis,
count: emojis.length,
offset,
total,
};
}
99 changes: 70 additions & 29 deletions apps/meteor/app/api/server/lib/getUploadFormData.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,90 @@
import { Readable } from 'stream';

import { Meteor } from 'meteor/meteor';
import type { Request } from 'express';
import busboy from 'busboy';
import { Request } from 'express';
import { ValidateFunction } from 'ajv';

export interface IFormDataFields {
file: any;
type UploadResult = {
file: Readable;
filename: string;
encoding: string;
mimetype: string;
fileBuffer: Buffer;
}

export interface IFormDataUpload {
[key: string]: IFormDataFields | any;
}
};

export const getUploadFormData = async ({ request }: { request: Request }): Promise<IFormDataUpload> =>
new Promise<IFormDataUpload>((resolve, reject) => {
export const getUploadFormData = async <T extends string, K, V extends ValidateFunction<K>>(
{ request }: { request: Request },
options: {
field?: T;
validate?: V;
} = {},
): Promise<
[
UploadResult,
K extends unknown
? {
[k: string]: string;
}
: K,
T,
]
> =>
new Promise((resolve, reject) => {
const bb = busboy({ headers: request.headers, defParamCharset: 'utf8' });
const fields: { [K: string]: string } = Object.create(null);

const fields: IFormDataUpload = {};
let uploadedFile: UploadResult | undefined;

bb.on('file', (fieldname: string, file: any, { filename, encoding, mimeType: mimetype }: Record<string, any>) => {
const fileData: any[] = [];
let assetName: T | undefined;

file.on('data', (data: any) => fileData.push(data));
bb.on(
'file',
(
fieldname: string,
file: Readable,
{ filename, encoding, mimeType: mimetype }: { filename: string; encoding: string; mimeType: string },
) => {
const fileData: Uint8Array[] = [];

file.on('end', () => {
if (fields.hasOwnProperty(fieldname)) {
return reject('Just 1 file is allowed');
}
file.on('data', (data: any) => fileData.push(data));

fields[fieldname] = {
file,
filename,
encoding,
mimetype,
fileBuffer: Buffer.concat(fileData),
};
});
});
file.on('end', () => {
if (uploadedFile) {
return reject('Just 1 file is allowed');
}
if (options.field && fieldname !== options.field) {
return reject(new Meteor.Error('invalid-field'));
}
uploadedFile = {
file,
filename,
encoding,
mimetype,
fileBuffer: Buffer.concat(fileData),
};

bb.on('field', (fieldname: string, value: any) => {
assetName = fieldname as T;
});
},
);

bb.on('field', (fieldname, value) => {
fields[fieldname] = value;
});

bb.on('finish', () => resolve(fields));
bb.on('finish', () => {
if (!uploadedFile || !assetName) {
return reject('No file uploaded');
}
if (options.validate === undefined) {
return resolve([uploadedFile, fields, assetName]);
}
if (!options.validate(fields)) {
return reject(`Invalid fields${options.validate.errors?.join(', ')}`);
}
return resolve([uploadedFile, fields, assetName]);
});

request.pipe(bb);
});
Loading

0 comments on commit 1fb1259

Please sign in to comment.