Skip to content

Commit cb4bc13

Browse files
[DURACOM-453] fix security level patch update, fix style in admin table, fix missing config in field models
1 parent b383541 commit cb4bc13

14 files changed

Lines changed: 223 additions & 41 deletions

File tree

src/app/core/data/object-updates/patch-operation-service/metadata-patch-operation.service.spec.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ describe('MetadataPatchOperationService', () => {
2525
key: 'dc.title',
2626
value: 'Deleted title',
2727
place: 0,
28+
securityLevel: 1,
2829
}),
2930
changeType: FieldChangeType.REMOVE,
3031
},
@@ -48,12 +49,13 @@ describe('MetadataPatchOperationService', () => {
4849
key: 'dc.title',
4950
value: 'Added title',
5051
place: 0,
52+
securityLevel: 1,
5153
}),
5254
changeType: FieldChangeType.ADD,
5355
},
5456
});
5557
expected = [
56-
{ op: 'add', path: '/metadata/dc.title/-', value: [{ value: 'Added title', language: undefined }] },
58+
{ op: 'add', path: '/metadata/dc.title/-', value: [{ value: 'Added title', language: undefined, securityLevel: 1 }] },
5759
] as any[];
5860
result = service.fieldUpdatesToPatchOperations(fieldUpdates);
5961
});
@@ -71,12 +73,13 @@ describe('MetadataPatchOperationService', () => {
7173
key: 'dc.title',
7274
value: 'Changed title',
7375
place: 0,
76+
securityLevel: 1,
7477
}),
7578
changeType: FieldChangeType.UPDATE,
7679
},
7780
});
7881
expected = [
79-
{ op: 'replace', path: '/metadata/dc.title/0', value: { value: 'Changed title', language: undefined } },
82+
{ op: 'replace', path: '/metadata/dc.title/0', value: { value: 'Changed title', language: undefined, securityLevel: 1 } },
8083
] as any[];
8184
result = service.fieldUpdatesToPatchOperations(fieldUpdates);
8285
});
@@ -94,6 +97,7 @@ describe('MetadataPatchOperationService', () => {
9497
key: 'dc.title',
9598
value: 'First deleted title',
9699
place: 0,
100+
securityLevel: 1,
97101
}),
98102
changeType: FieldChangeType.REMOVE,
99103
},
@@ -102,6 +106,7 @@ describe('MetadataPatchOperationService', () => {
102106
key: 'dc.title',
103107
value: 'Second deleted title',
104108
place: 1,
109+
securityLevel: 1,
105110
}),
106111
changeType: FieldChangeType.REMOVE,
107112
},
@@ -110,6 +115,7 @@ describe('MetadataPatchOperationService', () => {
110115
key: 'dc.title',
111116
value: 'Third deleted title',
112117
place: 2,
118+
securityLevel: 1,
113119
}),
114120
changeType: FieldChangeType.REMOVE,
115121
},
@@ -135,6 +141,7 @@ describe('MetadataPatchOperationService', () => {
135141
key: 'dc.title',
136142
value: 'Third deleted title',
137143
place: 2,
144+
securityLevel: 1,
138145
}),
139146
changeType: FieldChangeType.REMOVE,
140147
},
@@ -143,6 +150,7 @@ describe('MetadataPatchOperationService', () => {
143150
key: 'dc.title',
144151
value: 'Second deleted title',
145152
place: 1,
153+
securityLevel: 1,
146154
}),
147155
changeType: FieldChangeType.REMOVE,
148156
},
@@ -151,6 +159,7 @@ describe('MetadataPatchOperationService', () => {
151159
key: 'dc.title',
152160
value: 'First deleted title',
153161
place: 0,
162+
securityLevel: 1,
154163
}),
155164
changeType: FieldChangeType.REMOVE,
156165
},
@@ -176,6 +185,7 @@ describe('MetadataPatchOperationService', () => {
176185
key: 'dc.title',
177186
value: 'Second deleted title',
178187
place: 1,
188+
securityLevel: 1,
179189
}),
180190
changeType: FieldChangeType.REMOVE,
181191
},
@@ -184,6 +194,7 @@ describe('MetadataPatchOperationService', () => {
184194
key: 'dc.title',
185195
value: 'Third deleted title',
186196
place: 2,
197+
securityLevel: 1,
187198
}),
188199
changeType: FieldChangeType.REMOVE,
189200
},
@@ -192,6 +203,7 @@ describe('MetadataPatchOperationService', () => {
192203
key: 'dc.title',
193204
value: 'First deleted title',
194205
place: 0,
206+
securityLevel: 1,
195207
}),
196208
changeType: FieldChangeType.REMOVE,
197209
},
@@ -217,6 +229,7 @@ describe('MetadataPatchOperationService', () => {
217229
key: 'dc.title',
218230
value: 'Second deleted title',
219231
place: 1,
232+
securityLevel: 1,
220233
}),
221234
changeType: FieldChangeType.REMOVE,
222235
},
@@ -225,6 +238,7 @@ describe('MetadataPatchOperationService', () => {
225238
key: 'dc.title',
226239
value: 'Third changed title',
227240
place: 2,
241+
securityLevel: 1,
228242
}),
229243
changeType: FieldChangeType.UPDATE,
230244
},
@@ -233,13 +247,14 @@ describe('MetadataPatchOperationService', () => {
233247
key: 'dc.title',
234248
value: 'First deleted title',
235249
place: 0,
250+
securityLevel: 1,
236251
}),
237252
changeType: FieldChangeType.REMOVE,
238253
},
239254
});
240255
expected = [
241256
{ op: 'remove', path: '/metadata/dc.title/1' },
242-
{ op: 'replace', path: '/metadata/dc.title/1', value: { value: 'Third changed title', language: undefined } },
257+
{ op: 'replace', path: '/metadata/dc.title/1', value: { value: 'Third changed title', language: undefined ,securityLevel: 1 } },
243258
{ op: 'remove', path: '/metadata/dc.title/0' },
244259
] as any[];
245260
result = service.fieldUpdatesToPatchOperations(fieldUpdates);

