Skip to content

Recipes

Complete policies for common jobs. Each one starts from nothing allowed and adds only what the job needs. Bind each with policy.bind(app) before giving it to a client, except the first, which needs no binding.

A dashboard or report

Reads everything the token can, and changes nothing.

from pyquickbase import Policy

policy = Policy.read_only()

A support agent

Reads tasks without costs, a page at a time, and changes only their status and notes.

from pyquickbase import Policy, allow, deny, fields

policy = Policy(
    classes={"internal": ["Tasks.Amount", "Tasks.Code"]},
    rules=[
        allow.read("Tasks", max_paging_depth=50),
        allow.update("Tasks", ["Status", "Notes"]),
        deny.all(fields.classed("internal")),
    ],
)

A data-entry bot

Adds tasks and can't read, change, or delete anything. Writing a field doesn't need read access to it.

from pyquickbase import Policy, allow

policy = Policy(rules=[allow.insert("Tasks", ["Title", "Status", "Due Date", "Project"])])

One project's assistant

Reads and updates only one project's tasks, and deletes at most three records at a time.

from pyquickbase import F, Policy, allow, limit

policy = Policy(
    rules=[
        allow.read("Tasks", max_paging_depth=100),
        allow.update("Tasks", ["Status", "Notes", "Due Date"]),
        allow.delete("Tasks", max_records_per_delete=3),
        limit.rows("Tasks", F("Project") == "Roof"),
    ]
)

limit.rows() doesn't check an update by Record ID#, so pair it with a role whose record-level rules do.

A schema assistant

Adds and changes fields on one table, but can't delete fields or tables, or make formulas.

from pyquickbase import Policy, allow

policy = Policy(
    rules=[
        allow.read("Tasks"),
        allow.schema("Tasks", "add_field", "change_field"),
    ]
)

See Schema changes for every verb, and which table each one is granted on.

A nightly sync

Upserts records by a unique code, in batches of up to 500 rows, with a rule of your own.

from pyquickbase import Decision, Policy, WriteRequest, allow, fields


class Batches:
    def decide(self, request):
        if isinstance(request, WriteRequest) and (request.row_count or 0) > 500:
            return Decision(allowed=False, verb="insert", reason="Up to 500 rows at a time")
        return None


policy = Policy(
    rules=[
        allow.read("Tasks", ["Code"]),
        allow.insert("Tasks", fields.all()),
        allow.update("Tasks", fields.all()),
        Batches(),
    ]
)

An upsert needs both insert and update. See Rules of your own.