openfga / language

Grammar for the OpenFGA modeling language
https://openfga.dev
Apache License 2.0
17 stars 7 forks source link

Wrong error message thrown when the base relation used in the from contains a rewrite #244

Closed rhamzeh closed 1 month ago

rhamzeh commented 5 months ago

Discussed in https://github.com/orgs/openfga/discussions/297

Originally posted by Chedi April 14, 2024


While trying to model some nested relation, I noticed that accessing any parent level except the one just above the current level gives me an error. For example

model
  schema 1.1

type user

type system
  relations
    define admin: [user]
    define staff: [user] or admin

type organization
  relations
    define system: [system]

type resource
  relations
    define system      : system from organization   
    define organization: [organization]

    define can_delete: staff from system

The error being

`can_delete` is an impossible relation for `resource` (no entrypoint)

The error message is incorrect, it should be:

`system` relation used inside from allows only direct relation.

The referenced base relation used after the from system in staff from system MUST be a directly assignable relation that has no rewrites and does not allow direct assignment of <type>:* and <type>#<relation>, so it MUST be of the form:

define system: [<type>, <type2>, etc..]

And this validation should take precedence over no entry point (also in this case, there is an entry point)