commit ab16e7d805eb209e65711c723a7af9d960be1eb8
Author: Tim Graham <timograham@gmail.com>
Date: Fri Nov 16 15:30:24 2018 -0500
Fixed #29930 -- Allowed editing in admin with view-only inlines.
diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
index 3a228516cc..0b420bb3a3 100644
a
|
b
|
class ModelAdmin(BaseModelAdmin):
|
1556 | 1556 | new_object = self.save_form(request, form, change=not add) |
1557 | 1557 | else: |
1558 | 1558 | new_object = form.instance |
1559 | | formsets, inline_instances = self._create_formsets(request, new_object, change=not add) |
| 1559 | formsets_, inline_instances_ = self._create_formsets(request, new_object, change=not add) |
| 1560 | formsets, inline_instances = [], [] |
| 1561 | for inline, instance in zip(formsets_, inline_instances_): |
| 1562 | if (inline._has_add_permission(request, new_object) or |
| 1563 | inline.has_change_permission(request, new_object) or |
| 1564 | inline.has_delete_permission(request, new_object)): |
| 1565 | formsets.append(inline) |
| 1566 | inline_instances.append(instance) |
1560 | 1567 | if all_valid(formsets) and form_validated: |
1561 | 1568 | self.save_model(request, new_object, form, not add) |
1562 | | self.save_related(request, form, formsets, not add) |
| 1569 | if False: |
| 1570 | self.save_related(request, form, formsets, not add) |
1563 | 1571 | change_message = self.construct_change_message(request, form, formsets, add) |
1564 | 1572 | if add: |
1565 | 1573 | self.log_addition(request, new_object, change_message) |
diff --git a/docs/releases/2.1.4.txt b/docs/releases/2.1.4.txt
index 82378b16a0..0f0430e31a 100644
a
|
b
|
Bugfixes
|
16 | 16 | * Prevented repetitive calls to ``geos_version_tuple()`` in the ``WKBWriter`` |
17 | 17 | class in an attempt to fix a random crash involving ``LooseVersion`` |
18 | 18 | (:ticket:`29959`). |
| 19 | |
| 20 | * Fixed "Please correct the errors below" error message when editing an object |
| 21 | in the admin if the user only has the "view" permission on inlines |
| 22 | (:ticket:`29930`). |
diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py
index c7ccf55fa0..e7dbad85ee 100644
a
|
b
|
class AdminViewPermissionsTest(TestCase):
|
1912 | 1912 | new_article = Article.objects.latest('id') |
1913 | 1913 | self.assertRedirects(post, reverse('admin:admin_views_article_change', args=(new_article.pk,))) |
1914 | 1914 | |
| 1915 | def test_change_view_with_view_only_inlines(self): |
| 1916 | """ |
| 1917 | User with change permission to a section but view-only for inlines. |
| 1918 | """ |
| 1919 | self.viewuser.user_permissions.add(get_perm(Section, get_permission_codename('change', Section._meta))) |
| 1920 | self.client.force_login(self.viewuser) |
| 1921 | data = { |
| 1922 | 'name': 'Can edit name with view-only inlines', |
| 1923 | 'article_set-TOTAL_FORMS': 3, |
| 1924 | 'article_set-INITIAL_FORMS': 3, |
| 1925 | } |
| 1926 | response = self.client.post(reverse('admin:admin_views_section_change', args=(self.s1.pk,)), data) |
| 1927 | # print(response.content.replace(b'\\n', b'\n')) |
| 1928 | self.assertRedirects(response, reverse('admin:admin_views_section_changelist')) |
| 1929 | self.assertEqual(Section.objects.get(pk=self.s1.pk).name, data['name']) |
| 1930 | |
1915 | 1931 | def test_delete_view(self): |
1916 | 1932 | """Delete view should restrict access and actually delete items.""" |
1917 | 1933 | delete_dict = {'post': 'yes'} |