Skip to content

Commit

Permalink
禁止删除唯一标识的属性
Browse files Browse the repository at this point in the history
  • Loading branch information
pycook committed Jul 21, 2023
1 parent 63af79e commit fb904b0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,6 @@ docker-compose up -d

---

_**欢迎关注我们的公众号,点击联系我们,加入微信、qq运维群,获得更多产品、行业相关资讯**_
_**欢迎关注我们的公众号,点击联系我们,加入微信、qq运维群(336164978),获得更多产品、行业相关资讯**_

![公众号](docs/images/qrcode_for_gzh.jpg)
4 changes: 4 additions & 0 deletions cmdb-api/api/lib/cmdb/attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from api.lib.perm.acl.acl import is_app_admin
from api.lib.perm.acl.acl import validate_permission
from api.models.cmdb import Attribute
from api.models.cmdb import CIType
from api.models.cmdb import CITypeAttribute
from api.models.cmdb import CITypeAttributeGroupItem
from api.models.cmdb import PreferenceShowAttributes
Expand Down Expand Up @@ -315,6 +316,9 @@ def delete(_id):
attr = Attribute.get_by_id(_id) or abort(404, ErrFormat.attribute_not_found.format("id={}".format(_id)))
name = attr.name

if CIType.get_by(unique_id=attr.id, first=True, to_dict=False) is not None:
return abort(400, ErrFormat.attribute_is_unique_id)

if attr.uid and attr.uid != g.user.uid:
return abort(403, ErrFormat.cannot_delete_attribute)

Expand Down
1 change: 1 addition & 0 deletions cmdb-api/api/lib/cmdb/resp_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class ErrFormat(CommonErrFormat):
argument_file_not_found = "文件似乎并未上传"

attribute_not_found = "属性 {} 不存在!"
attribute_is_unique_id = "该属性是模型的唯一标识,不能被删除!"
attribute_value_type_cannot_change = "属性的值类型不允许修改!"
attribute_list_value_cannot_change = "多值不被允许修改!"
attribute_index_cannot_change = "修改索引 非管理员不被允许!"
Expand Down

0 comments on commit fb904b0

Please sign in to comment.