Fixed #21219 -- Added a way to set different permission for static files... #1779

Closed
wants to merge 2 commits into
from

Conversation

Projects
None yet
2 participants
@vajrasky
Contributor

vajrasky commented Oct 19, 2013

....

Previously, when collecting static files, the files would receive permission
from FILE_UPLOAD_PERMISSIONS. Now, user has an option to give different
permission from uploaded files permission by subclassing StaticFilesStorage
and setting file_permissions_mode class attribute to the desired permission.

Fixed #21219 -- Added a way to set different permission for static fi…
…les.

Previously, when collecting static files, the files would receive permission
from FILE_UPLOAD_PERMISSIONS. Now, user has an option to give different
permission from uploaded files permission by subclassing StaticFilesStorage
and setting file_permissions_mode class attribute to the desired permission.
django/core/files/storage.py
@@ -171,7 +171,7 @@ def _save(self, name, content):
try:
if settings.FILE_UPLOAD_DIRECTORY_PERMISSIONS is not None:
# os.makedirs applies the global umask, so we reset it,
- # for consistency with FILE_UPLOAD_PERMISSIONS behavior.
+ # for consistency with file_permissions_mode behavior.

This comment has been minimized.

@vajrasky

vajrasky Oct 20, 2013

Contributor

I should not have changed this, since the FileSystemStorage would never use file_permissions_mode class attribute. I'll wait another review before I update this pull request.

@vajrasky

vajrasky Oct 20, 2013

Contributor

I should not have changed this, since the FileSystemStorage would never use file_permissions_mode class attribute. I'll wait another review before I update this pull request.

@@ -232,8 +232,14 @@ def _save(self, name, content):
# OK, the file save worked. Break out of the loop.
break
- if settings.FILE_UPLOAD_PERMISSIONS is not None:
- os.chmod(full_path, settings.FILE_UPLOAD_PERMISSIONS)
+ if self.__class__ is not FileSystemStorage and \

This comment has been minimized.

@timgraham

timgraham Oct 21, 2013

Member

if hasattr(self, 'file_permissions_mode'): ?

@timgraham

timgraham Oct 21, 2013

Member

if hasattr(self, 'file_permissions_mode'): ?

django/core/files/storage.py
- os.chmod(full_path, settings.FILE_UPLOAD_PERMISSIONS)
+ if self.__class__ is not FileSystemStorage and \
+ 'file_permissions_mode' in self.__class__.__dict__:
+ mode = self.__class__.__dict__['file_permissions_mode']

This comment has been minimized.

@timgraham

timgraham Oct 21, 2013

Member

mode = self.file_permissions_mode?

@timgraham

timgraham Oct 21, 2013

Member

mode = self.file_permissions_mode?

docs/ref/contrib/staticfiles.txt
+the class attribute `file_permissions_mode` to the desired permission. For
+example:
+
+ .. code-block:: css+django

This comment has been minimized.

@timgraham

timgraham Oct 21, 2013

Member

css+django? just use a double colon after "example" and you should be able to omit the ".. code-block" directive

@timgraham

timgraham Oct 21, 2013

Member

css+django? just use a double colon after "example" and you should be able to omit the ".. code-block" directive

docs/ref/contrib/staticfiles.txt
+ class CustomStaticFilesStorage(storage.StaticFilesStorage):
+ file_permissions_mode = 0o600
+
+Then set :setting:`STATICFILES_STORAGE` to :class:`CustomStaticFilesStorage`.

This comment has been minimized.

@timgraham

timgraham Oct 21, 2013

Member

remove :class: (it won't create a link and will generate a error when building the docs)

@timgraham

timgraham Oct 21, 2013

Member

remove :class: (it won't create a link and will generate a error when building the docs)

Made changes asked in review by Tim Graham.
- Simplified checking and assigning the class attribute.
- Fixed documentation link.
@timgraham

This comment has been minimized.

Show comment
Hide comment
@timgraham

timgraham Oct 24, 2013

Member

Updated in #1803

Member

timgraham commented Oct 24, 2013

Updated in #1803

@timgraham timgraham closed this Oct 24, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment