Setting permissions on uploaded S3 files
authorBryan <btbonval@gmail.com>
Fri, 17 Jan 2014 01:41:56 +0000 (20:41 -0500)
committerBryan <btbonval@gmail.com>
Fri, 17 Jan 2014 01:41:56 +0000 (20:41 -0500)
karmaworld/apps/notes/models.py

index e9d5ad4ee82cc497680abd6d92be0894828a2e35..6e16d87b7a0986e4c76bccfb236082fea985d0b9 100644 (file)
@@ -20,6 +20,8 @@ from karmaworld.apps.notes.gdrive import UPLOADED_NOTES_SESSION_KEY
 import os
 import urllib
 
+from boto.s3.acl import Grant
+
 from django.conf import settings
 from django.core.files import File
 from django.core.files.storage import FileSystemStorage
@@ -242,6 +244,12 @@ class Note(Document):
             newkey.set_contents_from_string(html)
             if not newkey.exists():
                 raise LookupError('Unable to find uploaded S3 document {0}'.format(str(newkey)))
+
+            # set the permissions for everyone to read.
+            all_read = Grant(permission=u'READ', type=u'GROUP',
+                         uri=u'http://acs.amazonaws.com/groups/global/AllUsers')
+            policy = newkey.get_acl().acl.add_grant(all_read)
+
         # If the code reaches here, either:
         # filepath exists on S3 but static_html is not marked.
         # or