Ticket #21219: add_static_file_permission.diff
File add_static_file_permission.diff, 7.0 KB (added by , 11 years ago) |
---|
-
django/conf/global_settings.py
diff --git a/django/conf/global_settings.py b/django/conf/global_settings.py index 6dd25e1..be39c5e 100644
a b STATICFILES_FINDERS = ( 610 610 # 'django.contrib.staticfiles.finders.DefaultStorageFinder', 611 611 ) 612 612 613 # The numeric mode to set newly-collected static files to. The value should be 614 # a mode you'd pass directly to os.chmod; see 615 # http://docs.python.org/lib/os-file-dir.html. 616 STATIC_FILE_PERMISSIONS = None 617 613 618 ############## 614 619 # MIGRATIONS # 615 620 ############## -
django/contrib/staticfiles/storage.py
diff --git a/django/contrib/staticfiles/storage.py b/django/contrib/staticfiles/storage.py index a527379..15984c0 100644
a b class StaticFilesStorage(FileSystemStorage): 28 28 ``STATIC_ROOT`` and ``STATIC_URL``. 29 29 """ 30 30 def __init__(self, location=None, base_url=None, *args, **kwargs): 31 self.permissions_mode = settings.STATIC_FILE_PERMISSIONS 31 32 if location is None: 32 33 location = settings.STATIC_ROOT 33 34 if base_url is None: -
django/core/files/storage.py
diff --git a/django/core/files/storage.py b/django/core/files/storage.py index b42981c..295a634 100644
a b class FileSystemStorage(Storage): 146 146 """ 147 147 Standard filesystem storage 148 148 """ 149 permissions_mode = None 149 150 150 151 def __init__(self, location=None, base_url=None): 151 152 if location is None: … … class FileSystemStorage(Storage): 171 172 try: 172 173 if settings.FILE_UPLOAD_DIRECTORY_PERMISSIONS is not None: 173 174 # os.makedirs applies the global umask, so we reset it, 174 # for consistency with FILE_UPLOAD_PERMISSIONSbehavior.175 # for consistency with self.permissions_mode behavior. 175 176 old_umask = os.umask(0) 176 177 try: 177 178 os.makedirs(directory, settings.FILE_UPLOAD_DIRECTORY_PERMISSIONS) … … class FileSystemStorage(Storage): 232 233 # OK, the file save worked. Break out of the loop. 233 234 break 234 235 235 if settings.FILE_UPLOAD_PERMISSIONS is not None: 236 if self.permissions_mode is not None: 237 os.chmod(full_path, self.permissions_mode) 238 elif settings.FILE_UPLOAD_PERMISSIONS: 236 239 os.chmod(full_path, settings.FILE_UPLOAD_PERMISSIONS) 237 240 238 241 return name -
docs/ref/contrib/staticfiles.txt
diff --git a/docs/ref/contrib/staticfiles.txt b/docs/ref/contrib/staticfiles.txt index 1a9fd25..4d8a954 100644
a b following settings: 28 28 * :setting:`STATICFILES_DIRS` 29 29 * :setting:`STATICFILES_STORAGE` 30 30 * :setting:`STATICFILES_FINDERS` 31 * :setting:`STATIC_FILE_PERMISSIONS` 31 32 32 33 Management Commands 33 34 =================== … … files: 322 323 323 324 .. _staticfiles-development-view: 324 325 326 Permissions 327 =========== 328 329 When running :djadmin:`collectstatic` management command, the newly-collected 330 static files will derive their permissions from 331 :setting:`STATIC_FILE_PERMISSIONS`. If it is ``None``, they will get the 332 permissions from :setting:`FILE_UPLOAD_PERMISSIONS`. 333 325 334 Static file development view 326 335 ---------------------------- 327 336 -
docs/ref/settings.txt
diff --git a/docs/ref/settings.txt b/docs/ref/settings.txt index 4c46f3a..ffda162 100644
a b setting. 2678 2678 Static file finders are currently considered a private interface, and this 2679 2679 interface is thus undocumented. 2680 2680 2681 STATIC_FILE_PERMISSIONS 2682 ----------------------- 2683 2684 Default: ``None`` 2685 2686 The numeric mode (i.e. ``0644``) to set newly-collected static files to. For 2687 more information about what these modes mean, see the documentation for 2688 :func:`os.chmod`. 2689 2690 If this isn't given or is ``None``, you'll get FILE_UPLOAD_PERMISSIONS 2691 permission. 2692 2693 .. warning:: 2694 2695 **Always prefix the mode with a 0.** 2696 2697 If you're not familiar with file modes, please note that the leading 2698 ``0`` is very important: it indicates an octal number, which is the 2699 way that modes must be specified. If you try to use ``644``, you'll 2700 get totally incorrect behavior. 2701 2681 2702 Core Settings Topical Index 2682 2703 =========================== 2683 2704 -
docs/releases/1.7.txt
diff --git a/docs/releases/1.7.txt b/docs/releases/1.7.txt index 7a49f13..0b7d357 100644
a b Signals 337 337 * The ``enter`` argument was added to the 338 338 :data:`~django.test.signals.setting_changed` signal. 339 339 340 Static File 341 ^^^^^^^^^^^ 342 343 * The new :setting:`STATIC_FILE_PERMISSIONS` controls the file system 344 permissions of newly-collected static files during deployment. 345 340 346 Templates 341 347 ^^^^^^^^^ 342 348 -
tests/staticfiles_tests/tests.py
diff --git a/tests/staticfiles_tests/tests.py b/tests/staticfiles_tests/tests.py index b73eea3..d1b852d 100644
a b import posixpath 7 7 import shutil 8 8 import sys 9 9 import tempfile 10 import unittest 10 11 11 12 from django.template import loader, Context 12 13 from django.conf import settings … … from django.utils._os import rmtree_errorhandler, upath 21 22 from django.utils import six 22 23 23 24 from django.contrib.staticfiles import finders, storage 25 from django.contrib.staticfiles.management.commands import collectstatic 24 26 25 27 TEST_ROOT = os.path.dirname(upath(__file__)) 26 28 TEST_SETTINGS = { … … class TestAppStaticStorage(TestCase): 804 806 st.path('bar') 805 807 finally: 806 808 sys.getfilesystemencoding = old_enc_func 809 810 811 @unittest.skipIf(sys.platform.startswith('win'), 812 "Windows only partially supports umasks and chmod.") 813 class TestStaticFilePermissions(BaseCollectionTestCase, StaticFilesTestCase): 814 815 @override_settings(STATIC_FILE_PERMISSIONS=0o654) 816 def test_collect_static_file_permissions(self): 817 command = collectstatic.Command() 818 command.execute(**self.defaults) 819 mode = os.stat( 820 settings.STATIC_ROOT + os.path.sep + "test.txt")[0] & 0o777 821 self.assertEqual(mode, 0o654) 822 823 @override_settings(STATIC_FILE_PERMISSIONS=None, 824 FILE_UPLOAD_PERMISSIONS=0o655) 825 def test_collect_static_file_default_permissions(self): 826 command = collectstatic.Command() 827 command.execute(**self.defaults) 828 mode = os.stat( 829 settings.STATIC_ROOT + os.path.sep + "test.txt")[0] & 0o777 830 self.assertEqual(mode, 0o655) 831 832 # It is very hard to pass settings to external process, so we use instance 833 # of collectstatic command directly to collect static files. 834 def run_collectstatic(self, **kwargs): 835 self.defaults = {'interactive': False, 836 'post_process': True, 837 'verbosity': '0', 838 'ignore_patterns': ['*.ignoreme'], 839 'use_default_ignore_patterns': True, 840 'clear': False, 841 'link': False, 842 'dry_run': False}