1

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).

Prachi Sharma
  • 331
  • 1
  • 5
  • 14

1 Answers1

0

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.

Mohamed ElKalioby
  • 1,908
  • 1
  • 12
  • 13
  • But my users can re-locate i.e., their locations can change and I need to pick their latest location. Also, I do get some users who don't have account, yet they can access the resources (given the permission). So I cannot go with models approach. And about adding logic in view, I already have multiple views for different purposes. I cannot just edit all the views to add the logic. – Prachi Sharma Jun 11 '21 at 04:06