def get_queryset(self): queryset = super().get_queryset() user_groups = self.request.user.groups.all() if UNICEFUser.as_group( ) in user_groups or UNICEFAuditFocalPoint.as_group() in user_groups: # no need to filter queryset pass elif Auditor.as_group() in user_groups: queryset = queryset.filter(staff_members__user=self.request.user) else: queryset = queryset.none() queryset = queryset.prefetch_related( 'partner', Prefetch('agreement', PurchaseOrder.objects.prefetch_related('auditor_firm'))) if self.action in ['list', 'export_list_csv']: queryset = queryset.filter( agreement__auditor_firm__unicef_users_allowed=self. unicef_engagements) return queryset
def is_auditor(self, request, view): if not request.user.groups.filter(id=Auditor.as_group().id).exists(): return False audit_organization = view.get_parent_object() return audit_organization.staff_members.filter( user_id=request.user.id).exists()
def get_redirect_url(self, *args, **kwargs): if not self.request.user.is_staff: if ThirdPartyMonitor.as_group() in self.request.user.groups.all(): return '/tpm/' if Auditor.as_group() in self.request.user.groups.all(): return '/ap/' return super().get_redirect_url(*args, **kwargs)
def get_permission_context(self): context = super().get_permission_context() if Auditor.as_group() in self.request.user.groups.all(): context += [ AuditStaffMemberCondition(self.get_parent_object(), self.request.user), ] return context
def get_permission_context(self): context = super().get_permission_context() if Auditor.as_group() in self.request.user.groups.all(): context += [ AuditStaffMemberCondition(self.get_parent_object(), self.request.user), ] return context
def get_permission_context(self): context = super().get_permission_context() if Auditor.as_group() in self.request.user.groups.all() and \ hasattr(self.request.user, 'purchase_order_auditorstaffmember'): context += [ AuditStaffMemberCondition(self.request.user.purchase_order_auditorstaffmember.auditor_firm, self.request.user), ] return context
def get_permission_context(self): context = super().get_permission_context() if Auditor.as_group() in self.request.user.groups.all() and \ hasattr(self.request.user, 'purchase_order_auditorstaffmember'): context += [ AuditStaffMemberCondition( self.request.user.purchase_order_auditorstaffmember. auditor_firm, self.request.user), ] return context
def get_queryset(self): queryset = super().get_queryset() user_groups = self.request.user.groups.all() if UNICEFUser.as_group() in user_groups or UNICEFAuditFocalPoint.as_group() in user_groups: # no need to filter queryset pass elif Auditor.as_group() in user_groups: queryset = queryset.filter(staff_members__user=self.request.user) else: queryset = queryset.none() return queryset
def get_queryset(self): queryset = super().get_queryset() user_groups = self.request.user.groups.all() if UNICEFUser.as_group( ) in user_groups or UNICEFAuditFocalPoint.as_group() in user_groups: # no need to filter queryset pass elif Auditor.as_group() in user_groups: queryset = queryset.filter(staff_members__user=self.request.user) else: queryset = queryset.none() return queryset
def get_queryset(self): queryset = super(EngagementViewSet, self).get_queryset() user_groups = self.request.user.groups.all() if UNICEFUser.as_group( ) in user_groups or UNICEFAuditFocalPoint.as_group() in user_groups: # no need to filter queryset pass elif Auditor.as_group() in user_groups: queryset = queryset.filter(staff_members__user=self.request.user) else: queryset = queryset.none() queryset = queryset.prefetch_related( 'partner', Prefetch('agreement', PurchaseOrder.objects.prefetch_related('auditor_firm'))) return queryset
def get_queryset(self): queryset = super().get_queryset() user_groups = self.request.user.groups.all() if UNICEFUser.as_group() in user_groups or UNICEFAuditFocalPoint.as_group() in user_groups: # no need to filter queryset pass elif Auditor.as_group() in user_groups: queryset = queryset.filter(staff_members__user=self.request.user) else: queryset = queryset.none() queryset = queryset.prefetch_related( 'partner', Prefetch('agreement', PurchaseOrder.objects.prefetch_related('auditor_firm')) ) if self.action in ['list', 'export_list_csv']: queryset = queryset.filter(agreement__auditor_firm__unicef_users_allowed=self.unicef_engagements) return queryset
def is_auditor(self, request, view): if not request.user.groups.filter(id=Auditor.as_group().id).exists(): return False audit_organization = view.get_parent_object() return audit_organization.staff_members.filter(user_id=request.user.id).exists()
def create_user_receiver(instance, created, **kwargs): if created: instance.user.groups.add(Auditor.as_group()) instance.user.profile.countries_available.add(connection.tenant)
def create_user_receiver(instance, created, **kwargs): if created: instance.user.groups.add(Auditor.as_group())
def create_user_receiver(instance, created, **kwargs): if created: instance.user.groups.add(Auditor.as_group()) instance.user.profile.countries_available.add(connection.tenant)
def test_list_view_without_audit_organization(self): user = UserFactory(unicef_user=True) user.groups.add(Auditor.as_group()) self._test_list(user, [self.engagement, self.second_engagement])