Skip to content

Commit

Permalink
Merge branch 'release/2024.3.0' into release/2024.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
shipko committed Mar 23, 2024
2 parents be9fd84 + 2c5b0dc commit ab217ac
Show file tree
Hide file tree
Showing 84 changed files with 4,289 additions and 604 deletions.
48 changes: 48 additions & 0 deletions docker-compose.deploy.yml
@@ -0,0 +1,48 @@
# THIS IS NOT TO BE USED FOR PERSONAL DEPLOYMENTS!
# Internal Docker Compose Image used for internal testing deployments

version: "3.7"

services:
hoppscotch-db:
image: postgres:15
user: postgres
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: testpass
POSTGRES_DB: hoppscotch
healthcheck:
test:
[
"CMD-SHELL",
"sh -c 'pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}'"
]
interval: 5s
timeout: 5s
retries: 10

hoppscotch-aio:
container_name: hoppscotch-aio
build:
dockerfile: prod.Dockerfile
context: .
target: aio
environment:
- DATABASE_URL=postgresql://postgres:testpass@hoppscotch-db:5432/hoppscotch
- ENABLE_SUBPATH_BASED_ACCESS=true
env_file:
- ./.env
depends_on:
hoppscotch-db:
condition: service_healthy
command: ["sh", "-c", "pnpm exec prisma migrate deploy && node /usr/src/app/aio_run.mjs"]
healthcheck:
test:
- CMD
- curl
- '-f'
- 'http://localhost:80'
interval: 2s
timeout: 10s
retries: 30

10 changes: 7 additions & 3 deletions healthcheck.sh
Expand Up @@ -9,6 +9,10 @@ curlCheck() {
fi
}

curlCheck "http://localhost:3000"
curlCheck "http://localhost:3100"
curlCheck "http://localhost:3170/ping"
if [ "$ENABLE_SUBPATH_BASED_ACCESS" = "true" ]; then
curlCheck "http://localhost:80/backend/ping"
else
curlCheck "http://localhost:3000"
curlCheck "http://localhost:3100"
curlCheck "http://localhost:3170/ping"
fi
11 changes: 11 additions & 0 deletions packages/hoppscotch-backend/src/errors.ts
Expand Up @@ -84,6 +84,12 @@ export const USER_ALREADY_INVITED = 'admin/user_already_invited' as const;
*/
export const USER_UPDATE_FAILED = 'user/update_failed' as const;

/**
* User display name validation failure
* (UserService)
*/
export const USER_SHORT_DISPLAY_NAME = 'user/short_display_name' as const;

/**
* User deletion failure
* (UserService)
Expand Down Expand Up @@ -750,3 +756,8 @@ export const DATABASE_TABLE_NOT_EXIST =
* (InfraConfigService)
*/
export const POSTHOG_CLIENT_NOT_INITIALIZED = 'posthog/client_not_initialized';

/**
* Inputs supplied are invalid
*/
export const INVALID_PARAMS = 'invalid_parameters' as const;
@@ -1,4 +1,11 @@
import { Controller, Get, Param, Query, UseGuards } from '@nestjs/common';
import {
Controller,
Get,
HttpStatus,
Param,
Query,
UseGuards,
} from '@nestjs/common';
import { TeamCollectionService } from './team-collection.service';
import * as E from 'fp-ts/Either';
import { ThrottlerBehindProxyGuard } from 'src/guards/throttler-behind-proxy.guard';
Expand All @@ -7,27 +14,36 @@ import { RequiresTeamRole } from 'src/team/decorators/requires-team-role.decorat
import { TeamMemberRole } from '@prisma/client';
import { RESTTeamMemberGuard } from 'src/team/guards/rest-team-member.guard';
import { throwHTTPErr } from 'src/utils';
import { RESTError } from 'src/types/RESTError';
import { INVALID_PARAMS } from 'src/errors';

