Commit 507f8200 authored by Bryan  BRANCOTTE's avatar Bryan BRANCOTTE
Browse files

Merge branch 'curator-can-edit-mapping' into 'master'

Curators can edit mapping

Closes #235

See merge request !83
parents fbfa7070 d0cef5d0
......@@ -1047,16 +1047,46 @@ class DataSourceDetailViewTestCase(ViewTestCase):
class DataSourceMappingEditTestCase(ViewTestCase):
def test_works(self):
url = reverse('viralhostrangedb:data-source-mapping-label-edit', args=[self.private_data_source_of_toto.pk])
url = reverse('viralhostrangedb:data-source-mapping-label-edit', args=[self.public_data_source_of_user.pk])
response = self.client.get(url)
self.assertRedirects(
response,
expected_url=reverse('basetheme_bootstrap:login') + "?next=" + url
)
self.client.force_login(self.user)
response = self.client.get(url)
self.assertEqual(response.status_code, 404)
self.client.force_login(self.toto)
self.assertEqual(self.client.get(url).status_code, 404)
self.private_data_source_of_user.allowed_users.add(self.toto, through_defaults=dict(can_write=False))
self.assertEqual(self.client.get(url).status_code, 404)
self.private_data_source_of_user.allowed_users.remove(self.toto)
self.private_data_source_of_user.allowed_users.add(self.toto, through_defaults=dict(can_write=True))
self.assertEqual(self.client.get(url).status_code, 404)
self.public_data_source_of_user.allowed_users.add(self.toto, through_defaults=dict(can_write=False))
self.assertEqual(self.client.get(url).status_code, 404)
self.public_data_source_of_user.allowed_users.remove(self.toto)
self.public_data_source_of_user.allowed_users.add(self.toto, through_defaults=dict(can_write=True))
self.assertEqual(self.client.get(url).status_code, 200)
self.public_data_source_of_user.allowed_users.remove(self.toto)
self.assertEqual(self.client.get(url).status_code, 404)
business_process.set_curator(self.toto, True)
self.assertEqual(self.client.get(url).status_code, 200)
business_process.set_curator(self.toto, False)
self.assertEqual(self.client.get(url).status_code, 404)
self.public_data_source_of_user.public = False
self.public_data_source_of_user.save()
business_process.set_curator(self.toto, True)
self.assertEqual(self.client.get(url).status_code, 404, "Curators cannot see private ds")
business_process.set_curator(self.toto, False)
self.public_data_source_of_user.public = True
self.public_data_source_of_user.save()
self.client.force_login(self.user)
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
......@@ -1976,17 +2006,36 @@ class DataSourceRangeMappingEditTestCase(ViewTestCase):
)
self.client.force_login(self.toto)
response = self.client.get(url)
self.assertEqual(response.status_code, 404)
self.assertEqual(self.client.get(url).status_code, 404)
self.private_data_source_of_user.allowed_users.add(self.toto, through_defaults=dict(can_write=False))
response = self.client.get(url)
self.assertEqual(response.status_code, 404)
self.assertEqual(self.client.get(url).status_code, 404)
self.private_data_source_of_user.allowed_users.remove(self.toto)
self.private_data_source_of_user.allowed_users.add(self.toto, through_defaults=dict(can_write=True))
response = self.client.get(url)
self.assertEqual(response.status_code, 404)
self.assertEqual(self.client.get(url).status_code, 404)
self.public_data_source_of_user.allowed_users.add(self.toto, through_defaults=dict(can_write=False))
self.assertEqual(self.client.get(url).status_code, 404)
self.public_data_source_of_user.allowed_users.remove(self.toto)
self.public_data_source_of_user.allowed_users.add(self.toto, through_defaults=dict(can_write=True))
self.assertEqual(self.client.get(url).status_code, 200)
self.public_data_source_of_user.allowed_users.remove(self.toto)
self.assertEqual(self.client.get(url).status_code, 404)
business_process.set_curator(self.toto, True)
self.assertEqual(self.client.get(url).status_code, 200)
business_process.set_curator(self.toto, False)
self.assertEqual(self.client.get(url).status_code, 404)
self.public_data_source_of_user.public = False
self.public_data_source_of_user.save()
business_process.set_curator(self.toto, True)
self.assertEqual(self.client.get(url).status_code, 404, "Curators cannot see private ds")
business_process.set_curator(self.toto, False)
self.public_data_source_of_user.public = True
self.public_data_source_of_user.save()
self.client.force_login(self.user)
response = self.client.get(url)
......
......@@ -168,7 +168,7 @@ def data_source_data_update(request, pk):
@login_required
def data_source_mapping_edit(request, pk):
data_source = get_object_or_404(mixins.only_editor_or_owned_queryset_filter(
data_source = get_object_or_404(mixins.only_editor_or_curator_or_owned_queryset_filter(
self=None,
request=request,
queryset=models.DataSource.objects,
......@@ -223,7 +223,7 @@ def data_source_mapping_edit(request, pk):
@login_required
def data_source_mapping_range_edit(request, pk):
data_source = get_object_or_404(mixins.only_editor_or_owned_queryset_filter(
data_source = get_object_or_404(mixins.only_editor_or_curator_or_owned_queryset_filter(
self=None,
request=request,
queryset=models.DataSource.objects,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment