generated from coulomb/repo-seed
Access controlled knowledge gateway functionality
This commit is contained in:
@@ -294,6 +294,32 @@ class LocalSnapshotStore:
|
||||
for row in rows
|
||||
]
|
||||
|
||||
def search_with_policy(
|
||||
self,
|
||||
query: str,
|
||||
*,
|
||||
subject: str,
|
||||
gateway: Any,
|
||||
action: str = "search",
|
||||
limit: int = 20,
|
||||
context: dict[str, Any] | None = None,
|
||||
) -> dict[str, Any]:
|
||||
"""Search and apply a policy gateway before returning result rows."""
|
||||
|
||||
matches = []
|
||||
for result in self.search(query, limit=limit):
|
||||
item = result.to_dict()
|
||||
item["policy"] = self.policy_metadata(result.path)
|
||||
matches.append(item)
|
||||
return gateway.filter_results(subject, action, matches, context=context)
|
||||
|
||||
def policy_metadata(self, path: str) -> dict[str, Any]:
|
||||
"""Return document-derived policy metadata for an indexed source path."""
|
||||
|
||||
from markitect_tool.policy import policy_metadata_from_document
|
||||
|
||||
return policy_metadata_from_document(self.get_document(path), path=path)
|
||||
|
||||
def build(
|
||||
self,
|
||||
paths: list[str | Path],
|
||||
|
||||
Reference in New Issue
Block a user