Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
Signed-off-by: Stepan Kiryakov <[email protected]>
  • Loading branch information
Stepan-Kirjakov committed Jan 27, 2025
1 parent fd3f7d7 commit c9c3358
Show file tree
Hide file tree
Showing 29 changed files with 1,257 additions and 106 deletions.
48 changes: 46 additions & 2 deletions api-gateway/src/api/service/formulas.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { IAuthUser, PinoLogger } from '@guardian/common';
import { Body, Controller, Delete, Get, HttpCode, HttpException, HttpStatus, Param, Post, Put, Query, Response } from '@nestjs/common';
import { Permissions } from '@guardian/interfaces';
import { Permissions, UserPermissions } from '@guardian/interfaces';
import { ApiBody, ApiInternalServerErrorResponse, ApiOkResponse, ApiOperation, ApiTags, ApiQuery, ApiExtraModels, ApiParam } from '@nestjs/swagger';
import { Examples, InternalServerErrorDTO, FormulaDTO, FormulaRelationshipsDTO, pageHeader } from '#middlewares';
import { Examples, InternalServerErrorDTO, FormulaDTO, FormulaRelationshipsDTO, pageHeader, FormulasOptionsDTO, FormulasDataDTO } from '#middlewares';
import { Guardians, InternalException, EntityOwner } from '#helpers';
import { AuthUser, Auth } from '#auth';

Expand Down Expand Up @@ -413,4 +413,48 @@ export class FormulasApi {
await InternalException(error, this.logger);
}
}

/**
* Get rules and data
*/
@Post('/data')
@Auth()
@ApiOperation({
summary: '',
description: '',
})
@ApiBody({
description: 'Options.',
type: FormulasOptionsDTO,
required: true
})
@ApiOkResponse({
description: 'Successful operation.',
type: FormulasDataDTO,
})
@ApiInternalServerErrorResponse({
description: 'Internal server error.',
type: InternalServerErrorDTO,
})
@ApiExtraModels(FormulasDataDTO, InternalServerErrorDTO)
@HttpCode(HttpStatus.CREATED)
async getSchemaRuleData(
@AuthUser() user: IAuthUser,
@Body() options: FormulasOptionsDTO
): Promise<FormulasDataDTO> {
try {
if (!options) {
throw new HttpException('Invalid config.', HttpStatus.UNPROCESSABLE_ENTITY);
}
if (!UserPermissions.has(user, Permissions.SCHEMAS_RULE_EXECUTE)) {
return null;
} else {
const owner = new EntityOwner(user);
const guardian = new Guardians();
return await guardian.getFormulasData(options, owner);
}
} catch (error) {
await InternalException(error, this.logger);
}
}
}
13 changes: 7 additions & 6 deletions api-gateway/src/api/service/schema-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { IAuthUser, PinoLogger } from '@guardian/common';
import { Body, Controller, Delete, Get, HttpCode, HttpException, HttpStatus, Param, Post, Put, Query, Response } from '@nestjs/common';
import { Permissions, UserPermissions } from '@guardian/interfaces';
import { ApiBody, ApiInternalServerErrorResponse, ApiOkResponse, ApiOperation, ApiTags, ApiQuery, ApiExtraModels, ApiParam } from '@nestjs/swagger';
import { Examples, InternalServerErrorDTO, SchemaRuleDTO, SchemaRuleDataDTO, SchemaRuleRelationshipsDTO, pageHeader } from '#middlewares';
import { Examples, InternalServerErrorDTO, SchemaRuleDTO, SchemaRuleDataDTO, SchemaRuleOptionsDTO, SchemaRuleRelationshipsDTO, pageHeader } from '#middlewares';
import { Guardians, InternalException, EntityOwner } from '#helpers';
import { AuthUser, Auth } from '#auth';

