This commit is contained in:
王思川 2022-11-10 01:05:35 +08:00
parent 399c40c219
commit 8b5501c71d
2 changed files with 12 additions and 27 deletions

View File

@ -24,7 +24,7 @@ def func01(schema: Schemas.CreateIndicatorReqBody, db: Session = Depends(get_db)
category_obj = Crud.get_category_by_id(db=db, category_id=schema.category_id) category_obj = Crud.get_category_by_id(db=db, category_id=schema.category_id)
if not category_obj: if not category_obj:
raise HTTPException(status_code=202, detail="Category Not Found") raise HTTPException(status_code=404, detail="Category Not Found")
index_obj = Crud.create_indicator(db=db, schema=schema) index_obj = Crud.create_indicator(db=db, schema=schema)
@ -40,7 +40,7 @@ def func01(schema: Schemas.CreateIndicatorReqBody, db: Session = Depends(get_db)
def func02(iid: str, db: Session = Depends(get_db)): def func02(iid: str, db: Session = Depends(get_db)):
index_obj = Crud.get_indicator_by_iid(db=db, iid=iid) index_obj = Crud.get_indicator_by_iid(db=db, iid=iid)
if not index_obj: if not index_obj:
raise HTTPException(status_code=400, detail="Indicator Not Existed") raise HTTPException(status_code=404, detail="Indicator Not Existed")
Crud.delete_indicator(db=db, iid=iid) Crud.delete_indicator(db=db, iid=iid)
@ -52,11 +52,11 @@ def func02(iid: str, db: Session = Depends(get_db)):
def func03(iid: str, schema: Schemas.EditIndicatorReqBody, db: Session = Depends(get_db)): def func03(iid: str, schema: Schemas.EditIndicatorReqBody, db: Session = Depends(get_db)):
index_obj = Crud.get_indicator_by_iid(db=db, iid=iid) index_obj = Crud.get_indicator_by_iid(db=db, iid=iid)
if not index_obj: if not index_obj:
raise HTTPException(status_code=202, detail="Indicator Not Found") raise HTTPException(status_code=404, detail="Indicator Not Found")
category_obj = Crud.get_category_by_id(db=db, category_id=schema.category_id) category_obj = Crud.get_category_by_id(db=db, category_id=schema.category_id)
if not category_obj: if not category_obj:
raise HTTPException(status_code=202, detail="Category Not Found") raise HTTPException(status_code=404, detail="Category Not Found")
Crud.edit_indicator(db=db, schema=schema, iid=iid) Crud.edit_indicator(db=db, schema=schema, iid=iid)
@ -68,7 +68,7 @@ def func03(iid: str, schema: Schemas.EditIndicatorReqBody, db: Session = Depends
def func04(iid: str, db: Session = Depends(get_db)): def func04(iid: str, db: Session = Depends(get_db)):
index_obj = Crud.get_indicator_by_iid(db, iid=iid) index_obj = Crud.get_indicator_by_iid(db, iid=iid)
if index_obj is None: if index_obj is None:
raise HTTPException(status_code=202, detail="Indicator Not Found") raise HTTPException(status_code=404, detail="Indicator Not Found")
return index_obj.to_dict() return index_obj.to_dict()
@ -78,7 +78,7 @@ def func04(iid: str, db: Session = Depends(get_db)):
def func05(iid: str, db: Session = Depends(get_db)): def func05(iid: str, db: Session = Depends(get_db)):
index_obj = Crud.get_indicator_by_iid(db, iid=iid) index_obj = Crud.get_indicator_by_iid(db, iid=iid)
if not index_obj: if not index_obj:
raise HTTPException(status_code=400, detail="Indicator Not Found") raise HTTPException(status_code=404, detail="Indicator Not Found")
return index_obj.to_dict() return index_obj.to_dict()
@ -99,7 +99,7 @@ def func07(schema: Schemas.RegisterIndicatorReqBody, db: Session = Depends(get_d
category_obj = Crud.get_category_by_name(db=db, title=schema.category) category_obj = Crud.get_category_by_name(db=db, title=schema.category)
if not category_obj: if not category_obj:
raise HTTPException(status_code=202, detail="Category Not Found") raise HTTPException(status_code=404, detail="Category Not Found")
real_schema = schema.dict() real_schema = schema.dict()
real_schema.pop("category") real_schema.pop("category")
@ -120,7 +120,7 @@ def func07(schema: Schemas.RegisterIndicatorReqBody, db: Session = Depends(get_d
def func08(iid: str, body: Schemas.EditParamReqBody, db: Session = Depends(get_db)): def func08(iid: str, body: Schemas.EditParamReqBody, db: Session = Depends(get_db)):
index_obj = Crud.get_indicator_by_iid(db=db, iid=iid) index_obj = Crud.get_indicator_by_iid(db=db, iid=iid)
if not index_obj: if not index_obj:
raise HTTPException(status_code=400, detail="Indicator Not Found") raise HTTPException(status_code=404, detail="Indicator Not Found")
Crud.create_parameter(db=db, schema=body, _iid=iid) Crud.create_parameter(db=db, schema=body, _iid=iid)
@ -131,7 +131,7 @@ def func08(iid: str, body: Schemas.EditParamReqBody, db: Session = Depends(get_d
def func09(pid: str, schema: Schemas.EditParamReqBody, db: Session = Depends(get_db)): def func09(pid: str, schema: Schemas.EditParamReqBody, db: Session = Depends(get_db)):
data = Crud.get_parameter_by_pid(db=db, pid=pid) data = Crud.get_parameter_by_pid(db=db, pid=pid)
if not data: if not data:
raise HTTPException(status_code=202, detail="Parameter Not Existed") raise HTTPException(status_code=404, detail="Parameter Not Existed")
Crud.edit_parameter(db=db, pid=pid, schema=schema) Crud.edit_parameter(db=db, pid=pid, schema=schema)
@ -143,7 +143,7 @@ def func09(pid: str, schema: Schemas.EditParamReqBody, db: Session = Depends(get
def func10(pid: str, db: Session = Depends(get_db)): def func10(pid: str, db: Session = Depends(get_db)):
data = Crud.get_parameter_by_pid(db=db, pid=pid) data = Crud.get_parameter_by_pid(db=db, pid=pid)
if not data: if not data:
raise HTTPException(status_code=202, detail="Parameter Not Existed") raise HTTPException(status_code=404, detail="Parameter Not Existed")
Crud.delete_parameter(db=db, pid=pid) Crud.delete_parameter(db=db, pid=pid)
@ -165,12 +165,12 @@ def func11(schema: Schemas.CreateCategoryReqBody, db: Session = Depends(get_db))
def func12(schema: Schemas.DeleteCategoryReqBody, db: Session = Depends(get_db)): def func12(schema: Schemas.DeleteCategoryReqBody, db: Session = Depends(get_db)):
data = Crud.get_category_by_id(db=db, category_id=schema.category_id) data = Crud.get_category_by_id(db=db, category_id=schema.category_id)
if not data: if not data:
raise HTTPException(status_code=202, detail="Category Not Existed") raise HTTPException(status_code=404, detail="Category Not Found")
try: try:
Crud.delete_category(db=db, category_id=schema.category_id) Crud.delete_category(db=db, category_id=schema.category_id)
except IntegrityError: except IntegrityError:
raise HTTPException(status_code=400, detail="Cannot Delete Category") raise HTTPException(status_code=202, detail="Category Is Being Used")
return {"info": "Success"} return {"info": "Success"}

View File

@ -1,15 +0,0 @@
[request_definition]
r = sub, obj, act
[policy_definition]
p = sub, obj, act
[role_definition]
g = _, _
g2 = _, _
[policy_effect]
e = some(where (p.eft == allow))
[matchers]
m = g(r.sub, p.sub) && g2(r.obj, p.obj) && r.act == p.act || r.sub == "管理员"