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 Dec 10, 2024
1 parent 408ee8b commit efc8485
Show file tree
Hide file tree
Showing 20 changed files with 2,786 additions and 8 deletions.
111 changes: 110 additions & 1 deletion api-gateway/src/api/service/policy-labels.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 } from '@guardian/interfaces';
import { ApiBody, ApiInternalServerErrorResponse, ApiOkResponse, ApiOperation, ApiTags, ApiQuery, ApiExtraModels, ApiParam } from '@nestjs/swagger';
import { Examples, InternalServerErrorDTO, PolicyLabelDTO, PolicyLabelRelationshipsDTO, pageHeader } from '#middlewares';
import { Examples, InternalServerErrorDTO, PolicyLabelDTO, PolicyLabelRelationshipsDTO, VcDocumentDTO, pageHeader } from '#middlewares';
import { Guardians, InternalException, EntityOwner } from '#helpers';
import { AuthUser, Auth } from '#auth';

Expand Down Expand Up @@ -490,4 +490,113 @@ export class PolicyLabelsApi {
await InternalException(error, this.logger);
}
}

/**
* Get documents
*/
@Get('/:labelId/documents')
@Auth(Permissions.STATISTICS_STATISTIC_READ)
@ApiOperation({
summary: 'Return a list of all documents.',
description: 'Returns all documents.',
})
@ApiParam({
name: 'labelId',
type: String,
description: 'policy label Identifier',
required: true,
example: Examples.DB_ID
})
@ApiQuery({
name: 'pageIndex',
type: Number,
description: 'The number of pages to skip before starting to collect the result set',
required: false,
example: 0
})
@ApiQuery({
name: 'pageSize',
type: Number,
description: 'The numbers of items to return',
required: false,
example: 20
})
@ApiOkResponse({
description: 'Successful operation.',
isArray: true,
headers: pageHeader,
type: VcDocumentDTO
})
@ApiInternalServerErrorResponse({
description: 'Internal server error.',
type: InternalServerErrorDTO,
})
@ApiExtraModels(VcDocumentDTO, InternalServerErrorDTO)
@HttpCode(HttpStatus.OK)
async getPolicyLabelDocuments(
@AuthUser() user: IAuthUser,
@Response() res: any,
@Param('labelId') labelId: string,
@Query('pageIndex') pageIndex?: number,
@Query('pageSize') pageSize?: number
): Promise<VcDocumentDTO[]> {
try {
const owner = new EntityOwner(user);
const guardians = new Guardians();
const { items, count } = await guardians.getPolicyLabelDocuments(labelId, owner, pageIndex, pageSize);
return res.header('X-Total-Count', count).send(items);
} catch (error) {
await InternalException(error, this.logger);
}
}


/**
* Get document
*/
@Get('/:labelId/documents/:documentId')
@Auth(Permissions.STATISTICS_STATISTIC_READ)
@ApiOperation({
summary: 'Return a list of all documents.',
description: 'Returns all documents.',
})
@ApiParam({
name: 'labelId',
type: String,
description: 'policy label Identifier',
required: true,
example: Examples.DB_ID
})
@ApiParam({
name: 'documentId',
type: String,
description: 'Document Identifier',
required: true,
example: Examples.DB_ID
})
@ApiOkResponse({
description: 'Successful operation.',
isArray: true,
headers: pageHeader,
type: VcDocumentDTO
})
@ApiInternalServerErrorResponse({
description: 'Internal server error.',
type: InternalServerErrorDTO,
})
@ApiExtraModels(VcDocumentDTO, InternalServerErrorDTO)
@HttpCode(HttpStatus.OK)
async getPolicyLabelDocument(
@AuthUser() user: IAuthUser,
@Param('labelId') labelId: string,
@Param('documentId') documentId: string,
): Promise<VcDocumentDTO[]> {
try {
const owner = new EntityOwner(user);
const guardians = new Guardians();
return await guardians.getPolicyLabelDocument(documentId, labelId, owner);
} catch (error) {
await InternalException(error, this.logger);
}
}
}
36 changes: 36 additions & 0 deletions api-gateway/src/helpers/guardians.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3344,4 +3344,40 @@ export class Guardians extends NatsService {
public async searchComponents(options: any, owner: IOwner) {
return await this.sendMessage(MessageAPI.SEARCH_POLICY_LABEL_COMPONENTS, { options, owner });
}

/**
* Return documents
*
* @param labelId
* @param owner
* @param pageIndex
* @param pageSize
*
* @returns {ResponseAndCount<any>}
*/
public async getPolicyLabelDocuments(
labelId: string,
owner: IOwner,
pageIndex?: number,
pageSize?: number
): Promise<ResponseAndCount<any>> {
return await this.sendMessage(MessageAPI.GET_POLICY_LABEL_DOCUMENTS, { labelId, owner, pageIndex, pageSize });
}

/**
* Return documents
*
* @param documentId
* @param labelId
* @param owner
*
* @returns {any}
*/
public async getPolicyLabelDocument(
documentId: string,
labelId: string,
owner: IOwner,
): Promise<any> {
return await this.sendMessage(MessageAPI.GET_POLICY_LABEL_DOCUMENT, { documentId, labelId, owner });
}
}
47 changes: 47 additions & 0 deletions frontend/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ import { StatisticDefinitionConfigurationComponent } from './modules/statistics/
import { StatisticDefinitionsComponent } from './modules/statistics/policy-statistics/statistic-definitions/statistic-definitions.component';
import { SchemaRuleConfigurationComponent } from './modules/statistics/schema-rules/schema-rule-configuration/schema-rule-configuration.component';
import { SchemaRulesComponent } from './modules/statistics/schema-rules/schema-rules/schema-rules.component';
import { PolicyLabelAssessmentConfigurationComponent } from './modules/statistics/policy-labels/policy-label-assessment-configuration/policy-label-assessment-configuration.component';
import { PolicyLabelAssessmentsComponent } from './modules/statistics/policy-labels/policy-label-assessments/policy-label-assessments.component';
import { PolicyLabelAssessmentViewComponent } from './modules/statistics/policy-labels/policy-label-assessment-view/policy-label-assessment-view.component';

@Injectable({
providedIn: 'root'
Expand Down Expand Up @@ -630,6 +633,50 @@ const routes: Routes = [
]
}
},
{
path: 'policy-label/:labelId/assessment',
component: PolicyLabelAssessmentConfigurationComponent,
canActivate: [PermissionsGuard],
data: {
roles: [
UserRole.STANDARD_REGISTRY,
UserRole.USER
],
permissions: [
Permissions.STATISTICS_LABEL_READ
]
}
},
{
path: 'policy-label/:labelId/assessments',
component: PolicyLabelAssessmentsComponent,
canActivate: [PermissionsGuard],
data: {
roles: [
UserRole.STANDARD_REGISTRY,
UserRole.USER
],
permissions: [
Permissions.STATISTICS_LABEL_READ
]
}
},
{
path: 'policy-label/:labelId/assessment/:assessmentId',
component: PolicyLabelAssessmentViewComponent,
canActivate: [PermissionsGuard],
data: {
roles: [
UserRole.STANDARD_REGISTRY,
UserRole.USER
],
permissions: [
Permissions.STATISTICS_LABEL_READ
]
}
},




{ path: '', component: HomeComponent },
Expand Down
23 changes: 23 additions & 0 deletions frontend/src/app/modules/common/models/label-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export interface IValidatorStep {
type: string,
config: any,
auto: boolean,
disabled?: boolean,
subIndexes?: ISubStep[],
update: () => void;
}
Expand Down Expand Up @@ -144,7 +145,27 @@ class ValidateNamespace {
}

public getField(schema: string, path: string): any {
const fullPath = [...(path || '').split('.')];
const document = this.documents?.find((doc) => doc.schema === schema);
if (!document) {
return undefined;
}
return this.getFieldValue(document, fullPath);
}

private getFieldValue(document: any, fullPath: string[]): any {
let value: any = document?.document?.credentialSubject;
if (Array.isArray(value)) {
value = value[0];
}
for (let i = 0; i < fullPath.length; i++) {
if (value) {
value = value[fullPath[i]]
} else {
return undefined;
}
}
return value;
}
}

Expand Down Expand Up @@ -415,6 +436,7 @@ class RuleValidator {
for (const variable of this.variables) {
const value = this.namespace.getField(variable.schemaId, variable.path);
(variable as any).value = value;
(variable as any).isArray = Array.isArray(value);
this.scope.setVariable(variable.id, (variable as any).value);
}
}
Expand Down Expand Up @@ -616,6 +638,7 @@ class StatisticValidator {
for (const variable of this.variables) {
const value = this.namespace.getField(variable.schemaId, variable.path);
(variable as any).value = value;
(variable as any).isArray = Array.isArray(value);
this.scope.setVariable(variable.id, (variable as any).value);
}
}
Expand Down
Loading

0 comments on commit efc8485

Please sign in to comment.