Skip to content

Commit a2696c4

Browse files
andrepapotivictor-accarini
authored andcommitted
forms: update MuliplePatchForm to acocmodate for the new 'planning_to_review' field
Signed-off-by: andrepapoti <[email protected]>
1 parent 7a5f625 commit a2696c4

File tree

4 files changed

+42
-6
lines changed

4 files changed

+42
-6
lines changed

patchwork/api/patch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ def has_object_permission(self, request, view, obj):
428428
if 'planning_to_review' in data:
429429
for review_data in data:
430430
user_id = review_data['user']
431-
if request.user.id == reviewing_user:
431+
if request.user.id == user_id:
432432
return True
433433
detail = "Only the user can declare it's own intention to reviewing a patch"
434434
raise PermissionDenied(detail=detail)

patchwork/forms.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ class MultiplePatchForm(forms.Form):
216216
label='Archived',
217217
)
218218

219-
def __init__(self, project, *args, **kwargs):
219+
def __init__(self, project, user=None, *args, **kwargs):
220220
super(MultiplePatchForm, self).__init__(*args, **kwargs)
221221
self.fields['delegate'] = OptionalModelChoiceField(
222222
queryset=_get_delegate_qs(project=project),
@@ -231,6 +231,20 @@ def __init__(self, project, *args, **kwargs):
231231
className='change-property-state',
232232
label='Change state',
233233
)
234+
self.user = user
235+
if self.user:
236+
self.fields['review_status'] = OptionalBooleanField(
237+
className='archive-patch-select',
238+
choices=[
239+
('*', 'no change'),
240+
('True', 'Planning to review'),
241+
('False', 'Not planning to review'),
242+
],
243+
coerce=lambda x: x == 'True',
244+
empty_value='*',
245+
required=False,
246+
initial='*',
247+
)
234248

235249
def save(self, instance, commit=True):
236250
opts = instance.__class__._meta
@@ -252,8 +266,27 @@ def save(self, instance, commit=True):
252266
if field.is_no_change(data[f.name]):
253267
continue
254268

269+
if f.name == 'review_status':
270+
if data[f.name]:
271+
self.instance.planning_to_review.add(self.user)
272+
else:
273+
self.instance.planning_to_review.remove(self.user)
274+
continue
275+
255276
setattr(instance, f.name, data[f.name])
256277

257278
if commit:
258279
instance.save()
259280
return instance
281+
282+
def review_status_only(self):
283+
review_status_only = True
284+
field_names = set(self.fields.keys())
285+
field_names.discard({'review_status', 'action'})
286+
287+
for field_name in field_names:
288+
data = self.data.get(field_name, '*')
289+
if data != '*':
290+
review_status_only = False
291+
292+
return review_status_only

patchwork/models.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ def save(self, *args, **kwargs):
582582

583583
self.refresh_tag_counts()
584584

585-
def is_editable(self, user):
585+
def is_editable(self, user, declare_interest_only=False):
586586
if not user.is_authenticated:
587587
return False
588588

@@ -593,7 +593,8 @@ def is_editable(self, user):
593593
if self.project.is_editable(user):
594594
self._edited_by = user
595595
return True
596-
return False
596+
597+
return declare_interest_only
597598

598599
@staticmethod
599600
def filter_unique_checks(checks):

patchwork/views/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,9 @@ def generic_list(
242242
if data and data.get('form', '') == 'patch-list-form':
243243
data_tmp = data
244244

245-
properties_form = MultiplePatchForm(project, data=data_tmp)
245+
properties_form = MultiplePatchForm(
246+
project, data=data_tmp, user=request.user
247+
)
246248
create_bundle_form = CreateBundleForm()
247249

248250
if request.method == 'POST' and data.get('form') == 'patch-list-form':
@@ -344,7 +346,7 @@ def process_multiplepatch_form(request, form, action, patches, context):
344346

345347
changed_patches = 0
346348
for patch in patches:
347-
if not patch.is_editable(request.user):
349+
if not patch.is_editable(request.user, form.review_status_only()):
348350
errors.append(
349351
"You don't have permissions to edit patch '%s'" % patch.name
350352
)

0 commit comments

Comments
 (0)