From efd8db8d084619f1f9500340024792ced9e8493b Mon Sep 17 00:00:00 2001 From: benjaoming Date: Wed, 16 Jan 2013 10:22:30 +0100 Subject: [PATCH] WARNING! May break your config: Clean up settings variale names in images and attachments plugins and use unified defaults. Issue #91. --- wiki/conf/settings.py | 11 +++++++++++ wiki/plugins/attachments/settings.py | 19 ++++++++++++------- wiki/plugins/images/settings.py | 24 ++++++++++++++---------- 3 files changed, 37 insertions(+), 17 deletions(-) diff --git a/wiki/conf/settings.py b/wiki/conf/settings.py index 8d44ae7f..ce0c5216 100644 --- a/wiki/conf/settings.py +++ b/wiki/conf/settings.py @@ -67,6 +67,10 @@ ANONYMOUS_WRITE = getattr( django_settings, 'WIKI_ANONYMOUS_WRITE', False ) # Defaults to ANONYMOUS_WRITE. ANONYMOUS_CREATE = getattr( django_settings, 'WIKI_ANONYMOUS_CREATE', ANONYMOUS_WRITE ) +# Default setting to allow anonymous users upload access (used in +# plugins.attachments and plugins.images). +ANONYMOUS_UPLOAD = getattr( django_settings, 'WIKI_ANONYMOUS_UPLOAD', False ) + # Sign up, login and logout views should be accessible ACCOUNT_HANDLING = getattr( django_settings, 'WIKI_ACCOUNT_HANDLING', True ) @@ -115,6 +119,13 @@ REVISIONS_PER_MINUTES_ANONYMOUS = getattr( django_settings, 'WIKI_REVISIONS_PER_ # Number of minutes for looking up REVISIONS_PER_MINUTES and REVISIONS_PER_MINUTES_ANONYMOUS REVISIONS_MINUTES_LOOKBACK = getattr( django_settings, 'WIKI_REVISIONS_MINUTES_LOOKBACK', 2 ) +########### +# STORAGE # +########### + +from django.core.files.storage import default_storage +STORAGE_BACKEND = getattr(django_settings, 'WIKI_STORAGE_BACKEND', default_storage) + #################### # PLANNED SETTINGS # #################### diff --git a/wiki/plugins/attachments/settings.py b/wiki/plugins/attachments/settings.py index 8e3bc9e4..3e7ada9a 100644 --- a/wiki/plugins/attachments/settings.py +++ b/wiki/plugins/attachments/settings.py @@ -1,11 +1,14 @@ from django.conf import settings as django_settings +from wiki.conf import settings as wiki_settings from django.core.exceptions import ImproperlyConfigured APP_LABEL = 'wiki' SLUG = "attachments" -# Allow anonymous users to upload (not nice on an open network) -ANONYMOUS = getattr(django_settings, 'WIKI_ATTACHMENTS_ANONYMOUS', False) +# Allow anonymous users upload access (not nice on an open network) +# WIKI_ATTACHMENTS_ANONYMOUS can override this, otherwise the default +# in wiki.conf.settings is used. +ANONYMOUS = getattr( django_settings, 'WIKI_ATTACHMENTS_ANONYMOUS', wiki_settings.ANONYMOUS_UPLOAD ) # Maximum file sizes: Please using something like LimitRequestBody on # your web server. @@ -15,12 +18,12 @@ ANONYMOUS = getattr(django_settings, 'WIKI_ATTACHMENTS_ANONYMOUS', False) # You should NEVER enable directory indexing in MEDIA_ROOT/UPLOAD_PATH ! # Actually, you can completely disable serving it, if you want. Files are # sent to the user through a Django view that reads and streams a file. -UPLOAD_PATH = getattr(django_settings, 'WIKI_UPLOAD_PATH', 'wiki/uploads/%aid/') +UPLOAD_PATH = getattr(django_settings, 'WIKI_ATTACHMENTS_PATH', 'wiki/attachments/%aid/') # Should the upload path be obscurified? If so, a random hash will be added to the path # such that someone can not guess the location of files (if you have # restricted permissions and the files are still located within the web server's -UPLOAD_PATH_OBSCURIFY = getattr(django_settings, 'WIKI_UPLOAD_PATH_OBSCURIFY', True) +UPLOAD_PATH_OBSCURIFY = getattr(django_settings, 'WIKI_ATTACHMENTS_PATH_OBSCURIFY', True) # Allowed extensions. Empty to disallow uploads completely. # No files are saved without appending ".upload" to the file to ensure that @@ -28,10 +31,12 @@ UPLOAD_PATH_OBSCURIFY = getattr(django_settings, 'WIKI_UPLOAD_PATH_OBSCURIFY', T # Case insensitive. # You are asked to explicitly enter all file extensions that you want # to allow. For your own safety. -FILE_EXTENSIONS = getattr(django_settings, 'WIKI_FILE_EXTENSIONS', ['pdf', 'doc', 'odt', 'docx', 'txt']) +FILE_EXTENSIONS = getattr(django_settings, 'WIKI_ATTACHMENTS_EXTENSIONS', ['pdf', 'doc', 'odt', 'docx', 'txt']) -from django.core.files.storage import default_storage -STORAGE_BACKEND = getattr(django_settings, 'WIKI_STORAGE_BACKEND', default_storage) +# Storage backend to use, default is to use the same as the rest of the +# wiki, which is set in WIKI_STORAGE_BACKEND, but you can override it +# with WIKI_ATTACHMENTS_STORAGE_BACKEND +STORAGE_BACKEND = getattr(django_settings, 'WIKI_ATTACHMENTS_STORAGE_BACKEND', wiki_settings.STORAGE_BACKEND) # SAFETY FIRST! Only store files with an appended .upload extension to be sure # that something nasty does not get executed on the server. diff --git a/wiki/plugins/images/settings.py b/wiki/plugins/images/settings.py index 8069f2fd..91485d27 100644 --- a/wiki/plugins/images/settings.py +++ b/wiki/plugins/images/settings.py @@ -1,19 +1,23 @@ from django.conf import settings as django_settings +from wiki.conf import settings as wiki_settings + +SLUG = 'images' +APP_LABEL = 'wiki' # Where to store images -IMAGE_PATH = getattr(django_settings, 'WIKI_IMAGE_PATH', "wiki/images/%aid/") +IMAGE_PATH = getattr(django_settings, 'WIKI_IMAGES_PATH', "wiki/images/%aid/") -from django.core.files.storage import default_storage -STORAGE_BACKEND = getattr(django_settings, 'WIKI_STORAGE_BACKEND', default_storage) +# Storage backend to use, default is to use the same as the rest of the +# wiki, which is set in WIKI_STORAGE_BACKEND, but you can override it +# with WIKI_IMAGES_STORAGE_BACKEND +STORAGE_BACKEND = getattr(django_settings, 'WIKI_IMAGES_STORAGE_BACKEND', wiki_settings.STORAGE_BACKEND) # Should the upload path be obscurified? If so, a random hash will be added to the path # such that someone can not guess the location of files (if you have # restricted permissions and the files are still located within the web server's -IMAGE_PATH_OBSCURIFY = getattr(django_settings, 'WIKI_IMAGE_PATH_OBSCURIFY', True) - -# Allow anonymous users to upload (not nice on an open network) -ANONYMOUS = getattr(django_settings, 'WIKI_ATTACHMENTS_ANONYMOUS', False) - -SLUG = 'images' +IMAGE_PATH_OBSCURIFY = getattr(django_settings, 'WIKI_IMAGES_PATH_OBSCURIFY', True) -APP_LABEL = 'wiki' \ No newline at end of file +# Allow anonymous users upload access (not nice on an open network) +# WIKI_IMAGES_ANONYMOUS can override this, otherwise the default +# in wiki.conf.settings is used. +ANONYMOUS = getattr( django_settings, 'WIKI_IMAGES_ANONYMOUS', wiki_settings.ANONYMOUS_UPLOAD ) \ No newline at end of file -- 2.45.2