Home > Blockchain >  Is it possible to use complex logic in DRF ViewSet Permission Classes?
Is it possible to use complex logic in DRF ViewSet Permission Classes?

Time:02-16

In the app I'm working on, I'd like it so that to create a task for a committee, you must be a member of the committee, the head of the committee, or an admin user, but you must also be authenticated. I understand this can be done with a few OR operators, but in the case that I need something more complex, I was hoping I could use nested lists of permission classes as such:

permission_classes = [
                         IsAuthenticated & 
                         [
                             IsCommitteeHead | 
                             IsCommitteeMember | 
                             IsAdminUser
                         ]
                     ]

Will this syntax work properly, or does rest_framework not understand this?

CodePudding user response:

Yes, from the enter image description here

I really hate hard coding and recommend you to learn someway to avoid hard coding always.

  • Related