@UseGuards(ThrottlerBehindProxyGuard)
@Controller({ path: 'team-collection', version: '1' })
export class TeamCollectionController {
constructor(private readonly teamCollectionService: TeamCollectionService) {}

@Get('search/:teamID/:searchQuery')
@Get('search/:teamID')
@RequiresTeamRole(
TeamMemberRole.VIEWER,
TeamMemberRole.EDITOR,
TeamMemberRole.OWNER,
)
@UseGuards(JwtAuthGuard, RESTTeamMemberGuard)
async searchByTitle(
@Param('searchQuery') searchQuery: string,
@Query('searchQuery') searchQuery: string,
@Param('teamID') teamID: string,
@Query('take') take: string,
@Query('skip') skip: string,
) {
if (!teamID || !searchQuery) {
return <RESTError>{
message: INVALID_PARAMS,
statusCode: HttpStatus.BAD_REQUEST,
};
}

const res = await this.teamCollectionService.searchByTitle(
searchQuery,
searchQuery.trim(),
teamID,
parseInt(take),
parseInt(skip),
Expand Down
23 changes: 23 additions & 0 deletions packages/hoppscotch-backend/src/user/user.resolver.ts
Expand Up @@ -58,6 +58,29 @@ export class UserResolver {
if (E.isLeft(updatedUser)) throwErr(updatedUser.left);
return updatedUser.right;
}

@Mutation(() => User, {
description: 'Update a users display name',
})
@UseGuards(GqlAuthGuard)
async updateDisplayName(
@GqlUser() user: AuthUser,
@Args({
name: 'updatedDisplayName',
description: 'New name of user',
type: () => String,
})
updatedDisplayName: string,
) {
const updatedUser = await this.userService.updateUserDisplayName(
user.uid,
updatedDisplayName,
);

if (E.isLeft(updatedUser)) throwErr(updatedUser.left);
return updatedUser.right;
}

@Mutation(() => Boolean, {
description: 'Delete an user account',
})
Expand Down
15 changes: 14 additions & 1 deletion packages/hoppscotch-backend/src/user/user.service.spec.ts
@@ -1,4 +1,9 @@
import { JSON_INVALID, USERS_NOT_FOUND, USER_NOT_FOUND } from 'src/errors';
import {
JSON_INVALID,
USERS_NOT_FOUND,
USER_NOT_FOUND,
USER_SHORT_DISPLAY_NAME,
} from 'src/errors';
import { mockDeep, mockReset } from 'jest-mock-extended';
import { PrismaService } from 'src/prisma/prisma.service';
import { AuthUser } from 'src/types/AuthUser';
Expand Down Expand Up @@ -480,6 +485,14 @@ describe('UserService', () => {
);
expect(result).toEqualLeft(USER_NOT_FOUND);
});
test('should resolve left and error when short display name is passed', async () => {
const newDisplayName = '';
const result = await userService.updateUserDisplayName(
user.uid,
newDisplayName,
);
expect(result).toEqualLeft(USER_SHORT_DISPLAY_NAME);
});
});

describe('fetchAllUsers', () => {
Expand Down
10 changes: 9 additions & 1 deletion packages/hoppscotch-backend/src/user/user.service.ts
Expand Up @@ -8,7 +8,11 @@ import * as T from 'fp-ts/Task';
import * as A from 'fp-ts/Array';
import { pipe, constVoid } from 'fp-ts/function';
import { AuthUser } from 'src/types/AuthUser';
import { USERS_NOT_FOUND, USER_NOT_FOUND } from 'src/errors';
import {
USERS_NOT_FOUND,
USER_NOT_FOUND,
USER_SHORT_DISPLAY_NAME,
} from 'src/errors';
import { SessionType, User } from './user.model';
import { USER_UPDATE_FAILED } from 'src/errors';
import { PubSubService } from 'src/pubsub/pubsub.service';
Expand Down Expand Up @@ -291,6 +295,10 @@ export class UserService {
* @returns a Either of User or error
*/
async updateUserDisplayName(userUID: string, displayName: string) {
if (!displayName || displayName.length === 0) {
return E.left(USER_SHORT_DISPLAY_NAME);
}

try {
const dbUpdatedUser = await this.prisma.user.update({
where: { uid: userUID },
Expand Down
47 changes: 23 additions & 24 deletions packages/hoppscotch-backend/src/utils.ts
Expand Up @@ -261,29 +261,28 @@ export function checkEnvironmentAuthProvider(
* Source: https://stackoverflow.com/a/32648526
*/
export function escapeSqlLikeString(str: string) {
if (typeof str != 'string')
return str;
if (typeof str != 'string') return str;

return str.replace(/[\0\x08\x09\x1a\n\r"'\\\%]/g, function (char) {
switch (char) {
case "\0":
return "\\0";
case "\x08":
return "\\b";
case "\x09":
return "\\t";
case "\x1a":
return "\\z";
case "\n":
return "\\n";
case "\r":
return "\\r";
case "\"":
case "'":
case "\\":
case "%":
return "\\"+char; // prepends a backslash to backslash, percent,
// and double/single quotes
}
});
return str.replace(/[\0\x08\x09\x1a\n\r"'\\\%]/g, function (char) {
switch (char) {
case '\0':
return '\\0';
case '\x08':
return '\\b';
case '\x09':
return '\\t';
case '\x1a':
return '\\z';
case '\n':
return '\\n';
case '\r':
return '\\r';
case '"':
case "'":
case '\\':
case '%':
return '\\' + char; // prepends a backslash to backslash, percent,
// and double/single quotes
}
});
}

0 comments on commit ab217ac

Please sign in to comment.