MultiPaaS

Who can read which records

Inside an app-tenant, MultiPaaS decides record by record who can read and change each one. The signed-in user's roles and the record's shares decide it. Your app doesn't filter anything: a query returns only the records that user may read, and a change to a record they may not change is refused. An app-tenant belongs to one environment, and the records, shares and role grants here apply within it. A change to a role itself applies in every environment.

By default, each member sees only their own records

A new application's Member role can create records. It can't read every record of an entity.

Every entity starts out managed. When a member creates a record of a managed entity, they become its manager. They can read, change, delete and share it. Another member of the same app-tenant doesn't see it.

The App manager role can read, change and delete every record in the app-tenant.

If you are moving from a database where row-level security matched each row's user_id to the signed-in user, you get that behavior without a column or a policy.

Letting every member see every record

A role can read every record of an entity when it holds record.view_all for that entity. On a managed entity, record.edit_all adds changing them, and record.manage_all adds deleting and sharing them. Records that belong to a parent work differently, as described below.

To let every member read every record of an entity, add record.view_all for that entity to the Member role, with CLI 1.1.0 or later:

multipaas roles update --app APP_ID --role member --add-permission record.view_all=ENTITY_ID

Or do it in the MultiPaaS web app under the application's Roles.

To give it to some members only, declare a separate role with the CLI:

multipaas roles create --app APP_ID --key reader --name Reader --permission record.view_all=ENTITY_ID

Then give that role to the members who need it: pick it when you invite them in the web app, or name it in memberships.jsonl when you import.

The two setups side by side, for an entity of notes:

Each member sees only their own notes Every member sees every note
Role setup Member, unchanged Member, plus record.view_all for the notes entity
A member's list of notes The notes they created, and notes shared with them Every note in the app-tenant
Changing another member's note Refused Refused, unless the role also holds record.edit_all

Share every new record with the app-tenant

Some records are for everyone in the app-tenant, such as alerts a job posts or a word list an import fills. Instead of giving a role record.view_all, have the entity share each new record with everyone in its app-tenant, with CLI 1.7.0 or later:

multipaas entity update --app APP_ID --id ENTITY_ID --share-with-tenant view

view lets everyone in the app-tenant read each new record, and edit lets them change it too. It applies to every record created in an app-tenant from then on, by a member, an app identity or an import; app-wide records aren't shared. Records created before you turn it on aren't shared; share them with shareRecords. --share-with-tenant off stops it for new records, and records already shared stay shared.

The record's creator still manages it, and the share is an ordinary one: a manager can remove it from the record's Sharing tab, or from your app with unshareRecords. Only a managed entity can share its new records, so turn this off before you make an entity unmanaged. You can also set it on the entity's Managers tab in the web app.

Sharing records

A record's manager can share it with one user, with a group, or with everyone in the app-tenant, to view, edit or manage. Share one record from the record's Sharing tab in the web app, or many at once from your app.

Sharing from your app

The generated API has two mutations for sharing, on an API version made after they were added:

mutation {
  shareRecords(input: { ids: ["RECORD_ID", "RECORD_ID"], with: { everyone: true }, level: VIEW }) {
    sharedRootCount
  }
}
mutation {
  unshareRecords(input: { ids: ["RECORD_ID"], with: { everyone: true } }) {
    unsharedRootCount
  }
}

with names exactly one of everyone: true, userId or groupId. level is VIEW, EDIT or MANAGE. Each call takes 1 to 100 record ids of any entities, and either changes every record or none. To share more, call again with the next 100. Sharing a record that belongs to a parent shares the record it is shared through, as on the Sharing tab, and a record counts once however many of its ids you pass. Unsharing a principal that has no share on a record leaves it alone and doesn't count it.

