diff --git a/tock/hours/tests/test_views.py b/tock/hours/tests/test_views.py index 031d5945..ae4e18c5 100644 --- a/tock/hours/tests/test_views.py +++ b/tock/hours/tests/test_views.py @@ -511,6 +511,9 @@ def test_project_choice_filtering(self): org_coe = Organization.objects.create(name='CoE') org_coe.save() + org_other = Organization.objects.create(name='Other') + org_other.save() + accounting_code = AccountingCode.objects.get(pk=1) project_18f = Project.objects.create( @@ -527,6 +530,13 @@ def test_project_choice_filtering(self): ) project_coe.save() + project_other = Project.objects.create( + name='a project with a non-18F/CoE org', + accounting_code=accounting_code, + organization=org_other + ) + project_other.save() + project_none = Project.objects.create( name='a project with no org assignment', accounting_code=accounting_code, @@ -553,6 +563,7 @@ def test_project_choice_filtering(self): project_18f_found = False project_coe_found = False + project_other_found = False project_none_found = False str_formset = str(response.context['formset']).split('\n') for line in str_formset: @@ -560,11 +571,15 @@ def test_project_choice_filtering(self): project_18f_found = True if line.find(f'option value="{project_coe.id}"') > 0: project_coe_found = True + if line.find(f'option value="{project_other.id}"') > 0: + project_other_found = True if line.find(f'option value="{project_none.id}"') > 0: project_none_found = True self.assertTrue(project_18f_found) - self.assertFalse(project_coe_found) + # special cased to now show CoE projects too!! + self.assertTrue(project_coe_found) + self.assertFalse(project_other_found) self.assertTrue(project_none_found) def test_holiday_prefill(self): diff --git a/tock/hours/views.py b/tock/hours/views.py index 5420bbe8..e6218f32 100644 --- a/tock/hours/views.py +++ b/tock/hours/views.py @@ -31,7 +31,7 @@ TimecardForm, TimecardFormSet, projects_as_choices, timecard_formset_factory) from .models import (Project, ReportingPeriod, Timecard, TimecardNote, - TimecardObject, TimecardPrefillData) + TimecardObject, TimecardPrefillData, Organization) class BulkTimecardSerializer(serializers.Serializer): @@ -496,6 +496,17 @@ def get_context_data(self, **kwargs): # already-generated choices. Ideally we should be passing these # into the formset constructor. projects = reporting_period.get_projects().filter(Q(organization=self.request.user.user_data.organization) | Q(organization=None)) + + # 18F and CoE need to see each others projects + special_orgs = Organization.objects.filter(Q(name="18F") | Q(name="CoE")) + if (self.request.user.user_data.organization in special_orgs): + # special case: for users in the 18F or CoE organizations, show + # projects for both organizations + projects = reporting_period.get_projects().filter( + Q(organization__in=special_orgs) + | Q(organization=None) + ) + choices = projects_as_choices(projects) for form in formset.forms: