Role.create()
Learn: Roles |
---|
We recommend you use FSL to create and update user-defined roles. See Role schema. |
Create a role.
Description
The Role.create()
method creates a role with the provided data.
Only resources with an admin
key can create or manage user-defined roles.
Roles are created in the current database. To establish the same roles
throughout a database hierarchy, you must separately create identical roles in
each child database that requires them.
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
data |
Yes |
Object describing the role. |
data fields
Name | Type | Required | Description |
---|---|---|---|
name |
Yes |
A unique name. |
|
membership |
One or more membership configuration objects. See Membership definition. |
||
privileges |
Yes |
One or more privilege configuration objects. See Privileges definition. |
|
data |
User-defined metadata that stores supplemental information. |
Examples
Role.create({
name: "customer",
privileges: [
{
resource: "Product",
actions: {
read: true
}
},
{
resource: "Order",
actions: {
read: "(ref) => Query.identity() == ref.customer"
}
},
{
resource: "Customer",
actions: {
read: "(ref) => Query.identity() == ref"
}
},
{
resource: "getOrCreateCart",
actions: {
call: "(id) => Query.identity()?.id == id"
}
},
{
resource: "checkout",
actions: {
call: "(name) => true"
}
}
],
membership: [
{
resource: "Customer"
}
],
data: {
desc: "End user customer role"
}
})
{
name: "customer",
coll: Role,
ts: Time("2099-07-31T12:37:05.280Z"),
privileges: [
{
resource: "Product",
actions: {
read: true
}
},
{
resource: "Order",
actions: {
read: "(ref) => Query.identity() == ref.customer"
}
},
{
resource: "Customer",
actions: {
read: "(ref) => Query.identity() == ref"
}
},
{
resource: "getOrCreateCart",
actions: {
call: "(id) => Query.identity()?.id == id"
}
},
{
resource: "checkout",
actions: {
call: "(name) => true"
}
}
],
membership: [
{
resource: "Customer"
}
],
data: {
desc: "End user customer role"
}
}
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!