What's the best way to implement roles/authorization in nestjs? I'm not using CASL right now, I'm not sure if it suits my simple use case.
For a brief background:
A. the project uses typeorm
B. notably, there are two roles: student and instructor
C. majority of the database tables/entities have the same way of doing CRUD operations (in this case, let's call these specific entities as "domain entities/records" because they are directly related to the business domain of the project)
D. each domain record has a foreign key that points to an Activity record upon creation (Activity a non-domain entity, but just note that this table has columns such as **startDate **and endDate)
E. no other app roles/permissions are expected to be changed/created in the future.
F. API implementation is REST
Here are some of the typical rules:
-
all users can MANAGE (FULL CRUD) domain entities/records as long as they own these records (i.e., they were the one who created such)
-
in addition to rule 1, instructor-users can also READ other domain records as long as the owner of these records are their own students
-
additional logic to rule 1; student-users can only CREATE a domain record if the current date of creation/api request is within the
start/endDate(in reference to the Activity relation previously mentioned, background item D) -
instructor-users can MANAGE non-domain entities/records, while student-users can only READ them
Any suggestions on how to implement these with best practices? Do I still need to use CASL for this?