Skip to content

Instantly share code, notes, and snippets.

@vicradon
Created September 22, 2020 22:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vicradon/9eedc365dd76df363aad7552bf578c4a to your computer and use it in GitHub Desktop.
Save vicradon/9eedc365dd76df363aad7552bf578c4a to your computer and use it in GitHub Desktop.
A question to be asked on the fauna discuss forum

I have a Student role which I created using this FQL

CreateRole({
  name: "Student",
  privileges: [
    {
      resource: Collection("Courses"),
      actions: { read: true },
    },
    {
      resource: Collection("Teachers"),
      actions: { read: true },
    },
  ],
  membership: [
    {
      resource: Collection("Students"),
      predicate: Query(
        Lambda(
          "ref",
          Equals(Select(["data", "metadata", "role"], Get("ref")), "student")
        )
      ),
    },
  ],
});

When I try reading from the Courses collection using a server key like this

Paginate(Documents(Collection("Courses")), {size: 2})

I get this result

{
  after: [Ref(Collection("Courses"), "277389193509865985")],
  data: [
    Ref(Collection("Courses"), "277389193509863937"),
    Ref(Collection("Courses"), "277389193509864961")
  ]
}

But when I try reading from the collection using a token from a member of this role, I get this result

{data: []}

Here's a sample document from the Courses collection

{
  "ref": Ref(Collection("Courses"), "277389193509863937"),
  "ts": 1600797799527000,
  "data": {
    "title": "Liaison Technician",
    "description": "Quam provident autem perferendis deserunt.",
    "teachers": [],
    "code": "LIA 241",
    "availableFor": Ref(Collection("Classes"), "277389192880720389"),
    "creditLoad": 2
  }
}

Here's a sample document from the Students collection

{
  "ref": Ref(Collection("Students"), "277362121690317319"),
  "ts": 1600771983156000,
  "data": {
    "metadata": {
      "firstName": "Loma",
      "lastName": "Glover",
      "email": "loma.glover@skulment.edu",
      "role": "student",
      "currentClass": "Grade 7"
    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment