People and roles#
One installation of an app can be used by several people: a household's shopping list, a team's time off. The person who installed it is its owner; the others are members.
Who sees what#
What each person sees follows from where each value lives (see state). A list that several people work on is written as the groceries list in start is, with "scope": "shared", "conflict": "merge" and "key": "id"; without "scope": "shared" each person sees only their own list, and nothing reports it.
Who is acting: user#
user is whoever is acting: user.id, user.name, user.kind (person, agent or app), user.roles, and user.person, the person behind the act. For a person, user.person is that person; for an agent working for someone, it is that someone.
- Record who did something with
user.person, in the action they ran:askForTimeOffstoresuser.person.idanduser.person.nameon the request, so a request an agent files for Sam is Sam's. - Compare with
user.person.idto let a person, or an agent acting for them, act on their own records:user.person.id == item.personId. - Require
user.kind == 'person'for an act a person must do themselves, not through an agent, and say so in therequiremessage.
Ids and names#
A person's id never changes; their name is what the host calls them now. Store the id on a record: you compare it with user.person.id, and it finds the person again. A name stored beside it is a copy, as it was then.
When you run an app with nobody named, its one person has the id "local-user" and the name "You", so a name stored then reads "You" to everyone. Run it with people named (see the end of this topic) to see real names: each person then has the id and the name you give, and a name left out is the id.
To show the name of someone a record names, find their id in a list of the app's people, such as the one below.
Roles#
A role names what someone may do anywhere in the app, such as approving time off. Declare each role the guards test, with a description:
JSON
{
"approver": { "description": "Approves or declines other people's time off." }
}
The definition never says who holds a role: the host assigns roles. The owner holds every declared role unless the host's policy says otherwise; a member holds the roles the owner or the host's policy gives them, and none by default. Test a role with 'approver' in user.roles.
Only the person who set it up may. Declare a role, require it in the action, and show the control only when it holds. The owner holds the role, and nobody else does until given it. This patch lets only the owner of the groceries app take things off the list:
JSON
[
{ "op": "add", "path": "/roles", "value": { "organizer": { "description": "Set the list up, and may take things off it." } } },
{ "op": "add", "path": "/actions/removeItem/require", "value": [ { "that": "'organizer' in user.roles", "message": "Only the person who set up the list can take things off it." } ] },
{ "op": "add", "path": "/surfaces/visual/views/home/body/children/1/slots/item/children/2/when", "value": "'organizer' in user.roles" }
]
A link between a person and one record ("the manager of this request") is not a role: store the person's id on the record and compare it with user.person.id. That is how the time off flow keeps an approver from deciding their own request: user.person.id != item.personId.
Who uses the app#
An app cannot ask for the list of everyone who uses it: no expression and no operation gives the people of an installation.
The directory, core:directory, is an organization's list of people, not the app's. It knows only whom the host's directory lists; on the reference host it lists nobody unless a sample document answers for it. Use it only in an app for an organization whose host connects its directory (its operations are in capabilities).
For a household or a team, use a shared list that people add themselves to, with one press: it works on every host. Each person's id and name come from user.person. This patch gives the groceries app one, and shows a name found by id. Its join keeps one record for each person, under their id: an if adds the record, or changes it when the person has one, the shape of any "one answer each" app:
JSON
[
{ "op": "add", "path": "/types/Person", "value": { "type": "object", "properties": { "id": { "type": "string" }, "name": { "type": "string" } }, "required": ["id", "name"], "additionalProperties": false } },
{ "op": "add", "path": "/state/people", "value": { "type": "Person[]", "initial": [], "scope": "shared", "conflict": "merge", "key": "id", "description": "The people of the household who joined the list." } },
{ "op": "add", "path": "/actions/join", "value": { "description": "Join the household's list, or bring your name on it up to date.", "steps": [ { "if": "state.people.exists(p, p.id == user.person.id)", "then": [ { "patch": "state.people", "where": "item.id == user.person.id", "with": { "name": "=user.person.name" } } ], "else": [ { "append": "state.people", "value": { "id": "=user.person.id", "name": "=user.person.name" } } ] } ] } },
{ "op": "add", "path": "/surfaces/visual/views/home/body/children/-", "value": { "control": "core:button", "props": { "label": "=state.people.exists(p, p.id == user.person.id) ? 'Update my name' : 'Join this list'" }, "on": { "press": { "run": "join" } } } },
{ "op": "add", "path": "/surfaces/visual/views/home/body/children/-", "value": { "control": "core:text", "props": { "value": "=`Joined as ${default(state.people.find(p, p.id == user.person.id).name, 'nobody yet')}`" } } }
]
To give a record to someone, offer the joined people in a core:choice (each value an id, each label a name) and store the id. Someone who has not joined cannot be chosen, so say on the screen that each person joins once.
Who may act#
- Every member may run every action that is not
internal, unless the host's policy narrows it. Guard each action that not everyone may run, withalloworrequire. - Guard actions, not screens. A section's
whenand a button'swhendecide what is shown; the guards decide what is allowed, for every surface.
Permissions with several people#
The owner answers most grant requests once, for everyone; with several people, the reference host asks the owner as the app opens. Each person answers for personal capabilities (see capabilities).
Trying it with several people#
Look at the app as each kind of person: the tool you were given to look at an app takes the people who use it, the owner first, and oad run takes them at a terminal:
oad run timeoff.oad.json --person 'olga:Olga' --person 'sam:Sam' --person 'ana:Ana:approver'
Give a member only roles the app declares.
Next#
statefor scopes and conflicts.flowsfor records that move through stages.agentsfor what an agent acting for a person may do.capabilitiesfor the directory and when permissions are asked.