Skip to content

Commit 9400ff7

Browse files
authored
Refactor folder permissions (#1264)
* fix code style according to Django’s style guide * fix code style according to Django’s style guide * separate Permission in where, who and what * fix FolderPermissions: Unable to read child folders. * simplify code for better readability * Update German translation strings * fix steps to build documentation * changes for version 2.1.3 * Add more changes to the log. * replace test for deprecated quoted_logical_path against pretty_logical_path * fix failing unit tests * adopt __init__ to GH actions * drop support for Python-3.6 * fix isort complains * fix failing unit tests * fix isort complains * increase test coverage * increase test coverage * fix annotation #1264 (comment) * fix annotation #1264 (comment) * exclude some version combinations * readd Python-3.10 with Django-3.2 * add missing requirements * force testing * install lxml only for Python-3.10 * fix yaml syntax * swap dependencies with e.d. * apt-get install extra development libraries Co-authored-by: Jacob Rief <jacob.rief@uibk.ac.at>
1 parent 7a0584b commit 9400ff7

File tree

14 files changed

+413
-264
lines changed

14 files changed

+413
-264
lines changed

.github/workflows/test.yml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,22 @@ jobs:
88
strategy:
99
fail-fast: false
1010
matrix:
11-
python-version: [ 3.6, 3.7, 3.8, 3.9 ]
11+
python-version: [ '3.7', '3.8', '3.9', '3.10' ]
1212
requirements-file: [
1313
django-2.2.txt,
1414
django-3.0.txt,
1515
django-3.1.txt,
1616
django-3.2.txt
1717
]
18+
exclude:
19+
- python-version: 3.9
20+
requirements-file: django-2.2.txt
21+
- python-version: 3.10
22+
requirements-file: django-2.2.txt
23+
- python-version: 3.10
24+
requirements-file: django-3.0.txt
25+
- python-version: 3.10
26+
requirements-file: django-3.1.txt
1827
os: [
1928
ubuntu-20.04,
2029
]
@@ -25,12 +34,16 @@ jobs:
2534
uses: actions/setup-python@v2
2635
with:
2736
python-version: ${{ matrix.python-version }}
37+
- name: library prerequisites
38+
run: sudo apt-get install python-dev libpq-dev libmagic1 gcc libxml2-dev libxslt1-dev libjpeg62 libopenjp2-7 -y
39+
- name: Install extra dependencies
40+
run: pip install lxml
41+
if: matrix.python-version == '3.10'
2842
- name: Install dependencies
2943
run: |
3044
python -m pip install --upgrade pip
3145
pip install -r tests/requirements/${{ matrix.requirements-file }}
3246
python setup.py install
33-
3447
- name: Run coverage
3548
run: coverage run setup.py test
3649

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
.settings/
1414
.tox/
1515
__pycache__/
16-
build/
16+
docs/_build/
1717
dist/
1818
env/
1919
.venv/

CHANGELOG.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22
CHANGELOG
33
=========
44

5+
2.1.3 (next)
6+
============
7+
8+
* Improve the list view of Folder permissions.
9+
* Fix: Folder permissions were disabled for descendants, if parent folder
10+
has type set to CHILDREN.
11+
* The input field for Folder changes from a standard HTML select element to
12+
a very wide autocomplete field, showing the complete path in Filer.
13+
514

615
2.1.2 (2021-11-09)
716
==================

docs/conf.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,6 @@
5757
# The full version, including alpha/beta/rc tags.
5858
release = __version__
5959

60-
for c in ('a', 'b', 'dev', 'r'):
61-
if c in release:
62-
tags.add('develop')
63-
break
64-
6560
# The language for content autogenerated by Sphinx. Refer to documentation
6661
# for a list of supported languages.
6762
#language = None

filer/__init__.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@
77
3. git add filer/__init__.py CHANGELOG.rst
88
4. git commit -m 'Bump to {new version}'
99
5. git push
10-
6. Assure that all tests pass on https://travis-ci.org/github/divio/django-filer.
10+
6. Assure that all tests pass on https://github.com/django-cms/django-filer/actions
1111
7. git tag {new version}
1212
8. git push --tags
13-
9. python setup.py sdist
14-
10. twine upload dist/django-filer-{new version}.tar.gz
13+
9. Check that new version is published on PyPI
1514
"""
1615

17-
__version__ = '2.1.2'
16+
__version__ = '2.2dev1'
1817

1918
default_app_config = 'filer.apps.FilerConfig'

filer/admin/folderadmin.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,18 +319,18 @@ def directory_listing(self, request, folder_id=None, viewtype=None):
319319
virtual_items = []
320320

321321
perms = FolderPermission.objects.get_read_id_list(request.user)
322-
root_exclude_kw = {'parent__isnull': False, 'parent__id__in': perms}
323322
if perms != 'All':
324323
file_qs = file_qs.filter(
325324
models.Q(folder__id__in=perms)
326325
| models.Q(folder_id__isnull=True)
327326
| models.Q(owner=request.user)
328327
)
329328
folder_qs = folder_qs.filter(models.Q(id__in=perms) | models.Q(owner=request.user))
329+
root_exclude_kwargs = {'parent__isnull': False, 'parent__id__in': perms}
330330
else:
331-
root_exclude_kw.pop('parent__id__in')
331+
root_exclude_kwargs = {'parent__isnull': False}
332332
if folder.is_root:
333-
folder_qs = folder_qs.exclude(**root_exclude_kw)
333+
folder_qs = folder_qs.exclude(**root_exclude_kwargs)
334334

335335
folder_children += folder_qs
336336
folder_files += file_qs

filer/admin/permissionadmin.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
from django.contrib import admin
2+
from django.utils.translation import gettext_lazy as _
23

34
from .. import settings
45

56

67
class PermissionAdmin(admin.ModelAdmin):
78
fieldsets = [
89
(None, {'fields': ['type', 'folder']}),
9-
(None, {'fields': ['user', 'group', 'everybody']}),
10-
(None, {'fields': ['can_edit', 'can_read', 'can_add_children']}),
10+
(_("Who"), {'fields': ['user', 'group', 'everybody']}),
11+
(_("What"), {'fields': ['can_edit', 'can_read', 'can_add_children']}),
1112
]
12-
raw_id_fields = ['user', 'group']
1313
list_filter = ['group']
14-
list_display = ['__str__', 'folder', 'user']
14+
list_display = ['pretty_logical_path', 'who', 'what']
1515
search_fields = ['user__username', 'group__name', 'folder__name']
16-
autocomplete_fields = ['user', 'group']
16+
autocomplete_fields = ['user', 'group', 'folder']
17+
18+
class Media:
19+
css = {'all': ['filer/css/admin_folderpermissions.css']}
1720

1821
def get_queryset(self, request):
1922
qs = super(PermissionAdmin, self).get_queryset(request)
280 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)