Data filtering

A document store asks which documents a user can read, and shows only those. Each document has a department and a classification. An auditor reads the documents of all departments, up to the clearance of the auditor.

Bundle documents, revision 2026-12-03, decision data.documents.filter.visible

Examples

Input: auditor

{
  "user": {
    "clearance": "internal",
    "department": "audit",
    "name": "carol",
    "role": "auditor"
  }
}

Ask the decision serverOpen in the debugger

Files

Show tree shaking for the decision

1# The documents of the library that the user can read. The document store asks for `visible` and shows only
2# these documents, so the policy filters the data and does not only answer yes or no.
3package documents.filter
4
5levels := {"public": 0, "internal": 1, "confidential": 2}
6
7visible contains {"id": document.id, "title": document.title} if {
8 some document in data.documents.library
9 readable(document)
10}
11
12# Each user can read a public document.
13readable(document) if document.classification == "public"
14
15# A user can read a document of the department of the user, up to the clearance of the user.
16readable(document) if {
17 document.department == input.user.department
18 cleared(document)
19}
20
21# An auditor can read a document of each department, up to the clearance of the auditor.
22readable(document) if {
23 input.user.role == "auditor"
24 cleared(document)
25}
26
27cleared(document) if levels[document.classification] <= levels[input.user.clearance]
28