diff --git a/mediathread/factories.py b/mediathread/factories.py index 10a5d96b8..f95faf557 100644 --- a/mediathread/factories.py +++ b/mediathread/factories.py @@ -65,7 +65,7 @@ def create_collaboration(self, create, extracted, **kwargs): if create: Collaboration.objects.get_or_create( content_type=ContentType.objects.get_for_model(Course), - object_pk=str(self.pk)) + object_pk=str(self.pk), slug=self.slug()) class SourceFactory(factory.DjangoModelFactory): diff --git a/mediathread/projects/tests/test_models.py b/mediathread/projects/tests/test_models.py index f67420394..79e787244 100644 --- a/mediathread/projects/tests/test_models.py +++ b/mediathread/projects/tests/test_models.py @@ -365,7 +365,7 @@ def test_reset_publish_to_world(self): policy='PublicEditorsAreOwners') self.assertEquals( public.public_url(), - '/s/collaboration/%s/' % public.get_collaboration().id) + '/s/%s/project/%s/' % (self.sample_course.slug(), public.id)) Project.objects.reset_publish_to_world(self.sample_course) self.assertIsNone(public.public_url()) diff --git a/mediathread/projects/tests/test_views.py b/mediathread/projects/tests/test_views.py index ff8feea4b..5d283f54e 100644 --- a/mediathread/projects/tests/test_views.py +++ b/mediathread/projects/tests/test_views.py @@ -6,14 +6,15 @@ from django.core.urlresolvers import reverse from django.test import TestCase from django.test.client import RequestFactory +import reversion from mediathread.factories import MediathreadTestMixin, UserFactory, \ AssetFactory, SherdNoteFactory, ProjectFactory, AssignmentItemFactory, \ ProjectNoteFactory from mediathread.projects.models import Project, \ - RESPONSE_VIEW_POLICY, RESPONSE_VIEW_NEVER, RESPONSE_VIEW_SUBMITTED + RESPONSE_VIEW_POLICY, RESPONSE_VIEW_NEVER, RESPONSE_VIEW_SUBMITTED, \ + PUBLISH_WHOLE_WORLD from mediathread.projects.views import SelectionAssignmentView, ProjectItemView -import reversion class ProjectViewTest(MediathreadTestMixin, TestCase): @@ -339,6 +340,48 @@ def test_project_revisions(self): the_json = loads(response.content) self.assertEquals(len(the_json['revisions']), 1) + def test_project_view_readonly(self): + version = self.project_private.versions().next() + url = reverse('project-view-readonly', + kwargs={'project_id': self.project_private.id, + 'version_number': version.revision_id}) + + # anonymous + response = self.client.get(url, {}) + self.assertEquals(response.status_code, 403) + + # forbidden + self.client.login(username=self.student_two.username, password='test') + response = self.client.get(url, {}) + self.assertEquals(response.status_code, 403) + + # owner + self.client.login(username=self.student_one.username, password='test') + response = self.client.get(url, {}) + self.assertEquals(response.status_code, 200) + + # ajax + response = self.client.get(url, {}, + HTTP_X_REQUESTED_WITH='XmlHttpRequest') + self.assertEquals(response.status_code, 200) + + def test_project_public_view(self): + url = self.project_private.get_collaboration().get_absolute_url() + + # still private + response = self.client.get(url, {}) + self.assertEquals(response.status_code, 403) + + # reset to public + self.project_private.create_or_update_collaboration( + PUBLISH_WHOLE_WORLD[0]) + self.project_private.date_submitted = datetime.now() + self.project_private.save() + + url = self.project_private.public_url() + response = self.client.get(url, {}) + self.assertEquals(response.status_code, 200) + def test_project_workspace_errors(self): project_id = self.project_private.id url = reverse('project-workspace', args=[project_id]) diff --git a/mediathread/projects/views.py b/mediathread/projects/views.py index b6121ca81..5c000b024 100644 --- a/mediathread/projects/views.py +++ b/mediathread/projects/views.py @@ -251,7 +251,9 @@ def project_view_readonly(request, project_id, version_number=None): context_instance=RequestContext(request)) else: if version_number: - version = get_object_or_404(Version, revision_id=version_number) + version = get_object_or_404(Version, + object_id=str(project.id), + revision_id=version_number) project = version.object_version.object panels = []