mirror of https://github.com/veops/cmdb.git
fix(api): update CI for unique identifier
This commit is contained in:
parent
aaa4ca1327
commit
d0129439cd
|
@ -524,10 +524,14 @@ class CIManager(object):
|
||||||
raw_dict = copy.deepcopy(ci_dict)
|
raw_dict = copy.deepcopy(ci_dict)
|
||||||
|
|
||||||
ci_attr2type_attr = {type_attr.attr_id: type_attr for type_attr, _ in attrs}
|
ci_attr2type_attr = {type_attr.attr_id: type_attr for type_attr, _ in attrs}
|
||||||
|
unique_name = None
|
||||||
for _, attr in attrs:
|
for _, attr in attrs:
|
||||||
if attr.default and attr.default.get('default') == AttributeDefaultValueEnum.UPDATED_AT:
|
if attr.default and attr.default.get('default') == AttributeDefaultValueEnum.UPDATED_AT:
|
||||||
ci_dict[attr.name] = now
|
ci_dict[attr.name] = now
|
||||||
|
|
||||||
|
if attr.id == ci_type.unique_id:
|
||||||
|
unique_name = attr.name
|
||||||
|
|
||||||
value_manager = AttributeValueManager()
|
value_manager = AttributeValueManager()
|
||||||
|
|
||||||
password_dict = dict()
|
password_dict = dict()
|
||||||
|
@ -557,7 +561,8 @@ class CIManager(object):
|
||||||
|
|
||||||
ci_dict = {k: v for k, v in ci_dict.items() if k in ci_type_attrs_name}
|
ci_dict = {k: v for k, v in ci_dict.items() if k in ci_type_attrs_name}
|
||||||
key2attr = value_manager.valid_attr_value(ci_dict, ci.type_id, ci.id, ci_type_attrs_name,
|
key2attr = value_manager.valid_attr_value(ci_dict, ci.type_id, ci.id, ci_type_attrs_name,
|
||||||
ci_attr2type_attr=ci_attr2type_attr)
|
ci_attr2type_attr=ci_attr2type_attr,
|
||||||
|
unique_name=unique_name)
|
||||||
|
|
||||||
if computed_attrs:
|
if computed_attrs:
|
||||||
value_manager.handle_ci_compute_attributes(ci_dict, computed_attrs, ci)
|
value_manager.handle_ci_compute_attributes(ci_dict, computed_attrs, ci)
|
||||||
|
|
|
@ -136,7 +136,7 @@ class AttributeValueManager(object):
|
||||||
if not re.compile(expr).match(str(value)):
|
if not re.compile(expr).match(str(value)):
|
||||||
return abort(400, ErrFormat.attribute_value_invalid2.format(alias, value))
|
return abort(400, ErrFormat.attribute_value_invalid2.format(alias, value))
|
||||||
|
|
||||||
def _validate(self, attr, value, value_table, ci=None, type_id=None, ci_id=None, type_attr=None):
|
def _validate(self, attr, value, value_table, ci=None, type_id=None, ci_id=None, type_attr=None, unique_name=None):
|
||||||
if not attr.is_reference:
|
if not attr.is_reference:
|
||||||
ci = ci or {}
|
ci = ci or {}
|
||||||
v = self._deserialize_value(attr.alias, attr.value_type, value)
|
v = self._deserialize_value(attr.alias, attr.value_type, value)
|
||||||
|
@ -146,7 +146,7 @@ class AttributeValueManager(object):
|
||||||
else:
|
else:
|
||||||
v = value or None
|
v = value or None
|
||||||
|
|
||||||
attr.is_unique and self._check_is_unique(
|
(attr.is_unique or attr.name == unique_name) and self._check_is_unique(
|
||||||
value_table, attr, ci and ci.id or ci_id, ci and ci.type_id or type_id, v)
|
value_table, attr, ci and ci.id or ci_id, ci and ci.type_id or type_id, v)
|
||||||
self._check_is_required(ci and ci.type_id or type_id, attr, v, type_attr=type_attr)
|
self._check_is_required(ci and ci.type_id or type_id, attr, v, type_attr=type_attr)
|
||||||
if attr.is_reference:
|
if attr.is_reference:
|
||||||
|
@ -237,7 +237,10 @@ class AttributeValueManager(object):
|
||||||
if computed_value is not None:
|
if computed_value is not None:
|
||||||
ci_dict[attr['name']] = computed_value
|
ci_dict[attr['name']] = computed_value
|
||||||
|
|
||||||
def valid_attr_value(self, ci_dict, type_id, ci_id, name2attr, alias2attr=None, ci_attr2type_attr=None):
|
def valid_attr_value(self, ci_dict, type_id, ci_id, name2attr,
|
||||||
|
alias2attr=None,
|
||||||
|
ci_attr2type_attr=None,
|
||||||
|
unique_name=None):
|
||||||
key2attr = dict()
|
key2attr = dict()
|
||||||
alias2attr = alias2attr or {}
|
alias2attr = alias2attr or {}
|
||||||
ci_attr2type_attr = ci_attr2type_attr or {}
|
ci_attr2type_attr = ci_attr2type_attr or {}
|
||||||
|
@ -268,7 +271,8 @@ class AttributeValueManager(object):
|
||||||
|
|
||||||
else:
|
else:
|
||||||
value = self._validate(attr, value, value_table, ci=None, type_id=type_id, ci_id=ci_id,
|
value = self._validate(attr, value, value_table, ci=None, type_id=type_id, ci_id=ci_id,
|
||||||
type_attr=ci_attr2type_attr.get(attr.id))
|
type_attr=ci_attr2type_attr.get(attr.id),
|
||||||
|
unique_name=unique_name)
|
||||||
ci_dict[key] = value
|
ci_dict[key] = value
|
||||||
except BadRequest as e:
|
except BadRequest as e:
|
||||||
raise
|
raise
|
||||||
|
|
Loading…
Reference in New Issue