Every request to Hasura executes against a set of session variables. Normally there are some main variables for the authorization context:
X-Hasura-User-Id: this variable usually denotes the user executing the request.
X-Hasura-Role: This variable denotes the role with which the user is executing the current request. Hasura has a built-in notion of a role, and will explicitly look for this variable to infer the role.
X-Hasura-campuses: this variable contains the campus that the user currently is on.
In our database we have several roles which are simple arbitrary names.
Each role can be given a set of permissions and actions (select, insert, update, delete). That will execute against each table of the database.
Example:
To give the user with a certain role a permission to make a request, we must set a permission rule that would look something like this:
{ "user_id": { "_eq": "X-Hasura-User-Id" } }
This is the same as saying : if the value of the user_id column equals the value of the session variable X-Hasura-User-Id, it allows this request to execute on the current row and get information on that user id.
These are the roles presented in the database:
anonymous: this role allows non logged in users to query tables (only using the select action):
users : columns id, loginobject : columns id, childAttr, campus, name, typeresult : columns groupId, objectId, progressId, userId, grade, campustransactions : columns objectId, userId, amount, typeprogress : columns isDone, objectId, userId, id, grade, campususer : this role allows the following queries:
selects action:
without permission rules:
event_usergroupgroup_usermatchregistration_usereventobjectobject_childobject_statusobject_typeregistrationroletransaction_typeevent_user_viewobject_children_viewregistration_user_viewuser_public_viewwith permission rules:
audit, the user only can query this table if the user id from the X-Hasura-User-Id variable is equal to one of the members, or the auditorId.result, the user only can query this table if the X-Hasura-User-Id is equal to the userId or one of the members from their group.transaction, this table can be queried by users if the X-Hasura-User-Id is equal to the userId.record, the same applies to this table and the tables below.progressuser_roleuser, the same applies to this table but with the id.user_role_viewaudit_privateprogress_by_path_viewprogress_viewxpxp_by_eventxp_by_pathcampus-admin : this role allows users to query every table, but with the variables X-Hasura-campus checked (campus check). This means that users with this role will only be able to query information from their own campus. Example: a user in campus madere can only query the content associated to that campus. The following tables can be queried:
select action:
group_statusobject_statusobject_typeresult_typeroletransaction_typeuser_roleuser_public_viewuser_role_viewevent_userauditgroupgroup_usermatchobjecteventprogressrecordregistrationregistration_userresulttransactionuserprogress_by_path_viewaudit_privateevent_user_viewevent_with_results_ready_viewprogress_viewregistration_user_viewregistration_with_event_ready_viewtoad_result_viewxp_by_eventxp_by_pathcampus-admin-read-only : this role allows users to query almost all tables (only using the select action). But with the same permission rule in the campus-admin. The following tables can be queried:
group_statusobject_statusobject_typeresult_typeroletransaction_typeuser_roleuser_public_viewuser_role_viewevent_userauditgroupgroup_usermatchobjecteventprogressrecordregistrationregistration_userresulttransactionuserprogress_by_path_viewaudit_privateevent_user_viewevent_with_results_ready_viewprogress_viewregistration_user_viewregistration_with_event_ready_viewtoad_result_viewxp_by_eventxp_by_pathadmin-read-only : this role allows users to query all tables only using the select action.admin : this role allows users to query using any action in any table on the database.You can see more about each role by going to the graphiql in the docs section. Note that you must be logged in with the user role you desire to see. For the role
anonymousyou do not need to be logged in. If you want to see the possible tables that can be queried by an admin, you must login with an admin, and so onβ¦
A role is given by default to every user, if an user has more roles, the highest would be taken by default when login.
This table can describe the permissions for each table of the database and each user role.
β
: with permission rules
π© : without permission rules
β : not allowed
S : select
U : update
I : insert
D : delete
| tables | anonymous |
user |
campus-admin |
campus-admin-read-only |
admin |
admin-read-only |
|---|---|---|---|---|---|---|
| Β | Sβ Uβ Iβ Dβ | Sβ Uβ Iβ Dβ | Sβ Uβ Iβ Dβ | Sβ Uβ Iβ Dβ | Sβ Uβ Iβ Dβ | Sβ Uβ Iβ Dβ |
| event_user | β β β β | π© β β β | β β β β | β β β β | β β β β | β β β β |
| audit | β β β β | β β β β | β β β β | β β β β | β β β β | β β β β |
| group | β β β β | π© β β β | β β β β | β β β β | β β β β | β β β β |
| group_user | β β β β | π© β β β | β β β β | β β β β | β β β β | β β β β |
| match | β β β β | π© β β β | β β β β | β β β β | β β β β | β β β β |
| progress | π© β β β | β β β β | β β β β | β β β β | β β β β | β β β β |
| record | β β β β | β β β β | β β β β | β β β β | β β β β | β β β β |
| registration_user | β β β β | π© β β β | β β β β | β β β β | β β β β | β β β β |
| result | π© β β β | β β β β | β β β β | β β β β | β β β β | β β β β |
| transaction | π© β β β | β β β β | β β β β | β β β β | β β β β | β β β β |
| user | π© β β β | β π© β β | β β β β | β β β β | β β β β | β β β β |
| audit_expired_view | β β β β | β β β β | β β β β | β β β β | β β β β | β β β β |
| audit_private | β β β β | β β β β | β β β β | β β β β | β β β β | β β β β |
| discordToken | β β β β | β β β β | β β β β | β β β β | β β β β | β β β β |
| event | β β β β | π© β β β | β β β β | β β β β | β β β β | β β β β |
| event_user_view | β β β β | π© β β β | β β β β | β β β β | β β β β | β β β β |
| object | π© β β β | π© β β β | β β β β | β β β β | β β β β | β β β β |
| event_with_results_ready_view | β β β β | β β β β | β β β β | β β β β | β β β β | β β β β |
| group_status | β β β β | β β β β | π© β β β | π© β β β | β β β β | β β β β |
| job | β β β β | β β β β | β β β β | β β β β | β β β β | β β β β |
| match_to_remove_view | β β β β | β β β β | β β β β | β β β β | β β β β | β β β β |
| object_child | β β β β | π© β β β | β β β β | β β β β | β β β β | β β β β |
| object_children_view | β β β β | π© β β β | β β β β | β β β β | β β β β | β β β β |
| object_status | β β β β | π© β β β | π© β β β | π© β β β | β β β β | β β β β |
| object_type | β β β β | π© β β β | π© β β β | π© β β β | β β β β | β β β β |
| progress_by_path_view | β β β β | β β β β | β β β β | β β β β | β β β β | β β β β |
| progress_view | β β β β | β β β β | β β β β | β β β β | β β β β | β β β β |
| registration | β β β β | π© β β β | β β β β | β β β β | β β β β | β β β β |
| registration_user_view | β β β β | π© β β β | β β β β | β β β β | β β β β | β β β β |
| registration_with_event_ready_view | β β β β | β β β β | β β β β | β β β β | β β β β | β β β β |
| result_type | β β β β | β β β β | π© β β β | π© β β β | β β β β | β β β β |
| role | β β β β | π© β β β | π© β β β | π© β β β | β β β β | β β β β |
| toad_result_view | β β β β | β β β β | β β β β | β β β β | β β β β | β β β β |
| token | β β β β | β β β β | β β β β | β β β β | β β β β | β β β β |
| token_status | β β β β | β β β β | β β β β | β β β β | β β β β | β β β β |
| transaction_type | β β β β | π© β β β | π© β β β | π© β β β | β β β β | β β β β |
| user_public_view | β β β β | π© β β β | π© β β β | π© β β β | β β β β | β β β β |
| user_role | β β β β | β β β β | π© β β β | π© β β β | β β β β | β β β β |
| user_roles_view | β β β β | β β β β | π© β β β | π© β β β | β β β β | β β β β |
| xp | β β β β | β β β β | β β β β | β β β β | β β β β | β β β β |
| xp_by_event | β β β β | β β β β | β β β β | β β β β | β β β β | β β β β |
| xp_by_path | β β β β | β β β β | β β β β | β β β β | β β β β | β β β β |