mirror of https://github.com/veops/cmdb.git
fix delete ci_type
This commit is contained in:
parent
5d299bd71a
commit
0263842b70
|
@ -13,6 +13,7 @@ from flask.cli import with_appcontext
|
|||
import api.lib.cmdb.ci
|
||||
from api.extensions import db
|
||||
from api.extensions import rd
|
||||
from api.lib.cmdb.cache import AttributeCache
|
||||
from api.lib.cmdb.ci_type import CITypeTriggerManager
|
||||
from api.lib.cmdb.const import PermEnum
|
||||
from api.lib.cmdb.const import REDIS_PREFIX_CI
|
||||
|
@ -275,8 +276,9 @@ def cmdb_index_table_upgrade():
|
|||
Migrate data from tables c_value_integers, c_value_floats, and c_value_datetime
|
||||
"""
|
||||
for attr in Attribute.get_by(to_dict=False):
|
||||
if attr.value_type not in {ValueTypeEnum.TEXT, ValueTypeEnum.JSON}:
|
||||
if attr.value_type not in {ValueTypeEnum.TEXT, ValueTypeEnum.JSON} and not attr.is_index:
|
||||
attr.update(is_index=True)
|
||||
AttributeCache.clean(attr)
|
||||
|
||||
from api.models.cmdb import CIValueInteger, CIIndexValueInteger
|
||||
from api.models.cmdb import CIValueFloat, CIIndexValueFloat
|
||||
|
|
|
@ -476,7 +476,10 @@ class AutoDiscoveryCICRUD(DBMixin):
|
|||
except:
|
||||
pass
|
||||
|
||||
adc.update(is_accept=True, accept_by=nickname or g.user.nickname, accept_time=datetime.datetime.now())
|
||||
adc.update(is_accept=True,
|
||||
accept_by=nickname or g.user.nickname,
|
||||
accept_time=datetime.datetime.now(),
|
||||
ci_id=ci_id)
|
||||
|
||||
|
||||
class AutoDiscoveryHTTPManager(object):
|
||||
|
|
|
@ -750,10 +750,10 @@ class CIRelationManager(object):
|
|||
first_existed = CIRelation.get_by(first_ci_id=first_ci_id, relation_type_id=type_relation.relation_type_id)
|
||||
second_existed = CIRelation.get_by(second_ci_id=second_ci_id, relation_type_id=type_relation.relation_type_id)
|
||||
if type_relation.constraint == ConstraintEnum.One2One and (first_existed or second_existed):
|
||||
return abort(400, ErrFormat.relation_constraint.format("1对1"))
|
||||
return abort(400, ErrFormat.relation_constraint.format("1-1"))
|
||||
|
||||
if type_relation.constraint == ConstraintEnum.One2Many and second_existed:
|
||||
return abort(400, ErrFormat.relation_constraint.format("1对多"))
|
||||
return abort(400, ErrFormat.relation_constraint.format("1-N"))
|
||||
|
||||
@classmethod
|
||||
def add(cls, first_ci_id, second_ci_id, more=None, relation_type_id=None):
|
||||
|
|
|
@ -37,6 +37,7 @@ from api.models.cmdb import CITypeGroupItem
|
|||
from api.models.cmdb import CITypeRelation
|
||||
from api.models.cmdb import CITypeTrigger
|
||||
from api.models.cmdb import CITypeUniqueConstraint
|
||||
from api.models.cmdb import PreferenceRelationView
|
||||
from api.models.cmdb import PreferenceShowAttributes
|
||||
from api.models.cmdb import PreferenceTreeView
|
||||
from api.models.cmdb import RelationType
|
||||
|
@ -190,6 +191,12 @@ class CITypeManager(object):
|
|||
if CI.get_by(type_id=type_id, first=True, to_dict=False) is not None:
|
||||
return abort(400, ErrFormat.ci_exists_and_cannot_delete_type)
|
||||
|
||||
relation_views = PreferenceRelationView.get_by(to_dict=False)
|
||||
for rv in relation_views:
|
||||
for item in (rv.cr_ids or []):
|
||||
if item.get('parent_id') == type_id or item.get('child_id') == type_id:
|
||||
return abort(400, ErrFormat.ci_relation_view_exists_and_cannot_delete_type.format(rv.name))
|
||||
|
||||
for item in CITypeRelation.get_by(parent_id=type_id, to_dict=False):
|
||||
item.soft_delete()
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@ class ErrFormat(CommonErrFormat):
|
|||
unique_key_not_define = "主键未定义或者已被删除"
|
||||
only_owner_can_delete = "只有创建人才能删除它!"
|
||||
ci_exists_and_cannot_delete_type = "因为CI已经存在,不能删除模型"
|
||||
ci_relation_view_exists_and_cannot_delete_type = "因为关系视图 {} 引用了该模型,不能删除模型"
|
||||
ci_type_group_not_found = "模型分组 {} 不存在"
|
||||
ci_type_group_exists = "模型分组 {} 已经存在"
|
||||
ci_type_relation_not_found = "模型关系 {} 不存在"
|
||||
|
|
Loading…
Reference in New Issue