Removing feedback_state fields when saving a model from the GUI
Change-Id: I5cd9dcb202594b9a29473483c8af1d3c9d5ed71e
diff --git a/src/app/core/services/helpers/config.helpers.spec.ts b/src/app/core/services/helpers/config.helpers.spec.ts
index 03b53d0..decc059 100644
--- a/src/app/core/services/helpers/config.helpers.spec.ts
+++ b/src/app/core/services/helpers/config.helpers.spec.ts
@@ -374,12 +374,7 @@
{
type: 'string',
name: 'bar',
- validators: [
- {
- bool_value: true,
- name: 'required'
- }
- ],
+ validators: [],
read_only: false
}
],
@@ -397,6 +392,38 @@
expect(res).not.toHaveProp('baz');
});
+
+ it('should remove properties marked as read_only', () => {
+ const model: IXosModeldef = {
+ name: 'Test',
+ app: 'test',
+ fields: [
+ {
+ type: 'number',
+ name: 'write_allowed',
+ validators: [],
+ read_only: false
+ },
+ {
+ type: 'string',
+ name: 'read_only',
+ validators: [],
+ read_only: true
+ }
+ ],
+ description: '',
+ verbose_name: ''
+ };
+
+ const item: any = {
+ write_allowed: 'existing',
+ read_only: 'remove me'
+ };
+
+ const res = service['removeExtraFields'](item, model);
+
+ expect(res).not.toHaveProp('read_only');
+ });
});
});
});
diff --git a/src/app/core/services/helpers/config.helpers.ts b/src/app/core/services/helpers/config.helpers.ts
index 194bea1..0e17d73 100644
--- a/src/app/core/services/helpers/config.helpers.ts
+++ b/src/app/core/services/helpers/config.helpers.ts
@@ -97,7 +97,9 @@
public form_excluded_fields = this.excluded_fields.concat([
'id',
'policy_status',
+ 'policy_code',
'backend_status',
+ 'backend_code',
]);
constructor(
@@ -319,7 +321,7 @@
return;
}
- // remove fields added by the GUI
+ // remove fields that are not part of the model
item = this.removeExtraFields(item, model);
const itemCopy = angular.copy(item);
@@ -356,8 +358,9 @@
private removeExtraFields(item: any, modelDef: IXosModeldef) {
_.forEach(Object.keys(item), prop => {
- const hasField = _.findIndex(modelDef.fields, {name: prop}) > -1;
- if (!hasField) {
+ const field = _.find(modelDef.fields, {name: prop});
+ const hasField = angular.isDefined(field);
+ if (!hasField || field.read_only) {
delete item[prop];
}
});