Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid state: Type User occurs more than once as the target of a relation #1676

Open
Eggwise opened this issue Feb 23, 2023 · 2 comments
Open

Comments

@Eggwise
Copy link

Eggwise commented Feb 23, 2023

Hi folks 馃憢 ,

We use Oso for a large energy-provider in the Netherlands. We built our own data-filtering adapter for Strapi (nodeJS).
Works like a charm.

But now i come across a problem.
In the system we have users. Then we have a new entity: UserRelation, this defines a relationship between user A and user B.
Using this entity we can define relationships between users like, John is friend of Lisa. etc.

We have rules for reading, updating etc users and i want to re-use these when defining rules for UserRelations
So i define this rule for listing user relations on the /user-relations endpoint.

allow(user: User, "read", relation: UserRelation) if
    allow(user, "read", relation.user_from) and
    allow(user, "read", relation.user_to);

But now i get this error.

error: Invalid state: Type `User` occurs more than once as the target of a relation
OperationalError::InvalidState: Invalid state: Type `User` occurs more than once as the target of a relation

But this (incomplete) rule works:

allow(user: User, "read", relation: UserRelation) if
    allow(user, "read", relation.user_from);

Why is this behaviour? Is this something we can disable ? I would like to re-use my rules.

i use npm oso "^0.26.0"

Help much appreciated 馃檹

@Eggwise
Copy link
Author

Eggwise commented Feb 23, 2023

#1531

@Eggwise
Copy link
Author

Eggwise commented Mar 9, 2023

Any news on this?

This also occurs when i have something like this:

#cant use this..#    Invalid state: Type `User` occurs more than once as the target of a relation

relation_is_within_organization(user: User, relation: UserRelation) if
   relation.type.organization.id = user.organization.id and
   relation.user_from.organization.id = user.organization.id and
   relation.user_to.organization.id = user.organization.id;

This is wierd, because this means i cannot make rules where i test multiple attributes on a user's value

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant