Generic custom action
Publish documents with ownership, classification and an approval threshold.
An editor agent publishes workspace documents for their owners. Publishing publicly needs a reviewer's approval, and confidential documents are never published by agents.
1. Register actions and resource types
In the dashboard, open Actions & resources. Register each resource type, then each action. To paste an attribute schema, switch the attribute editor to JSON.
Resource type document: attributes
{
"owner_id": { "type": "id", "required": true },
"workspace_id": { "type": "id", "required": true }
}Action documents.publish on document: context attributes
{
"document_classification": { "type": "enum", "required": true, "values": ["public", "internal", "confidential"] },
"requested_visibility": { "type": "enum", "required": true, "values": ["team", "company", "public"], "provenance": "caller" }
}2. Policy
Replace <YOUR_POLICY_ID> with a new policy ID, then
validate, test and publish it with reqlo policies push --publish.
id: <YOUR_POLICY_ID>
name: Document publishing
rules:
- id: owners-publish-internally
effect: allow
actions: [documents.publish]
agents: { tags: [editor] }
subjects: { kinds: [user] }
condition: resource.attributes.owner_id == subject.id && context.requested_visibility in ["team", "company"]
- id: public-needs-review
effect: require_approval
actions: [documents.publish]
condition: context.requested_visibility == "public"
approval: { expires_in_seconds: 3600 }
- id: never-confidential
effect: deny
actions: [documents.publish]
condition: context.document_classification == "confidential"Owners and admins can approve requests from this policy in Approvals. To route them to specific people,
create an approval channel and add channel_id: APC_… to the rule's approval.
3. Authorize on the server
const doc = await db.documents.find(args.documentId);
const decision = await reqlo.authorize({
agent: { id: "agt_editor" },
subject: { id: session.userId, kind: "user" },
action: "documents.publish",
resource: { type: "document", id: doc.id, attributes: { owner_id: doc.ownerId, workspace_id: doc.workspaceId } },
context: { document_classification: doc.classification, requested_visibility: args.visibility },
});
if (decision.decision === "allow") await db.documents.publish(doc.id, args.visibility);
else if (decision.decision === "approval_required") await holdForReview(doc.id, decision.approval!.id);
else return { error: "Publishing isn't allowed." };Notes
requested_visibilitycomes from the model, so it isprovenance: callerand only ever narrows what is allowed.- Ownership and classification come from the database.
- An approved public publish is redeemed with the identical request. See Human approvals.
Every example uses the same request model; only the customer-defined actions, resources and attributes differ. See Core concepts.
Something wrong or unclear? Report an issue with this page.