mrkwtz
09/20/2024, 2:08 PM/** user represents a registered user's account in our application */
definition user {}
/** organization represents an organization that contains documents */
definition organization {
/** administrator indicates that the user is an admin of the org */
relation administrator: user
/** view_all_documents indicates whether a user can view all documents in the org */
permission view_all_documents = administrator
}
/** document represents a document with access control */
definition document {
/** docorg indicates that the organization owns this document */
relation docorg: organization
/** reader indicates that the user is a reader on the document */
relation reader: user
/** writer indicates that the user is a writer on the document */
relation writer: user
/** view indicates whether the user can view the document */
permission view = reader + writer + docorg->view_all_documents
}
Why is there a need for a permission in the organization definition, why can't I (in the document definition, view permission) just directly refer to docorg->administrator?mrkwtz
09/20/2024, 2:14 PMInfo: It is recommended that the right side of all arrows refer to permissions, instead of relations. This allows for easy nested computation, and is more readable.
I also found that info, but I don't understand why it allows for easy nested computation and also IMO it's not "more readable" because for me it's confusing that a permission for a definition (in this example document) is stored somewhere else than the definition it gives access to.Joey
09/20/2024, 2:45 PMJoey
09/20/2024, 2:45 PMJoey
09/20/2024, 2:45 PMadministrator
to be a computed permissionJoey
09/20/2024, 2:45 PMJoey
09/20/2024, 2:45 PMJoey
09/20/2024, 2:46 PMJoey
09/20/2024, 2:46 PMJoey
09/20/2024, 2:46 PMpermission can_admin = administrator
yetitwo
09/20/2024, 2:48 PMcan_admin
- like if you wanted to add some sort of superuser administrator to the mix and add a + organization->superuser
mrkwtz
09/20/2024, 2:59 PMadministrator
to be a computed permission
Is that something you observe often and what can be the reason / rationale behind it?
> it would be a permission right next to the relation
> permission can_admin = administrator
With your example right, but with the example I provided from the docs you create a permission "view_all_documents" which, IMO, should belong to the document definition and not to organization. Because in the example you create a permission for a definition outside of that said definition.
I understand why it works but doing it like that, for me personally, looks counter intuitive.Joey
09/20/2024, 3:20 PMJoey
09/20/2024, 3:21 PMJoey
09/20/2024, 3:21 PMdocument:whatever#view_all_documents@user:tom
doesn't make senseJoey
09/20/2024, 3:21 PMorganization:someorg#view_all_documents@user:tom
doesJoey
09/20/2024, 3:22 PM