From: Bryan Date: Fri, 17 Jan 2014 05:31:40 +0000 (-0500) Subject: Note HTML uploads to S3 with correct content-type and permissions. X-Git-Tag: release-20150131~233 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=d27b96ae375a443913b90c82a03d5b6d84c3b08f;p=oweals%2Fkarmaworld.git Note HTML uploads to S3 with correct content-type and permissions. --- diff --git a/karmaworld/apps/notes/models.py b/karmaworld/apps/notes/models.py index 6e16d87..59625b7 100644 --- a/karmaworld/apps/notes/models.py +++ b/karmaworld/apps/notes/models.py @@ -40,6 +40,15 @@ from karmaworld.settings.manual_unique_together import auto_add_check_unique_tog logger = logging.getLogger(__name__) fs = FileSystemStorage(location=settings.MEDIA_ROOT) +# Dictionary for S3 upload headers +s3_upload_headers = { + 'Content-Type': 'text/html', +} + +# This is a bit hacky, but nothing else works. Grabbed this from a proper +# file configured via S3 management console. +# https://github.com/FinalsClub/karmaworld/issues/273#issuecomment-32572169 +all_read_xml_acl = '\n710efc05767903a0eae5064bbc541f1c8e68f8f344fa809dc92682146b401d9cAndrew710efc05767903a0eae5064bbc541f1c8e68f8f344fa809dc92682146b401d9cAndrewREAD710efc05767903a0eae5064bbc541f1c8e68f8f344fa809dc92682146b401d9cAndrewWRITE710efc05767903a0eae5064bbc541f1c8e68f8f344fa809dc92682146b401d9cAndrewREAD_ACP710efc05767903a0eae5064bbc541f1c8e68f8f344fa809dc92682146b401d9cAndrewWRITE_ACPhttp://acs.amazonaws.com/groups/global/AllUsersREAD' def _choose_upload_to(instance, filename): # /school/course/year/month/day @@ -241,14 +250,12 @@ class Note(Document): # Create the new key (key == filename in S3 bucket) newkey = default_storage.bucket.new_key(filepath) # Upload data! - newkey.set_contents_from_string(html) + newkey.set_contents_from_string(html, headers=s3_upload_headers) 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) + newkey.set_xml_acl(all_read_xml_acl) # If the code reaches here, either: # filepath exists on S3 but static_html is not marked.