feat: add configurable association education links
This commit is contained in:
1 parent
d3c5461de5
commit
740d00880a
14 files changed
+490
-4
No files matched your search
@@ -32,3 +32,53 @@ def write_edu_platforms(body: EduPlatformsWrite, db: Session = Depends(get_db))
|
||||
except ValueError as exc:
|
||||
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=str(exc)) from exc
|
||||
return {"ok": True}
|
||||
|
||||
|
||||
class AssociationEducationWrite(BaseModel):
|
||||
webUrl: str = Field(max_length=2048)
|
||||
mobileUrl: str = Field(max_length=2048)
|
||||
|
||||
|
||||
def _association_access(db: Session, principal: dict, *, write: bool = False) -> None:
|
||||
from app.models.rbac import AdminUser
|
||||
from app.services.rbac import granted_resources
|
||||
|
||||
try:
|
||||
user_id = int(principal.get("sub", ""))
|
||||
except (ValueError, TypeError):
|
||||
raise HTTPException(status_code=401, detail="登录已失效") from None
|
||||
user = db.get(AdminUser, user_id)
|
||||
if user is None or user.status != "active":
|
||||
raise HTTPException(status_code=401, detail="登录已失效")
|
||||
resources = granted_resources(db, user_id)
|
||||
allowed = any(
|
||||
(item.type == "button" and item.permission == "edu:edit") if write
|
||||
else (item.type == "menu" and item.path == "/edu")
|
||||
for item in resources
|
||||
)
|
||||
if not allowed:
|
||||
raise HTTPException(status_code=403, detail="没有继续教育操作权限")
|
||||
|
||||
|
||||
@router.get("/edu/association")
|
||||
def read_association(db: Session = Depends(get_db), principal: dict = Depends(require_staff)) -> dict:
|
||||
from app.services.association_education import read_links
|
||||
|
||||
_association_access(db, principal)
|
||||
return read_links(db)
|
||||
|
||||
|
||||
@router.put("/edu/association")
|
||||
def write_association(
|
||||
body: AssociationEducationWrite,
|
||||
db: Session = Depends(get_db),
|
||||
principal: dict = Depends(require_staff),
|
||||
) -> dict:
|
||||
from app.services.association_education import save_links
|
||||
|
||||
_association_access(db, principal, write=True)
|
||||
try:
|
||||
save_links(db, body.webUrl, body.mobileUrl)
|
||||
except ValueError as exc:
|
||||
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
||||
return {"ok": True}
|
||||
Reference in new issue
Block a user