Morning folks!
I'm working on this schema:
attribute owner_type string
relation owner @user @team @organization
relation collaborator @user @team#member @organization#member
relation viewers @user @team#member @organization#member
action view = viewers
action edit = owner or collaborator
action edit_as_owner = owner
action edit_as_collaborator = collaborator
action transfer = (is_user_type(owner_type) and owner) or (is_group_type(owner_type) and owner.transfer_maps)
}
rule is_user_type(owner_type string) {
owner_type == 'user'
}
rule is_group_type(owner_type string) {
owner_type == 'team' || owner_type == 'organization'
}
entity user {
attribute transfer_own_maps boolean
action transfer_maps = transfer_own_maps
}
entity team {
relation parent @organization
relation admin @user
relation owner @user
relation member @user
action transfer_maps = admin or owner
}
entity organization {
relation admin @user
relation owner @user
relation member @user @team#member
action transfer_maps = admin or owner
}```
I have some doubts around the multiple-type relation `owner` of the `maps` entity.
Basically what I want to accomplish is being able to determine if an user can transfer the map ownership to another user or team/org.
For that I added an action in the `organization` and `team` entities that checks if the user is the admin or the owner of the team/organization that owns the map, in those cases they can transfer.
I had to add a dummy action `transfer_maps` on the user model named the same way as the one used on the team/organization entities because otherwise it won't work.
I also had to add a `owner_type` in the `maps` entity so I was able to do this in the `transfer` action:
`action transfer = (is_user_type(owner_type) and owner) or (is_group_type(owner_type) and owner.transfer_maps)`
I'm wondering if that seems correct. Thanks!