Skip to content

Commit

Permalink
Fix edit asset form validator (#863)
Browse files Browse the repository at this point in the history
  • Loading branch information
illfixit authored Oct 4, 2024
1 parent c4562ba commit 69ad5ab
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,25 @@ const checkIdAvailability = (id: string): void => {
}
};

const checkIfNoAlwaysTruePolicyExists = (): void => {
if (policyDefinitionIdAvailable(ALWAYS_TRUE_POLICY_ID).available) {
createPolicyDefinitionV2({
policyDefinitionId: ALWAYS_TRUE_POLICY_ID,
expression: {
type: 'EMPTY',
},
});
}
};

export const createDataOffer = (
request: DataOfferCreationRequest,
): IdResponseDto => {
const commonId = request.uiAssetCreateRequest.id;
let accessPolicyId = null;
let contractPolicyId = null;

checkIfNoAlwaysTruePolicyExists();
checkIdAvailability(commonId);
createAsset(request.uiAssetCreateRequest);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {Observable, combineLatest, of} from 'rxjs';
import {catchError, map} from 'rxjs/operators';
import {IdAvailabilityResponse} from '@sovity.de/edc-client';
import {EdcApiService} from 'src/app/core/services/api/edc-api.service';
import {ALWAYS_TRUE_POLICY_ID} from './model/always-true-policy-id';
import {EditAssetFormValue} from './model/edit-asset-form-model';

/**
Expand All @@ -29,20 +28,7 @@ export class EditAssetFormValidators {
}

const assetId = control.value! as string;
if (value.publishMode === 'PUBLISH_UNRESTRICTED') {
return combineLatest([
this.assetIdExistsErrorMessage(assetId),
this.contractDefinitionIdErrorMessage(assetId),
this.policyIdExistsErrorMessage(ALWAYS_TRUE_POLICY_ID).pipe(
map((errorMessage) =>
// We want to throw an error if always-true was not found
errorMessage ? null : 'Always True Policy does not exist.',
),
),
]).pipe(
map((errorMessages) => this.buildValidationErrors(errorMessages)),
);
} else if (value.publishMode === 'PUBLISH_RESTRICTED') {
if (value.publishMode !== 'DO_NOT_PUBLISH') {
return combineLatest([
this.assetIdExistsErrorMessage(assetId),
this.contractDefinitionIdErrorMessage(assetId),
Expand All @@ -55,7 +41,6 @@ export class EditAssetFormValidators {
map((result) => this.buildValidationErrors([result])),
);
}

return of(null);
};
}
Expand Down

0 comments on commit 69ad5ab

Please sign in to comment.