Add Authorization checks (#2209)

### What problem does this PR solve?

Add Authorization checks 
#2203

### Type of change


- [x] New Feature (non-breaking change which adds functionality)

---------

Co-authored-by: Feiue <10215101452@stu.ecun.edu.cn>
Co-authored-by: Kevin Hu <kevinhu.sh@gmail.com>
This commit is contained in:
LiuHua 2024-09-03 13:45:02 +08:00 committed by GitHub
parent 6d232f1bdb
commit 4d9e9f0dbb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -100,6 +100,15 @@ def update():
def detail():
kb_id = request.args["kb_id"]
try:
tenants = TenantService.get_joined_tenants_by_user_id(current_user.id)
for m in tenants:
if KnowledgebaseService.query(
tenant_id=m["tenant_id"], id=kb_id):
break
else:
return get_json_result(
data=False, retmsg=f'Only owner of knowledgebase authorized for this operation.',
retcode=RetCode.OPERATING_ERROR)
kb = KnowledgebaseService.get_detail(kb_id)
if not kb:
return get_data_error_result(