Skip to content

Commit

Permalink
Merge pull request #698 from stmos/devel
Browse files Browse the repository at this point in the history
Google Storage Backend: settings ACLs when file is uploaded
  • Loading branch information
sww314 committed May 13, 2019
2 parents 3047db7 + d9a0c47 commit a07ab2c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 7 additions & 3 deletions storages/backends/gcloud.py
Expand Up @@ -174,10 +174,14 @@ def _save(self, name, content):
encoded_name = self._encode_name(name)
file = GoogleCloudFile(encoded_name, 'rw', self)
file.blob.cache_control = self.cache_control
file.blob.upload_from_file(content, rewind=True, size=content.size,
content_type=file.mime_type)
if self.default_acl:
file.blob.acl.save_predefined(self.default_acl)
file.blob.upload_from_file(
content, rewind=True, size=content.size,
content_type=file.mime_type, predefined_acl=self.default_acl)
else:
file.blob.upload_from_file(
content, rewind=True, size=content.size,
content_type=file.mime_type)
return cleaned_name

def delete(self, name):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_gcloud.py
Expand Up @@ -131,8 +131,8 @@ def test_save_with_default_acl(self):

self.storage._client.get_bucket.assert_called_with(self.bucket_name)
self.storage._bucket.get_blob().upload_from_file.assert_called_with(
content, rewind=True, size=len(data), content_type=mimetypes.guess_type(filename)[0])
self.storage._bucket.get_blob().acl.save_predefined.assert_called_with('publicRead')
content, rewind=True, size=len(data), content_type=mimetypes.guess_type(filename)[0],
predefined_acl='publicRead')

def test_delete(self):
self.storage.delete(self.filename)
Expand Down

0 comments on commit a07ab2c

Please sign in to comment.