Expand Down Expand Up @@ -390,24 +390,25 @@ export class SchemaRulesApi {
description: '',
})
@ApiBody({
description: 'Configuration.',
type: SchemaRuleDataDTO,
description: 'Options.',
type: SchemaRuleOptionsDTO,
required: true
})
@ApiOkResponse({
description: 'Successful operation.',
type: SchemaRuleDataDTO,
isArray: true
})
@ApiInternalServerErrorResponse({
description: 'Internal server error.',
type: InternalServerErrorDTO,
})
@ApiExtraModels(SchemaRuleDataDTO, InternalServerErrorDTO)
@ApiExtraModels(SchemaRuleOptionsDTO, SchemaRuleDataDTO, InternalServerErrorDTO)
@HttpCode(HttpStatus.CREATED)
async getSchemaRuleData(
@AuthUser() user: IAuthUser,
@Body() options: any
): Promise<SchemaRuleDataDTO> {
@Body() options: SchemaRuleOptionsDTO
): Promise<SchemaRuleDataDTO[]> {
try {
if (!options) {
throw new HttpException('Invalid config.', HttpStatus.UNPROCESSABLE_ENTITY);
Expand Down
19 changes: 17 additions & 2 deletions api-gateway/src/helpers/guardians.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ import {
PolicyLabelDocumentRelationshipsDTO,
PolicyLabelComponentsDTO,
PolicyLabelFiltersDTO,
FormulaDTO
FormulaDTO,
SchemaRuleOptionsDTO,
FormulasOptionsDTO,
FormulasDataDTO
} from '#middlewares';

/**
Expand Down Expand Up @@ -3191,7 +3194,7 @@ export class Guardians extends NatsService {
*
* @returns Schema Rule Data
*/
public async getSchemaRuleData(options: any, owner: IOwner): Promise<SchemaRuleDataDTO> {
public async getSchemaRuleData(options: SchemaRuleOptionsDTO, owner: IOwner): Promise<SchemaRuleDataDTO[]> {
return await this.sendMessage(MessageAPI.GET_SCHEMA_RULE_DATA, { options, owner });
}

Expand Down Expand Up @@ -3585,4 +3588,16 @@ export class Guardians extends NatsService {
public async getFormulaRelationships(formulaId: string, owner: IOwner): Promise<boolean> {
return await this.sendMessage(MessageAPI.GET_FORMULA_RELATIONSHIPS, { formulaId, owner });
}

/**
* Get Formulas Data
*
* @param options
* @param owner
*
* @returns Formulas Data
*/
public async getFormulasData(options: FormulasOptionsDTO, owner: IOwner): Promise<FormulasDataDTO> {
return await this.sendMessage(MessageAPI.GET_FORMULAS_DATA, { options, owner });
}
}
82 changes: 80 additions & 2 deletions api-gateway/src/middlewares/validation/schemas/formulas.dto.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { ApiProperty } from '@nestjs/swagger';
import { ApiExtraModels, ApiProperty } from '@nestjs/swagger';
import { Examples } from '../examples.js';
import { IsObject, IsOptional, IsString } from 'class-validator';
import { IsArray, IsBoolean, IsObject, IsOptional, IsString } from 'class-validator';
import { EntityStatus } from '@guardian/interfaces';
import { VcDocumentDTO } from './document.dto.js';
import { SchemaDTO } from './schemas.dto.js';

export class FormulaDTO {
@ApiProperty({
Expand Down Expand Up @@ -86,4 +88,80 @@ export class FormulaDTO {

export class FormulaRelationshipsDTO {

}

export class FormulasOptionsDTO {
@ApiProperty({
type: 'string',
required: false,
example: Examples.DB_ID
})
@IsOptional()
@IsString()
policyId?: string;

@ApiProperty({
type: 'string',
required: false,
example: Examples.DB_ID
})
@IsOptional()
@IsString()
schemaId?: string;

@ApiProperty({
type: 'string',
required: false,
example: Examples.DB_ID
})
@IsOptional()
@IsString()
documentId?: string;

@ApiProperty({
type: 'string',
required: false,
example: Examples.DB_ID
})
@IsOptional()
@IsString()
parentId?: string;
}

@ApiExtraModels(FormulaDTO, SchemaDTO, VcDocumentDTO)
export class FormulasDataDTO {
@ApiProperty({
type: () => FormulaDTO,
required: false,
isArray: true
})
@IsOptional()
@IsArray()
formulas?: FormulaDTO[];

@ApiProperty({
type: () => VcDocumentDTO,
required: false,
})
@IsOptional()
@IsObject()
document?: VcDocumentDTO;

@ApiProperty({
type: () => VcDocumentDTO,
required: false,
isArray: true,
})
@IsOptional()
@IsArray()
relationships?: VcDocumentDTO[];

@ApiProperty({
type: () => SchemaDTO,
required: false,
isArray: true,
})
@IsOptional()
@IsArray()
schemas?: SchemaDTO[];
}
42 changes: 40 additions & 2 deletions api-gateway/src/middlewares/validation/schemas/schema-rules.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,44 @@ export class SchemaRuleRelationshipsDTO {
schemas?: SchemaDTO[];
}

export class SchemaRuleOptionsDTO {
@ApiProperty({
type: 'string',
required: false,
example: Examples.DB_ID
})
@IsOptional()
@IsString()
policyId?: string;

@ApiProperty({
type: 'string',
required: false,
example: Examples.DB_ID
})
@IsOptional()
@IsString()
schemaId?: string;

@ApiProperty({
type: 'string',
required: false,
example: Examples.DB_ID
})
@IsOptional()
@IsString()
documentId?: string;

@ApiProperty({
type: 'string',
required: false,
example: Examples.DB_ID
})
@IsOptional()
@IsString()
parentId?: string;
}

@ApiExtraModels(SchemaRuleDTO, VcDocumentDTO)
export class SchemaRuleDataDTO {
@ApiProperty({
Expand All @@ -149,6 +187,6 @@ export class SchemaRuleDataDTO {
isArray: true,
})
@IsOptional()
@IsObject()
relationships?: VcDocumentDTO;
@IsArray()
relationships?: VcDocumentDTO[];
}
16 changes: 15 additions & 1 deletion common/src/import-export/policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,4 +374,18 @@ export class PolicyImportExport {
return policyCategoryIds;
}

}
/**
* Load all schemas (deep find)
* @param policy policy
*
* @returns schemas
*/
public static async fastLoadSchemas(policy: Policy) {
const topicId = policy.topicId;
const tools: any[] = policy.tools || [];
const toolsTopicMap = tools.map((t) => t.topicId);
const schemas = await new DatabaseServer().find(Schema, { topicId, readonly: false });
const toolSchemas = await DatabaseServer.getSchemas({ topicId: { $in: toolsTopicMap } });
return { schemas, toolSchemas };
}
}
48 changes: 24 additions & 24 deletions frontend/src/app/modules/common/material.module.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {ReactiveFormsModule} from '@angular/forms';
import {DragDropModule} from '@angular/cdk/drag-drop';
import {CdkTableModule} from '@angular/cdk/table';
import {TabViewModule} from 'primeng/tabview';
import {AccordionModule} from 'primeng/accordion';
import {TableModule} from 'primeng/table';
import {ButtonModule} from 'primeng/button';
import {SelectButtonModule} from 'primeng/selectbutton';
import {CalendarModule} from 'primeng/calendar';
import {RadioButtonModule} from 'primeng/radiobutton';
import {ProgressSpinnerModule} from 'primeng/progressspinner';
import {ToolbarModule} from 'primeng/toolbar';
import {OverlayPanelModule} from 'primeng/overlaypanel';
import {ProgressBarModule} from 'primeng/progressbar';
import {CheckboxModule} from 'primeng/checkbox';
import {ChipsModule} from 'primeng/chips';
import {StepsModule} from 'primeng/steps';
import {DropdownModule} from 'primeng/dropdown';
import {MultiSelectModule} from 'primeng/multiselect';
import {InputNumberModule} from 'primeng/inputnumber';
import {TooltipModule} from 'primeng/tooltip';
import {TreeModule} from 'primeng/tree';
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { ReactiveFormsModule } from '@angular/forms';
import { DragDropModule } from '@angular/cdk/drag-drop';
import { CdkTableModule } from '@angular/cdk/table';
import { TabViewModule } from 'primeng/tabview';
import { AccordionModule } from 'primeng/accordion';
import { TableModule } from 'primeng/table';
import { ButtonModule } from 'primeng/button';
import { SelectButtonModule } from 'primeng/selectbutton';
import { CalendarModule } from 'primeng/calendar';
import { RadioButtonModule } from 'primeng/radiobutton';
import { ProgressSpinnerModule } from 'primeng/progressspinner';
import { ToolbarModule } from 'primeng/toolbar';
import { OverlayPanelModule } from 'primeng/overlaypanel';
import { ProgressBarModule } from 'primeng/progressbar';
import { CheckboxModule } from 'primeng/checkbox';
import { ChipsModule } from 'primeng/chips';
import { StepsModule } from 'primeng/steps';
import { DropdownModule } from 'primeng/dropdown';
import { MultiSelectModule } from 'primeng/multiselect';
import { InputNumberModule } from 'primeng/inputnumber';
import { TooltipModule } from 'primeng/tooltip';
import { TreeModule } from 'primeng/tree';

@NgModule({
declarations: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { mathKeyboard } from './keyboards/math-keyboard';
})
export class MathLiveComponent implements OnInit, OnDestroy {
@ViewChild('mathLiveContent', { static: true }) mathLiveContent: ElementRef;
@Input('readonly') readonly: boolean = false;
@Input('value') value!: string;
@Output('valueChange') valueChange = new EventEmitter<string>();
@Output('keyboard') keyboard = new EventEmitter<boolean>();
Expand Down Expand Up @@ -48,6 +49,7 @@ export class MathLiveComponent implements OnInit, OnDestroy {
this.valueChange.emit(this.value);
});
this.mfe.value = this.value || '';
this.mfe.readonly = this.readonly;
}

ngAfterViewInit() {
Expand Down
Loading

0 comments on commit c9c3358

Please sign in to comment.