Skip to content

Commit c352534

Browse files
[DURACOM-453] port metadata security update, init and administrate
1 parent ab0885e commit c352534

15 files changed

Lines changed: 136 additions & 14 deletions

src/app/dso-shared/dso-edit-metadata/dso-edit-metadata-form.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ export class DsoEditMetadataValue {
8989
if (this.originalValue.value !== this.newValue.value || this.originalValue.language !== this.newValue.language
9090
|| this.originalValue.authority !== this.newValue.authority || this.originalValue.confidence !== this.newValue.confidence) {
9191
this.change = DsoEditMetadataChangeType.UPDATE;
92+
} else if (!hasValue(this.originalValue.authority) && hasValue(this.newValue.authority)) {
93+
this.change = DsoEditMetadataChangeType.ADD;
9294
} else {
9395
this.change = undefined;
9496
}
@@ -362,8 +364,10 @@ export class DsoEditMetadataForm {
362364
});
363365
});
364366
// Reset the order of values within their fields to match their place property
367+
// And reinstate the security level values
365368
this.fieldKeys.forEach((field: string) => {
366369
this.setValuesForFieldSorted(field, this.fields[field]);
370+
this.reinstateSecurityLevel(field);
367371
});
368372
this.reinstatableNewValues = {};
369373
}
@@ -399,6 +403,19 @@ export class DsoEditMetadataForm {
399403
this.fields[mdField] = values.sort((a: DsoEditMetadataValue, b: DsoEditMetadataValue) => a.newValue.place - b.newValue.place);
400404
}
401405

