@@ -20,6 +20,7 @@
from django.test import TestCase
from django.core.urlresolvers import reverse
from patchwork.models import Patch, Person, State
+from patchwork.tests.factory import factory
from patchwork.tests.utils import defaults, create_maintainer
class MultipleUpdateTest(TestCase):
@@ -116,3 +117,38 @@ class MultipleUpdateTest(TestCase):
response = self._testDelegateChange('')
for p in self.patches:
self.assertEquals(Patch.objects.get(pk = p.pk).delegate, None)
+
+ def testFormShownWhenUserHasEditRightsOnPatches(self):
+ project = factory.makeProject()
+ user_person = Person.objects.get(user = self.user)
+ patch1 = factory.makePatch(project = project, submitter = user_person)
+ patch2 = factory.makePatch(project = project, submitter = user_person)
+
+ # Our user has edit rights on both patches, but not on the project.
+ self.assertTrue(patch1.is_editable(self.user))
+ self.assertTrue(patch2.is_editable(self.user))
+ self.assertFalse(project.is_editable(self.user))
+
+ # Even though our user has no edit rights on the project, they can
+ # edit all patches in the list, so the form is shown.
+ url = reverse('patchwork.views.patch.list', args = [project.linkname])
+ response = self.client.get(url)
+ self.assertContains(response, self.properties_form_id,
+ status_code = 200)
+
+ def testFormNotShownWhenUserHasNoEditRightsOnPatches(self):
+ project = factory.makeProject()
+ user_person = Person.objects.get(user = self.user)
+ patch1 = factory.makePatch(project = project, submitter = user_person)
+ patch2 = factory.makePatch(project = project)
+
+ # Here our user has edit rights on only one patch.
+ self.assertTrue(patch1.is_editable(self.user))
+ self.assertFalse(patch2.is_editable(self.user))
+ self.assertFalse(project.is_editable(self.user))
+
+ # Since the user can't edit one of the patches, the form is not shown.
+ url = reverse('patchwork.views.patch.list', args = [project.linkname])
+ response = self.client.get(url)
+ self.assertNotContains(response, self.properties_form_id,
+ status_code = 200)
@@ -42,9 +42,7 @@ def generic_list(request, project, view,
if request.method == 'POST':
data = request.POST
user = request.user
- properties_form = None
- if project.is_editable(user):
- properties_form = MultiplePatchForm(project, data = data)
+ properties_form = MultiplePatchForm(project, data = data)
if request.method == 'POST' and data.get('form') == 'patchlistform':
action = data.get('action', '').lower()
@@ -59,7 +57,7 @@ def generic_list(request, project, view,
if action in bundle_actions:
errors = set_bundle(user, project, action, data, ps, context)
- elif properties_form and action == properties_form.action:
+ elif action == properties_form.action:
errors = process_multiplepatch_form(properties_form, user,
action, ps, context)
else:
@@ -84,6 +82,9 @@ def generic_list(request, project, view,
patches = patches.order_by(order.query())
paginator = Paginator(request, patches)
+ for patch in paginator.current_page.object_list:
+ if not patch.is_editable(user):
+ properties_form = None
context.update({
'page': paginator.current_page,
We used to show that form only when the user is a maintainer of the project to which the patches in the list apply, but now the user just need to have edit rights on all patches to see the form, which makes sense and as a bonus will make it possible to do bulk changes on the bundle view. Signed-off-by: Guilherme Salgado <guilherme.salgado@linaro.org> --- apps/patchwork/tests/updates.py | 36 ++++++++++++++++++++++++++++++++++++ apps/patchwork/views/__init__.py | 9 +++++---- 2 files changed, 41 insertions(+), 4 deletions(-)