Repository navigation
Closed
Labels
priority: mediumMedium prioritytype: bugSomething isn't workingtype: maintenanceRelated to general repository maintenanceworkload: hoursLikely takes hours to resolve
Description
Problem
In foca/security/access_control/access_control_server.py:
- The same collection lookup through
current_app.config.foca.db.dbs[...]is copied four times (withtype: ignores). putPermissionwrites to the collection directly, bypassing theAdapterused bypostPermission, so the two endpoints store differently shaped documents.getAllPermissions/getPermissiondelptypeandidunconditionally; one stored rule withoutidmakes the list endpoint fail with 500.except Exceptionturns everything, including bad requests, into 500 and logs a second time.
In foca_casbin_adapter/: CasbinRule.dict() scans dir(self); CasbinRule.__repr__ calls print(); load_policy is typed with CasbinRule instead of casbin.model.Model; an assert validates the collection; save_policy appends instead of replacing, which creates duplicates.
Proposal
- One helper
_get_permissions_collection()(orget_collection()from Fix ignoredmypyerrors #144 work if it lands first). - Route
putthrough the adapter (upsert byid), so both write paths storeptype,id,v0..v5. - Tolerant reads (
dict.pop(key, None)); narrow exception handling and let the global handler log. CasbinRuleas a dataclass with fixed fields andto_dict(); removeprint(); correct types;ValueErrorinstead ofassert;save_policyreplaces the stored policy set.- Same PR also covers the refined proposals in Implement pagination for access control
GETmethods #113 (pagination), Implement support user permission check in access control #112 (own permissions) and Implement configurable identifiers for access control #142 (identifiers), see comments there.
Acceptance criteria
-
postandputstore identically shaped documents (test). - List and get work for documents without
id/ptype(test). - Malformed requests yield 400, missing IDs 404, not 500 (tests).
-
save_policycalled twice yields no duplicates (test). - No
print(), noassertfor runtime validation in the adapter.
Breaking changes
None for the HTTP API beyond #113/#112/#142. CasbinRule.dict() is renamed to to_dict() (internal).
Related
Metadata
Metadata
Assignees
Labels
priority: mediumMedium prioritytype: bugSomething isn't workingtype: maintenanceRelated to general repository maintenanceworkload: hoursLikely takes hours to resolve
Activity