Repository: akvo/akvo-rsr

Issue:
Search in EUTF akvo site
Partner team had a training and workshop with EUTF last week and discovered that search terms in EUTF akvo site returned unrelated results.

Search for tombouctou shows up a project of SNV in EUTF akvo page, which is confusing for the partner as they expect to see their own projects only on their akvo site. 

<img width="1070" alt="screen shot 2017-02-06 at 15 56 41" src="https://cloud.githubusercontent.com/assets/21127166/22652066/45bdf606-ec85-11e6-9c05-25d421b329c1.png">

What the partner expects is to see just projects where they are one of the participating partners. 
If the search does not match any of their projects, it should then not return anything. 


Discussion:
Duplicate of https://github.com/akvo/akvo-rsr/issues/1853

Resolving patch:
diff --git a/akvo/rest/views/typeahead.py b/akvo/rest/views/typeahead.py
--- a/akvo/rest/views/typeahead.py
+++ b/akvo/rest/views/typeahead.py
@@ -66,32 +66,22 @@ def typeahead_project(request):
     the current context -- changes depending on whether we are on a partner
     site, or the RSR site.
 
-    If a project query parameter with a project id is passed, the info for all
-    projects associated with partners for the specified project is returned.
+    If a published query parameter is passed, only projects that have been
+    published are returned.
 
     NOTE: The unauthenticated user gets information about all the projects when
     using this API endpoint.  More permission checking will need to be added,
     if the amount of data being returned is changed.
 
     """
-    project_id = request.GET.get('project', None)
-    if project_id is None:
-        project = None
-
+    if request.GET.get('published', '0') == '0':
+        # Project editor - organization projects, all
+        page = request.rsr_page
+        projects = page.organisation.all_projects() if page else Project.objects.all()
     else:
-        try:
-            project = Project.objects.get(id=project_id)
-        except Project.DoesNotExist:
-            project = None
-
-    if project is None:
         # Search bar - organization projects, published
         projects = _project_directory_coll(request)
 
-    else:
-        # Project editor - all projects of partners for this project
-        projects = Project.objects.of_partners(project.partners.distinct()).distinct()
-
     projects = projects.exclude(title='')
     return Response(
         rejig(projects, TypeaheadProjectSerializer(projects, many=True))


Test patch:
diff --git a/akvo/rsr/tests/rest/test_typeahead.py b/akvo/rsr/tests/rest/test_typeahead.py
--- a/akvo/rsr/tests/rest/test_typeahead.py
+++ b/akvo/rsr/tests/rest/test_typeahead.py
@@ -40,18 +40,15 @@ def setUp(self):
                     iati_organisation_role=Partnership.IATI_REPORTING_ORGANISATION
                 )
 
-            if i == 1:
-                self.project = project
-
     def _create_client(self, host=None):
         """ Create and return a client with the given host."""
         if not host:
             host = settings.RSR_DOMAIN
         return Client(HTTP_HOST=host)
 
-    def test_searchable_projects_on_rsr_host(self):
+    def test_published_projects_on_rsr_host(self):
         # Given
-        url = '/rest/v1/typeaheads/projects?format=json'
+        url = '/rest/v1/typeaheads/projects?format=json&published=1'
         client = self._create_client()
 
         # When
@@ -61,9 +58,9 @@ def test_searchable_projects_on_rsr_host(self):
         self.assertEqual(response.status_code, 200)
         self.assertEqual(len(response.data['results']), 3)
 
-    def test_project_editor_typeaheads_on_rsr_host(self):
+    def test_all_projects_on_rsr_host(self):
         # Given
-        url = '/rest/v1/typeaheads/projects?format=json&project={}'.format(self.project.id)
+        url = '/rest/v1/typeaheads/projects?format=json'
         client = self._create_client()
 
         # When
@@ -71,11 +68,11 @@ def test_project_editor_typeaheads_on_rsr_host(self):
 
         # Then
         self.assertEqual(response.status_code, 200)
-        self.assertEqual(len(response.data['results']), 2)
+        self.assertEqual(len(response.data['results']), 5)
 
-    def test_searchable_projects_on_partner_site(self):
+    def test_published_projects_on_partner_site(self):
         # Given
-        url = '/rest/v1/typeaheads/projects?format=json'
+        url = '/rest/v1/typeaheads/projects?format=json&published=1'
         host = 'akvo.{}'.format(settings.AKVOAPP_DOMAIN)
         client = self._create_client(host)
 
@@ -88,7 +85,7 @@ def test_searchable_projects_on_partner_site(self):
 
     def test_all_projects_on_partner_site(self):
         # Given
-        url = '/rest/v1/typeaheads/projects?format=json&project={}'.format(self.project.id)
+        url = '/rest/v1/typeaheads/projects?format=json'
         host = 'akvo.{}'.format(settings.AKVOAPP_DOMAIN)
         client = self._create_client(host)