| 123456789101112131415161718192021222324252627282930313233 |
- import json,urllib.request,urllib.error
- BASE='http://localhost:8980/js/a'
- def call(m,p,b=None,t=None):
- d=json.dumps(b).encode() if b is not None else None
- r=urllib.request.Request(BASE+p,data=d,method=m); r.add_header('Content-Type','application/json')
- if t:r.add_header('x-token',t)
- try:
- with urllib.request.urlopen(r,timeout=30) as x:return json.loads(x.read().decode())
- except urllib.error.HTTPError as e:return {'http':e.code,'body':e.read().decode()[:300]}
- def login(u,p):return call('POST','/auth/login',{'username':u,'password':p,'force':True})['data']['token']
- A=login('vsuserA','Vs1118pass');B=login('vsuserB','Vs1118pass');C=login('vsuserC','Vs1118pass')
- D1='2123022706158374913'
- # canManage flags on 4 list types for B
- for path,key,code_key in [('/ai/skill/list?pageSize=100','vs_skill','name'),('/ai/pack/list?pageSize=100','vs_pack','packCode'),('/ai/kb/list?pageSize=100','vs_kb','kbCode')]:
- r=call('GET',path,t=B); rows=r['data']['rows']
- by={x[code_key]:x for x in rows}
- dept=[k for k in by if k.endswith('_dept')][0]; pub=[k for k in by if k.endswith('_pub')][0]
- print(path,'B canManage dept',by[dept]['canManage'],'pub',by[pub]['canManage'])
- # update authorization pack/kb by B
- r=call('PUT','/ai/pack',{'id':'2123022767378436098','packCode':'vs_pack_dept','packName':'VS部门场景包','visibleScope':'1','ownerDeptId':D1},B)
- print('B update pack ->',r.get('code'),r.get('message'))
- r=call('PUT','/ai/kb',{'id':'2123022767873363969','kbName':'VS部门知识库','kbCode':'vs_kb_dept','embeddingModelId':1761400000000020401,'visibleScope':'1','ownerDeptId':D1},B)
- print('B update kb ->',r.get('code'),r.get('message'))
- # delete authorization pack/kb by C (create temp records first)
- r=call('POST','/ai/pack',{'packCode':'vs_pack_del','packName':'VS删除包','status':'0','visibleScope':'2'},A)
- r=call('GET','/ai/pack/list?pageSize=100',t=A); row=[x for x in r['data']['rows'] if x['packCode']=='vs_pack_del']; pid=row[0]['id']
- print('C delete pack ->',call('DELETE','/ai/pack/'+pid,t=C))
- print('B delete pack ->',call('DELETE','/ai/pack/'+pid,t=B))
- print('A delete pack ->',call('DELETE','/ai/pack/'+pid,t=A))
- r=call('POST','/ai/kb',{'kbName':'VS删除库','kbCode':'vs_kb_del','embeddingModelId':1761400000000020401,'retrievalMode':'vector','status':'0','visibleScope':'2'},A)
- r=call('GET','/ai/kb/list?pageSize=100',t=A); row=[x for x in r['data']['rows'] if x['kbCode']=='vs_kb_del']; kid=row[0]['id']
- print('C delete kb ->',call('DELETE','/ai/kb/'+kid,t=C).get('code'))
- print('A delete kb ->',call('DELETE','/ai/kb/'+kid,t=A).get('code'))
|