Skip to content

Let people see only their own items

Save the person who makes each Item in a Property. On the Template, add a Role whose callback returns that person, and a Grant that shows the Template’s Properties to the Role. The Runtime shows each Item to the people who hold a Role on it, and to nobody else.

In the tickets App, open saves the person who makes the call, with openedBy: ctx.principalId. On the ticket Template, opener returns that person. agents returns the agent Role, which every agent holds:

tickets.ts
const opener = ticket.addRole('opener', async (item) => {
const openedBy = item.properties.openedBy;
return typeof openedBy === 'string' ? [openedBy] : [];
});
const agents = ticket.addRole('agents', async () => [agent.prn]);
ticket.addGrant(opener, Object.values(ticket.properties));
ticket.addGrant(agents, Object.values(ticket.properties));

Alice and Carol are customers, and each of them opened one ticket. Bob is an agent:

As Alice: sees "Printer", open
As Carol: sees "Laptop", open
As Bob: sees "Printer", open
As Bob: sees "Laptop", open
As Carol: Alice's ticket is not there

Look at who sees what. Each customer sees the ticket she opened, and Bob sees both. Carol asks for Alice’s ticket by its Identifier and finds nothing.

No Query filters by person. list selects every ticket with selectItems(), and the Runtime returns the tickets the caller holds a Role on. A person who holds neither Role finds no ticket, which is why agents have a Role of their own.

The whole App: Support tickets with an SLA. Step by step: Tutorial: who can do what.