Skip to content

Commit 80189ae

Browse files
authored
Merge pull request #3613 from unicef/develop
dev
2 parents 41a2ea1 + 3dce587 commit 80189ae

File tree

6 files changed

+50
-5
lines changed

6 files changed

+50
-5
lines changed

src/etools/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
VERSION = __version__ = '11.1.1'
1+
VERSION = __version__ = '11.1.6'
22
NAME = 'eTools'

src/etools/applications/organizations/models.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ def relationship_types(self):
103103
not self.partner.hidden:
104104
_list.append('partner')
105105
if hasattr(self, 'auditorfirm') and \
106-
self.auditorfirm.purchase_orders.filter(engagement__isnull=False).exists() and \
107106
not self.auditorfirm.hidden:
108107
_list.append('audit')
109108
if hasattr(self, 'tpmpartner') and \

src/etools/applications/partners/admin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,7 @@ class AgreementAdmin(
731731
'partner_manager',
732732
'signed_by',
733733
'terms_acknowledged_by',
734+
'authorized_officers',
734735
)
735736
fieldsets = (
736737
(_('Agreement Details'), {

src/etools/applications/users/filters.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
from django.db import models
22

3+
from django_filters import rest_framework as filters
34
from rest_framework.filters import BaseFilterBackend
45

6+
from etools.applications.organizations.models import Organization
7+
58

69
class UserRoleFilter(BaseFilterBackend):
710
def filter_queryset(self, request, queryset, view):
@@ -26,3 +29,15 @@ def filter_queryset(self, request, queryset, view):
2629
filters |= models.Q(is_active=True, has_active_realm=False)
2730
return queryset.filter(filters)
2831
return queryset
32+
33+
34+
class OrganizationFilter(filters.FilterSet):
35+
organization_id = filters.NumberFilter()
36+
organization_type = filters.ChoiceFilter(choices=(('audit', 'audit'), ('partner', 'partner'), ('tpm', 'tpm')))
37+
38+
class Meta:
39+
model = Organization
40+
fields = ['organization_id', 'organization_type']
41+
42+
def filter_queryset(self, queryset):
43+
return queryset

src/etools/applications/users/tests/test_views_v3.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010

1111
from etools.applications.action_points.models import PME
1212
from etools.applications.audit.models import Auditor, UNICEFAuditFocalPoint, UNICEFUser
13-
from etools.applications.audit.tests.factories import AuditFocalPointUserFactory, AuditorUserFactory, EngagementFactory
13+
from etools.applications.audit.tests.factories import (
14+
AuditFocalPointUserFactory,
15+
AuditorUserFactory,
16+
AuditPartnerFactory,
17+
EngagementFactory,
18+
)
1419
from etools.applications.core.tests.cases import BaseTenantTestCase
1520
from etools.applications.organizations.tests.factories import OrganizationFactory
1621
from etools.applications.partners.permissions import PARTNERSHIP_MANAGER_GROUP, UNICEF_USER
@@ -132,6 +137,22 @@ def test_get_auditor_firms(self):
132137
self.assertEqual(len(response.data), 1)
133138
self.assertEqual(response.data[0]['id'], engagement.agreement.auditor_firm.organization.id)
134139

140+
def test_get_auditor_firms_with_org_id(self):
141+
PartnerFactory(organization=OrganizationFactory())
142+
EngagementFactory()
143+
audit_firm = AuditPartnerFactory()
144+
145+
with self.assertNumQueries(3):
146+
response = self.forced_auth_req(
147+
"get",
148+
self.url,
149+
data={"organization_type": "audit", "organization_id": audit_firm.organization.pk},
150+
user=self.partnership_manager,
151+
)
152+
self.assertEqual(response.status_code, status.HTTP_200_OK)
153+
self.assertEqual(len(response.data), 1)
154+
self.assertEqual(response.data[0]['id'], audit_firm.organization.id)
155+
135156
def test_get_tpm_firms(self):
136157
PartnerFactory(organization=OrganizationFactory())
137158
EngagementFactory()

src/etools/applications/users/views_v3.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from etools.applications.partners.permissions import user_group_permission
2929
from etools.applications.partners.views.v3 import PMPBaseViewMixin
3030
from etools.applications.users import views as v1, views_v2 as v2
31-
from etools.applications.users.filters import UserRoleFilter, UserStatusFilter
31+
from etools.applications.users.filters import OrganizationFilter, UserRoleFilter, UserStatusFilter
3232
from etools.applications.users.mixins import (
3333
AUDIT_ACTIVE_GROUPS,
3434
GroupEditPermissionMixin,
@@ -224,6 +224,8 @@ class OrganizationListView(ListAPIView):
224224
model = Organization
225225
serializer_class = SimpleOrganizationSerializer
226226
permission_classes = (IsAuthenticated, IsUNICEFUser)
227+
filter_backends = (DjangoFilterBackend,)
228+
filterset_class = OrganizationFilter
227229

228230
def get_queryset(self):
229231
queryset = Organization.objects.all() \
@@ -241,8 +243,15 @@ def get_queryset(self):
241243
auditorfirm__hidden=False),
242244
"tpm": dict(tpmpartner__countries=connection.tenant, tpmpartner__hidden=False)
243245
}
246+
organization_type = self.request.query_params.get('organization_type', 'partner')
247+
# Audit firms without audits are included when organization_id is present
248+
# so that staff members can be added in AMP (ch35468)
249+
if organization_type == 'audit' and 'organization_id' in self.request.query_params:
250+
organization_type_filter['audit'] = dict(auditorfirm__hidden=False,
251+
id__in=[int(self.request.query_params['organization_id'])])
252+
244253
return queryset\
245-
.filter(**organization_type_filter[self.request.query_params.get('organization_type', 'partner')])\
254+
.filter(**organization_type_filter[organization_type])\
246255
.distinct()
247256

248257

0 commit comments

Comments
 (0)