diff options
Diffstat (limited to 'tools/pharos-dashboard/dashboard/views/registration.py')
-rw-r--r-- | tools/pharos-dashboard/dashboard/views/registration.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/tools/pharos-dashboard/dashboard/views/registration.py b/tools/pharos-dashboard/dashboard/views/registration.py new file mode 100644 index 00000000..516fb298 --- /dev/null +++ b/tools/pharos-dashboard/dashboard/views/registration.py @@ -0,0 +1,16 @@ +from django.contrib.auth.mixins import UserPassesTestMixin + + +class BookingUserTestMixin(UserPassesTestMixin): + # Test if a user has permission to book this Pod + def test_func(self): + user = self.request.user + # Check if User is troubleshooter / admin + if user.has_perm(('dashboard.add_booking')): + return True + # Check if User owns this resource + user_resources = user.userresource_set.get_queryset() + for user_resource in user_resources: + if user_resource.resource_id == self.resource.resource_id: + return True + return False |