Move Impersonate from User to Workspace (#2630)
* Fix impersonate * align core typeorm config with metadata config + add allowImpersonation to workspace * move allowImpersonation to workspace * remove allowImpersonation from workspaceMember workspace table
This commit is contained in:
@ -162,24 +162,6 @@ export const seedWorkspaceMemberFieldMetadata = async (
|
||||
isSystem: false,
|
||||
defaultValue: undefined,
|
||||
},
|
||||
{
|
||||
id: SeedWorkspaceMemberFieldMetadataIds.AllowImpersonation,
|
||||
objectMetadataId: SeedObjectMetadataIds.WorkspaceMember,
|
||||
isCustom: false,
|
||||
workspaceId: SeedWorkspaceId,
|
||||
isActive: true,
|
||||
type: FieldMetadataType.BOOLEAN,
|
||||
name: 'allowImpersonation',
|
||||
label: 'Admin Access',
|
||||
targetColumnMap: {
|
||||
value: 'allowImpersonation',
|
||||
},
|
||||
description: 'Allow Admin Access',
|
||||
icon: 'IconEye',
|
||||
isNullable: false,
|
||||
isSystem: false,
|
||||
defaultValue: { value: false },
|
||||
},
|
||||
{
|
||||
id: SeedWorkspaceMemberFieldMetadataIds.ColorScheme,
|
||||
objectMetadataId: SeedObjectMetadataIds.WorkspaceMember,
|
||||
|
||||
21
server/src/database/typeorm/core/core.datasource.ts
Normal file
21
server/src/database/typeorm/core/core.datasource.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { TypeOrmModuleOptions } from '@nestjs/typeorm';
|
||||
|
||||
import { DataSource, DataSourceOptions } from 'typeorm';
|
||||
import { config } from 'dotenv';
|
||||
config();
|
||||
const configService = new ConfigService();
|
||||
export const typeORMCoreModuleOptions: TypeOrmModuleOptions = {
|
||||
url: configService.get<string>('PG_DATABASE_URL'),
|
||||
type: 'postgres',
|
||||
logging: ['error'],
|
||||
schema: 'core',
|
||||
entities: ['dist/src/core/**/*.entity{.ts,.js}'],
|
||||
synchronize: false,
|
||||
migrationsRun: false,
|
||||
migrationsTableName: '_typeorm_migrations',
|
||||
migrations: ['dist/src/database/typeorm/core/migrations/*{.ts,.js}'],
|
||||
};
|
||||
export const connectionSource = new DataSource(
|
||||
typeORMCoreModuleOptions as DataSourceOptions,
|
||||
);
|
||||
@ -0,0 +1,43 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class AddAllowImpersonationToWorkspace1700654387203
|
||||
implements MigrationInterface
|
||||
{
|
||||
name = 'AddAllowImpersonationToWorkspace1700654387203';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "core"."user" DROP CONSTRAINT "FK_5d77e050eabd28d203b301235a7"`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "core"."refreshToken" DROP CONSTRAINT "FK_610102b60fea1455310ccd299de"`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "core"."workspace" ADD "allowImpersonation" boolean NOT NULL DEFAULT true`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "core"."user" ADD CONSTRAINT "FK_2ec910029395fa7655621c88908" FOREIGN KEY ("defaultWorkspaceId") REFERENCES "core"."workspace"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "core"."refreshToken" ADD CONSTRAINT "FK_7008a2b0fb083127f60b5f4448e" FOREIGN KEY ("userId") REFERENCES "core"."user"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "core"."refreshToken" DROP CONSTRAINT "FK_7008a2b0fb083127f60b5f4448e"`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "core"."user" DROP CONSTRAINT "FK_2ec910029395fa7655621c88908"`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "core"."workspace" DROP COLUMN "allowImpersonation"`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "core"."refreshToken" ADD CONSTRAINT "FK_610102b60fea1455310ccd299de" FOREIGN KEY ("userId") REFERENCES "core"."user"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "core"."user" ADD CONSTRAINT "FK_5d77e050eabd28d203b301235a7" FOREIGN KEY ("defaultWorkspaceId") REFERENCES "core"."workspace"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -10,17 +10,11 @@ export const typeORMMetadataModuleOptions: TypeOrmModuleOptions = {
|
||||
type: 'postgres',
|
||||
logging: ['error'],
|
||||
schema: 'metadata',
|
||||
entities: [
|
||||
'dist/src/metadata/**/*.entity{.ts,.js}',
|
||||
'dist/src/core/**/*.entity{.ts,.js}',
|
||||
],
|
||||
entities: ['dist/src/metadata/**/*.entity{.ts,.js}'],
|
||||
synchronize: false,
|
||||
migrationsRun: false,
|
||||
migrationsTableName: '_typeorm_migrations',
|
||||
migrations: [
|
||||
'dist/src/database/typeorm/metadata/migrations/*{.ts,.js}',
|
||||
'dist/src/database/typeorm/core/migrations/*{.ts,.js}',
|
||||
],
|
||||
migrations: ['dist/src/database/typeorm/metadata/migrations/*{.ts,.js}'],
|
||||
};
|
||||
export const connectionSource = new DataSource(
|
||||
typeORMMetadataModuleOptions as DataSourceOptions,
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule, TypeOrmModuleOptions } from '@nestjs/typeorm';
|
||||
|
||||
import { typeORMCoreModuleOptions } from 'src/database/typeorm/core/core.datasource';
|
||||
|
||||
import { TypeORMService } from './typeorm.service';
|
||||
|
||||
import { typeORMMetadataModuleOptions } from './metadata/metadata.datasource';
|
||||
@ -10,12 +12,21 @@ const metadataTypeORMFactory = async (): Promise<TypeOrmModuleOptions> => ({
|
||||
name: 'metadata',
|
||||
});
|
||||
|
||||
const coreTypeORMFactory = async (): Promise<TypeOrmModuleOptions> => ({
|
||||
...typeORMCoreModuleOptions,
|
||||
name: 'core',
|
||||
});
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
TypeOrmModule.forRootAsync({
|
||||
useFactory: metadataTypeORMFactory,
|
||||
name: 'metadata',
|
||||
}),
|
||||
TypeOrmModule.forRootAsync({
|
||||
useFactory: coreTypeORMFactory,
|
||||
name: 'core',
|
||||
}),
|
||||
],
|
||||
providers: [TypeORMService],
|
||||
exports: [TypeORMService],
|
||||
|
||||
Reference in New Issue
Block a user