Dependencies upgrade (#510)

This commit is contained in:
Montassar Ghanmy
2024-05-07 17:01:56 +01:00
committed by GitHub
parent 0487ceb7b3
commit 3b20806622
15 changed files with 5080 additions and 5846 deletions
+3273 -4190
View File
File diff suppressed because it is too large Load Diff
+27 -28
View File
@@ -30,7 +30,7 @@
"test:unit:watch": "npm run test:unit -- --watchAll --verbose false | pino-pretty", "test:unit:watch": "npm run test:unit -- --watchAll --verbose false | pino-pretty",
"test:merge:json": "npx istanbul report --dir coverage/merged --include 'coverage/**/coverage-final.json' json-summary", "test:merge:json": "npx istanbul report --dir coverage/merged --include 'coverage/**/coverage-final.json' json-summary",
"test:merge:text": "npx istanbul report --dir coverage/merged --include 'coverage/**/coverage-final.json' text > coverage/merged/coverage-report.txt", "test:merge:text": "npx istanbul report --dir coverage/merged --include 'coverage/**/coverage-final.json' text > coverage/merged/coverage-report.txt",
"test:all": "jest test --forceExit --coverage --detectOpenHandles --testTimeout=300000 --verbose false --runInBand", "test:all": "jest test --forceExit --coverage --detectOpenHandles --testTimeout=600000 --verbose false --runInBand",
"kill": "kill $(lsof -t -i:3000) | exit 0" "kill": "kill $(lsof -t -i:3000) | exit 0"
}, },
"jest": { "jest": {
@@ -48,14 +48,14 @@
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+https://github.com/Tdrive/tdrive-backend.git" "url": "git+https://github.com/linagora/twake-drive.git"
}, },
"author": "Tdrive", "author": "Tdrive",
"license": "ISC", "license": "ISC",
"bugs": { "bugs": {
"url": "https://github.com/Tdrive/tdrive-backend/issues" "url": "https://github.com/linagora/twake-drive/issues"
}, },
"homepage": "https://github.com/Tdrive/tdrive-backend#readme", "homepage": "https://github.com/linagora/twake-drive#readme",
"bin": { "bin": {
"tdrive-cli": "bin/tdrive-cli" "tdrive-cli": "bin/tdrive-cli"
}, },
@@ -98,34 +98,37 @@
"prettier": "^2.1.2", "prettier": "^2.1.2",
"rimraf": "^3.0.2", "rimraf": "^3.0.2",
"ts-jest": "^29.1.2", "ts-jest": "^29.1.2",
"ts-node": "^9.0.0", "ts-node": "^10.9.2",
"ts-node-dev": "^1.1.8", "ts-node-dev": "^2.0.0",
"tsc-watch": "^4.2.9", "tsc-watch": "^4.2.9",
"tsconfig-paths": "^3.14.1", "tsconfig-paths": "^4.2.0",
"typescript": "^4.9.5" "typescript": "^5.4.5"
}, },
"dependencies": { "dependencies": {
"@elastic/elasticsearch": "7", "@elastic/elasticsearch": "7",
"@fastify/caching": "^7.0.0", "@fastify/caching": "^8.3.0",
"@fastify/cookie": "^6.0.0", "@fastify/cookie": "^9.3.1",
"@fastify/formbody": "^6.0.0", "@fastify/cors": "^9.0.1",
"@fastify/static": "^5.0.1", "@fastify/formbody": "^7.4.0",
"@fastify/jwt": "^8.0.0",
"@fastify/multipart": "^8.2.0",
"@fastify/sensible": "^5.6.0",
"@fastify/static": "^7.0.3",
"@fastify/swagger": "^8.14.0",
"@ffprobe-installer/ffprobe": "^1.4.1", "@ffprobe-installer/ffprobe": "^1.4.1",
"@opensearch-project/opensearch": "^2.4.0", "@opensearch-project/opensearch": "^2.4.0",
"@sentry/node": "^6.19.7", "@sentry/node": "^6.19.7",
"@sentry/tracing": "^6.19.7", "@sentry/tracing": "^6.19.7",
"@socket.io/redis-adapter": "^7.2.0", "@socket.io/redis-adapter": "^7.2.0",
"@types/http-proxy": "^1.17.11", "@types/http-proxy": "^1.17.14",
"@types/i18n": "^0.13.6", "@types/i18n": "^0.13.12",
"@types/pdf-parse": "^1.1.1", "@types/pdf-parse": "^1.1.4",
"@types/redis": "^4.0.11",
"@types/sharp": "^0.29.5", "@types/sharp": "^0.29.5",
"@types/socket.io-parser": "^3.0.0",
"amqp-connection-manager": "^3.7.0", "amqp-connection-manager": "^3.7.0",
"amqplib": "^0.8.0", "amqplib": "^0.8.0",
"analytics-node": "^5.0.0", "analytics-node": "^5.0.0",
"archiver": "^5.3.1", "archiver": "^5.3.1",
"axios": "^0.21.3", "axios": "^1.6.8",
"bcrypt": "^5.0.1", "bcrypt": "^5.0.1",
"cassandra-driver": "^4.6.0", "cassandra-driver": "^4.6.0",
"class-transformer": "^0.3.1", "class-transformer": "^0.3.1",
@@ -134,29 +137,25 @@
"deep-object-diff": "^1.1.0", "deep-object-diff": "^1.1.0",
"emoji-name-map": "^1.2.9", "emoji-name-map": "^1.2.9",
"eta": "^2.2.0", "eta": "^2.2.0",
"fastify": "^3.29.4", "fastify": "^4.26.2",
"fastify-cors": "^4.1.0", "fastify-cors": "^4.1.0",
"fastify-formbody": "^5.0.0",
"fastify-jwt": "^2.2.0", "fastify-jwt": "^2.2.0",
"fastify-multipart": "5.3.1", "fastify-multipart": "5.3.1",
"fastify-plugin": "^2.3.4", "fastify-plugin": "^4.5.1",
"fastify-sensible": "=3.0.1", "fastify-sensible": "=3.0.1",
"fastify-socket.io": "^3.0.0", "fastify-socket.io": "^5.0.0",
"fastify-static": "^4.7.0", "fastify-websocket": "^4.3.0",
"fastify-swagger": "^4.12.6",
"fastify-websocket": "^2.0.11",
"fluent-ffmpeg": "^2.1.2", "fluent-ffmpeg": "^2.1.2",
"fold-to-ascii": "^5.0.0", "fold-to-ascii": "^5.0.0",
"free-email-domains": "1.0.26", "free-email-domains": "1.0.26",
"generate-password": "^1.6.0", "generate-password": "^1.6.0",
"get-website-favicon": "^0.0.7",
"html-metadata-parser": "^2.0.4", "html-metadata-parser": "^2.0.4",
"html-to-text": "^8.2.1", "html-to-text": "^8.2.1",
"i18n": "^0.15.1", "i18n": "^0.15.1",
"idtoken-verifier": "^2.2.3",
"jsonwebtoken": "^9.0.0", "jsonwebtoken": "^9.0.0",
"jwks-rsa": "^3.0.1", "jwks-rsa": "^3.0.1",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"loupe": "^3.1.0",
"minio": "^7.1.3", "minio": "^7.1.3",
"moment": "^2.29.4", "moment": "^2.29.4",
"mongodb": "^5.9.2", "mongodb": "^5.9.2",
@@ -181,7 +180,7 @@
"redis": "3", "redis": "3",
"reflect-metadata": "^0.1.13", "reflect-metadata": "^0.1.13",
"rxjs": "^6.6.3", "rxjs": "^6.6.3",
"sharp": "^0.33.1", "sharp": "^0.33.3",
"short-uuid": "^4.2.2", "short-uuid": "^4.2.2",
"socket.io": "^4.6.2", "socket.io": "^4.6.2",
"socket.io-client": "^3.0.0", "socket.io-client": "^3.0.0",
+2 -2
View File
@@ -9,8 +9,8 @@ export interface authenticateDecorator {
declare module "fastify" { declare module "fastify" {
interface FastifyInstance { interface FastifyInstance {
authenticate(): void; authenticate(request: FastifyRequest): void;
authenticateOptional(): void; authenticateOptional(request: FastifyRequest): void;
io: SocketIO.Server; io: SocketIO.Server;
} }
@@ -9,7 +9,6 @@ export type TdriveLogger = pino.Logger;
export const logger = pino({ export const logger = pino({
name: "TdriveApp", name: "TdriveApp",
level: config.get("level", "info") || "info", level: config.get("level", "info") || "info",
prettyPrint: false,
mixin() { mixin() {
return executionStorage.getStore() ? executionStorage.getStore() : {}; return executionStorage.getStore() ? executionStorage.getStore() : {};
}, },
@@ -1,5 +1,5 @@
import { FastifyPluginCallback, FastifyRequest } from "fastify"; import { FastifyPluginCallback, FastifyRequest } from "fastify";
import fastifyJwt from "fastify-jwt"; import fastifyJwt from "@fastify/jwt";
import cookie from "@fastify/cookie"; import cookie from "@fastify/cookie";
import fp from "fastify-plugin"; import fp from "fastify-plugin";
import config from "../../../../config"; import config from "../../../../config";
@@ -1,6 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types */ /* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types */
import { EntityDefinition } from "../types";
type EntityOption = { type EntityOption = {
type?: string; type?: string;
ttl?: number; ttl?: number;
@@ -18,11 +16,10 @@ type EntityOption = {
export function Entity(name: string, options: EntityOption): ClassDecorator { export function Entity(name: string, options: EntityOption): ClassDecorator {
// eslint-disable-next-line @typescript-eslint/ban-types // eslint-disable-next-line @typescript-eslint/ban-types
return function (constructor: Function): void { return function (constructor: Function): void {
const entityDefinition: EntityDefinition = { constructor.prototype._entity = {
name, name,
type: options.type || name, type: options.type || name,
options, options,
}; };
constructor.prototype._entity = entityDefinition;
}; };
} }
@@ -115,6 +115,10 @@ export default class StorageService extends TdriveService<StorageAPI> implements
const chunks = options?.totalChunks || 1; const chunks = options?.totalChunks || 1;
let count = 1; let count = 1;
//check that the file a really exists
await self._read(options?.totalChunks ? `${path}/chunk${count}` : path);
let stream: any; let stream: any;
async function factory(callback: (err?: Error, stream?: Stream) => unknown) { async function factory(callback: (err?: Error, stream?: Stream) => unknown) {
if (count > chunks) { if (count > chunks) {
@@ -136,6 +140,7 @@ export default class StorageService extends TdriveService<StorageAPI> implements
if (decipher) { if (decipher) {
stream = stream.pipe(decipher); stream = stream.pipe(decipher);
} }
callback(null, stream);
} catch (err) { } catch (err) {
logger.error(err); logger.error(err);
callback(err, null); callback(err, null);
@@ -163,6 +168,7 @@ export default class StorageService extends TdriveService<StorageAPI> implements
stream = stream.pipe(decipher); stream = stream.pipe(decipher);
} catch (err) { } catch (err) {
logger.error("Unable to createDecipheriv: %s", err); logger.error("Unable to createDecipheriv: %s", err);
throw err;
} }
} }
return stream; return stream;
@@ -1,19 +1,20 @@
import { logger, TdriveService } from "../../framework"; import { logger, TdriveService } from "../../framework";
import { Server, IncomingMessage, ServerResponse } from "http"; import { Server, IncomingMessage, ServerResponse } from "http";
import { FastifyInstance, fastify } from "fastify"; import { FastifyInstance, fastify, FastifyRegisterOptions, FastifyServerOptions } from "fastify";
import sensible from "fastify-sensible"; import sensible from "@fastify/sensible";
import multipart from "fastify-multipart"; import multipart from "fastify-multipart";
import formbody from "@fastify/formbody"; import formbody from "@fastify/formbody";
import fastifyStatic from "@fastify/static"; import fastifyStatic from "@fastify/static";
import corsPlugin, { FastifyCorsOptions } from "fastify-cors"; import corsPlugin, { FastifyCorsOptions } from "@fastify/cors";
import { serverErrorHandler } from "./error"; import { serverErrorHandler } from "./error";
import WebServerAPI from "./provider"; import WebServerAPI from "./provider";
import jwtPlugin from "../auth/web/jwt"; import jwtPlugin from "../auth/web/jwt";
import path from "path"; import path from "path";
import swaggerPlugin from "fastify-swagger"; import swaggerPlugin, { FastifySwaggerOptions } from "@fastify/swagger";
import { SkipCLI } from "../../framework/decorators/skip"; import { SkipCLI } from "../../framework/decorators/skip";
import fs from "fs"; import fs from "fs";
import { ExecutionContext, executionStorage } from "../../framework/execution-storage"; import { ExecutionContext, executionStorage } from "../../framework/execution-storage";
import { FastifyListenOptions } from "fastify/types/instance";
export default class WebServerService extends TdriveService<WebServerAPI> implements WebServerAPI { export default class WebServerService extends TdriveService<WebServerAPI> implements WebServerAPI {
name = "webserver"; name = "webserver";
@@ -102,9 +103,11 @@ export default class WebServerService extends TdriveService<WebServerAPI> implem
staticCSP: false, staticCSP: false,
transformStaticCSP: header => header, transformStaticCSP: header => header,
exposeRoute: true, exposeRoute: true,
}); } as FastifyRegisterOptions<FastifySwaggerOptions>);
this.server.register(jwtPlugin); this.server.register(jwtPlugin);
this.server.register(sensible, { errorHandler: false }); this.server.register(sensible, {
errorHandler: false,
} as FastifyRegisterOptions<FastifyServerOptions>);
this.server.register(multipart); this.server.register(multipart);
this.server.register(formbody); this.server.register(formbody);
this.server.register(corsPlugin, this.configuration.get<FastifyCorsOptions>("cors", {})); this.server.register(corsPlugin, this.configuration.get<FastifyCorsOptions>("cors", {}));
@@ -138,7 +141,10 @@ export default class WebServerService extends TdriveService<WebServerAPI> implem
res.type("text/html").send(stream); res.type("text/html").send(stream);
}); });
await this.server.listen(this.configuration.get<number>("port", 3000), "0.0.0.0"); await this.server.listen({
port: this.configuration.get<number>("port", 3000),
host: "0.0.0.0",
} as FastifyListenOptions);
this.server.ready(err => { this.server.ready(err => {
if (err) throw err; if (err) throw err;
@@ -1,4 +1,4 @@
import { FastifyInstance, FastifyReply, FastifyRequest, HTTPMethods } from "fastify"; import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
import _ from "lodash"; import _ from "lodash";
import { v4 } from "uuid"; import { v4 } from "uuid";
import { CrudException } from "../../../../core/platform/framework/api/crud-service"; import { CrudException } from "../../../../core/platform/framework/api/crud-service";
@@ -155,7 +155,7 @@ export class ApplicationsApiController {
fastify.inject( fastify.inject(
{ {
method: request.method as HTTPMethods, method: request.method as any,
url: route, url: route,
payload: request.body as any, payload: request.body as any,
headers: _.pick(request.headers, "authorization"), headers: _.pick(request.headers, "authorization"),
@@ -20,7 +20,7 @@ export class FileController {
if (request.isMultipart()) { if (request.isMultipart()) {
file = await request.file(); file = await request.file();
} }
const q = request.query; const q: any = request.query;
const options: UploadOptions = { const options: UploadOptions = {
totalChunks: parseInt(q.resumableTotalChunks || q.total_chunks) || 1, totalChunks: parseInt(q.resumableTotalChunks || q.total_chunks) || 1,
totalSize: parseInt(q.resumableTotalSize || q.total_size) || 0, totalSize: parseInt(q.resumableTotalSize || q.total_size) || 0,
@@ -126,7 +126,7 @@ export class FileController {
file = await request.file(); file = await request.file();
} }
const q = request.query; const q: any = request.query;
const options: any = { const options: any = {
totalChunks: parseInt(q.resumableTotalChunks || q.total_chunks) || 1, totalChunks: parseInt(q.resumableTotalChunks || q.total_chunks) || 1,
chunkNumber: parseInt(q.resumableChunkNumber || q.chunk_number) || 1, chunkNumber: parseInt(q.resumableChunkNumber || q.chunk_number) || 1,
@@ -22,7 +22,6 @@ import {
WorkspaceBaseRequest, WorkspaceBaseRequest,
WorkspaceInviteDomainBody, WorkspaceInviteDomainBody,
WorkspaceRequest, WorkspaceRequest,
WorkspaceUsersBaseRequest,
WorkspaceUsersRequest, WorkspaceUsersRequest,
} from "./types"; } from "./types";
import { WorkspaceUsersCrudController } from "./controllers/workspace-users"; import { WorkspaceUsersCrudController } from "./controllers/workspace-users";
@@ -52,25 +51,28 @@ const routes: FastifyPluginCallback = (fastify: FastifyInstance, options, next)
} }
}; };
const companyCheck = async (request: FastifyRequest<{ Params: WorkspaceBaseRequest }>) => { const companyCheck = async (request: FastifyRequest) => {
await checkUserBelongsToCompany(request.currentUser.id, request.params.company_id); await checkUserBelongsToCompany(
request.currentUser.id,
(request.params as WorkspaceBaseRequest).company_id,
);
}; };
const checkWorkspace = async (request: FastifyRequest<{ Params: WorkspaceUsersBaseRequest }>) => { const checkWorkspace = async (request: FastifyRequest) => {
const params = request.params as WorkspaceUsersRequest;
const workspace = await gr.services.workspaces.get({ const workspace = await gr.services.workspaces.get({
company_id: request.params.company_id, company_id: params.company_id,
id: request.params.workspace_id, id: params.workspace_id,
}); });
if (!workspace) { if (!workspace) {
throw fastify.httpErrors.notFound(`Workspace ${request.params.workspace_id} not found`); throw fastify.httpErrors.notFound(`Workspace ${params.workspace_id} not found`);
} }
}; };
const checkUserWorkspace = async ( const checkUserWorkspace = async (request: FastifyRequest): Promise<WorkspaceUser> => {
request: FastifyRequest<{ Params: WorkspaceUsersRequest }>, const params = request.params as WorkspaceUsersRequest;
): Promise<WorkspaceUser> => { const companyId = params.workspace_id;
const companyId = request.params.workspace_id; const workspaceId = params.workspace_id;
const workspaceId = request.params.workspace_id;
const userId = request.currentUser.id; const userId = request.currentUser.id;
const workspaceUser = await gr.services.workspaces.getUser({ const workspaceUser = await gr.services.workspaces.getUser({
workspaceId, workspaceId,
@@ -91,14 +93,12 @@ const routes: FastifyPluginCallback = (fastify: FastifyInstance, options, next)
return workspaceUser; return workspaceUser;
}; };
const checkUserHasCompanyMemberLevel = async ( const checkUserHasCompanyMemberLevel = async (request: FastifyRequest) => {
request: FastifyRequest<{ Params: WorkspaceUsersRequest }>,
) => {
if (!request.currentUser.id) { if (!request.currentUser.id) {
throw fastify.httpErrors.forbidden("You must be authenticated"); throw fastify.httpErrors.forbidden("You must be authenticated");
} }
const companyUser = await gr.services.companies.getCompanyUser( const companyUser = await gr.services.companies.getCompanyUser(
{ id: request.params.company_id }, { id: (request.params as WorkspaceUsersRequest).company_id },
{ id: request.currentUser.id }, { id: request.currentUser.id },
); );
@@ -107,15 +107,14 @@ const routes: FastifyPluginCallback = (fastify: FastifyInstance, options, next)
} }
}; };
const checkUserIsWorkspaceAdmin = async ( const checkUserIsWorkspaceAdmin = async (request: FastifyRequest) => {
request: FastifyRequest<{ Params: WorkspaceUsersRequest }>,
) => {
if (!request.currentUser.id) { if (!request.currentUser.id) {
throw fastify.httpErrors.forbidden("You must be authenticated"); throw fastify.httpErrors.forbidden("You must be authenticated");
} }
const workspaceUser = await checkUserWorkspace(request); const workspaceUser = await checkUserWorkspace(request);
const params = request.params as WorkspaceUsersRequest;
const companyUser = await gr.services.companies.getCompanyUser( const companyUser = await gr.services.companies.getCompanyUser(
{ id: request.params.company_id }, { id: params.company_id },
{ id: request.currentUser.id }, { id: request.currentUser.id },
); );
if (!hasWorkspaceAdminLevel(workspaceUser?.role, companyUser?.role)) { if (!hasWorkspaceAdminLevel(workspaceUser?.role, companyUser?.role)) {
@@ -123,15 +122,13 @@ const routes: FastifyPluginCallback = (fastify: FastifyInstance, options, next)
} }
}; };
const checkUserIsWorkspaceMember = async ( const checkUserIsWorkspaceMember = async (request: FastifyRequest) => {
request: FastifyRequest<{ Params: WorkspaceUsersRequest }>,
) => {
if (!request.currentUser.id) { if (!request.currentUser.id) {
throw fastify.httpErrors.forbidden("You must be authenticated"); throw fastify.httpErrors.forbidden("You must be authenticated");
} }
const workspaceUser = await checkUserWorkspace(request); const workspaceUser = await checkUserWorkspace(request);
const companyUser = await gr.services.companies.getCompanyUser( const companyUser = await gr.services.companies.getCompanyUser(
{ id: request.params.company_id }, { id: (request.params as WorkspaceUsersRequest).company_id },
{ id: request.currentUser.id }, { id: request.currentUser.id },
); );
if (!hasWorkspaceMemberLevel(workspaceUser?.role, companyUser?.role)) { if (!hasWorkspaceMemberLevel(workspaceUser?.role, companyUser?.role)) {
@@ -161,7 +158,7 @@ const routes: FastifyPluginCallback = (fastify: FastifyInstance, options, next)
method: "GET", method: "GET",
url: `${workspacesUrl}`, url: `${workspacesUrl}`,
preHandler: [accessControl, companyCheck], preHandler: [accessControl, companyCheck],
preValidation: [fastify.authenticate], preValidation: fastify.authenticate,
schema: getWorkspacesSchema, schema: getWorkspacesSchema,
handler: workspacesController.list.bind(workspacesController), handler: workspacesController.list.bind(workspacesController),
}); });
@@ -170,7 +167,7 @@ const routes: FastifyPluginCallback = (fastify: FastifyInstance, options, next)
method: "GET", method: "GET",
url: `${workspacesUrl}/:id`, url: `${workspacesUrl}/:id`,
preHandler: [accessControl, companyCheck], preHandler: [accessControl, companyCheck],
preValidation: [fastify.authenticate], preValidation: fastify.authenticate,
schema: getWorkspaceSchema, schema: getWorkspaceSchema,
handler: workspacesController.get.bind(workspacesController), handler: workspacesController.get.bind(workspacesController),
}); });
@@ -185,7 +182,7 @@ const routes: FastifyPluginCallback = (fastify: FastifyInstance, options, next)
method: "POST", method: "POST",
url: `${workspacesUrl}`, url: `${workspacesUrl}`,
preHandler: [accessControl, companyCheck], preHandler: [accessControl, companyCheck],
preValidation: [fastify.authenticate], preValidation: fastify.authenticate,
schema: createWorkspaceSchema, schema: createWorkspaceSchema,
handler: workspacesController.save.bind(workspacesController), handler: workspacesController.save.bind(workspacesController),
}); });
@@ -194,7 +191,7 @@ const routes: FastifyPluginCallback = (fastify: FastifyInstance, options, next)
method: "POST", method: "POST",
url: `${workspacesUrl}/:id`, url: `${workspacesUrl}/:id`,
preHandler: [accessControl, companyCheck], preHandler: [accessControl, companyCheck],
preValidation: [fastify.authenticate], preValidation: fastify.authenticate,
schema: updateWorkspaceSchema, schema: updateWorkspaceSchema,
handler: workspacesController.save.bind(workspacesController), handler: workspacesController.save.bind(workspacesController),
}); });
@@ -203,7 +200,7 @@ const routes: FastifyPluginCallback = (fastify: FastifyInstance, options, next)
method: "DELETE", method: "DELETE",
url: `${workspacesUrl}/:id`, url: `${workspacesUrl}/:id`,
preHandler: [accessControl, companyCheck], preHandler: [accessControl, companyCheck],
preValidation: [fastify.authenticate], preValidation: fastify.authenticate,
handler: workspacesController.delete.bind(workspacesController), handler: workspacesController.delete.bind(workspacesController),
}); });
@@ -211,7 +208,7 @@ const routes: FastifyPluginCallback = (fastify: FastifyInstance, options, next)
method: "POST", method: "POST",
url: `${workspacesUrl}/:id/invite_domain`, url: `${workspacesUrl}/:id/invite_domain`,
preHandler: [validateDomain, companyCheck], preHandler: [validateDomain, companyCheck],
preValidation: [fastify.authenticate], preValidation: fastify.authenticate,
handler: workspacesController.setInviteDomain.bind(workspacesController), handler: workspacesController.setInviteDomain.bind(workspacesController),
}); });
@@ -219,7 +216,7 @@ const routes: FastifyPluginCallback = (fastify: FastifyInstance, options, next)
method: "GET", method: "GET",
url: `${workspaceUsersUrl}`, url: `${workspaceUsersUrl}`,
preHandler: [accessControl, companyCheck, checkWorkspace], preHandler: [accessControl, companyCheck, checkWorkspace],
preValidation: [fastify.authenticate], preValidation: fastify.authenticate,
schema: getWorkspaceUsersSchema, schema: getWorkspaceUsersSchema,
handler: workspaceUsersController.list.bind(workspaceUsersController), handler: workspaceUsersController.list.bind(workspaceUsersController),
}); });
@@ -228,7 +225,7 @@ const routes: FastifyPluginCallback = (fastify: FastifyInstance, options, next)
method: "GET", method: "GET",
url: `${workspaceUsersUrl}/:user_id`, url: `${workspaceUsersUrl}/:user_id`,
preHandler: [accessControl, companyCheck, checkWorkspace], preHandler: [accessControl, companyCheck, checkWorkspace],
preValidation: [fastify.authenticate], preValidation: fastify.authenticate,
schema: getWorkspaceUserSchema, schema: getWorkspaceUserSchema,
handler: workspaceUsersController.get.bind(workspaceUsersController), handler: workspaceUsersController.get.bind(workspaceUsersController),
}); });
@@ -237,7 +234,7 @@ const routes: FastifyPluginCallback = (fastify: FastifyInstance, options, next)
method: "POST", method: "POST",
url: `${workspaceUsersUrl}`, url: `${workspaceUsersUrl}`,
preHandler: [accessControl, companyCheck, checkUserIsWorkspaceAdmin], preHandler: [accessControl, companyCheck, checkUserIsWorkspaceAdmin],
preValidation: [fastify.authenticate], preValidation: fastify.authenticate,
schema: createWorkspaceUserSchema, schema: createWorkspaceUserSchema,
handler: workspaceUsersController.save.bind(workspaceUsersController), handler: workspaceUsersController.save.bind(workspaceUsersController),
}); });
@@ -246,7 +243,7 @@ const routes: FastifyPluginCallback = (fastify: FastifyInstance, options, next)
method: "POST", method: "POST",
url: `${workspaceUsersUrl}/:user_id`, url: `${workspaceUsersUrl}/:user_id`,
preHandler: [accessControl, companyCheck, checkUserIsWorkspaceAdmin], preHandler: [accessControl, companyCheck, checkUserIsWorkspaceAdmin],
preValidation: [fastify.authenticate], preValidation: fastify.authenticate,
schema: updateWorkspaceUserSchema, schema: updateWorkspaceUserSchema,
handler: workspaceUsersController.save.bind(workspaceUsersController), handler: workspaceUsersController.save.bind(workspaceUsersController),
}); });
@@ -255,7 +252,7 @@ const routes: FastifyPluginCallback = (fastify: FastifyInstance, options, next)
method: "DELETE", method: "DELETE",
url: `${workspaceUsersUrl}/:user_id`, url: `${workspaceUsersUrl}/:user_id`,
preHandler: [accessControl, companyCheck, checkUserIsWorkspaceAdmin], preHandler: [accessControl, companyCheck, checkUserIsWorkspaceAdmin],
preValidation: [fastify.authenticate], preValidation: fastify.authenticate,
schema: deleteWorkspaceUserSchema, schema: deleteWorkspaceUserSchema,
handler: workspaceUsersController.delete.bind(workspaceUsersController), handler: workspaceUsersController.delete.bind(workspaceUsersController),
}); });
@@ -269,7 +266,7 @@ const routes: FastifyPluginCallback = (fastify: FastifyInstance, options, next)
checkUserHasCompanyMemberLevel, checkUserHasCompanyMemberLevel,
checkUserIsWorkspaceMember, checkUserIsWorkspaceMember,
], ],
preValidation: [fastify.authenticate], preValidation: fastify.authenticate,
schema: inviteWorkspaceUserSchema, schema: inviteWorkspaceUserSchema,
handler: workspaceUsersController.invite.bind(workspaceUsersController), handler: workspaceUsersController.invite.bind(workspaceUsersController),
}); });
@@ -283,7 +280,7 @@ const routes: FastifyPluginCallback = (fastify: FastifyInstance, options, next)
checkUserHasCompanyMemberLevel, checkUserHasCompanyMemberLevel,
checkUserIsWorkspaceMember, checkUserIsWorkspaceMember,
], ],
preValidation: [fastify.authenticate], preValidation: fastify.authenticate,
schema: deleteWorkspacePendingUsersSchema, schema: deleteWorkspacePendingUsersSchema,
handler: workspaceUsersController.deletePending.bind(workspaceUsersController), handler: workspaceUsersController.deletePending.bind(workspaceUsersController),
}); });
@@ -297,7 +294,7 @@ const routes: FastifyPluginCallback = (fastify: FastifyInstance, options, next)
checkUserHasCompanyMemberLevel, checkUserHasCompanyMemberLevel,
checkUserIsWorkspaceMember, checkUserIsWorkspaceMember,
], ],
preValidation: [fastify.authenticate], preValidation: fastify.authenticate,
schema: getWorkspacePendingUsersSchema, schema: getWorkspacePendingUsersSchema,
handler: workspaceUsersController.listPending.bind(workspaceUsersController), handler: workspaceUsersController.listPending.bind(workspaceUsersController),
}); });
@@ -311,7 +308,7 @@ const routes: FastifyPluginCallback = (fastify: FastifyInstance, options, next)
checkUserIsWorkspaceMember, checkUserIsWorkspaceMember,
checkUserHasCompanyMemberLevel, checkUserHasCompanyMemberLevel,
], ],
preValidation: [fastify.authenticate], preValidation: fastify.authenticate,
schema: getWorkspaceInviteTokenSchema, schema: getWorkspaceInviteTokenSchema,
handler: workspaceInviteTokensController.list.bind(workspaceInviteTokensController), handler: workspaceInviteTokensController.list.bind(workspaceInviteTokensController),
}); });
@@ -325,7 +322,7 @@ const routes: FastifyPluginCallback = (fastify: FastifyInstance, options, next)
checkUserIsWorkspaceMember, checkUserIsWorkspaceMember,
checkUserHasCompanyMemberLevel, checkUserHasCompanyMemberLevel,
], ],
preValidation: [fastify.authenticate], preValidation: fastify.authenticate,
schema: postWorkspaceInviteTokenSchema, schema: postWorkspaceInviteTokenSchema,
handler: workspaceInviteTokensController.save.bind(workspaceInviteTokensController), handler: workspaceInviteTokensController.save.bind(workspaceInviteTokensController),
}); });
@@ -339,7 +336,7 @@ const routes: FastifyPluginCallback = (fastify: FastifyInstance, options, next)
checkUserIsWorkspaceMember, checkUserIsWorkspaceMember,
checkUserHasCompanyMemberLevel, checkUserHasCompanyMemberLevel,
], ],
preValidation: [fastify.authenticate], preValidation: fastify.authenticate,
schema: deleteWorkspaceInviteTokenSchema, schema: deleteWorkspaceInviteTokenSchema,
handler: workspaceInviteTokensController.delete.bind(workspaceInviteTokensController), handler: workspaceInviteTokensController.delete.bind(workspaceInviteTokensController),
}); });
@@ -348,7 +345,7 @@ const routes: FastifyPluginCallback = (fastify: FastifyInstance, options, next)
method: "POST", method: "POST",
url: "/join", url: "/join",
preHandler: [], preHandler: [],
preValidation: [fastify.authenticateOptional], preValidation: fastify.authenticateOptional,
schema: joinInviteTokenSchema, schema: joinInviteTokenSchema,
handler: workspaceInviteTokensController.join.bind(workspaceInviteTokensController), handler: workspaceInviteTokensController.join.bind(workspaceInviteTokensController),
}); });
+1 -1
View File
@@ -1,5 +1,5 @@
import { FastifyReply } from "fastify"; import { FastifyReply } from "fastify";
import { HttpErrorCodes } from "fastify-sensible/lib/httpError"; import { HttpErrorCodes } from "@fastify/sensible/lib/httpError";
import { CrudException } from "../core/platform/framework/api/crud-service"; import { CrudException } from "../core/platform/framework/api/crud-service";
export function handleError(reply: FastifyReply, err: Error): void { export function handleError(reply: FastifyReply, err: Error): void {
@@ -27,8 +27,8 @@ describe('The PostgresQueryBuilder', () => {
const query = subj.buildSelect(TestDbEntity, filter as { [key: string]: any }, null); const query = subj.buildSelect(TestDbEntity, filter as { [key: string]: any }, null);
//then //then
expect(normalizeWhitespace(query[0] as string)).toBe(`SELECT * FROM "test_table" WHERE id = $1 AND company_id = $2 ORDER BY id DESC LIMIT 100 OFFSET 0`); expect(normalizeWhitespace(query[0] as string)).toBe(`SELECT * FROM "test_table" WHERE company_id = $1 AND id = $2 ORDER BY id DESC LIMIT 100 OFFSET 0`);
expect(query[1]).toEqual([filter.id, filter.company_id]); expect(query[1]).toEqual([filter.company_id, filter.id]);
}); });
test('buildSelect query with array in filters', async () => { test('buildSelect query with array in filters', async () => {
+1 -2
View File
@@ -5,7 +5,7 @@
"module": "commonjs", "module": "commonjs",
"esModuleInterop": true, "esModuleInterop": true,
"allowSyntheticDefaultImports": true, "allowSyntheticDefaultImports": true,
"target": "es6", "target": "ESNext",
"noImplicitAny": false, "noImplicitAny": false,
"moduleResolution": "node", "moduleResolution": "node",
"sourceMap": true, "sourceMap": true,
@@ -13,7 +13,6 @@
"baseUrl": ".", "baseUrl": ".",
"paths": { "paths": {
"*": [ "*": [
"node_modules/*",
"src/types/*" "src/types/*"
], ],
"src/*": ["src/*"] "src/*": ["src/*"]
+1710 -1562
View File
File diff suppressed because it is too large Load Diff