src/app/core/data/object-updates/patch-operation-service/metadata-patch-operation.service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export class MetadataPatchOperationService implements PatchOperationService {
7777
const val = {
7878
value: metadatum.value,
7979
language: metadatum.language,
80+
securityLevel: metadatum.securityLevel,
8081
};
8182

8283
let operation: MetadataPatchOperation;

src/app/core/json-patch/builder/json-patch-operations-builder.ts

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { Injectable } from '@angular/core';
2+
import { ConfidenceType } from '@dspace/core/shared/confidence-type';
3+
import { Metadata } from '@dspace/core/shared/metadata.utils';
24
import {
35
dateToISOFormat,
46
dateToString,
@@ -52,7 +54,7 @@ export class JsonPatchOperationsBuilder {
5254
new NewPatchAddOperationAction(
5355
path.rootElement,
5456
path.subRootElement,
55-
path.path, this.prepareValue(value, plain, first, languages)));
57+
path.path, this.prepareValue(value, plain, first, null, languages)));
5658
}
5759

5860
/**
@@ -64,9 +66,10 @@ export class JsonPatchOperationsBuilder {
6466
* the value to update the referenced path
6567
* @param plain
6668
* a boolean representing if the value to be added is a plain text value
69+
* @param securityLevel
6770
* @param language
6871
*/
69-
replace(path: JsonPatchOperationPathObject, value, plain = false, language = null) {
72+
replace(path: JsonPatchOperationPathObject, value, plain = false, securityLevel = null, language = null) {
7073
if (hasNoValue(value) || (typeof value === 'object' && hasNoValue(value.value))) {
7174
this.remove(path);
7275
} else {
@@ -75,7 +78,7 @@ export class JsonPatchOperationsBuilder {
7578
path.rootElement,
7679
path.subRootElement,
7780
path.path,
78-
this.prepareValue(value, plain, false, language)));
81+
this.prepareValue(value, plain, false, securityLevel, language)));
7982
}
8083
}
8184

