Ticket #29930: 29930.diff

File 29930.diff, 3.6 KB (added by Tim Graham, 5 years ago)
  • django/contrib/admin/options.py

    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):  
    15561556                new_object = self.save_form(request, form, change=not add)
    15571557            else:
    15581558                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)
    15601567            if all_valid(formsets) and form_validated:
    15611568                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)
    15631571                change_message = self.construct_change_message(request, form, formsets, add)
    15641572                if add:
    15651573                    self.log_addition(request, new_object, change_message)
  • docs/releases/2.1.4.txt

    diff --git a/docs/releases/2.1.4.txt b/docs/releases/2.1.4.txt
    index 82378b16a0..0f0430e31a 100644
    a b Bugfixes  
    1616* Prevented repetitive calls to ``geos_version_tuple()`` in the ``WKBWriter``
    1717  class in an attempt to fix a random crash involving ``LooseVersion``
    1818  (: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`).
  • tests/admin_views/tests.py

    diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py
    index c7ccf55fa0..e7dbad85ee 100644
    a b class AdminViewPermissionsTest(TestCase):  
    19121912        new_article = Article.objects.latest('id')
    19131913        self.assertRedirects(post, reverse('admin:admin_views_article_change', args=(new_article.pk,)))
    19141914
     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
    19151931    def test_delete_view(self):
    19161932        """Delete view should restrict access and actually delete items."""
    19171933        delete_dict = {'post': 'yes'}
Back to Top