예제 #1
0
파일: views.py 프로젝트: azizur77/etools
    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
예제 #2
0
    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()
예제 #3
0
    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)
예제 #4
0
파일: views.py 프로젝트: unicef/etools
    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
예제 #5
0
파일: views.py 프로젝트: azizur77/etools
    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
예제 #6
0
파일: views.py 프로젝트: unicef/etools
    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
예제 #7
0
파일: views.py 프로젝트: azizur77/etools
    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
예제 #8
0
파일: views.py 프로젝트: unicef/etools
    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
예제 #9
0
파일: views.py 프로젝트: azizur77/etools
    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
예제 #10
0
파일: views.py 프로젝트: adi130987/etools
    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
예제 #11
0
파일: views.py 프로젝트: unicef/etools
    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
예제 #12
0
    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()
예제 #13
0
파일: signals.py 프로젝트: unicef/etools
def create_user_receiver(instance, created, **kwargs):
    if created:
        instance.user.groups.add(Auditor.as_group())
        instance.user.profile.countries_available.add(connection.tenant)
예제 #14
0
def create_user_receiver(instance, created, **kwargs):
    if created:
        instance.user.groups.add(Auditor.as_group())
예제 #15
0
def create_user_receiver(instance, created, **kwargs):
    if created:
        instance.user.groups.add(Auditor.as_group())
        instance.user.profile.countries_available.add(connection.tenant)
예제 #16
0
    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])