{"action":"created","comment":{"url":"https://api.github.com/repos/fsr-itse/1327/pulls/comments/28457161","id":28457161,"diff_hunk":"@@ -201,3 +203,187 @@ def test_view_permissions(self):\n \n \t\t\tpermission_names = [permission[0] for permission in subclass._meta.permissions]\n \t\t\tself.assertIn(subclass.VIEW_PERMISSION_NAME, permission_names, msg=\"All Document subclasses must declare the permission named in VIEW_PERMISSION_NAME\")\n+\n+\n+class TestAttachments(WebTest):\n+\t\"\"\"\n+\t\tTests that test the work with attachment.\n+\t\tInformationdocuments are used as testclass. It is assumed that the behaviour is similar with other documenttypes\n+\t\"\"\"\n+\n+\tcsrf_checks = False\n+\n+\tdef setUp(self):\n+\t\tself.user = UserProfile.objects.create_superuser(\"test\", \"test\", \"test@test.test\")\n+\n+\t\tself.group = Group.objects.create(name=\"testgroup\")\n+\t\tfor permission in get_perms_for_model(InformationDocument):\n+\t\t\tpermission_name = \"{}.{}\".format(permission.content_type.app_label, permission.codename)\n+\t\t\tassign_perm(permission_name, self.group)\n+\t\tself.group.save()\n+\n+\t\tself.group_user = UserProfile.objects.create_user(\"groupuser\", \"test\", \"test@test.test\")\n+\t\tself.group_user.groups.add(self.group)\n+\t\tself.group_user.save()\n+\n+\t\tself.document = InformationDocument(author=self.user, title=\"test\", text=\"blabla\")\n+\t\tself.document.save()\n+\n+\t\tattachment_file = ContentFile(\"test content of test attachment\")\n+\t\tself.attachment = Attachment.objects.create(document=self.document)\n+\t\tself.attachment.file.save('temp.txt', attachment_file)\n+\t\tself.attachment.save()\n+\n+\tdef tearDown(self):\n+\t\tself.attachment.file.delete()\n+\n+\tdef test_create_attachment(self):\n+\t\tupload_files = [\n+\t\t\t('file', 'test.txt', bytes(tempfile.SpooledTemporaryFile(max_size=10000, prefix='txt', mode='r')))\n+\t\t]\n+\n+\t\t# test that user that has no change permission on a document can not add an attachment\n+\t\t# and see the corresponding page\n+\t\tnormal_user = UserProfile.objects.create_user(\"normal\", \"test\", \"normal@test.test\")\n+\n+\t\tresponse = self.app.get(reverse('information_pages:attachments', args=[self.document.url_title]),\n+\t\t\t\t\t\t\t\t\tuser=normal_user,\n+\t\t\t\t\t\t\t\t\texpect_errors=True)\n+\t\tself.assertEqual(response.status_code, 403)\n+\n+\t\tresponse = self.app.post(reverse('information_pages:attachments', args=[self.document.url_title]),\n+\t\t\t\t\t\t\t\t\tcontent_type='multipart/form-data',\n+\t\t\t\t\t\t\t\t\tupload_files=upload_files,\n+\t\t\t\t\t\t\t\t\tuser=normal_user,\n+\t\t\t\t\t\t\t\t\texpect_errors=True)\n+\t\tself.assertEqual(response.status_code, 403)\n+\n+\t\t# test that user that is allowed to view the document may not add attachments to it\n+\t\t# and see the corresponding page\n+\t\tassign_perm(\"view_informationdocument\", normal_user, self.document)\n+\n+\t\tresponse = self.app.get(reverse('information_pages:attachments', args=[self.document.url_title]),\n+\t\t\t\t\t\t\t\t\tuser=normal_user,\n+\t\t\t\t\t\t\t\t\texpect_errors=True)\n+\t\tself.assertEqual(response.status_code, 403)\n+\n+\t\tresponse = self.app.post(reverse('information_pages:attachments', args=[self.document.url_title]),\n+\t\t\t\t\t\t\t\t\tcontent_type='multipart/form-data',\n+\t\t\t\t\t\t\t\t\tupload_files=upload_files,\n+\t\t\t\t\t\t\t\t\tuser=normal_user,\n+\t\t\t\t\t\t\t\t\texpect_errors=True)\n+\t\tself.assertEqual(response.status_code, 403)\n+\n+\t\t# test that member of group that has according permissions is allowed to upload attachments","path":"_1327/documents/tests.py","position":91,"original_position":91,"commit_id":"e0cccb93f58949063d4567c1456def2914856ac6","original_commit_id":"e0cccb93f58949063d4567c1456def2914856ac6","user":{"login":"janno42","id":1781719,"avatar_url":"https://avatars.githubusercontent.com/u/1781719?v=3","gravatar_id":"","url":"https://api.github.com/users/janno42","html_url":"https://github.com/janno42","followers_url":"https://api.github.com/users/janno42/followers","following_url":"https://api.github.com/users/janno42/following{/other_user}","gists_url":"https://api.github.com/users/janno42/gists{/gist_id}","starred_url":"https://api.github.com/users/janno42/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/janno42/subscriptions","organizations_url":"https://api.github.com/users/janno42/orgs","repos_url":"https://api.github.com/users/janno42/repos","events_url":"https://api.github.com/users/janno42/events{/privacy}","received_events_url":"https://api.github.com/users/janno42/received_events","type":"User","site_admin":false},"body":"member of group **who**","created_at":"2015-04-15T20:05:31Z","updated_at":"2015-04-15T20:05:31Z","html_url":"https://github.com/fsr-itse/1327/pull/113#discussion_r28457161","pull_request_url":"https://api.github.com/repos/fsr-itse/1327/pulls/113","_links":{"self":{"href":"https://api.github.com/repos/fsr-itse/1327/pulls/comments/28457161"},"html":{"href":"https://github.com/fsr-itse/1327/pull/113#discussion_r28457161"},"pull_request":{"href":"https://api.github.com/repos/fsr-itse/1327/pulls/113"}}},"pull_request":{"url":"https://api.github.com/repos/fsr-itse/1327/pulls/113","id":33370381,"html_url":"https://github.com/fsr-itse/1327/pull/113","diff_url":"https://github.com/fsr-itse/1327/pull/113.diff","patch_url":"https://github.com/fsr-itse/1327/pull/113.patch","issue_url":"https://api.github.com/repos/fsr-itse/1327/issues/113","number":113,"state":"open","locked":false,"title":"File uploading","user":{"login":"Bartzi","id":2399349,"avatar_url":"https://avatars.githubusercontent.com/u/2399349?v=3","gravatar_id":"","url":"https://api.github.com/users/Bartzi","html_url":"https://github.com/Bartzi","followers_url":"https://api.github.com/users/Bartzi/followers","following_url":"https://api.github.com/users/Bartzi/following{/other_user}","gists_url":"https://api.github.com/users/Bartzi/gists{/gist_id}","starred_url":"https://api.github.com/users/Bartzi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Bartzi/subscriptions","organizations_url":"https://api.github.com/users/Bartzi/orgs","repos_url":"https://api.github.com/users/Bartzi/repos","events_url":"https://api.github.com/users/Bartzi/events{/privacy}","received_events_url":"https://api.github.com/users/Bartzi/received_events","type":"User","site_admin":false},"body":"Fixes #36 \r\nIt is now possible to add attachments to documents, attachments can be uploaded and will be saved in a media folder, attachments can be deleted and downloaded. This PR also includes tests for that functionality.\r\n\r\n**Please Note**\r\nThe download feature needs the server to use the mod_sendfile extension as the file download first needs to be checked for sufficient permissions and is then handled by the webserver (this is a nice way i think)","created_at":"2015-04-15T16:05:57Z","updated_at":"2015-04-15T20:05:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9ac7befca49943ae55af56dbaca75b73f4700d23","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/fsr-itse/1327/pulls/113/commits","review_comments_url":"https://api.github.com/repos/fsr-itse/1327/pulls/113/comments","review_comment_url":"https://api.github.com/repos/fsr-itse/1327/pulls/comments{/number}","comments_url":"https://api.github.com/repos/fsr-itse/1327/issues/113/comments","statuses_url":"https://api.github.com/repos/fsr-itse/1327/statuses/e0cccb93f58949063d4567c1456def2914856ac6","head":{"label":"Bartzi:file_uploading","ref":"file_uploading","sha":"e0cccb93f58949063d4567c1456def2914856ac6","user":{"login":"Bartzi","id":2399349,"avatar_url":"https://avatars.githubusercontent.com/u/2399349?v=3","gravatar_id":"","url":"https://api.github.com/users/Bartzi","html_url":"https://github.com/Bartzi","followers_url":"https://api.github.com/users/Bartzi/followers","following_url":"https://api.github.com/users/Bartzi/following{/other_user}","gists_url":"https://api.github.com/users/Bartzi/gists{/gist_id}","starred_url":"https://api.github.com/users/Bartzi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Bartzi/subscriptions","organizations_url":"https://api.github.com/users/Bartzi/orgs","repos_url":"https://api.github.com/users/Bartzi/repos","events_url":"https://api.github.com/users/Bartzi/events{/privacy}","received_events_url":"https://api.github.com/users/Bartzi/received_events","type":"User","site_admin":false},"repo":{"id":23915154,"name":"1327","full_name":"Bartzi/1327","owner":{"login":"Bartzi","id":2399349,"avatar_url":"https://avatars.githubusercontent.com/u/2399349?v=3","gravatar_id":"","url":"https://api.github.com/users/Bartzi","html_url":"https://github.com/Bartzi","followers_url":"https://api.github.com/users/Bartzi/followers","following_url":"https://api.github.com/users/Bartzi/following{/other_user}","gists_url":"https://api.github.com/users/Bartzi/gists{/gist_id}","starred_url":"https://api.github.com/users/Bartzi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Bartzi/subscriptions","organizations_url":"https://api.github.com/users/Bartzi/orgs","repos_url":"https://api.github.com/users/Bartzi/repos","events_url":"https://api.github.com/users/Bartzi/events{/privacy}","received_events_url":"https://api.github.com/users/Bartzi/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Bartzi/1327","description":"A student representatives website","fork":true,"url":"https://api.github.com/repos/Bartzi/1327","forks_url":"https://api.github.com/repos/Bartzi/1327/forks","keys_url":"https://api.github.com/repos/Bartzi/1327/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Bartzi/1327/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Bartzi/1327/teams","hooks_url":"https://api.github.com/repos/Bartzi/1327/hooks","issue_events_url":"https://api.github.com/repos/Bartzi/1327/issues/events{/number}","events_url":"https://api.github.com/repos/Bartzi/1327/events","assignees_url":"https://api.github.com/repos/Bartzi/1327/assignees{/user}","branches_url":"https://api.github.com/repos/Bartzi/1327/branches{/branch}","tags_url":"https://api.github.com/repos/Bartzi/1327/tags","blobs_url":"https://api.github.com/repos/Bartzi/1327/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Bartzi/1327/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Bartzi/1327/git/refs{/sha}","trees_url":"https://api.github.com/repos/Bartzi/1327/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Bartzi/1327/statuses/{sha}","languages_url":"https://api.github.com/repos/Bartzi/1327/languages","stargazers_url":"https://api.github.com/repos/Bartzi/1327/stargazers","contributors_url":"https://api.github.com/repos/Bartzi/1327/contributors","subscribers_url":"https://api.github.com/repos/Bartzi/1327/subscribers","subscription_url":"https://api.github.com/repos/Bartzi/1327/subscription","commits_url":"https://api.github.com/repos/Bartzi/1327/commits{/sha}","git_commits_url":"https://api.github.com/repos/Bartzi/1327/git/commits{/sha}","comments_url":"https://api.github.com/repos/Bartzi/1327/comments{/number}","issue_comment_url":"https://api.github.com/repos/Bartzi/1327/issues/comments{/number}","contents_url":"https://api.github.com/repos/Bartzi/1327/contents/{+path}","compare_url":"https://api.github.com/repos/Bartzi/1327/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Bartzi/1327/merges","archive_url":"https://api.github.com/repos/Bartzi/1327/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Bartzi/1327/downloads","issues_url":"https://api.github.com/repos/Bartzi/1327/issues{/number}","pulls_url":"https://api.github.com/repos/Bartzi/1327/pulls{/number}","milestones_url":"https://api.github.com/repos/Bartzi/1327/milestones{/number}","notifications_url":"https://api.github.com/repos/Bartzi/1327/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Bartzi/1327/labels{/name}","releases_url":"https://api.github.com/repos/Bartzi/1327/releases{/id}","created_at":"2014-09-11T11:15:54Z","updated_at":"2015-04-13T16:45:30Z","pushed_at":"2015-04-15T16:00:43Z","git_url":"git://github.com/Bartzi/1327.git","ssh_url":"git@github.com:Bartzi/1327.git","clone_url":"https://github.com/Bartzi/1327.git","svn_url":"https://github.com/Bartzi/1327","homepage":null,"size":654,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"fsr-itse:master","ref":"master","sha":"394580fde860a31f64bd6a8d731e57c583570505","user":{"login":"fsr-itse","id":1298457,"avatar_url":"https://avatars.githubusercontent.com/u/1298457?v=3","gravatar_id":"","url":"https://api.github.com/users/fsr-itse","html_url":"https://github.com/fsr-itse","followers_url":"https://api.github.com/users/fsr-itse/followers","following_url":"https://api.github.com/users/fsr-itse/following{/other_user}","gists_url":"https://api.github.com/users/fsr-itse/gists{/gist_id}","starred_url":"https://api.github.com/users/fsr-itse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fsr-itse/subscriptions","organizations_url":"https://api.github.com/users/fsr-itse/orgs","repos_url":"https://api.github.com/users/fsr-itse/repos","events_url":"https://api.github.com/users/fsr-itse/events{/privacy}","received_events_url":"https://api.github.com/users/fsr-itse/received_events","type":"Organization","site_admin":false},"repo":{"id":22120153,"name":"1327","full_name":"fsr-itse/1327","owner":{"login":"fsr-itse","id":1298457,"avatar_url":"https://avatars.githubusercontent.com/u/1298457?v=3","gravatar_id":"","url":"https://api.github.com/users/fsr-itse","html_url":"https://github.com/fsr-itse","followers_url":"https://api.github.com/users/fsr-itse/followers","following_url":"https://api.github.com/users/fsr-itse/following{/other_user}","gists_url":"https://api.github.com/users/fsr-itse/gists{/gist_id}","starred_url":"https://api.github.com/users/fsr-itse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fsr-itse/subscriptions","organizations_url":"https://api.github.com/users/fsr-itse/orgs","repos_url":"https://api.github.com/users/fsr-itse/repos","events_url":"https://api.github.com/users/fsr-itse/events{/privacy}","received_events_url":"https://api.github.com/users/fsr-itse/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/fsr-itse/1327","description":"A student representatives website","fork":false,"url":"https://api.github.com/repos/fsr-itse/1327","forks_url":"https://api.github.com/repos/fsr-itse/1327/forks","keys_url":"https://api.github.com/repos/fsr-itse/1327/keys{/key_id}","collaborators_url":"https://api.github.com/repos/fsr-itse/1327/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/fsr-itse/1327/teams","hooks_url":"https://api.github.com/repos/fsr-itse/1327/hooks","issue_events_url":"https://api.github.com/repos/fsr-itse/1327/issues/events{/number}","events_url":"https://api.github.com/repos/fsr-itse/1327/events","assignees_url":"https://api.github.com/repos/fsr-itse/1327/assignees{/user}","branches_url":"https://api.github.com/repos/fsr-itse/1327/branches{/branch}","tags_url":"https://api.github.com/repos/fsr-itse/1327/tags","blobs_url":"https://api.github.com/repos/fsr-itse/1327/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/fsr-itse/1327/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/fsr-itse/1327/git/refs{/sha}","trees_url":"https://api.github.com/repos/fsr-itse/1327/git/trees{/sha}","statuses_url":"https://api.github.com/repos/fsr-itse/1327/statuses/{sha}","languages_url":"https://api.github.com/repos/fsr-itse/1327/languages","stargazers_url":"https://api.github.com/repos/fsr-itse/1327/stargazers","contributors_url":"https://api.github.com/repos/fsr-itse/1327/contributors","subscribers_url":"https://api.github.com/repos/fsr-itse/1327/subscribers","subscription_url":"https://api.github.com/repos/fsr-itse/1327/subscription","commits_url":"https://api.github.com/repos/fsr-itse/1327/commits{/sha}","git_commits_url":"https://api.github.com/repos/fsr-itse/1327/git/commits{/sha}","comments_url":"https://api.github.com/repos/fsr-itse/1327/comments{/number}","issue_comment_url":"https://api.github.com/repos/fsr-itse/1327/issues/comments{/number}","contents_url":"https://api.github.com/repos/fsr-itse/1327/contents/{+path}","compare_url":"https://api.github.com/repos/fsr-itse/1327/compare/{base}...{head}","merges_url":"https://api.github.com/repos/fsr-itse/1327/merges","archive_url":"https://api.github.com/repos/fsr-itse/1327/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/fsr-itse/1327/downloads","issues_url":"https://api.github.com/repos/fsr-itse/1327/issues{/number}","pulls_url":"https://api.github.com/repos/fsr-itse/1327/pulls{/number}","milestones_url":"https://api.github.com/repos/fsr-itse/1327/milestones{/number}","notifications_url":"https://api.github.com/repos/fsr-itse/1327/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/fsr-itse/1327/labels{/name}","releases_url":"https://api.github.com/repos/fsr-itse/1327/releases{/id}","created_at":"2014-07-22T20:48:36Z","updated_at":"2015-04-13T22:17:27Z","pushed_at":"2015-04-15T16:05:58Z","git_url":"git://github.com/fsr-itse/1327.git","ssh_url":"git@github.com:fsr-itse/1327.git","clone_url":"https://github.com/fsr-itse/1327.git","svn_url":"https://github.com/fsr-itse/1327","homepage":null,"size":1343,"stargazers_count":5,"watchers_count":5,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":9,"mirror_url":null,"open_issues_count":26,"forks":9,"open_issues":26,"watchers":5,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/fsr-itse/1327/pulls/113"},"html":{"href":"https://github.com/fsr-itse/1327/pull/113"},"issue":{"href":"https://api.github.com/repos/fsr-itse/1327/issues/113"},"comments":{"href":"https://api.github.com/repos/fsr-itse/1327/issues/113/comments"},"review_comments":{"href":"https://api.github.com/repos/fsr-itse/1327/pulls/113/comments"},"review_comment":{"href":"https://api.github.com/repos/fsr-itse/1327/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/fsr-itse/1327/pulls/113/commits"},"statuses":{"href":"https://api.github.com/repos/fsr-itse/1327/statuses/e0cccb93f58949063d4567c1456def2914856ac6"}}}}