Repository: akvo/akvo-rsr

Issue:
Users should have permissions on projects in content owned organisations



Discussion:

Resolving patch:
diff --git a/akvo/rsr/permissions.py b/akvo/rsr/permissions.py
--- a/akvo/rsr/permissions.py
+++ b/akvo/rsr/permissions.py
@@ -200,7 +200,7 @@ def user_has_perm(user, employments, project_id):
     # hierarchy, and restrict access based on whether the owner has enabled
     # restrictions or not.
     if hierarchy_org is None or not hierarchy_org.enable_restrictions:
-        all_projects = organisations.all_projects()
+        all_projects = organisations.content_owned_organisations().all_projects()
 
     else:
         collaborator_ids = get_organisation_collaborator_org_ids(hierarchy_org.id)
diff --git a/akvo/urls.py b/akvo/urls.py
--- a/akvo/urls.py
+++ b/akvo/urls.py
@@ -134,11 +134,19 @@
     url(r'^myrsr/updates/$',
         my_rsr.my_updates, name='my_updates'),
 
+    url(r'^myrsr/projects_old/$',
+        my_rsr.my_projects, name='my_projects_old'),
+
     url(r'^myrsr/projects/$',
-        my_rsr.my_projects, name='my_projects'),
+        RedirectView.as_view(url='/my-rsr/projects/'),
+        name='my_projects'),
+
+    url(r'^myrsr/project_editor_old/(?P<project_id>\d+)/$',
+        my_rsr.project_editor, name='project_editor_old'),
 
     url(r'^myrsr/project_editor/(?P<project_id>\d+)/$',
-        my_rsr.project_editor, name='project_editor'),
+        RedirectView.as_view(url='/my-rsr/projects/%(project_id)s/'),
+        name='project_editor'),
 
     url(r'^myrsr/iati/$',
         my_rsr.my_iati, name='my_iati'),
@@ -249,14 +257,3 @@
 
 if settings.REQUIRED_AUTH_GROUPS:
     check_auth_groups(settings.REQUIRED_AUTH_GROUPS)
-
-# Enable new project editor
-if settings.RSR_DOMAIN != 'rsr.akvo.org':
-    urlpatterns = i18n_patterns(
-        url(r'^myrsr/projects/$',
-            RedirectView.as_view(url='/my-rsr/projects/'),
-            name='my_projects'),
-        url(r'^myrsr/project_editor/(?P<project_id>\d+)/$',
-            RedirectView.as_view(url='/my-rsr/projects/%(project_id)s/'),
-            name='project_editor'),
-    ) + urlpatterns


Test patch:
diff --git a/akvo/rsr/tests/test_permissions.py b/akvo/rsr/tests/test_permissions.py
--- a/akvo/rsr/tests/test_permissions.py
+++ b/akvo/rsr/tests/test_permissions.py
@@ -790,3 +790,23 @@ def test_hierarchy_published_only_projects_listed_for_managed_users(self):
         self.assertFalse(project.is_published())
         self.assertNotIn(project, projects)
         self.assertIn(self.project, projects)
+
+
+class ContentOwnedOrganisationsPermissionsTestCase(BaseTestCase):
+
+    def setUp(self):
+        super(ContentOwnedOrganisationsPermissionsTestCase, self).setUp()
+        self.user = self.create_user('foo@example.com', 'password')
+        self.org = self.create_organisation('EUTF')
+        self.org1 = self.create_organisation('EUTF Delegation 1')
+        self.project = self.create_project('EUTF Project')
+
+    def test_can_access_content_owned_org_projects(self):
+        # Given
+        self.make_employment(self.user, self.org, 'Admins')
+        self.org1.content_owner = self.org
+        self.org1.save()
+        self.make_partner(self.project, self.org1)
+
+        # When/Then
+        self.assertTrue(self.user.has_perm('rsr.change_project', self.project))