Best way of building middleware for intercepting requests in Django-Vuejs project

Viewed 135

I'm working on a Django-Vuejs based project. In my project, a user can have a folder. Inside that, he can create multiple files. Let say, user restricted users from India to access that folder. This folder restriction will now be followed in files as well. But, user can override these settings on file level i.e., user can change restrict settings for single file. So that, if one folder has 5 files. Folder is restricting India and now only one file allowing India. That means, one file will allow India, rest four will restrict India.

My question here is how my middleware should be designed for these settings? Should I create interceptors in Vuejs and define middleware for each route /folder/1 and /file/1 or create custom middleware in Django and check for the requested path in request and accordingly check for the access settings?

What's the best way to achieve this?

I've tried with rest_framework Permissions on folder level. It's working perfectly if the settings are only on folder level. But if settings get changed on file level, it still checks for folder permission and send response accordingly (since file is inside the folder).

1 Answers

I think you don't need a middleware for that, all the logic shall be in the view that will serve the file.

For the permissions, if I were you, I create a Model Called permissions and let the user permissions added to that model.

Related