Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ export class CreateConnectionPropertiesDs {
tables_audit: boolean;
human_readable_table_names: boolean;
allow_ai_requests: boolean;
default_showing_table: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,7 @@ export class FoundConnectionPropertiesDs {

@ApiProperty()
allow_ai_requests: boolean;

@ApiProperty()
default_showing_table: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
UseInterceptors,
} from '@nestjs/common';
import { HttpException } from '@nestjs/common/exceptions/http.exception.js';
import { ApiBearerAuth, ApiBody, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import { UseCaseType } from '../../common/data-injection.tokens.js';
import { MasterPassword, SlugUuid, UserId } from '../../decorators/index.js';
import { InTransactionEnum } from '../../enums/index.js';
Expand All @@ -21,14 +22,13 @@ import { SentryInterceptor } from '../../interceptors/index.js';
import { CreateConnectionPropertiesDs } from './application/data-structures/create-connection-properties.ds.js';
import { FoundConnectionPropertiesDs } from './application/data-structures/found-connection-properties.ds.js';
import { IConnectionPropertiesRO } from './connection-properties.interface.js';
import { CreateConnectionPropertiesDto } from './dto/create-connection-properties.dto.js';
import {
ICreateConnectionProperties,
IDeleteConnectionProperties,
IFindConnectionProperties,
IUpdateConnectionProperties,
} from './use-cases/connection-properties-use.cases.interface.js';
import { ApiBearerAuth, ApiBody, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import { CreateConnectionPropertiesDto } from './dto/create-connection-properties.dto.js';

@UseInterceptors(SentryInterceptor)
@Controller()
Expand Down Expand Up @@ -107,6 +107,7 @@ export class ConnectionPropertiesController {
tables_audit: connectionPropertiesData.tables_audit,
human_readable_table_names: connectionPropertiesData.human_readable_table_names,
allow_ai_requests: connectionPropertiesData.allow_ai_requests,
default_showing_table: connectionPropertiesData.default_showing_table,
};

return await this.createConnectionPropertiesUseCase.execute(createConnectionPropertiesDs, InTransactionEnum.ON);
Expand Down Expand Up @@ -151,6 +152,7 @@ export class ConnectionPropertiesController {
tables_audit: connectionPropertiesData.tables_audit,
human_readable_table_names: connectionPropertiesData.human_readable_table_names,
allow_ai_requests: connectionPropertiesData.allow_ai_requests,
default_showing_table: connectionPropertiesData.default_showing_table,
};

return await this.updateConnectionPropertiesUseCase.execute(inputData, InTransactionEnum.ON);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export class ConnectionPropertiesEntity {
@Column({ default: true })
allow_ai_requests: boolean;

@Column({ default: null })
default_showing_table: string;

@OneToOne((_) => ConnectionEntity, (connection) => connection.connection_properties, {
onDelete: 'CASCADE',
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,49 +1,55 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsArray, IsBoolean, IsOptional, IsString } from 'class-validator';
import { IsArray, IsBoolean, IsOptional, IsString, MaxLength } from 'class-validator';

export class CreateConnectionPropertiesDto {
@IsOptional()
@IsArray()
@ApiProperty({ isArray: true, type: String })
@ApiProperty({ isArray: true, type: String, required: false })
hidden_tables: Array<string>;

@IsOptional()
@IsString()
@ApiProperty()
@ApiProperty({ required: false })
logo_url: string;

@IsOptional()
@IsString()
@ApiProperty()
@ApiProperty({ required: false })
primary_color: string;

@IsOptional()
@IsString()
@ApiProperty()
@ApiProperty({ required: false })
secondary_color: string;

@IsOptional()
@IsString()
@ApiProperty()
@ApiProperty({ required: false })
hostname: string;

@IsOptional()
@IsString()
@ApiProperty()
@ApiProperty({ required: false })
company_name: string;

@IsOptional()
@IsBoolean()
@ApiProperty()
@ApiProperty({ required: false })
tables_audit: boolean;

@IsOptional()
@IsBoolean()
@ApiProperty()
@ApiProperty({ required: false })
human_readable_table_names: boolean;

@IsOptional()
@IsBoolean()
@ApiProperty()
@ApiProperty({ required: false })
allow_ai_requests: boolean;

@IsOptional()
@IsString()
@MaxLength(255)
@ApiProperty({ required: false })
default_showing_table: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ export function buildConnectionPropertiesEntity(
newConnectionProperties.tables_audit = propertiesInfo.tables_audit;
newConnectionProperties.human_readable_table_names = propertiesInfo.human_readable_table_names;
newConnectionProperties.allow_ai_requests = propertiesInfo.allow_ai_requests;
newConnectionProperties.default_showing_table = propertiesInfo.default_showing_table;
return newConnectionProperties;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ export function buildFoundConnectionPropertiesDs(
tables_audit: connectionProperties.tables_audit,
human_readable_table_names: connectionProperties.human_readable_table_names,
allow_ai_requests: connectionProperties.allow_ai_requests,
default_showing_table: connectionProperties.default_showing_table,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export function buildUpdateConnectionPropertiesObject(
tables_audit,
human_readable_table_names,
allow_ai_requests,
default_showing_table,
} = inputData;
return {
hidden_tables: hidden_tables,
Expand All @@ -24,6 +25,7 @@ export function buildUpdateConnectionPropertiesObject(
tables_audit: tables_audit,
human_readable_table_names: human_readable_table_names,
allow_ai_requests: allow_ai_requests,
default_showing_table: default_showing_table,
};
}

Expand All @@ -37,4 +39,5 @@ export interface IUpdateConnectionPropertiesObject {
tables_audit: boolean;
human_readable_table_names: boolean;
allow_ai_requests: boolean;
default_showing_table: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export async function validateCreateConnectionPropertiesDs(
createConnectionProperties: CreateConnectionPropertiesDs,
connection: ConnectionEntity,
): Promise<boolean> {
const { hidden_tables } = createConnectionProperties;
const { hidden_tables, default_showing_table } = createConnectionProperties;
const errors = [];
const dao = getDataAccessObject(connection);
const tablesInConnection = (await dao.getTablesFromDB()).map((table) => table.tableName);
Expand All @@ -25,6 +25,10 @@ export async function validateCreateConnectionPropertiesDs(
}
}

if (default_showing_table && !tablesInConnection.includes(default_showing_table)) {
errors.push(Messages.TABLE_WITH_NAME_NOT_EXISTS(default_showing_table));
}

if (errors.length > 0) {
throw new HttpException(
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class AddDefaultShowingTalbeIntoConnectionPropertiesEntity1739448612299 implements MigrationInterface {
name = 'AddDefaultShowingTalbeIntoConnectionPropertiesEntity1739448612299';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "connectionProperties" ADD "default_showing_table" character varying`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "connectionProperties" DROP COLUMN "default_showing_table"`);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2138,7 +2138,7 @@ test.serial(

t.is(updateConnectionResponse.status, 200);

const newConnectionProperties = mockFactory.generateConnectionPropertiesUserExcluded(null, false);
const newConnectionProperties = mockFactory.generateConnectionPropertiesUserExcluded(firstTableInfo.testTableName, false);
newConnectionProperties.hidden_tables = [];
newConnectionProperties.tables_audit = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ test.serial(`${currentTest} should return created connection properties`, async
t.is(createConnectionPropertiesRO.hidden_tables[0], newConnectionProperties.hidden_tables[0]);
t.is(createConnectionPropertiesRO.connectionId, createConnectionRO.id);
t.is(createConnectionPropertiesRO.allow_ai_requests, newConnectionProperties.allow_ai_requests);
t.is(createConnectionPropertiesRO.default_showing_table, newConnectionProperties.default_showing_table);
} catch (e) {
throw e;
}
Expand Down
1 change: 1 addition & 0 deletions backend/test/mock.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,7 @@ export class MockFactory {
tables_audit: tables_audit,
human_readable_table_names: faker.datatype.boolean(),
allow_ai_requests: faker.datatype.boolean(),
default_showing_table: tableName,
};
}

Expand Down
Loading