replace()

Replace a role.

Signature

replace(object: {*: Any}): Role

Description

The replace() method replaces a role with the object supplied. This method removes any fields on the existing role that aren’t supplied by the object, with some exceptions. The immutable metadata fields coll and ts aren’t removed and can’t be replaced.

The object must include the required fields.

Parameters

Parameter Type Required Description

data

Object

Yes

Object describing the role.

data fields

Name Type Required Description

name

String

Yes

Unique name.

privileges

Array

Yes

One or more privilege configuration objects.
See Privilege configuration object

membership

Array

One or more membership configuration objects.
See Membership configuration object

data

Object

User-defined metadata that stores supplemental information.

Return value

Type Description

Role

A document with replaced fields.

Examples

Role.byName("manager")?.replace({
  name: "manager",
  privileges: [
    {
      resource: "Store",
      actions: {
        create: true,
        read: true,
        write: true,
        delete: true
      }
    },
    {
      resource: "Manager",
      actions: {
        read: "(ref) => Query.identity() == ref"
      }
    }
  ],
  membership: [
    {
      resource: "Manager"
    }
  ]
})
{
  name: "manager",
  coll: Role,
  ts: Time("2023-07-27T22:38:33.860Z"),
  privileges: [
    {
      resource: "Store",
      actions: {
        create: true,
        read: true,
        write: true,
        delete: true
      }
    },
    {
      resource: "Manager",
      actions: {
        read: "(ref) => Query.identity() == ref"
      }
    }
  ],
  membership: [
    {
      resource: "Manager"
    }
  ]
}

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!