{"action":"created","comment":{"url":"https://api.github.com/repos/uktrade/data-hub-leeloo/pulls/comments/208512749","pull_request_review_id":144334273,"id":208512749,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIwODUxMjc0OQ==","diff_hunk":"@@ -31,58 +39,142 @@ class Document(BaseModel, ArchivableModel):\n     scanned_on = models.DateTimeField(\n         null=True, blank=True,\n     )\n+\n     av_clean = models.NullBooleanField(db_index=True)\n+    av_reason = models.CharField(max_length=settings.CHAR_FIELD_MAX_LENGTH, blank=True)\n \n-    @property\n-    def filename(self):\n-        \"\"\"Shortcut for getting a filename.\"\"\"\n-        return path.basename(self.path)\n+    status = models.CharField(\n+        max_length=settings.CHAR_FIELD_MAX_LENGTH,\n+        choices=UPLOAD_STATUSES,\n+        default=UPLOAD_STATUSES.not_virus_scanned,\n+    )\n+\n+    class Meta:\n+        unique_together = (\n+            ('bucket_id', 'path',),\n+        )\n \n     @property\n     def name(self):\n         \"\"\"Model name.\"\"\"\n         return self.path\n \n-    def generate_signed_url(self):\n-        \"\"\"Generate pre-signed download URL, but only if doc is AV clean.\"\"\"\n-        if self.av_clean:\n-            return sign_s3_url(settings.DOCUMENTS_BUCKET, self.path)\n+    def __repr__(self):\n+        \"\"\"String repr.\"\"\"\n+        return (\n+            f'Document('\n+            f'id={self.id!r}, '\n+            f'bucket_id={self.bucket_id!r}, '\n+            f'path={self.path!r}, '\n+            f'uploaded_on={self.uploaded_on!r}, '\n+            f'scan_initiated_on={self.scan_initiated_on!r}, '\n+            f'scanned_on={self.scanned_on!r}, '\n+            f'av_clean={self.av_clean!r}, '\n+            f'av_reason={self.av_reason!r}, '\n+            f'status={self.status!r}'\n+            f')'\n+        )\n \n-    def generate_signed_upload_url(self):\n+    def schedule_av_scan(self):\n+        \"\"\"Schedule AV scan.\"\"\"\n+        if not self.scan_initiated_on:\n+            self.mark_scan_scheduled()\n+\n+            virus_scan_document.apply_async(\n+                args=(\n+                    str(self.pk),\n+                    self.get_signed_url(allow_unsafe=True),","path":"datahub/documents/models.py","position":102,"original_position":102,"commit_id":"297a22d29cc72a7ccc72b90f13fee5694700c50c","original_commit_id":"297a22d29cc72a7ccc72b90f13fee5694700c50c","user":{"login":"reupen","id":12693549,"node_id":"MDQ6VXNlcjEyNjkzNTQ5","avatar_url":"https://avatars1.githubusercontent.com/u/12693549?v=4","gravatar_id":"","url":"https://api.github.com/users/reupen","html_url":"https://github.com/reupen","followers_url":"https://api.github.com/users/reupen/followers","following_url":"https://api.github.com/users/reupen/following{/other_user}","gists_url":"https://api.github.com/users/reupen/gists{/gist_id}","starred_url":"https://api.github.com/users/reupen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/reupen/subscriptions","organizations_url":"https://api.github.com/users/reupen/orgs","repos_url":"https://api.github.com/users/reupen/repos","events_url":"https://api.github.com/users/reupen/events{/privacy}","received_events_url":"https://api.github.com/users/reupen/received_events","type":"User","site_admin":false},"body":"Can the task get the pre-signed URL? It won't necessarily be executed straight away.","created_at":"2018-08-08T09:19:10Z","updated_at":"2018-08-08T09:19:10Z","html_url":"https://github.com/uktrade/data-hub-leeloo/pull/1019#discussion_r208512749","pull_request_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/pulls/1019","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/uktrade/data-hub-leeloo/pulls/comments/208512749"},"html":{"href":"https://github.com/uktrade/data-hub-leeloo/pull/1019#discussion_r208512749"},"pull_request":{"href":"https://api.github.com/repos/uktrade/data-hub-leeloo/pulls/1019"}}},"pull_request":{"url":"https://api.github.com/repos/uktrade/data-hub-leeloo/pulls/1019","id":200451056,"node_id":"MDExOlB1bGxSZXF1ZXN0MjAwNDUxMDU2","html_url":"https://github.com/uktrade/data-hub-leeloo/pull/1019","diff_url":"https://github.com/uktrade/data-hub-leeloo/pull/1019.diff","patch_url":"https://github.com/uktrade/data-hub-leeloo/pull/1019.patch","issue_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/issues/1019","number":1019,"state":"open","locked":false,"title":"Add proposition document upload","user":{"login":"elcct","id":5889630,"node_id":"MDQ6VXNlcjU4ODk2MzA=","avatar_url":"https://avatars2.githubusercontent.com/u/5889630?v=4","gravatar_id":"","url":"https://api.github.com/users/elcct","html_url":"https://github.com/elcct","followers_url":"https://api.github.com/users/elcct/followers","following_url":"https://api.github.com/users/elcct/following{/other_user}","gists_url":"https://api.github.com/users/elcct/gists{/gist_id}","starred_url":"https://api.github.com/users/elcct/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elcct/subscriptions","organizations_url":"https://api.github.com/users/elcct/orgs","repos_url":"https://api.github.com/users/elcct/repos","events_url":"https://api.github.com/users/elcct/events{/privacy}","received_events_url":"https://api.github.com/users/elcct/received_events","type":"User","site_admin":false},"body":"Issue number: DHI-111\r\n\r\n### Description of change\r\n\r\nThis updates existing Document Upload functionality, so that it is re-usable more easily. \r\nCommon views and base model has been moved to Documents app.\r\nS3 dependent code in virus scanning has been removed.\r\n\r\nBecause we have separate AWS credentials for different type of documents I have added `bucket` field to the shared Document model, so that it could be possible to find where file has actually been uploaded.\r\n\r\nThe flow looks like this:\r\n- Client calls POST `/v3/investment/<ip-uuid>/proposition/<p-uuid>/document` with filename, gets back proposition document details with signed upload url, where file needs to be uploaded to\r\n- Once uploaded, client POST to `/v3/investment/<ip-uuid>/proposition/<p-uuid>/document/<d-uuid>/upload-callback` with empty body. This initiates virus scanning.\r\n- Once scanning has completed, the download endpoint will return signed S3 URL to the document.\r\n\r\nExisting document upload endpoints could be removed in separate PR.\r\n\r\n### Checklist\r\n\r\n* [X] Has the README been updated (if needed)?\r\n","created_at":"2018-07-10T16:15:49Z","updated_at":"2018-08-08T09:19:10Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4f821c5f4998fbacfa6f6c173479b58bc323ef34","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/pulls/1019/commits","review_comments_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/pulls/1019/comments","review_comment_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/pulls/comments{/number}","comments_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/issues/1019/comments","statuses_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/statuses/297a22d29cc72a7ccc72b90f13fee5694700c50c","head":{"label":"uktrade:feature/proposition-document-upload","ref":"feature/proposition-document-upload","sha":"297a22d29cc72a7ccc72b90f13fee5694700c50c","user":{"login":"uktrade","id":15107524,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE1MTA3NTI0","avatar_url":"https://avatars2.githubusercontent.com/u/15107524?v=4","gravatar_id":"","url":"https://api.github.com/users/uktrade","html_url":"https://github.com/uktrade","followers_url":"https://api.github.com/users/uktrade/followers","following_url":"https://api.github.com/users/uktrade/following{/other_user}","gists_url":"https://api.github.com/users/uktrade/gists{/gist_id}","starred_url":"https://api.github.com/users/uktrade/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uktrade/subscriptions","organizations_url":"https://api.github.com/users/uktrade/orgs","repos_url":"https://api.github.com/users/uktrade/repos","events_url":"https://api.github.com/users/uktrade/events{/privacy}","received_events_url":"https://api.github.com/users/uktrade/received_events","type":"Organization","site_admin":false},"repo":{"id":73379434,"node_id":"MDEwOlJlcG9zaXRvcnk3MzM3OTQzNA==","name":"data-hub-leeloo","full_name":"uktrade/data-hub-leeloo","owner":{"login":"uktrade","id":15107524,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE1MTA3NTI0","avatar_url":"https://avatars2.githubusercontent.com/u/15107524?v=4","gravatar_id":"","url":"https://api.github.com/users/uktrade","html_url":"https://github.com/uktrade","followers_url":"https://api.github.com/users/uktrade/followers","following_url":"https://api.github.com/users/uktrade/following{/other_user}","gists_url":"https://api.github.com/users/uktrade/gists{/gist_id}","starred_url":"https://api.github.com/users/uktrade/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uktrade/subscriptions","organizations_url":"https://api.github.com/users/uktrade/orgs","repos_url":"https://api.github.com/users/uktrade/repos","events_url":"https://api.github.com/users/uktrade/events{/privacy}","received_events_url":"https://api.github.com/users/uktrade/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/uktrade/data-hub-leeloo","description":"Django API for Data Hub frontend","fork":false,"url":"https://api.github.com/repos/uktrade/data-hub-leeloo","forks_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/forks","keys_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/teams","hooks_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/hooks","issue_events_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/issues/events{/number}","events_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/events","assignees_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/assignees{/user}","branches_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/branches{/branch}","tags_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/tags","blobs_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/git/refs{/sha}","trees_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/statuses/{sha}","languages_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/languages","stargazers_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/stargazers","contributors_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/contributors","subscribers_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/subscribers","subscription_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/subscription","commits_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/commits{/sha}","git_commits_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/git/commits{/sha}","comments_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/comments{/number}","issue_comment_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/issues/comments{/number}","contents_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/contents/{+path}","compare_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/merges","archive_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/downloads","issues_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/issues{/number}","pulls_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/pulls{/number}","milestones_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/milestones{/number}","notifications_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/labels{/name}","releases_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/releases{/id}","deployments_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/deployments","created_at":"2016-11-10T12:21:01Z","updated_at":"2018-08-06T13:55:15Z","pushed_at":"2018-08-08T08:19:33Z","git_url":"git://github.com/uktrade/data-hub-leeloo.git","ssh_url":"git@github.com:uktrade/data-hub-leeloo.git","clone_url":"https://github.com/uktrade/data-hub-leeloo.git","svn_url":"https://github.com/uktrade/data-hub-leeloo","homepage":null,"size":5562,"stargazers_count":1,"watchers_count":1,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":9,"license":null,"forks":0,"open_issues":9,"watchers":1,"default_branch":"develop"}},"base":{"label":"uktrade:develop","ref":"develop","sha":"694a69d9d1018fb22634497df62a75110ec42d6c","user":{"login":"uktrade","id":15107524,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE1MTA3NTI0","avatar_url":"https://avatars2.githubusercontent.com/u/15107524?v=4","gravatar_id":"","url":"https://api.github.com/users/uktrade","html_url":"https://github.com/uktrade","followers_url":"https://api.github.com/users/uktrade/followers","following_url":"https://api.github.com/users/uktrade/following{/other_user}","gists_url":"https://api.github.com/users/uktrade/gists{/gist_id}","starred_url":"https://api.github.com/users/uktrade/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uktrade/subscriptions","organizations_url":"https://api.github.com/users/uktrade/orgs","repos_url":"https://api.github.com/users/uktrade/repos","events_url":"https://api.github.com/users/uktrade/events{/privacy}","received_events_url":"https://api.github.com/users/uktrade/received_events","type":"Organization","site_admin":false},"repo":{"id":73379434,"node_id":"MDEwOlJlcG9zaXRvcnk3MzM3OTQzNA==","name":"data-hub-leeloo","full_name":"uktrade/data-hub-leeloo","owner":{"login":"uktrade","id":15107524,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE1MTA3NTI0","avatar_url":"https://avatars2.githubusercontent.com/u/15107524?v=4","gravatar_id":"","url":"https://api.github.com/users/uktrade","html_url":"https://github.com/uktrade","followers_url":"https://api.github.com/users/uktrade/followers","following_url":"https://api.github.com/users/uktrade/following{/other_user}","gists_url":"https://api.github.com/users/uktrade/gists{/gist_id}","starred_url":"https://api.github.com/users/uktrade/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uktrade/subscriptions","organizations_url":"https://api.github.com/users/uktrade/orgs","repos_url":"https://api.github.com/users/uktrade/repos","events_url":"https://api.github.com/users/uktrade/events{/privacy}","received_events_url":"https://api.github.com/users/uktrade/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/uktrade/data-hub-leeloo","description":"Django API for Data Hub frontend","fork":false,"url":"https://api.github.com/repos/uktrade/data-hub-leeloo","forks_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/forks","keys_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/teams","hooks_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/hooks","issue_events_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/issues/events{/number}","events_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/events","assignees_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/assignees{/user}","branches_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/branches{/branch}","tags_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/tags","blobs_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/git/refs{/sha}","trees_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/statuses/{sha}","languages_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/languages","stargazers_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/stargazers","contributors_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/contributors","subscribers_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/subscribers","subscription_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/subscription","commits_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/commits{/sha}","git_commits_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/git/commits{/sha}","comments_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/comments{/number}","issue_comment_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/issues/comments{/number}","contents_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/contents/{+path}","compare_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/merges","archive_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/downloads","issues_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/issues{/number}","pulls_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/pulls{/number}","milestones_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/milestones{/number}","notifications_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/labels{/name}","releases_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/releases{/id}","deployments_url":"https://api.github.com/repos/uktrade/data-hub-leeloo/deployments","created_at":"2016-11-10T12:21:01Z","updated_at":"2018-08-06T13:55:15Z","pushed_at":"2018-08-08T08:19:33Z","git_url":"git://github.com/uktrade/data-hub-leeloo.git","ssh_url":"git@github.com:uktrade/data-hub-leeloo.git","clone_url":"https://github.com/uktrade/data-hub-leeloo.git","svn_url":"https://github.com/uktrade/data-hub-leeloo","homepage":null,"size":5562,"stargazers_count":1,"watchers_count":1,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":9,"license":null,"forks":0,"open_issues":9,"watchers":1,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/uktrade/data-hub-leeloo/pulls/1019"},"html":{"href":"https://github.com/uktrade/data-hub-leeloo/pull/1019"},"issue":{"href":"https://api.github.com/repos/uktrade/data-hub-leeloo/issues/1019"},"comments":{"href":"https://api.github.com/repos/uktrade/data-hub-leeloo/issues/1019/comments"},"review_comments":{"href":"https://api.github.com/repos/uktrade/data-hub-leeloo/pulls/1019/comments"},"review_comment":{"href":"https://api.github.com/repos/uktrade/data-hub-leeloo/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/uktrade/data-hub-leeloo/pulls/1019/commits"},"statuses":{"href":"https://api.github.com/repos/uktrade/data-hub-leeloo/statuses/297a22d29cc72a7ccc72b90f13fee5694700c50c"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"reupen"}}