406+
/**
407+
* Set the change property of each value within a metadata field,
408+
* in case the security level has been changed and we are trying to reinstate the changes
409+
* @param mdField
410+
*/
411+
private reinstateSecurityLevel(mdField: string){
412+
this.fields[mdField].forEach((value: DsoEditMetadataValue) => {
413+
if (hasValue(value.newValue.securityLevel) && value.newValue.securityLevel !== value.originalValue.securityLevel) {
414+
value.change = DsoEditMetadataChangeType.UPDATE;
415+
}
416+
});
417+
}
418+
402419
/**
403420
* Get the json PATCH operations for the current changes within this form
404421
* For each metadata field, it'll return operations in the following order: replace, remove (from last to first place), add and move
@@ -423,6 +440,17 @@ export class DsoEditMetadataForm {
423440
language: value.newValue.language,
424441
authority: value.newValue.authority,
425442
confidence: value.newValue.confidence,
443+
securityLevel: value.originalValue.securityLevel,
444+
}));
445+
}
446+
// "replace" the security level value
447+
if (value.originalValue.securityLevel !== value.newValue.securityLevel) {
448+
replaceOperations.push(new MetadataPatchReplaceOperation(field, value.originalValue.place, {
449+
securityLevel: value.newValue.securityLevel,
450+
value: value.newValue.value,
451+
language: value.newValue.language,
452+
authority: value.newValue.authority,
453+
confidence: value.newValue.confidence,
426454
}));
427455
}
428456
} else if (value.change === DsoEditMetadataChangeType.REMOVE) {
@@ -433,6 +461,7 @@ export class DsoEditMetadataForm {
433461
language: value.newValue.language,
434462
authority: value.newValue.authority,
435463
confidence: value.newValue.confidence,
464+
securityLevel: value.newValue.securityLevel,
436465
}));
437466
} else {
438467
console.warn('Illegal metadata change state detected for', value);

src/app/dso-shared/dso-edit-metadata/dso-edit-metadata-headers/dso-edit-metadata-headers.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<div class="flex-grow-1 ds-flex-cell ds-value-cell"><b class="dont-break-out preserve-line-breaks">{{ dsoType + '.edit.metadata.headers.value' | translate }}</b></div>
66
<div class="ds-flex-cell ds-lang-cell"><b>{{ dsoType + '.edit.metadata.headers.language' | translate }}</b></div>
77
<div class="ds-flex-cell ds-authority-cell"><b>{{ dsoType + '.edit.metadata.headers.authority' | translate }}</b></div>
8+
<div class="ds-flex-cell ds-security-cell"><b>{{'item.edit.metadata.headers.security'| translate}}</b></div>
89
<div class="text-center ds-flex-cell ds-edit-cell"><b>{{ dsoType + '.edit.metadata.headers.edit' | translate }}</b></div>
910
</div>
1011
</div>

src/app/dso-shared/dso-edit-metadata/dso-edit-metadata-headers/dso-edit-metadata-headers.component.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe('DsoEditMetadataHeadersComponent', () => {
2929
fixture.detectChanges();
3030
});
3131

32-
it('should display four headers', () => {
33-
expect(fixture.debugElement.queryAll(By.css('.ds-flex-cell')).length).toEqual(4);
32+
it('should display five headers', () => {
33+
expect(fixture.debugElement.queryAll(By.css('.ds-flex-cell')).length).toEqual(5);
3434
});
3535
});

src/app/dso-shared/dso-edit-metadata/dso-edit-metadata-shared/dso-edit-metadata-cells.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,18 @@
1717
max-width: var(--ds-dso-edit-authority-width);
1818
}
1919

20+
.ds-security-cell {
21+
min-width: var(--ds-dso-edit-security-width);
22+
max-width: var(--ds-dso-edit-security-width);
23+
}
2024

2125
.ds-edit-cell {
2226
min-width: var(--ds-dso-edit-actions-width);
27+
max-width: var(--ds-dso-edit-actions-width);
28+
}
29+
30+
.ds-value-cell {
31+
max-width: var(--ds-dso-edit-value-max-width);
2332
}
2433

2534
.ds-value-row {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<div role="row" class="visually-hidden">
22
<div role="columnheader">{{ dsoType + '.edit.metadata.headers.value' | translate }}</div>
33
<div role="columnheader">{{ dsoType + '.edit.metadata.headers.language' | translate }}</div>
4+
<div role="columnheader">{{ dsoType + '.edit.metadata.headers.authority' | translate }}</div>
45
<div role="columnheader">{{ dsoType + '.edit.metadata.headers.edit' | translate }}</div>
56
</div>

src/app/dso-shared/dso-edit-metadata/dso-edit-metadata-value/dso-edit-metadata-value.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ import {
6262
} from 'rxjs';
6363
import {
6464
distinctUntilChanged,
65+
filter,
6566
map,
6667
shareReplay,
6768
switchMap,
@@ -274,7 +275,7 @@ export class DsoEditMetadataValueComponent implements OnInit, OnChanges, OnDestr
274275

275276
this.sub = combineLatest([
276277
this._mdField$,
277-
this._metadataSecurityConfiguration$,
278+
this._metadataSecurityConfiguration$.pipe(filter(config => !!config)),
278279
]).subscribe(([mdField, metadataSecurityConfig]) => this.initSecurityLevel(mdField, metadataSecurityConfig));
279280

280281
this.canShowMetadataSecurity$ =

src/app/dso-shared/dso-edit-metadata/dso-edit-metadata.component.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@if (form) {
1+
@if (isFormInitialized$ | async) {
22
<div class="item-metadata">
33
<div class="button-row top d-flex my-2 space-children-mr ms-gap">
44
<button class="me-auto btn btn-success" id="dso-add-btn" [dsBtnDisabled]="form.newValue || (saving$ | async)"
@@ -79,6 +79,7 @@
7979
[form]="form"
8080
[dsoType]="dsoType"
8181
[saving$]="saving$"
82+
[metadataSecurityConfiguration]="(securitySettings$ | async)"
8283
[draggingMdField$]="draggingMdField$"
8384
[mdField]="mdField"
8485
(valueSaved)="onValueSaved()">

src/app/dso-shared/dso-edit-metadata/dso-edit-metadata.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ export class DsoEditMetadataComponent implements OnInit, OnDestroy {
243243
}),
244244
);
245245
} else {
246-
of(null);
246+
return of(null);
247247
}
248248
}
249249

src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
</div>
4646
@if (model.languageCodes && model.languageCodes.length > 0) {
47-
<div class="col-2" >
47+
<div class="col-sm-2" >
4848
<select
4949
#language="ngModel"
5050
[disabled]="model.readOnly"
@@ -61,7 +61,7 @@
6161
</div>
6262
}
6363
@if (model.hasSecurityToggle) {
64-
<div class="col-xs-2" [class.date-field-security]="model.type === 'DATE'">
64+
<div class="col-sm-2" [class.date-field-security]="model.type === 'DATE'">
6565
@if (model.toggleSecurityVisibility) {
6666
<ds-edit-metadata-security [readOnly]="model.readOnly"
6767
[securityConfigLevel]="model.securityConfigLevel"

src/app/submission/objects/submission-objects.effects.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ export class SubmissionObjectEffects {
160160
action.payload.sections,
161161
action.payload.item,
162162
null,
163+
action.payload.metadataSecurityConfiguration,
163164
))));
164165

165166
/**

0 commit comments

Comments
 (0)