chapter
chapter copied to clipboard
Ensure that the client always knows what the server permits
The potential problem
It's possible for the client side checkPermission https://github.com/freeCodeCamp/chapter/blob/730ac938d85d7c465cb464b8cbae3d5df36a6c26/client/src/util/check-permission.ts#L8-L15 to fail when the server would allow a request. There are two ways it can fail when it should not
- It does not pass the correct variableValues
- It relies on
events
orvenues
The first case isn't fundamental. If we're careful, it can be avoided. However, there are situations where the second case cannot be avoided.
For example, if a chapter administrator checks their permission
checkPermission(user, Permissions.EventEdit, { eventId: 1 })
this will fail even if they're an administrator of the chapter this event belongs to. This is because the checker
function needs the chapterId
to see if the administrator has the permission and it needs the list of events to get the chapterId
.
The potential solutions
- make
events
+venues
available to the client - stop client side checking and, instead, query the server whenever the client needs to know what's allowed
- put
events
andvenues
inside theuser
object. That waychecker
can findchapterId
just by inspecting `user
Option 3 seems like the cleanest solution to me, but I'd welcome any opinions before I try to implement this.