From 2b8d8ff521f36ecbd9140e459ab877ce3143aeef Mon Sep 17 00:00:00 2001 From: Bryan Date: Thu, 16 Jan 2014 20:41:56 -0500 Subject: [PATCH] Setting permissions on uploaded S3 files --- karmaworld/apps/notes/models.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/karmaworld/apps/notes/models.py b/karmaworld/apps/notes/models.py index e9d5ad4..6e16d87 100644 --- a/karmaworld/apps/notes/models.py +++ b/karmaworld/apps/notes/models.py @@ -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 -- 2.25.1