@@ -126,39 +129,67 @@ export class JsonPatchOperationsBuilder {
126129
path.path));
127130
}
128131

129-
protected prepareValue(value: any, plain: boolean, first: boolean, languages: string[] = null) {
132+
protected prepareValue(value: any, plain: boolean, first: boolean, securityLevel = null, languages: string[] = null) {
130133
let operationValue: any = null;
131134
if (hasValue(value)) {
132135
if (plain) {
133136
operationValue = value;
134137
} else {
135138
if (Array.isArray(value)) {
136139
operationValue = [];
137-
value.forEach((entry) => {
140+
value.forEach((entry, index) => {
138141
if ((typeof entry === 'object')) {
139-
operationValue.push(this.prepareObjectValue(entry));
142+
if (isNotEmpty(securityLevel)) {
143+
operationValue.push(this.prepareObjectValue(entry, securityLevel));
144+
} else {
145+
operationValue.push(this.prepareObjectValue(entry));
146+
}
140147
} else {
141-
operationValue.push(new FormFieldMetadataValueObject(entry));
148+
operationValue.push(new FormFieldMetadataValueObject(entry, languages ? languages[index] : null, securityLevel));
142149
}
143150
});
144151
} else if (typeof value === 'object') {
145-
operationValue = this.prepareObjectValue(value);
152+
if (isNotEmpty(securityLevel)) {
153+
operationValue = this.prepareObjectValue(value, securityLevel);
154+
} else {
155+
operationValue = this.prepareObjectValue(value);
156+
}
146157
} else {
147-
operationValue = new FormFieldMetadataValueObject(value);
158+
// add the possibility to add security level when value is string
159+
// in this case security level is set on metadata value
160+
if (isNotEmpty(securityLevel)) {
161+
operationValue = new FormFieldMetadataValueObject(value, null, securityLevel);
162+
} else {
163+
operationValue = new FormFieldMetadataValueObject(value, null);
164+
}
165+
148166
}
149167
}
150168
}
151169
return (first && !Array.isArray(operationValue)) ? [operationValue] : operationValue;
152170
}
153171

154-
protected prepareObjectValue(value: any) {
172+
protected prepareObjectValue(value: any, securityLevel = null) {
155173
let operationValue = Object.create({});
156174
if (isEmpty(value) || value instanceof FormFieldMetadataValueObject) {
157-
operationValue = value;
175+
if (isNotEmpty(securityLevel)) {
176+
operationValue = { ...value, securityLevel: securityLevel };
177+
} else {
178+
operationValue = value;
179+
}
180+
//Update confidence if was added once the field was already created, value is set only in constructor of FormFieldMetadataValueObject
181+
if (Metadata.hasValidAuthority(operationValue.authority) && (isEmpty(operationValue.confidence) || operationValue.confidence === -1)) {
182+
operationValue.confidence = ConfidenceType.CF_ACCEPTED;
183+
}
184+
158185
} else if (value instanceof Date) {
159-
operationValue = new FormFieldMetadataValueObject(dateToISOFormat(value));
186+
if (securityLevel != null) {
187+
operationValue = new FormFieldMetadataValueObject(dateToISOFormat(value), null, securityLevel);
188+
} else {
189+
operationValue = new FormFieldMetadataValueObject(dateToISOFormat(value));
190+
}
160191
} else if (value instanceof VocabularyEntry) {
161-
operationValue = this.prepareAuthorityValue(value);
192+
operationValue = this.prepareAuthorityValue(value, securityLevel);
162193
} else if (value instanceof FormFieldLanguageValueObject) {
163194
operationValue = new FormFieldMetadataValueObject(value.value, value.language);
164195
} else if (value.hasOwnProperty('authority')) {
@@ -180,12 +211,12 @@ export class JsonPatchOperationsBuilder {
180211
return operationValue;
181212
}
182213

183-
protected prepareAuthorityValue(value: any): FormFieldMetadataValueObject {
214+
protected prepareAuthorityValue(value: any, securityLevel = null): FormFieldMetadataValueObject {
184215
let operationValue: FormFieldMetadataValueObject;
185216
if (isNotEmpty(value.authority)) {
186-
operationValue = new FormFieldMetadataValueObject(value.value, value.language, value.authority);
217+
operationValue = new FormFieldMetadataValueObject(value.value, value.language, securityLevel, value.authority);
187218
} else {
188-
operationValue = new FormFieldMetadataValueObject(value.value, value.language);
219+
operationValue = new FormFieldMetadataValueObject(value.value, value.language, securityLevel);
189220
}
190221
return operationValue;
191222
}

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@
2727
max-width: var(--ds-dso-edit-actions-width);
2828
}
2929

30-
.ds-value-cell {
31-
max-width: var(--ds-dso-edit-value-max-width);
32-
}
33-
3430
.ds-value-row {
3531
background-color: white;
3632

src/app/shared/form/builder/ds-dynamic-form-ui/models/date-picker/date-picker.model.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { MetadataValue } from '@dspace/core/shared/metadata.models';
22
import {
33
isEmpty,
4+
isNotEmpty,
45
isNotUndefined,
56
} from '@dspace/shared/utils/empty.util';
67
import {
@@ -22,6 +23,9 @@ export interface DynamicDsDateControlModelConfig extends DynamicDatePickerModelC
2223
legend?: string;
2324
typeBindRelations?: DynamicFormControlRelation[];
2425
repeatable: boolean;
26+
securityLevel?: number;
27+
securityConfigLevel?: number[];
28+
toggleSecurityVisibility?: boolean;
2529
}
2630

2731
/**
@@ -32,6 +36,9 @@ export class DynamicDsDatePickerModel extends DynamicDateControlModel {
3236
@serializable() typeBindRelations: DynamicFormControlRelation[];
3337
@serializable() readonly type: string = DYNAMIC_FORM_CONTROL_TYPE_DSDATEPICKER;
3438
@serializable() metadataValue: MetadataValue;
39+
@serializable() securityLevel?: number;
40+
@serializable() securityConfigLevel?: number[];
41+
@serializable() toggleSecurityVisibility = true;
3542
malformedDate: boolean;
3643
legend: string;
3744
hasLanguages = false;
@@ -42,6 +49,11 @@ export class DynamicDsDatePickerModel extends DynamicDateControlModel {
4249
this.malformedDate = false;
4350
this.legend = config.legend;
4451
this.metadataValue = (config as any).metadataValue;
52+
this.securityLevel = config.securityLevel;
53+
this.securityConfigLevel = config.securityConfigLevel;
54+
if (isNotUndefined(config.toggleSecurityVisibility)) {
55+
this.toggleSecurityVisibility = config.toggleSecurityVisibility;
56+
}
4557
this.typeBindRelations = config.typeBindRelations ? config.typeBindRelations : [];
4658
this.hiddenUpdates = new BehaviorSubject<boolean>(this.hidden);
4759
this.repeatable = config.repeatable;
@@ -60,4 +72,11 @@ export class DynamicDsDatePickerModel extends DynamicDateControlModel {
6072
}
6173
}
6274

75+
get hasSecurityLevel(): boolean {
76+
return isNotEmpty(this.securityLevel);
77+
}
78+
79+
get hasSecurityToggle(): boolean {
80+
return isNotEmpty(this.securityConfigLevel) && this.securityConfigLevel.length > 1 && this.toggleSecurityVisibility;
81+
}
6382
}

0 commit comments

Comments
 (0)