Skip to content
This repository was archived by the owner on Nov 29, 2023. It is now read-only.

Commit a548bd5

Browse files
authored
Merge pull request django-ckeditor#178 from sbussetti/master
Allow uploads to be prefixed by any adhoc property on the user, not just the username
2 parents 2c846fb + 3f8aab1 commit a548bd5

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ Optional for file upload
161161
~~~~~~~~~~~~~~~~~~~~~~~~
162162
#. All uploaded files are slugified by default. To disable this feature, set ``CKEDITOR_UPLOAD_SLUGIFY_FILENAME`` to ``False``.
163163

164-
#. Set the ``CKEDITOR_RESTRICT_BY_USER`` setting to ``True`` in the project's ``settings.py`` file (default ``False``). This restricts access to uploaded images to the uploading user (e.g. each user only sees and uploads their own images). Superusers can still see all images. **NOTE**: This restriction is only enforced within the CKEditor media browser.
164+
#. Set the ``CKEDITOR_RESTRICT_BY_USER`` setting to ``True`` in the project's ``settings.py`` file (default ``False``). This restricts access to uploaded images to the uploading user (e.g. each user only sees and uploads their own images). Upload paths are prefixed by the string returned by ``get_username``. If ``CKEDITOR_RESTRICT_BY_USER`` is set to a string, the named property is used instead. Superusers can still see all images. **NOTE**: This restriction is only enforced within the CKEditor media browser.
165165

166166
#. Set the ``CKEDITOR_BROWSE_SHOW_DIRS`` setting to ``True`` to show directories on the "Browse Server" page. This enables image grouping by directory they are stored in, sorted by date.
167167

ckeditor_uploader/views.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,17 @@ def get_upload_filename(upload_name, user):
2222
user_path = ''
2323

2424
# If CKEDITOR_RESTRICT_BY_USER is True upload file to user specific path.
25-
if getattr(settings, 'CKEDITOR_RESTRICT_BY_USER', False):
26-
user_path = user.get_username()
25+
RESTRICT_BY_USER = getattr(settings, 'CKEDITOR_RESTRICT_BY_USER', False)
26+
if RESTRICT_BY_USER:
27+
try:
28+
user_prop = getattr(user, RESTRICT_BY_USER)
29+
except AttributeError:
30+
user_prop = getattr(user, 'get_username')
31+
32+
if callable(user_prop):
33+
user_path = user_prop()
34+
else:
35+
user_path = user_prop
2736

2837
# Generate date based path to put uploaded file.
2938
# If CKEDITOR_RESTRICT_BY_DATE is True upload file to date specific path.

0 commit comments

Comments
 (0)