Skip to content

Commit

Permalink
story #12868:Update Access Contract APP to restrict object downloads …
Browse files Browse the repository at this point in the history
…in Search APP.
  • Loading branch information
mohamed tizaoui committed Jun 24, 2024
1 parent fa3551e commit 127f19d
Show file tree
Hide file tree
Showing 14 changed files with 305 additions and 153 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,13 @@
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;

@Service
public class AccessContractInternalService {
Expand Down Expand Up @@ -259,12 +265,18 @@ public AccessContractDto patch(VitamContext vitamContext, final Map<String, Obje
LOGGER.debug("Patch Access Contract EvIdAppSession : {} ", vitamContext.getApplicationSessionId());
// Fix because Vitam doesn't allow String Array as action value (transformed to a string representation"[value1, value2]"
// Manual setting instead of updateRequest.addActions( UpdateActionHelper.set(fieldsUpdated));
JsonNode fieldsUpdated = converter.convertToUpperCaseFields(partialDto);

ArrayNode actions = JsonHandler.createArrayNode();
if (
Boolean.TRUE.equals(partialDto.get("everyDataObjectVersion")) ||
partialDto.get("dataObjectVersion") == null
) {
partialDto.put("dataObjectVersion", new HashSet<>());
}

JsonNode fieldsUpdated = converter.convertToUpperCaseFields(partialDto);
ObjectNode action = JsonHandler.createObjectNode();
action.set("$set", fieldsUpdated);

ArrayNode actions = JsonHandler.createArrayNode();
actions.add(action);

ObjectNode query = JsonHandler.createObjectNode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,35 +130,6 @@
></vitamui-common-autocomplete-multi-select>
</div>

<div>
<vitamui-common-slide-toggle formControlName="everyDataObjectVersion"
>{{ 'ACCESS_CONTRACT.CREATE_DIALOG.EVERY_DATA_OBJECT_VERSION' | translate }}

<i
class="vitamui-icon vitamui-icon-info align-middle primary"
vitamuiCommonToolTip="{{ 'ACCESS_CONTRACT.CREATE_DIALOG.EVERY_DATA_OBJECT_VERSION_TOOLTIP' | translate }}"
></i>
</vitamui-common-slide-toggle>
</div>

<div *ngIf="form.get('secondStep.everyDataObjectVersion').value === false">
<mat-form-field class="vitamui-mat-select pb-0">
<mat-select
formControlName="dataObjectVersion"
[placeholder]="'ACCESS_CONTRACT.CREATE_DIALOG.EVERY_DATA_OBJECT_VERSION_SELECT_PLACEHOLDER' | translate"
multiple
required
>
<mat-option *ngFor="let usage of usages" [value]="usage.key">
{{ usage.label }}
</mat-option>
</mat-select>
<div class="select-arrow">
<i class="material-icons">keyboard_arrow_down</i>
</div>
</mat-form-field>
</div>

<div class="actions">
<button type="button" class="btn primary" cdkStepperNext [disabled]="form.get('secondStep').errors">
{{ 'COMMON.NEXT' | translate }}
Expand All @@ -174,29 +145,63 @@
</cdk-step>

<cdk-step>
<div class="content mt-3">
<div class="content mt-3" formGroupName="thirdStep">
<div class="text medium light">{{ 'ACCESS_CONTRACT.CREATE_DIALOG.TITLE' | translate }}</div>
<div class="text large bold mb-3">{{ 'ACCESS_CONTRACT.CREATE_DIALOG.WRITING_PERMISSION_TITLE' | translate }}</div>

<div>
<vitamui-common-slide-toggle formControlName="writingPermission"
>{{ 'ACCESS_CONTRACT.CREATE_DIALOG.WRITING_PERMISSION' | translate }}
<i
class="vitamui-icon vitamui-icon-info align-middle primary"
vitamuiCommonToolTip="{{ 'ACCESS_CONTRACT.CREATE_DIALOG.WRITING_PERMISSION_TOOLTIP' | translate }}"
vitamuiCommonToolTipPosition="BOTTOM"
></i>
</vitamui-common-slide-toggle>
</div>
<div class="mt-4 mb-4">
<div class="title-text medium light">{{ 'ACCESS_CONTRACT.CREATE_DIALOG.WRITE_PERMISSION_AUTHORIZE' | translate }}</div>
<div class="mt-3">
<vitamui-common-slide-toggle formControlName="writingPermission"
>{{ 'ACCESS_CONTRACT.CREATE_DIALOG.AUTHORIZE_DESCRIPTIVE_METADATA_WRITE' | translate }}
<i
class="vitamui-icon vitamui-icon-info align-middle primary"
vitamuiCommonToolTip="{{ 'ACCESS_CONTRACT.CREATE_DIALOG.AUTHORIZE_DESCRIPTIVE_METADATA_WRITE' | translate }}"
vitamuiCommonToolTipPosition="BOTTOM"
></i>
</vitamui-common-slide-toggle>
</div>
<div>
<vitamui-common-slide-toggle formControlName="writingAuthorizedDesc"
>{{ 'ACCESS_CONTRACT.CREATE_DIALOG.AUTHORIZE_MANAGEMENT_METADATA_WRITE' | translate }}
</vitamui-common-slide-toggle>
</div>
</div>

<div class="mt-4 mb-4" class="half-width">
<div class="title-text medium light">{{ 'ACCESS_CONTRACT.CREATE_DIALOG.AUTHORIZE_OBJECT_DOWNLOAD' | translate }}</div>

<div class="mt-4 mb-4 equal-width-container">
<div>
<mat-button-toggle-group formControlName="downloadChoose" class="vitamui-button-toggle-group">
<mat-button-toggle value="ALL">{{ 'ACCESS_CONTRACT.CREATE_DIALOG.ALL' | translate }}</mat-button-toggle>
<mat-button-toggle value="NONE">{{ 'ACCESS_CONTRACT.CREATE_DIALOG.NONE' | translate }}</mat-button-toggle>
<mat-button-toggle value="SELECTION">{{ 'ACCESS_CONTRACT.CREATE_DIALOG.SELECTION' | translate }}</mat-button-toggle>
</mat-button-toggle-group>
</div>

<div *ngIf="form.controls.writingPermission.value === true">
<vitamui-common-slide-toggle formControlName="writingRestrictedDesc"
>{{ 'ACCESS_CONTRACT.CREATE_DIALOG.WRITING_RESTRICTED_DESC' | translate }}
</vitamui-common-slide-toggle>
<div class="mt-2 mb-4" *ngIf="form.get('thirdStep.downloadChoose').value === 'SELECTION'">
<mat-form-field class="vitamui-mat-select pb-0 full-width">
<mat-select
formControlName="dataObjectVersion"
[placeholder]="'ACCESS_CONTRACT.CREATE_DIALOG.EVERY_DATA_OBJECT_VERSION_SELECT_PLACEHOLDER' | translate"
multiple
required
>
<mat-option *ngFor="let usage of usages" [value]="usage.key">{{ usage.label }}</mat-option>
</mat-select>
<div class="select-arrow">
<i class="material-icons">keyboard_arrow_down</i>
</div>
</mat-form-field>
</div>
</div>
</div>

<div class="actions">
<button type="button" class="btn primary" cdkStepperNext>{{ 'COMMON.NEXT' | translate }}</button>
<button type="button" class="btn primary" [disabled]="form.get('thirdStep').errors" cdkStepperNext>
{{ 'COMMON.NEXT' | translate }}
</button>
<button type="button" class="btn cancel" (click)="onCancel()">{{ 'COMMON.UNDO' | translate }}</button>
</div>
<button type="button" class="btn link" cdkStepperPrevious>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.equal-width-container {
display: flex;
flex-direction: column;
}

.equal-width-container > * {
width: 100%;
}

.full-width {
width: 100%;
}

.half-width {
width: 47%;
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,21 +145,37 @@ export class AccessContractCreateComponent implements OnInit, OnDestroy {
{
everyOriginatingAgency: [true],
originatingAgencies: [[]],
everyDataObjectVersion: [true],
dataObjectVersion: [new Array<string>()],
},
{
validators: [this.secondStepValidator()],
},
),
/* <- step 3 -> */
writingPermission: [false],
writingRestrictedDesc: [true],
thirdStep: this.formBuilder.group(
{
writingPermission: [false],
downloadChoose: ['ALL'],
everyDataObjectVersion: [true],
dataObjectVersion: [new Array<string>()],
writingAuthorizedDesc: [false],
},
{
validators: [this.thirdStepValidator()],
},
),
/* <- step 4 -> */
rootUnits: [[], Validators.required],
excludedRootUnits: [[]],
});

this.form.get('thirdStep.downloadChoose').valueChanges.subscribe((val) => {
this.form.get('thirdStep.everyDataObjectVersion').setValue(val === 'ALL', { emitEvent: false });

if (val !== 'SELECTION') {
this.form.get('thirdStep.dataObjectVersion').setValue(null);
}
});
this.onWritingRestrictedDescChanges();
this.selectNodesControl.valueChanges.subscribe((value: { included: string[]; excluded: string[] }) => {
this.form.controls.rootUnits.setValue(value.included);
this.form.controls.excludedRootUnits.setValue(value.excluded);
Expand Down Expand Up @@ -200,6 +216,7 @@ export class AccessContractCreateComponent implements OnInit, OnDestroy {
accessContract.status === 'ACTIVE'
? (accessContract.activationDate = new Date().toISOString())
: (accessContract.deactivationDate = new Date().toISOString());

this.accessContractService.create(accessContract).subscribe(
() => {
this.isDisabledButton = false;
Expand Down Expand Up @@ -228,14 +245,36 @@ export class AccessContractCreateComponent implements OnInit, OnDestroy {
);
}

onWritingRestrictedDescChanges(): void {
this.form.get('thirdStep.writingAuthorizedDesc').valueChanges.subscribe((val) => {
if (val) {
this.form.get('thirdStep.writingPermission').setValue(true, { emitEvent: false });
}
});

this.form.get('thirdStep.writingPermission').valueChanges.subscribe((val) => {
if (!val) {
this.form.get('thirdStep.writingAuthorizedDesc').setValue(false, { emitEvent: false });
}
});
}

private thirdStepValidator(): ValidatorFn {
return (form: FormGroup): ValidationErrors | null => {
const downloadChoose = form.get('downloadChoose').value;
const dataObjectVersion = form.get('dataObjectVersion').value;
if (downloadChoose === 'SELECTION' && dataObjectVersion.length === 0) {
return { dataObjectVersion: true };
}
return null;
};
}

private secondStepValidator(): ValidatorFn {
return (form: FormGroup): ValidationErrors | null => {
if (form.get('everyOriginatingAgency').value == false && form.get('originatingAgencies').value.length == 0) {
return { originatingAgencies: true };
}
if (form.get('everyDataObjectVersion').value === false && form.get('dataObjectVersion').value.length == 0) {
return { dataObjectVersion: true };
}
return null;
};
}
Expand All @@ -253,8 +292,11 @@ export class AccessContractCreateComponent implements OnInit, OnDestroy {
...form.value,
everyOriginatingAgency: this.getControl(form, 'secondStep.everyOriginatingAgency').value,
originatingAgencies: this.getControl(form, 'secondStep.originatingAgencies').value,
everyDataObjectVersion: this.getControl(form, 'secondStep.everyDataObjectVersion').value,
dataObjectVersion: this.getControl(form, 'secondStep.dataObjectVersion').value,
writingPermission: this.getControl(form, 'thirdStep.writingPermission').value,
downloadChoose: this.getControl(form, 'thirdStep.downloadChoose').value,
everyDataObjectVersion: this.getControl(form, 'thirdStep.everyDataObjectVersion').value,
dataObjectVersion: this.getControl(form, 'thirdStep.dataObjectVersion').value,
writingRestrictedDesc: !this.getControl(form, 'thirdStep.writingAuthorizedDesc').value,
status: this.mapStatus(this.getControl(form, 'status').value),
accessLog: this.mapStatus(this.getControl(form, 'accessLog').value),
} as AccessContract;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
*/
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { ReactiveFormsModule } from '@angular/forms';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { MatButtonToggleModule } from '@angular/material/button-toggle';
import { MatLegacyFormFieldModule as MatFormFieldModule } from '@angular/material/legacy-form-field';
import { MatLegacyInputModule as MatInputModule } from '@angular/material/legacy-input';
Expand All @@ -52,6 +52,7 @@ import { AccessContractCreateComponent } from './access-contract-create.componen
@NgModule({
imports: [
CommonModule,
FormsModule,
SharedModule,
MatButtonToggleModule,
MatFormFieldModule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import { AccessContractNodeUpdateComponent } from './access-contract-nodes-tab/a
import { AccessContractPreviewComponent } from './access-contract-preview.component';
import { AccessContractUsageAndServicesTabComponent } from './access-contract-usage-and-services-tab/access-contract-usage-and-services-tab.component';
import { AccessContractWriteAccessTabComponent } from './access-contract-write-access-tab/access-contract-write-access-tab.component';
import { MatButtonToggleModule } from '@angular/material/button-toggle';

@NgModule({
imports: [
Expand All @@ -76,6 +77,7 @@ import { AccessContractWriteAccessTabComponent } from './access-contract-write-a
MatTabsModule,
MatFormFieldModule,
MatInputModule,
MatButtonToggleModule,
],
declarations: [
AccessContractPreviewComponent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,6 @@
</vitamui-common-autocomplete-multi-select>
</ng-container>

<vitamui-common-slide-toggle class="w-100 mt-2" formControlName="everyDataObjectVersion">
<span>{{ 'ACCESS_CONTRACT.TAB.USAGE.ALL_USAGES' | translate }}</span>
</vitamui-common-slide-toggle>

<mat-form-field class="vitamui-mat-select w-100 p-0" *ngIf="!form?.get('everyDataObjectVersion')?.value">
<mat-select
formControlName="dataObjectVersion"
placeholder="{{ 'ACCESS_CONTRACT.TAB.USAGE.SELECT_USAGES' | translate }}"
panelclass="vitamui-mat-select"
multiple
required
>
<mat-option *ngFor="let usage of usages" [value]="usage.key"> {{ usage.label }}</mat-option>
</mat-select>
<div class="select-arrow">
<i class="material-icons">keyboard_arrow_up</i>
<i class="material-icons">keyboard_arrow_down</i>
</div>
</mat-form-field>

<div *ngIf="form.controls.dataObjectVersion?.touched && form.controls.dataObjectVersion.errors?.required" class="text caption danger m-2">
{{ 'ACCESS_CONTRACT.TAB.USAGE.NO_USAGE_SELECTED' | translate }}
</div>

<button type="submit" class="btn primary mt-4" [disabled]="unChanged() || isInvalid() || submitted">
{{ 'COMMON.SAVE' | translate }}
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ describe('AccessContractUsageAndServicesTabComponent', () => {
const accessContractValue = {
everyOriginatingAgency: true,
originatingAgencies: ['test'],
everyDataObjectVersion: true,
dataObjectVersion: ['test'],
};

const previousValue: AccessContract = {
Expand Down
Loading

0 comments on commit 127f19d

Please sign in to comment.