The caller needs to manage the record each id is shared through. That is the record itself if its entity is managed; otherwise the nearest record up its parent chain whose entity is managed. The caller must manage that record: hold a share at MANAGE on it, directly, through a group or as everyone in the app-tenant (its creator gets one when they create it), or hold a role with record.manage_all for its entity or for an entity above it, as for reading. For an id whose entity is managed, that is the id's own entity. For an id whose entity isn't managed, it is the entity of the nearest managed record up its parent chain. The id's own creator, or record.manage_all on the id's entity alone, is then refused. A role with record.manage_all lets an app identity share records it didn't create, such as imported ones. shareRecords can't share with an app identity by userId; share with everyone in the app-tenant instead. unshareRecords refuses a userId or groupId that isn't a well-formed id, but doesn't check that the user or group exists, so a well-formed id that names no one unshares nothing and returns 0. Group ids come from the web app; the generated API doesn't list groups.

A refused call changes nothing. These four codes carry the ids at fault in extensions.ids, except an UNAUTHORIZED from a request with no app-tenant selected, which carries none:

Code When
NOT_FOUND The caller can't read the record, the id isn't a record id, or the record is deleted.
RECORD_NOT_SHAREABLE The record is app-wide, or its entity isn't managed and it has lost its parent's access: it has no parent, or its parent is deleted, is an app-wide record, or has no access of its own either.
UNAUTHORIZED The caller doesn't manage the record each id is shared through.
LAST_MANAGER The call would remove or lower the record's last share at MANAGE. A role with record.manage_all doesn't count toward it, so share the record at MANAGE with another user or group first.
VALIDATION Carries no ids, and names the field at fault: not exactly one of everyone, userId or groupId, no ids or more than 100, a userId or groupId that isn't a well-formed id, and, on shareRecords only, an unknown user or group or an app identity's userId.

Records that belong to a parent

Every entity starts out managed: each of its records is a separate unit of access, as described above.

Make an entity unmanaged when its records belong to a parent record, such as the recipes in a cookbook. Give it a required reference field to the parent, marked as the parent, then turn managed off:

multipaas field add --app APP_ID --entity RECIPE_ENTITY_ID --type reference --name cookbook --references COOKBOOK_ENTITY_ID --parent --required
multipaas entity update --app APP_ID --id RECIPE_ENTITY_ID --managed=false

A recipe then follows its cookbook's access: whoever can read the cookbook can read its recipes, including recipes other members added. A role with record.edit_all for the recipes entity can change and delete recipes. Adding a recipe to a cookbook, or moving one to another cookbook, takes edit access to that cookbook. Sharing a recipe takes managing its cookbook; record.manage_all for the recipes entity isn't enough.

A recipe loses its cookbook's access when it has no cookbook, when its cookbook is deleted, when its cookbook is an app-wide record, or when its cookbook has no access of its own either. Then not even the recipe's creator can read it. Only a role holding record.view_all, record.edit_all or record.manage_all for the recipes entity, or for an entity above it such as cookbooks, still can.

An app-wide record can be the parent only of a record whose entity is managed. Creating, changing or restoring a recipe in an app-tenant so that its cookbook is an app-wide record is refused with a VALIDATION error on the parent field, and an import line that does so gets the app-wide-parent problem from the check. Recipes already in that state stay as they are.

Two model changes are refused with a VALIDATION error, rule app-wide-parent, while a live recipe in an app-tenant names an app-wide record in the field, whether or not that cookbook is deleted. A deleted recipe doesn't block them. entity update --managed=false is refused on the field managed: give each such recipe a cookbook from its own app-tenant, or delete it, then run the command again. field update --parent, which makes an existing reference field the parent of an entity that isn't managed, is refused on the field isParent: make the entity managed first with entity update --managed, or give each such recipe a cookbook from its own app-tenant, or delete it, then run the command again.

The parent field above is required, so the generated API refuses to create a recipe without a cookbook, or to clear a recipe's cookbook, in an API version where that field is required. Keep an entity managed unless every one of its records will have a parent like that.

Who created a record

Each record's createdBy names the user who created it. MultiPaaS sets it, and your app can't. For an imported record it is the user the import row names, or whoever ran the import when the row names no one.

Access doesn't check createdBy. On a managed entity the creator can read the record because they manage it.

References to records you can't read

A reference to a record the signed-in user can't read returns null, the same as a reference to nothing.